diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml new file mode 100644 index 0000000..f884a29 --- /dev/null +++ b/.github/workflows/pypi-publish.yml @@ -0,0 +1,50 @@ +name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI + +on: push + +jobs: + build: + name: Build distribution 📦 + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + - name: Install pypa/build + run: | + python -m pip install --upgrade pip + pip install setuptools wheel + - name: Build a binary wheel and a source tarball + run: | + cd src + python setup.py -k rel sdist bdist_wheel + - name: Store the distribution packages + uses: actions/upload-artifact@v3 + with: + name: python-package-distributions + path: src/dist/ + + publish-to-pypi: + name: >- + Publish Python 🐍 distribution 📦 to PyPI + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes + needs: + - build + runs-on: ubuntu-latest + environment: + name: release + url: https://pypi.org/p/yatter # Replace with your PyPI project name + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file diff --git a/.github/workflows/python-publish-rel.yml b/.github/workflows/python-publish-rel.yml deleted file mode 100644 index efe15ff..0000000 --- a/.github/workflows/python-publish-rel.yml +++ /dev/null @@ -1,32 +0,0 @@ -# This workflows will upload a Python Package using Twine when a release is created -# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries - -name: Upload Python Package - -on: - release: - types: [created] - -jobs: - deploy: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - cd src - python setup.py -k rel sdist bdist_wheel - twine upload dist/* diff --git a/.github/workflows/testgha.yml b/.github/workflows/testgha.yml index 6524389..cc67652 100644 --- a/.github/workflows/testgha.yml +++ b/.github/workflows/testgha.yml @@ -20,7 +20,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel twine pytest DeepDiff + pip install setuptools wheel pytest DeepDiff pip install -r requirements.txt - name: Build yatter run: | diff --git a/VERSION b/VERSION index 9084fa2..65087b4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.0 +1.1.4 diff --git a/src/setup.py b/src/setup.py index b6be05c..77c3c9d 100644 --- a/src/setup.py +++ b/src/setup.py @@ -26,15 +26,15 @@ name="yatter", version=vers_taged, author="David Chaves-Fraga", - author_email="david.chaves@upm.es", + author_email="david.chaves@usc.es", license="Apache 2.0", description="A translator from YARRRML to RML mappings.", long_description=long_description, long_description_content_type="text/markdown", - url="https://github.com/oeg-upm/yarrrml-translator", + url="https://github.com/oeg-upm/yatter", project_urls={ - 'Source code': 'https://github.com/oeg-upm/yarrrml-translator', - 'Issue tracker': 'https://github.com/oeg-upm/yarrrml-translator/issues', + 'Source code': 'https://github.com/oeg-upm/yatter', + 'Issue tracker': 'https://github.com/oeg-upm/yatter/issues', }, include_package_data=True, packages=setuptools.find_packages(), diff --git a/src/yatter/__init__.py b/src/yatter/__init__.py index 6e4a89f..f586a89 100644 --- a/src/yatter/__init__.py +++ b/src/yatter/__init__.py @@ -69,7 +69,7 @@ def inverse_translation(rdf_mapping, mapping_format=RML_URI): triples_map = [tm[rdflib.Variable('triplesMap')] for tm in rdf_mapping.query(query).bindings] for tm in triples_map: - tm_name = tm.split("/")[-1] + tm_name = tm.split("/")[-1].split("#")[-1] yarrrml_tm = {YARRRML_SOURCES: [add_inverse_source(tm, rdf_mapping, mapping_format)]} subject, classes = add_inverse_subject(tm, rdf_mapping) yarrrml_tm.update(subject) diff --git a/src/yatter/__main__.py b/src/yatter/__main__.py index e1d8e5f..4b71d8c 100644 --- a/src/yatter/__main__.py +++ b/src/yatter/__main__.py @@ -14,6 +14,7 @@ def write_results(mapping): elif type(mapping) is dict: with open(args.output_mapping_path, "wb") as f: yaml = YAML() + yaml.width = 3000 yaml.default_flow_style = False yaml.dump(mapping, f) diff --git a/src/yatter/constants.py b/src/yatter/constants.py index df7387a..c5aad0a 100644 --- a/src/yatter/constants.py +++ b/src/yatter/constants.py @@ -81,6 +81,7 @@ R2RML_TERMTYPE = 'rr:termType' R2RML_LANGUAGE = 'rr:language' R2RML_IRI = 'rr:IRI' +R2RML_BLANK_NODE = 'rr:BlankNode' R2RML_LITERAL = 'rr:Literal' R2RML_REFOBJECT_CLASS = 'rr:RefObjectMap' R2RML_PARENT_TRIPLESMAP = 'rr:parentTriplesMap' @@ -92,6 +93,7 @@ R2RML_TABLE_NAME = 'rr:tableName' R2RML_COLUMN = 'rr:column' + ############################################################################## ############################# D2RQ CONSTANTS ########################### ############################################################################## @@ -154,6 +156,7 @@ YARRRML_IRI = '~iri' YARRRML_LANG = '~lang' +YARRRML_BLANK = 'blank' YARRRML_QUOTED = 'quoted' YARRRML_NON_ASSERTED = 'quotedNonAsserted' @@ -212,7 +215,8 @@ 'json': 'JSONPath', 'xpath': 'XPath', 'jsonpath': 'JSONPath', - "shp": "SHP" + "shp": "SHP", + "xlsx": "CSV" } YARRRML_DATABASES_DRIVER = { diff --git a/src/yatter/function.py b/src/yatter/function.py index b3628fd..26f0b4e 100644 --- a/src/yatter/function.py +++ b/src/yatter/function.py @@ -43,7 +43,7 @@ def add_internal_function(mapping_id, mapping_data, functions): def transform_function(mapping_id, function_value, functions): global local_id function_return = None - if YARRRML_JOIN in function_value[YARRRML_FUNCTION]: + if function_value[YARRRML_FUNCTION].replace(" ","").startswith(YARRRML_JOIN+"("): function_return = generate_extended_join(function_value[YARRRML_FUNCTION]) elif function_value[YARRRML_FUNCTION] != YARRRML_EQUAL: function_id = "function_" + mapping_id diff --git a/src/yatter/mapping.py b/src/yatter/mapping.py index 1edb0a9..4a0fa71 100644 --- a/src/yatter/mapping.py +++ b/src/yatter/mapping.py @@ -1,7 +1,6 @@ from .import * prefixes = {} - def add_mapping(mapping, mappings, it): map_template = "<" + mapping + "_" + str(it) + "> a " if mappings[mapping]: @@ -99,7 +98,7 @@ def add_inverse_prefix(rdf_mapping): def get_non_asserted_mappings(yarrrml_data, mapping_format): - mappings = dict.fromkeys(list(yarrrml_data.get(YARRRML_MAPPINGS).keys())) + mappings = dict.fromkeys(list(yarrrml_data.get(YARRRML_MAPPINGS).keys())) for mapping in yarrrml_data.get(YARRRML_MAPPINGS): keys = yarrrml_data.get(YARRRML_MAPPINGS).get(mapping).keys() for key in keys: diff --git a/src/yatter/predicateobject.py b/src/yatter/predicateobject.py index 3c6b4a4..7ddb90f 100644 --- a/src/yatter/predicateobject.py +++ b/src/yatter/predicateobject.py @@ -154,17 +154,21 @@ def add_predicate_object(data, mapping, predicate_object, mapping_format=RML_URI execution = True template += generate_rml_termmap(R2RML_PREDICATE, R2RML_PREDICATE_CLASS, pm_value, "\t\t\t") if execution: - template = template.replace(R2RML_CONSTANT + " " + pm_value, RML_EXECUTION + " <" + pm_value + ">") + template = template.replace(R2RML_CONSTANT + " \"" + pm_value + "\"", RML_EXECUTION + " <" + pm_value + ">") if YARRRML_TARGETS in pm: template = template[0:-3] + "\t" + RML_LOGICAL_TARGET + " <" + pm[YARRRML_TARGETS] + ">\n\t\t];\n" for om in object_list: iri = False + blank = False if type(om) == list: object_value = om[0] if YARRRML_IRI in om[0]: - object_value = om[0].split(YARRRML_IRI)[0] + object_value = om[0].split("~")[0] iri = True + if YARRRML_BLANK in om[0]: + object_value = om[0].split("~")[0] + blank = True if mapping_format == STAR_URI: template += generate_rml_termmap(STAR_OBJECT, R2RML_OBJECT_CLASS, object_value, "\t\t\t", mapping_format) @@ -172,9 +176,6 @@ def add_predicate_object(data, mapping, predicate_object, mapping_format=RML_URI object_map = generate_rml_termmap(R2RML_OBJECT, R2RML_OBJECT_CLASS, object_value, "\t\t\t", mapping_format) - if object_value not in prefixes and ":" not in object_value and R2RML_CONSTANT in object_map: - object_map = object_map.replace(object_value, f"\"{object_value}\"") - template += object_map if len(om) == 2: types = check_type(om[1]) @@ -204,6 +205,9 @@ def add_predicate_object(data, mapping, predicate_object, mapping_format=RML_URI if iri: template = template[0:len(template) - 5] + "\t\t\t" + R2RML_TERMTYPE + " " \ + R2RML_IRI + "\n\t\t];\n" + if blank: + template = template[0:len(template) - 5] + "\t\t\t" + R2RML_TERMTYPE + " " \ + + R2RML_BLANK_NODE + "\n\t\t];\n" elif YARRRML_MAPPING in om or YARRRML_NON_ASSERTED in om or YARRRML_QUOTED in om: if YARRRML_MAPPING in om: template += ref_mapping(data, mapping, om, YARRRML_MAPPING, R2RML_PARENT_TRIPLESMAP, mapping_format) @@ -226,10 +230,8 @@ def add_predicate_object(data, mapping, predicate_object, mapping_format=RML_URI template += generate_rml_termmap(STAR_OBJECT, R2RML_OBJECT_CLASS, object_value, "\t\t\t", mapping_format) elif YARRRML_FUNCTION in om: - template += generate_rml_termmap(R2RML_OBJECT, R2RML_OBJECT_CLASS, om[YARRRML_FUNCTION], "\t\t\t", - mapping_format) - template = template.replace(R2RML_CONSTANT + " " + om[YARRRML_FUNCTION], RML_EXECUTION + " <" + om.get( - YARRRML_FUNCTION) + ">") + template += generate_rml_termmap(R2RML_OBJECT, R2RML_OBJECT_CLASS, om[YARRRML_FUNCTION], "\t\t\t", mapping_format) + template = template.replace(R2RML_CONSTANT+" \""+om[YARRRML_FUNCTION]+ "\"", RML_EXECUTION + " <" + om.get(YARRRML_FUNCTION) + ">") else: template += generate_rml_termmap(R2RML_OBJECT, R2RML_OBJECT_CLASS, object_value, "\t\t\t", mapping_format) @@ -246,6 +248,9 @@ def add_predicate_object(data, mapping, predicate_object, mapping_format=RML_URI elif om.get(YARRRML_TYPE) == "literal": template = template[0:len(template) - 5] + "\t\t\t" + R2RML_TERMTYPE + " " \ + R2RML_LITERAL + "\n\t\t];\n" + elif om.get(YARRRML_TYPE) == YARRRML_BLANK: + template = template[0:len(template) - 5] + "\t\t\t" + R2RML_TERMTYPE + " " \ + + R2RML_BLANK_NODE + "\n\t\t];\n" if YARRRML_TARGETS in om: template = template[0:len(template) - 5] + "\t\t\t" + RML_LOGICAL_TARGET + " <" + om.get( YARRRML_TARGETS) + ">\n\t\t];\n" @@ -323,7 +328,7 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): yarrrml_poms = [] yaml = YAML() for c in classes: - yarrrml_pom = yaml.seq(['rdf:type', c.toPython()]) + yarrrml_pom = yaml.seq(['rdf:type', find_prefixes(c.toPython(),prefixes)]) yarrrml_pom.fa.set_flow_style() yarrrml_poms.append(yarrrml_pom) @@ -351,9 +356,11 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): f' ?object {RML_LANGUAGE_MAP} ?languageMap .' \ f' ?languageMap {R2RML_TEMPLATE}|{R2RML_CONSTANT}|{RML_REFERENCE} ?languageMapValue .}} }} ' \ f'OPTIONAL {{ ?object {R2RML_PARENT_TRIPLESMAP} ?parentTriplesMap .' \ - f'?object {R2RML_JOIN_CONITION} ?join_condition .' \ - f'?join_condition {R2RML_CHILD} ?child .' \ - f'?join_condition {R2RML_PARENT} ?parent }} }}' + f'OPTIONAL {{ '\ + f'?object {R2RML_JOIN_CONITION} ?join_condition .' \ + f'?join_condition {R2RML_CHILD} ?child .' \ + f'?join_condition {R2RML_PARENT} ?parent }} }}'\ + f'}}' for tm in rdf_mapping.query(query): yarrrml_pom = [] @@ -373,16 +380,22 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): elif prefix: predicate = tm['predicateValue'].toPython().replace(prefixes[prefix[0]], prefix[0] + ":") + predicate = find_prefixes(predicate,prefixes) + if tm['parentTriplesMap']: - yarrrml_pom = {'p': predicate, 'o': {'mapping': None, 'condition': - {'function': 'equal', 'parameters': []}}} - yarrrml_pom['o']['mapping'] = tm['parentTriplesMap'].split("/")[-1] - child = yaml.seq(['str1', '$(' + tm['child'] + ')']) - child.fa.set_flow_style() - parent = yaml.seq(['str2', '$(' + tm['parent'] + ')']) - parent.fa.set_flow_style() - yarrrml_pom['o']['condition']['parameters'].append(child) - yarrrml_pom['o']['condition']['parameters'].append(parent) + if tm['child']: + yarrrml_pom = {'p': predicate, 'o': {'mapping': None, 'condition': + {'function': 'equal', 'parameters': []}}} + yarrrml_pom['o']['mapping'] = tm['parentTriplesMap'].split("/")[-1] + child = yaml.seq(['str1', '$(' + tm['child'] + ')']) + child.fa.set_flow_style() + parent = yaml.seq(['str2', '$(' + tm['parent'] + ')']) + parent.fa.set_flow_style() + yarrrml_pom['o']['condition']['parameters'].append(child) + yarrrml_pom['o']['condition']['parameters'].append(parent) + else: + yarrrml_pom = {'p': predicate, 'o': {'mapping': tm['parentTriplesMap'].split("/")[-1]}} + else: datatype = None @@ -401,9 +414,7 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): if not object.startswith("http"): object = '$(' + object + ')' elif object.startswith("http") and "{" not in object: - prefix = list({i for i in prefixes if object.startswith(prefixes[i])}) - if prefix: - object = object.replace(prefixes[prefix[0]], prefix[0] + ":") + object = find_prefixes(object,prefixes) else: object = object.replace('{', '$(').replace('}', ')') @@ -441,11 +452,13 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): if type(yarrrml_pom) is list: if datatype: + datatype = find_prefixes(datatype,prefixes) yarrrml_pom.append(datatype) if language: yarrrml_pom.append(language) elif type(yarrrml_pom) is dict: if datatype: + datatype = find_prefixes(datatype, prefixes) yarrrml_pom[YARRRML_DATATYPE] = datatype if language: yarrrml_pom[YARRRML_LANGUAGE] = language @@ -456,3 +469,9 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): yarrrml_poms.append(yarrrml_pom) return yarrrml_poms + +def find_prefixes(text, prefixes): + prefix = list({i for i in prefixes if text.startswith(prefixes[i])}) + if len(prefix) > 0: + text = text.replace(prefixes[prefix[0]], prefix[0] + ":") + return text diff --git a/src/yatter/source.py b/src/yatter/source.py index d87f286..f5fb009 100644 --- a/src/yatter/source.py +++ b/src/yatter/source.py @@ -89,12 +89,12 @@ def add_source_simplified(mapping, source): source_extension = os.path.splitext(file_path)[1].replace(".","") ref_formulation_rml = YARRRML_REFERENCE_FORMULATIONS[reference_formulation] - if switch_in_reference_formulation(reference_formulation) != source_extension: + if switch_in_reference_formulation(reference_formulation, source_extension) != source_extension: raise Exception( "ERROR: mismatch extension and referenceFormulation in source " + source + " in mapping " + mapping) else: if len(source) == 1: # do not have iterator - if source_extension == "csv" or source_extension == "SQL2008": + if source_extension == "csv" or source_extension == "SQL2008" or source_extension == "xlsx": source_rdf += '"' + file_path + '"' + ";\n" + "\t\t" + RML_REFERENCE_FORMULATION + " ql:" \ + ref_formulation_rml + "\n" + "\t];\n" else: @@ -169,7 +169,7 @@ def database_source(mapping, source, db_identifier): return source_rdf -def switch_in_reference_formulation(value): +def switch_in_reference_formulation(value, source_extension=None): value = value.lower() if "json" in value: if "path" in value: @@ -181,6 +181,11 @@ def switch_in_reference_formulation(value): switcher = "xml" else: switcher = "xpath" + elif source_extension: + if source_extension == "xlsx": + switcher = "xlsx" + else: + switcher = value else: switcher = value return switcher @@ -277,7 +282,7 @@ def get_logical_source(logical_source_id, rdf_mapping): raise Exception() if source and reference_formulation and iterator: - yarrrml_source = [source.value + '~' + reference_formulation.toPython().replace(QL_URI, '').lower(), iterator.value] + yarrrml_source = [source.value + '~' + reference_formulation.toPython().replace(QL_URI, '').lower(), iterator.value] elif source and sql_query: # this means a database source source_dict = {"query": sql_query.value, "source": source.value} diff --git a/src/yatter/subject.py b/src/yatter/subject.py index cb92703..3b28037 100644 --- a/src/yatter/subject.py +++ b/src/yatter/subject.py @@ -48,12 +48,16 @@ def add_subject(data, mapping, mapping_format): subject_termmap = generate_rml_termmap(R2RML_SUBJECT, R2RML_SUBJECT_CLASS, subject_value, "\t\t", mapping_format) if YARRRML_FUNCTION in individual_subject: - subject_termmap = subject_termmap.replace(R2RML_CONSTANT+" "+subject_value, RML_EXECUTION + " <" + individual_subject.get( + subject_termmap = subject_termmap.replace(R2RML_CONSTANT+" \""+subject_value + "\"", RML_EXECUTION + " <" + individual_subject.get( YARRRML_FUNCTION) + ">") if YARRRML_TARGETS in individual_subject: subject_termmap = subject_termmap[0:-3]+"\t"+RML_LOGICAL_TARGET+" <"+individual_subject[YARRRML_TARGETS]+">\n\t];\n" + if YARRRML_TYPE in individual_subject: + if individual_subject.get(YARRRML_TYPE) == YARRRML_BLANK: + subject_termmap = subject_termmap[0:-3] + "\t" + R2RML_TERMTYPE + " " + R2RML_BLANK_NODE +"\n\t];\n" + rml_subjects.append(subject_termmap) if YARRRML_GRAPHS in data.get(YARRRML_MAPPINGS).get(mapping): diff --git a/src/yatter/termmap.py b/src/yatter/termmap.py index a522707..8693fe1 100644 --- a/src/yatter/termmap.py +++ b/src/yatter/termmap.py @@ -18,12 +18,17 @@ def get_termmap_type(text, mapping_format): ## Generates a TermMap (subject, predicate, object) based on the property, class and the text -def generate_rml_termmap(rml_property, rml_class, text, identation, mapping_format=RML_URI): - template = identation[0:-1] + rml_property + " [\n"+identation+"a " + rml_class + ";\n" + identation +def generate_rml_termmap(rml_property, rml_class, text, indentation, mapping_format=RML_URI): + from .mapping import prefixes + template = indentation[0:-1] + rml_property + " [\n" + indentation + "a " + rml_class + ";\n" + indentation term_map = get_termmap_type(text, mapping_format) if term_map == R2RML_TEMPLATE: text = generate_rml_template(text) text = text.replace('"', r'\"') + if ":" in text: + text_prefix_split = text.split(":") + if text_prefix_split[0] in prefixes: + text = prefixes[text_prefix_split[0]] + text_prefix_split[1] elif term_map == RML_REFERENCE or term_map == R2RML_COLUMN: text = text.replace("$(", "").replace(")", "") text = text.replace('"', r'\"') @@ -32,16 +37,19 @@ def generate_rml_termmap(rml_property, rml_class, text, identation, mapping_form if term_map == STAR_QUOTED: if 'quoted' in text: - template += term_map + " <" + text[YARRRML_QUOTED] + "_0>;\n" + identation[0:-1] + "];\n" + template += term_map + " <" + text[YARRRML_QUOTED] + "_0>;\n" + indentation[0:-1] + "];\n" else: - template += term_map + " <" + text[YARRRML_NON_ASSERTED] + "_0>;\n" + identation[0:-1] + "];\n" + template += term_map + " <" + text[YARRRML_NON_ASSERTED] + "_0>;\n" + indentation[0:-1] + "];\n" elif term_map != "rr:constant": - template += term_map + " \"" + text + "\";\n"+identation[0:-1]+"];\n" + template += term_map + " \"" + text + "\";\n"+indentation[0:-1]+"];\n" else: if text.startswith("http"): - template += term_map + " <" + text + ">;\n" + identation[0:-1] + "];\n" + template += term_map + " <" + text + ">;\n" + indentation[0:-1] + "];\n" else: - template += term_map + " " + text + ";\n"+identation[0:-1]+"];\n" + if ":" in text or "<" in text: + template += term_map + " " + text + ";\n"+indentation[0:-1]+"];\n" + else: + template += term_map + " \"" + text + "\";\n" + indentation[0:-1] + "];\n" return template diff --git a/test/r2rml/YARRRMLTC-r2rml-0016/mapping.ttl b/test/r2rml/YARRRMLTC-r2rml-0016/mapping.ttl new file mode 100644 index 0000000..7c12163 --- /dev/null +++ b/test/r2rml/YARRRMLTC-r2rml-0016/mapping.ttl @@ -0,0 +1,57 @@ +@prefix foaf: . +@prefix rdfs: . +@prefix ex: . +@prefix rr: . +@prefix rml: . +@prefix rdf: . +@prefix xsd: . +@prefix ql: . +@prefix d2rq: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . +@base . + + + a rr:TriplesMap; + + rr:logicalTable [ + a rr:LogicalTable; + rr:tableName "Student"; + rr:sqlVersion rr:SQL2008 + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:column "Name"; + rr:termType rr:BlankNode + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant foaf:Person; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant ex:Student; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant foaf:Name; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:column "Name"; + rr:termType rr:BlankNode + ]; + ]. + + diff --git a/test/r2rml/YARRRMLTC-r2rml-0016/mapping.yml b/test/r2rml/YARRRMLTC-r2rml-0016/mapping.yml new file mode 100644 index 0000000..7f22a3a --- /dev/null +++ b/test/r2rml/YARRRMLTC-r2rml-0016/mapping.yml @@ -0,0 +1,19 @@ +prefixes: + foaf: http://xmlns.com/foaf/0.1/ + rdfs: http://www.w3.org/2000/01/rdf-schema# + ex: http://example.com/ + +mappings: + TriplesMap1: + sources: + - table: Student + s: + value: $(Name) + type: blank + po: + - p: rdf:type + o: [foaf:Person, ex:Student] + - p: foaf:Name + o: + value: $(Name) + type: blank \ No newline at end of file diff --git a/test/r2rml/YARRRMLTC-r2rml-0016/test_yarrrmltc_r2rml_0016.py b/test/r2rml/YARRRMLTC-r2rml-0016/test_yarrrmltc_r2rml_0016.py new file mode 100644 index 0000000..9558f55 --- /dev/null +++ b/test/r2rml/YARRRMLTC-r2rml-0016/test_yarrrmltc_r2rml_0016.py @@ -0,0 +1,27 @@ +__author__ = "Marino Gonzalez Garcia" +__credits__ = ["Marino Gonzalez Garcia"] + +__license__ = "Apache-2.0" +__maintainer__ = "David Chaves-Fraga" +__email__ = "david.chaves@upm.es" + + +import os +from ruamel.yaml import YAML +import yatter +from rdflib.graph import Graph +from rdflib import compare +R2RML_URI = 'http://www.w3.org/ns/r2rml#' + + +def test_r2rml_yarrrmltc0016(): + expected_mapping = Graph() + expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + + translated_mapping = Graph() + yaml = YAML(typ='safe', pure=True) + mapping_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.yml') + translated_mapping.parse(data=yatter.translate(yaml.load(open(mapping_path)), mapping_format=R2RML_URI), format="ttl") + translated_mapping.serialize(destination="mapping.rml.ttl",format="ttl") + + assert compare.isomorphic(expected_mapping, translated_mapping) \ No newline at end of file diff --git a/test/rml-fnml/YARRRMLTC-0050b/mapping.ttl b/test/rml-fnml/YARRRMLTC-0050b/mapping.ttl new file mode 100644 index 0000000..17504bd --- /dev/null +++ b/test/rml-fnml/YARRRMLTC-0050b/mapping.ttl @@ -0,0 +1,76 @@ +@prefix ex: . +@prefix ontology: . +@prefix schema: . +@prefix idlab-fn: . +@prefix grel: . +@prefix owl: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix rr: . +@prefix rml: . +@prefix ql: . +@prefix d2rq: . +@prefix foaf: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@base . + + + a fnml:Execution; + fnml:function grel:string_split ; + fnml:input + [ + a fnml:Input; + fnml:parameter grel:p_string_sep; + fnml:valueMap [ + a fnml:ValueMap; + rr:constant ", "; + ]; + ], + [ + a fnml:Input; + fnml:parameter grel:valueParameter; + fnml:valueMap [ + a fnml:ValueMap; + rml:reference "directors"; + ]; + ]. + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "imdb_video_game_rating_modified.csv"; + rml:referenceFormulation ql:CSV; + + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "http://www.semanticweb.org/tijnd/Person/{title}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant schema:Person; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant schema:name; + ]; + rr:objectMap [ + a rr:ObjectMap; + fnml:execution ; + ]; + ]. + + diff --git a/test/rml-fnml/YARRRMLTC-0050b/mapping.yml b/test/rml-fnml/YARRRMLTC-0050b/mapping.yml new file mode 100644 index 0000000..95db5f6 --- /dev/null +++ b/test/rml-fnml/YARRRMLTC-0050b/mapping.yml @@ -0,0 +1,28 @@ +prefixes: + ex: "http://www.semanticweb.org/tijnd/" + ontology: "http://www.semanticweb.org/tijnd/ontology/" + schema: "https://schema.org/" + idlab-fn: "http://example.com/idlab/function/" + grel: "http://users.ugent.be/~bjdmeest/function/grel.ttl#" + owl: "http://www.w3.org/2002/07/owl#" + rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#" + rdfs: "http://www.w3.org/2000/01/rdf-schema#" + xsd: "http://www.w3.org/2001/XMLSchema#" +sources: + imdb: + access: imdb_video_game_rating_modified.csv + referenceFormulation: csv + +mappings: + director: + sources: + - imdb + s: ex:Person/$(title) #Not really the correct subject, only used to simply test it + po: + - [a, schema:Person] + - p: schema:name + o: + function: grel:string_split + parameters: + - [grel:p_string_sep, ", "] + - [grel:valueParameter, $(directors)] \ No newline at end of file diff --git a/test/rml-fnml/YARRRMLTC-0050b/test_yarrrmltc0050b.py b/test/rml-fnml/YARRRMLTC-0050b/test_yarrrmltc0050b.py new file mode 100644 index 0000000..903ecd5 --- /dev/null +++ b/test/rml-fnml/YARRRMLTC-0050b/test_yarrrmltc0050b.py @@ -0,0 +1,25 @@ +__author__ = "David Chaves-Fraga" +__credits__ = ["David Chaves-Fraga"] + +__license__ = "Apache-2.0" +__maintainer__ = "David Chaves-Fraga" +__email__ = "david.chaves@upm.es" + + +import os +from ruamel.yaml import YAML +import yatter +from rdflib.graph import Graph +from rdflib import compare + + +def test_yarrrmltc0050b(): + expected_mapping = Graph() + expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + + translated_mapping = Graph() + yaml = YAML(typ='safe', pure=True) + mapping_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.yml') + translated_mapping.parse(data=yatter.translate(yaml.load(open(mapping_path))), format="ttl") + + assert compare.isomorphic(expected_mapping, translated_mapping) \ No newline at end of file