From 529345980885bb76158242e7c8d7b09f3962da9c Mon Sep 17 00:00:00 2001 From: David Chaves Date: Fri, 5 May 2023 11:57:45 +0200 Subject: [PATCH 1/8] adding tec test from @dgarijo --- test/projects/TEC/mapping.ttl | 653 ++++++++++++++++++++++++++++++++++ test/projects/TEC/mapping.yml | 134 +++++++ test/projects/TEC/test_tec.py | 27 ++ 3 files changed, 814 insertions(+) create mode 100644 test/projects/TEC/mapping.ttl create mode 100644 test/projects/TEC/mapping.yml create mode 100644 test/projects/TEC/test_tec.py diff --git a/test/projects/TEC/mapping.ttl b/test/projects/TEC/mapping.ttl new file mode 100644 index 0000000..9b06272 --- /dev/null +++ b/test/projects/TEC/mapping.ttl @@ -0,0 +1,653 @@ +@prefix ecfo: . +@prefix qudt: . +@prefix skos: . +@prefix prov: . +@prefix time: . +@prefix schema: . +@prefix ecfo_instance: . +@prefix dc: . +@prefix rr: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix ql: . +@prefix d2rq: . +@prefix foaf: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . +@base . + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "./data/conversion_factors_2016_modified_v2.csv"; + rml:referenceFormulation ql:CSV + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "ecfo_instance:CF_{id}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant ecfo:EmissionConversionFactor; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant ecfo:hasAdditionalContext; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "Column Text"; + rr:language "en" + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant ecfo:hasScope; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "https://w3id.org/ecfo#{Scope}"; + rr:termType rr:IRI + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:value; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "GHG Conversion Factor 2016"; + rr:datatype xsd:float + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant ecfo:hasTag; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "https://w3id.org/ecfkg/i/{Level 1}"; + rr:termType rr:IRI + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant ecfo:hasTag; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "https://w3id.org/ecfkg/i/{Level 2}"; + rr:termType rr:IRI + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant ecfo:hasTag; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "https://w3id.org/ecfkg/i/{Level 3}"; + rr:termType rr:IRI + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant ecfo:hasTag; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "https://w3id.org/ecfkg/i/{Level 4}"; + rr:termType rr:IRI + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant ecfo:hasSourceUnit; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "uom_wd"; + rr:termType rr:IRI + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant ecfo:hasEmissionSource; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "https://w3id.org/ecfkg/i/{emission_source}"; + rr:termType rr:IRI + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant ecfo:hasTargetUnit; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "ghg_wd"; + rr:termType rr:IRI + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant ecfo:hasEmissionTarget; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "emission_target_wd"; + rr:termType rr:IRI + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant ecfo:hasApplicablePeriod; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "ecfo_instance:applicablePeriod/{valid_from}/{valid_to}"; + rr:termType rr:IRI + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant ecfo:hasApplicableLocation; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "region_wd"; + rr:termType rr:IRI + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant dc:publisher; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant ; + rr:termType rr:IRI + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant prov:wasDerivedFrom; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant ; + rr:datatype xsd:anyURI + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "./data/conversion_factors_2016_modified_v2.csv"; + rml:referenceFormulation ql:CSV + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:constant ; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant prov:Organization; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdfs:label; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant "BEIS"; + rr:language "en" + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdfs:seeAlso; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant ; + rr:datatype xsd:anyURI + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "./data/conversion_factors_2016_modified_v2.csv"; + rml:referenceFormulation ql:CSV + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "ecfo_instance:applicablePeriod/{valid_from}/{valid_to}/start"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant time:Instant; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant time:inXSDDate; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "valid_from"; + rr:datatype xsd:dateTime + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "./data/conversion_factors_2016_modified_v2.csv"; + rml:referenceFormulation ql:CSV + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "ecfo_instance:applicablePeriod/{valid_from}/{valid_to}/end"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant time:Instant; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant time:inXSDDate; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "valid_to"; + rr:datatype xsd:dateTime + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "./data/conversion_factors_2016_modified_v2.csv"; + rml:referenceFormulation ql:CSV + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "ecfo_instance:applicablePeriod/{valid_from}/{valid_to}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant time:TemporalEntity; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant time:hasBeginning; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "ecfo_instance:applicablePeriod/{valid_from}/{valid_to}/start"; + rr:termType rr:IRI + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant time:hasEnd; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "ecfo_instance:applicablePeriod/{valid_from}/{valid_to}/end"; + rr:termType rr:IRI + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "./data/conversion_factors_2016_modified_v2.csv"; + rml:referenceFormulation ql:CSV + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "https://w3id.org/ecfkg/i/{emission_source}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant skos:Concept; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdfs:label; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "emission_source"; + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "./data/conversion_factors_2016_modified_v2.csv"; + rml:referenceFormulation ql:CSV + ]; + rr:subjectMap [ + a rr:SubjectMap; + rml:reference "emission_target_wd"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant ecfo:ChemicalCompound; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdfs:label; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "emission_target"; + rr:language "en" + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant schema:molecularFormula; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "emission_target_formula"; + rr:language "en" + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "./data/conversion_factors_2016_modified_v2.csv"; + rml:referenceFormulation ql:CSV + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "https://w3id.org/ecfkg/i/{Level 1}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant skos:Concept; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdfs:label; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "Level 1"; + rr:language "en" + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "./data/conversion_factors_2016_modified_v2.csv"; + rml:referenceFormulation ql:CSV + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "https://w3id.org/ecfkg/i/{Level 2}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant skos:Concept; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdfs:label; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "Level 2"; + rr:language "en" + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "./data/conversion_factors_2016_modified_v2.csv"; + rml:referenceFormulation ql:CSV + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "https://w3id.org/ecfkg/i/{Level 3}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant skos:Concept; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdfs:label; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "Level 3"; + rr:language "en" + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "./data/conversion_factors_2016_modified_v2.csv"; + rml:referenceFormulation ql:CSV + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "https://w3id.org/ecfkg/i/{Level 4}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant skos:Concept; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdfs:label; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "Level 4"; + rr:language "en" + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "./data/conversion_factors_2016_modified_v2.csv"; + rml:referenceFormulation ql:CSV + ]; + rr:subjectMap [ + a rr:SubjectMap; + rml:reference "uom_wd"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant qudt:Unit; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdfs:label; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "UOM simple"; + rr:language "en" + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "./data/conversion_factors_2016_modified_v2.csv"; + rml:referenceFormulation ql:CSV + ]; + rr:subjectMap [ + a rr:SubjectMap; + rml:reference "ghg_wd"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant qudt:Unit; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdfs:label; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "GHG"; + rr:language "en" + ]; + ]. + + diff --git a/test/projects/TEC/mapping.yml b/test/projects/TEC/mapping.yml new file mode 100644 index 0000000..046db3c --- /dev/null +++ b/test/projects/TEC/mapping.yml @@ -0,0 +1,134 @@ +prefixes: + ecfo: "https://w3id.org/ecfo#" + qudt: "http://qudt.org/schema/qudt/" + skos: "http://www.w3.org/2004/02/skos/core#" + prov: "http://www.w3.org/ns/prov#" + time: "http://www.w3.org/2006/time#" + schema: "https://schema.org/" + ecfo_instance: "https://w3id.org/ecfkg/i/UK/BEIS/2016/" + dc: "http://purl.org/dc/elements/1.1/" + +sources: + main-source: ['./data/conversion_factors_2016_modified_v2.csv~csv'] +mappings: + CF: + sources: + - main-source + s: ecfo_instance:CF_$(id) + po: + - [a, ecfo:EmissionConversionFactor] + - [ecfo:hasAdditionalContext, $(Column Text), en~lang] + - [ecfo:hasScope, https://w3id.org/ecfo#$(Scope)~iri] + - [rdf:value, $(GHG Conversion Factor 2016),xsd:float] + - [ecfo:hasTag, https://w3id.org/ecfkg/i/$(Level 1)~iri] + - [ecfo:hasTag, https://w3id.org/ecfkg/i/$(Level 2)~iri] + - [ecfo:hasTag, https://w3id.org/ecfkg/i/$(Level 3)~iri] + - [ecfo:hasTag, https://w3id.org/ecfkg/i/$(Level 4)~iri] + - [ecfo:hasSourceUnit, $(uom_wd)~iri] + - [ecfo:hasEmissionSource, https://w3id.org/ecfkg/i/$(emission_source)~iri] + - [ecfo:hasTargetUnit, $(ghg_wd)~iri] + - [ecfo:hasEmissionTarget, $(emission_target_wd)~iri] + - [ecfo:hasApplicablePeriod, ecfo_instance:applicablePeriod/$(valid_from)/$(valid_to)~iri] + - [ecfo:hasApplicableLocation, $(region_wd)~iri] + - [dc:publisher, https://w3id.org/ecfkg/i/Organization/BEIS~iri] + - [prov:wasDerivedFrom, https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/558103/2016_Flat_format_file_v01-01.xlsx, xsd:anyURI] + + Agent: + sources: + - main-source + s: "https://w3id.org/ecfkg/i/Organization/BEIS" + po: + - [a, prov:Organization] + - [rdfs:label, 'BEIS', en~lang] + - [rdfs:seeAlso, 'https://www.gov.uk/government/organisations/department-for-business-energy-and-industrial-strategy/about',xsd:anyURI] + + TimeStart: + sources: + - main-source + s: ecfo_instance:applicablePeriod/$(valid_from)/$(valid_to)/start + po: + - [a, time:Instant] + - [time:inXSDDate, $(valid_from),xsd:dateTime] + + TimeEnd: + sources: + - main-source + s: ecfo_instance:applicablePeriod/$(valid_from)/$(valid_to)/end + po: + - [a, time:Instant] + - [time:inXSDDate, $(valid_to),xsd:dateTime ] + + TemporalEntity: + sources: + - main-source + + s: ecfo_instance:applicablePeriod/$(valid_from)/$(valid_to) + po: + - [a, time:TemporalEntity] + - [time:hasBeginning, ecfo_instance:applicablePeriod/$(valid_from)/$(valid_to)/start~iri] + - [time:hasEnd, ecfo_instance:applicablePeriod/$(valid_from)/$(valid_to)/end~iri] + + EmisisonSource: + sources: + - main-source + s: https://w3id.org/ecfkg/i/$(emission_source) + po: + - [a , skos:Concept] + - [rdfs:label, $(emission_source)] + + EmisisonTarget: + sources: + - main-source + s: $(emission_target_wd) + po: + - [a , ecfo:ChemicalCompound] + - [rdfs:label, $(emission_target), en~lang] + - [schema:molecularFormula, $(emission_target_formula), en~lang] + + L1: + sources: + - main-source + s: https://w3id.org/ecfkg/i/$(Level 1) + po: + - [a , skos:Concept] + - [rdfs:label, $(Level 1), en~lang] + + L2: + sources: + - main-source + s: https://w3id.org/ecfkg/i/$(Level 2) + po: + - [a , skos:Concept] + - [rdfs:label, $(Level 2), en~lang] + + L3: + sources: + - main-source + s: https://w3id.org/ecfkg/i/$(Level 3) + po: + - [a , skos:Concept] + - [rdfs:label, $(Level 3), en~lang] + + L4: + sources: + - main-source + s: https://w3id.org/ecfkg/i/$(Level 4) + po: + - [a , skos:Concept] + - [rdfs:label, $(Level 4), en~lang] + + sourceUnit: + sources: + - main-source + s: $(uom_wd) + po: + - [a , qudt:Unit] + - [rdfs:label, $(UOM simple), en~lang] + + targetUnit: + sources: + - main-source + s: $(ghg_wd) + po: + - [a , qudt:Unit] + - [rdfs:label, $(GHG), en~lang] \ No newline at end of file diff --git a/test/projects/TEC/test_tec.py b/test/projects/TEC/test_tec.py new file mode 100644 index 0000000..5119091 --- /dev/null +++ b/test/projects/TEC/test_tec.py @@ -0,0 +1,27 @@ +__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 +RML_URI = 'http://semweb.mmlab.be/ns/rml#' + + +def test_yarrrml_tec(): + 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=RML_URI), format="ttl") + + assert compare.isomorphic(expected_mapping, translated_mapping) \ No newline at end of file From a4e99da15fec32bc5efae33956f58d9cdb35d5cd Mon Sep 17 00:00:00 2001 From: David Chaves Date: Mon, 8 May 2023 17:05:32 +0200 Subject: [PATCH 2/8] solving #57 --- src/yatter/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yatter/__init__.py b/src/yatter/__init__.py index b1b226b..6e4a89f 100644 --- a/src/yatter/__init__.py +++ b/src/yatter/__init__.py @@ -65,7 +65,7 @@ def inverse_translation(rdf_mapping, mapping_format=RML_URI): rdf_mapping.bind('rr', rdflib.term.URIRef(R2RML_URI)) rdf_mapping.bind('ql', rdflib.term.URIRef(QL_URI)) yarrrml_mapping[YARRRML_PREFIXES] = add_inverse_prefix(rdf_mapping) - query = f'SELECT ?triplesMap WHERE {{ ?triplesMap {RDF_TYPE} {R2RML_TRIPLES_MAP} . }} ' + query = f'SELECT ?triplesMap WHERE {{ ?triplesMap {RML_LOGICAL_SOURCE}|{R2RML_LOGICAL_TABLE} ?source . }} ' triples_map = [tm[rdflib.Variable('triplesMap')] for tm in rdf_mapping.query(query).bindings] for tm in triples_map: From c62ea0ab6e8aa19f1adeec3086394781bdef18e0 Mon Sep 17 00:00:00 2001 From: David Chaves Date: Mon, 8 May 2023 18:03:25 +0200 Subject: [PATCH 3/8] adding testing for pretty R2RML #54 --- src/yatter/predicateobject.py | 4 ++-- test/r2rml/YARRRMLTC-0001/mapping.ttl | 8 +++++++ .../YARRRMLTC-0001/test_yarrrmltc0001.py | 13 ++++++++--- test/r2rml/YARRRMLTC-0002/mapping.ttl | 6 +++++ .../YARRRMLTC-0002/test_yarrrmltc0002.py | 12 +++++++--- test/r2rml/YARRRMLTC-0003/mapping.ttl | 6 +++++ .../YARRRMLTC-0003/test_yarrrmltc0003.py | 12 +++++++--- test/r2rml/YARRRMLTC-0004/mapping.ttl | 6 +++++ .../YARRRMLTC-0004/test_yarrrmltc0004.py | 12 +++++++--- test/r2rml/YARRRMLTC-0005/mapping.ttl | 6 +++++ test/r2rml/YARRRMLTC-0006/mapping.ttl | 10 +++++++-- .../YARRRMLTC-0006/test_yarrrmltc0006.py | 12 +++++++--- test/r2rml/YARRRMLTC-0007/mapping.ttl | 5 +++++ .../YARRRMLTC-0007/test_yarrrmltc0007.py | 12 +++++++--- test/r2rml/YARRRMLTC-0008/mapping.ttl | 6 +++++ test/r2rml/YARRRMLTC-0009/mapping.ttl | 22 ++++++++++++++----- .../YARRRMLTC-0009/test_yarrrmltc0009.py | 12 +++++++--- test/r2rml/YARRRMLTC-0010/mapping.ttl | 8 ++++++- .../YARRRMLTC-0010/test_yarrrmltc0010.py | 12 +++++++--- test/r2rml/YARRRMLTC-0011/mapping.ttl | 8 +++++-- .../YARRRMLTC-0011/test_yarrrmltc0011.py | 12 +++++++--- test/r2rml/YARRRMLTC-0012/mapping.ttl | 10 ++++++++- .../YARRRMLTC-0012/test_yarrrmltc0012.py | 12 +++++++--- test/r2rml/YARRRMLTC-0013/mapping.ttl | 8 +++++++ .../YARRRMLTC-0013/test_yarrrmltc0013.py | 12 +++++++--- test/r2rml/YARRRMLTC-0014/mapping.ttl | 8 +++++++ .../YARRRMLTC-0014/test_yarrrmltc0014.py | 12 +++++++--- test/r2rml/YARRRMLTC-0015/mapping.ttl | 10 ++++++++- .../YARRRMLTC-0015/test_yarrrmltc0015.py | 12 +++++++--- 29 files changed, 235 insertions(+), 53 deletions(-) diff --git a/src/yatter/predicateobject.py b/src/yatter/predicateobject.py index 4972923..c883ae4 100644 --- a/src/yatter/predicateobject.py +++ b/src/yatter/predicateobject.py @@ -281,7 +281,7 @@ def ref_mapping(data, mapping, om, yarrrml_key, ref_type_property, mapping_forma number_joins_rml = len(subject_list) * len(source_list) for i in range(number_joins_rml): template += "\t\t" + object + \ - " [ \n\t\t\ta " + R2RML_REFOBJECT_CLASS + \ + " [\n\t\t\ta " + R2RML_REFOBJECT_CLASS + \ ";\n\t\t\t" + ref_type_property + " <" + mapping_join + "_" + str(i) + ">;\n" if YARRRML_CONDITION in om: conditions = om.get(YARRRML_CONDITION) @@ -296,7 +296,7 @@ def ref_mapping(data, mapping, om, yarrrml_key, ref_type_property, mapping_forma template += "\t\t\t" + R2RML_JOIN_CONITION + \ " [\n\t\t\t\t" + R2RML_CHILD + " " + child + \ - ";\n\t\t\t\t" + R2RML_PARENT + " " + parent + ";\n\t\t\t]; \n" + ";\n\t\t\t\t" + R2RML_PARENT + " " + parent + ";\n\t\t\t];\n" else: logger.error("Error in reference mapping another mapping in mapping " + mapping) diff --git a/test/r2rml/YARRRMLTC-0001/mapping.ttl b/test/r2rml/YARRRMLTC-0001/mapping.ttl index b261431..d0712c7 100644 --- a/test/r2rml/YARRRMLTC-0001/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0001/mapping.ttl @@ -6,6 +6,12 @@ @prefix xsd: . @prefix ql: . @prefix d2rq: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . @base . @@ -30,3 +36,5 @@ rr:column "Name"; ]; ]. + + diff --git a/test/r2rml/YARRRMLTC-0001/test_yarrrmltc0001.py b/test/r2rml/YARRRMLTC-0001/test_yarrrmltc0001.py index efaf7a8..26d18ad 100644 --- a/test/r2rml/YARRRMLTC-0001/test_yarrrmltc0001.py +++ b/test/r2rml/YARRRMLTC-0001/test_yarrrmltc0001.py @@ -16,11 +16,18 @@ def test_yarrrmltc0001(): expected_mapping = Graph() - expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), 'r') as file: + expected_mapping_string = file.read() + expected_mapping.parse(data=expected_mapping_string, 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_string = yatter.translate(yaml.load(open(mapping_path)), mapping_format=R2RML_URI) + translated_mapping.parse(data=translated_mapping_string, format="ttl") + + if compare.isomorphic(expected_mapping, translated_mapping): + assert expected_mapping_string == translated_mapping_string + else: + assert False - assert compare.isomorphic(expected_mapping, translated_mapping) diff --git a/test/r2rml/YARRRMLTC-0002/mapping.ttl b/test/r2rml/YARRRMLTC-0002/mapping.ttl index 2785949..7b99df4 100644 --- a/test/r2rml/YARRRMLTC-0002/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0002/mapping.ttl @@ -7,6 +7,12 @@ @prefix xsd: . @prefix ql: . @prefix d2rq: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . @base . diff --git a/test/r2rml/YARRRMLTC-0002/test_yarrrmltc0002.py b/test/r2rml/YARRRMLTC-0002/test_yarrrmltc0002.py index aae4c92..8a9d848 100644 --- a/test/r2rml/YARRRMLTC-0002/test_yarrrmltc0002.py +++ b/test/r2rml/YARRRMLTC-0002/test_yarrrmltc0002.py @@ -16,11 +16,17 @@ def test_yarrrmltc0002(): expected_mapping = Graph() - expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), 'r') as file: + expected_mapping_string = file.read() + expected_mapping.parse(data=expected_mapping_string, 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_string = yatter.translate(yaml.load(open(mapping_path)), mapping_format=R2RML_URI) + translated_mapping.parse(data=translated_mapping_string, format="ttl") - assert compare.isomorphic(expected_mapping, translated_mapping) + if compare.isomorphic(expected_mapping, translated_mapping): + assert expected_mapping_string == translated_mapping_string + else: + assert False diff --git a/test/r2rml/YARRRMLTC-0003/mapping.ttl b/test/r2rml/YARRRMLTC-0003/mapping.ttl index 2fcf43b..eaa90c1 100644 --- a/test/r2rml/YARRRMLTC-0003/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0003/mapping.ttl @@ -6,6 +6,12 @@ @prefix xsd: . @prefix ql: . @prefix d2rq: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . @base . diff --git a/test/r2rml/YARRRMLTC-0003/test_yarrrmltc0003.py b/test/r2rml/YARRRMLTC-0003/test_yarrrmltc0003.py index 3d215f5..0b168f3 100644 --- a/test/r2rml/YARRRMLTC-0003/test_yarrrmltc0003.py +++ b/test/r2rml/YARRRMLTC-0003/test_yarrrmltc0003.py @@ -16,11 +16,17 @@ def test_yarrrmltc0003(): expected_mapping = Graph() - expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), 'r') as file: + expected_mapping_string = file.read() + expected_mapping.parse(data=expected_mapping_string, 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_string = yatter.translate(yaml.load(open(mapping_path)), mapping_format=R2RML_URI) + translated_mapping.parse(data=translated_mapping_string, format="ttl") - assert compare.isomorphic(expected_mapping, translated_mapping) + if compare.isomorphic(expected_mapping, translated_mapping): + assert expected_mapping_string == translated_mapping_string + else: + assert False diff --git a/test/r2rml/YARRRMLTC-0004/mapping.ttl b/test/r2rml/YARRRMLTC-0004/mapping.ttl index 3dc7edd..aecc911 100644 --- a/test/r2rml/YARRRMLTC-0004/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0004/mapping.ttl @@ -6,6 +6,12 @@ @prefix xsd: . @prefix ql: . @prefix d2rq: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . @base . diff --git a/test/r2rml/YARRRMLTC-0004/test_yarrrmltc0004.py b/test/r2rml/YARRRMLTC-0004/test_yarrrmltc0004.py index 2ff2989..e83813e 100644 --- a/test/r2rml/YARRRMLTC-0004/test_yarrrmltc0004.py +++ b/test/r2rml/YARRRMLTC-0004/test_yarrrmltc0004.py @@ -16,11 +16,17 @@ def test_yarrrmltc0004(): expected_mapping = Graph() - expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), 'r') as file: + expected_mapping_string = file.read() + expected_mapping.parse(data=expected_mapping_string, 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_string = yatter.translate(yaml.load(open(mapping_path)), mapping_format=R2RML_URI) + translated_mapping.parse(data=translated_mapping_string, format="ttl") - assert compare.isomorphic(expected_mapping, translated_mapping) + if compare.isomorphic(expected_mapping, translated_mapping): + assert expected_mapping_string == translated_mapping_string + else: + assert False diff --git a/test/r2rml/YARRRMLTC-0005/mapping.ttl b/test/r2rml/YARRRMLTC-0005/mapping.ttl index 898a953..4e8e9be 100644 --- a/test/r2rml/YARRRMLTC-0005/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0005/mapping.ttl @@ -6,6 +6,12 @@ @prefix xsd: . @prefix ql: . @prefix d2rq: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . @base . diff --git a/test/r2rml/YARRRMLTC-0006/mapping.ttl b/test/r2rml/YARRRMLTC-0006/mapping.ttl index c56dc2a..09fdc32 100644 --- a/test/r2rml/YARRRMLTC-0006/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0006/mapping.ttl @@ -8,6 +8,12 @@ @prefix ql: . @prefix d2rq: . @prefix foaf: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . @base . @@ -29,7 +35,7 @@ ]; rr:objectMap [ a rr:ObjectMap; - rr:constant mail:Note + rr:constant mail:Note; ]; ]; rr:predicateObjectMap [ @@ -103,7 +109,7 @@ ]; rr:objectMap [ a rr:ObjectMap; - rr:constant ex:DateTime + rr:constant ex:DateTime; ]; ]; rr:predicateObjectMap [ diff --git a/test/r2rml/YARRRMLTC-0006/test_yarrrmltc0006.py b/test/r2rml/YARRRMLTC-0006/test_yarrrmltc0006.py index e57424d..15dedde 100644 --- a/test/r2rml/YARRRMLTC-0006/test_yarrrmltc0006.py +++ b/test/r2rml/YARRRMLTC-0006/test_yarrrmltc0006.py @@ -16,11 +16,17 @@ def test_yarrrmltc0006(): expected_mapping = Graph() - expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), 'r') as file: + expected_mapping_string = file.read() + expected_mapping.parse(data=expected_mapping_string, 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_string = yatter.translate(yaml.load(open(mapping_path)), mapping_format=R2RML_URI) + translated_mapping.parse(data=translated_mapping_string, format="ttl") - assert compare.isomorphic(expected_mapping, translated_mapping) + if compare.isomorphic(expected_mapping, translated_mapping): + assert expected_mapping_string == translated_mapping_string + else: + assert False diff --git a/test/r2rml/YARRRMLTC-0007/mapping.ttl b/test/r2rml/YARRRMLTC-0007/mapping.ttl index 4b05c01..b9b6dc0 100644 --- a/test/r2rml/YARRRMLTC-0007/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0007/mapping.ttl @@ -10,6 +10,11 @@ @prefix ql: . @prefix d2rq: . @prefix foaf: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . @base . diff --git a/test/r2rml/YARRRMLTC-0007/test_yarrrmltc0007.py b/test/r2rml/YARRRMLTC-0007/test_yarrrmltc0007.py index 414c036..3a5ef3e 100644 --- a/test/r2rml/YARRRMLTC-0007/test_yarrrmltc0007.py +++ b/test/r2rml/YARRRMLTC-0007/test_yarrrmltc0007.py @@ -16,11 +16,17 @@ def test_yarrrmltc0007(): expected_mapping = Graph() - expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), 'r') as file: + expected_mapping_string = file.read() + expected_mapping.parse(data=expected_mapping_string, 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_string = yatter.translate(yaml.load(open(mapping_path)), mapping_format=R2RML_URI) + translated_mapping.parse(data=translated_mapping_string, format="ttl") - assert compare.isomorphic(expected_mapping, translated_mapping) + if compare.isomorphic(expected_mapping, translated_mapping): + assert expected_mapping_string == translated_mapping_string + else: + assert False diff --git a/test/r2rml/YARRRMLTC-0008/mapping.ttl b/test/r2rml/YARRRMLTC-0008/mapping.ttl index 50b6fbb..d32a25d 100644 --- a/test/r2rml/YARRRMLTC-0008/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0008/mapping.ttl @@ -2,6 +2,12 @@ @prefix foaf: . @prefix ex: . @prefix xsd: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . @base . a rr:TriplesMap; diff --git a/test/r2rml/YARRRMLTC-0009/mapping.ttl b/test/r2rml/YARRRMLTC-0009/mapping.ttl index c414fce..01f683d 100644 --- a/test/r2rml/YARRRMLTC-0009/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0009/mapping.ttl @@ -1,8 +1,18 @@ -@prefix rr: . -@prefix foaf: . -@prefix rdf: . -@prefix ex: . -@prefix xsd: . +@prefix foaf: . +@prefix rdf: . +@prefix ex: . +@prefix rr: . +@prefix rml: . +@prefix rdfs: . +@prefix xsd: . +@prefix ql: . +@prefix d2rq: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . @base . @@ -57,3 +67,5 @@ rr:column "Name"; ]; ]. + + diff --git a/test/r2rml/YARRRMLTC-0009/test_yarrrmltc0009.py b/test/r2rml/YARRRMLTC-0009/test_yarrrmltc0009.py index 095ffbe..e18a145 100644 --- a/test/r2rml/YARRRMLTC-0009/test_yarrrmltc0009.py +++ b/test/r2rml/YARRRMLTC-0009/test_yarrrmltc0009.py @@ -16,11 +16,17 @@ def test_yarrrmltc0009(): expected_mapping = Graph() - expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), 'r') as file: + expected_mapping_string = file.read() + expected_mapping.parse(data=expected_mapping_string, 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_string = yatter.translate(yaml.load(open(mapping_path)), mapping_format=R2RML_URI) + translated_mapping.parse(data=translated_mapping_string, format="ttl") - assert compare.isomorphic(expected_mapping, translated_mapping) \ No newline at end of file + if compare.isomorphic(expected_mapping, translated_mapping): + assert expected_mapping_string == translated_mapping_string + else: + assert False \ No newline at end of file diff --git a/test/r2rml/YARRRMLTC-0010/mapping.ttl b/test/r2rml/YARRRMLTC-0010/mapping.ttl index 7d76f1e..ef0ae47 100644 --- a/test/r2rml/YARRRMLTC-0010/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0010/mapping.ttl @@ -1,11 +1,17 @@ @prefix foaf: . +@prefix rdfs: . @prefix rr: . @prefix rml: . @prefix rdf: . -@prefix rdfs: . @prefix xsd: . @prefix ql: . @prefix d2rq: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . @base . diff --git a/test/r2rml/YARRRMLTC-0010/test_yarrrmltc0010.py b/test/r2rml/YARRRMLTC-0010/test_yarrrmltc0010.py index 36bafa7..752c5e3 100644 --- a/test/r2rml/YARRRMLTC-0010/test_yarrrmltc0010.py +++ b/test/r2rml/YARRRMLTC-0010/test_yarrrmltc0010.py @@ -16,11 +16,17 @@ def test_yarrrmltc0010(): expected_mapping = Graph() - expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), 'r') as file: + expected_mapping_string = file.read() + expected_mapping.parse(data=expected_mapping_string, 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_string = yatter.translate(yaml.load(open(mapping_path)), mapping_format=R2RML_URI) + translated_mapping.parse(data=translated_mapping_string, format="ttl") - assert compare.isomorphic(expected_mapping, translated_mapping) \ No newline at end of file + if compare.isomorphic(expected_mapping, translated_mapping): + assert expected_mapping_string == translated_mapping_string + else: + assert False \ No newline at end of file diff --git a/test/r2rml/YARRRMLTC-0011/mapping.ttl b/test/r2rml/YARRRMLTC-0011/mapping.ttl index 2790884..aac1147 100644 --- a/test/r2rml/YARRRMLTC-0011/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0011/mapping.ttl @@ -7,9 +7,13 @@ @prefix xsd: . @prefix ql: . @prefix d2rq: . -@prefix foaf: . -@base . @prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . +@base . a rr:TriplesMap; diff --git a/test/r2rml/YARRRMLTC-0011/test_yarrrmltc0011.py b/test/r2rml/YARRRMLTC-0011/test_yarrrmltc0011.py index a2b651d..67001aa 100644 --- a/test/r2rml/YARRRMLTC-0011/test_yarrrmltc0011.py +++ b/test/r2rml/YARRRMLTC-0011/test_yarrrmltc0011.py @@ -15,11 +15,17 @@ def test_yarrrmltc0011(): expected_mapping = Graph() - expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), 'r') as file: + expected_mapping_string = file.read() + expected_mapping.parse(data=expected_mapping_string, 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_string = yatter.translate(yaml.load(open(mapping_path)), mapping_format=R2RML_URI) + translated_mapping.parse(data=translated_mapping_string, format="ttl") - assert compare.isomorphic(expected_mapping, translated_mapping) \ No newline at end of file + if compare.isomorphic(expected_mapping, translated_mapping): + assert expected_mapping_string == translated_mapping_string + else: + assert False \ No newline at end of file diff --git a/test/r2rml/YARRRMLTC-0012/mapping.ttl b/test/r2rml/YARRRMLTC-0012/mapping.ttl index 92b4570..3cfa988 100644 --- a/test/r2rml/YARRRMLTC-0012/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0012/mapping.ttl @@ -7,6 +7,12 @@ @prefix xsd: . @prefix ql: . @prefix d2rq: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . @base . @@ -40,4 +46,6 @@ a rr:ObjectMap; rr:column "amount"; ]; - ]. \ No newline at end of file + ]. + + diff --git a/test/r2rml/YARRRMLTC-0012/test_yarrrmltc0012.py b/test/r2rml/YARRRMLTC-0012/test_yarrrmltc0012.py index 792670d..c7be6d2 100644 --- a/test/r2rml/YARRRMLTC-0012/test_yarrrmltc0012.py +++ b/test/r2rml/YARRRMLTC-0012/test_yarrrmltc0012.py @@ -16,11 +16,17 @@ def test_yarrrmltc0012(): expected_mapping = Graph() - expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), 'r') as file: + expected_mapping_string = file.read() + expected_mapping.parse(data=expected_mapping_string, 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_string = yatter.translate(yaml.load(open(mapping_path)), mapping_format=R2RML_URI) + translated_mapping.parse(data=translated_mapping_string, format="ttl") - assert compare.isomorphic(expected_mapping, translated_mapping) \ No newline at end of file + if compare.isomorphic(expected_mapping, translated_mapping): + assert expected_mapping_string == translated_mapping_string + else: + assert False \ No newline at end of file diff --git a/test/r2rml/YARRRMLTC-0013/mapping.ttl b/test/r2rml/YARRRMLTC-0013/mapping.ttl index b7cd713..74f7f3b 100644 --- a/test/r2rml/YARRRMLTC-0013/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0013/mapping.ttl @@ -7,6 +7,12 @@ @prefix rdfs: . @prefix ql: . @prefix d2rq: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . @base . @@ -97,3 +103,5 @@ rr:datatype xsd:float ]; ]. + + diff --git a/test/r2rml/YARRRMLTC-0013/test_yarrrmltc0013.py b/test/r2rml/YARRRMLTC-0013/test_yarrrmltc0013.py index 8d365fe..5ad5ede 100644 --- a/test/r2rml/YARRRMLTC-0013/test_yarrrmltc0013.py +++ b/test/r2rml/YARRRMLTC-0013/test_yarrrmltc0013.py @@ -16,11 +16,17 @@ def test_yarrrmltc00013(): expected_mapping = Graph() - expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), 'r') as file: + expected_mapping_string = file.read() + expected_mapping.parse(data=expected_mapping_string, 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_string = yatter.translate(yaml.load(open(mapping_path)), mapping_format=R2RML_URI) + translated_mapping.parse(data=translated_mapping_string, format="ttl") - assert compare.isomorphic(expected_mapping, translated_mapping) \ No newline at end of file + if compare.isomorphic(expected_mapping, translated_mapping): + assert expected_mapping_string == translated_mapping_string + else: + assert False \ No newline at end of file diff --git a/test/r2rml/YARRRMLTC-0014/mapping.ttl b/test/r2rml/YARRRMLTC-0014/mapping.ttl index 6ecfd8c..42dae90 100644 --- a/test/r2rml/YARRRMLTC-0014/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0014/mapping.ttl @@ -7,6 +7,12 @@ @prefix xsd: . @prefix ql: . @prefix d2rq: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . @base . @@ -35,3 +41,5 @@ rr:column "Name"; ]; ]. + + diff --git a/test/r2rml/YARRRMLTC-0014/test_yarrrmltc0014.py b/test/r2rml/YARRRMLTC-0014/test_yarrrmltc0014.py index 134e0e7..a518db2 100644 --- a/test/r2rml/YARRRMLTC-0014/test_yarrrmltc0014.py +++ b/test/r2rml/YARRRMLTC-0014/test_yarrrmltc0014.py @@ -16,11 +16,17 @@ def test_yarrrmltc0014(): expected_mapping = Graph() - expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), 'r') as file: + expected_mapping_string = file.read() + expected_mapping.parse(data=expected_mapping_string, 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_string = yatter.translate(yaml.load(open(mapping_path)), mapping_format=R2RML_URI) + translated_mapping.parse(data=translated_mapping_string, format="ttl") - assert compare.isomorphic(expected_mapping, translated_mapping) \ No newline at end of file + if compare.isomorphic(expected_mapping, translated_mapping): + assert expected_mapping_string == translated_mapping_string + else: + assert False \ No newline at end of file diff --git a/test/r2rml/YARRRMLTC-0015/mapping.ttl b/test/r2rml/YARRRMLTC-0015/mapping.ttl index 73af347..732d4cd 100644 --- a/test/r2rml/YARRRMLTC-0015/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0015/mapping.ttl @@ -7,6 +7,12 @@ @prefix xsd: . @prefix ql: . @prefix d2rq: . +@prefix schema: . +@prefix formats: . +@prefix comp: . +@prefix void: . +@prefix fnml: . +@prefix grel: . @base . @@ -43,6 +49,8 @@ rr:objectMap [ a rr:ObjectMap; rr:column "Name"; - rr:termType rr:IRI; + rr:termType rr:IRI ]; ]. + + diff --git a/test/r2rml/YARRRMLTC-0015/test_yarrrmltc0015.py b/test/r2rml/YARRRMLTC-0015/test_yarrrmltc0015.py index b444b76..846387a 100644 --- a/test/r2rml/YARRRMLTC-0015/test_yarrrmltc0015.py +++ b/test/r2rml/YARRRMLTC-0015/test_yarrrmltc0015.py @@ -16,11 +16,17 @@ def test_yarrrmltc0015(): expected_mapping = Graph() - expected_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), 'r') as file: + expected_mapping_string = file.read() + expected_mapping.parse(data=expected_mapping_string, 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_string = yatter.translate(yaml.load(open(mapping_path)), mapping_format=R2RML_URI) + translated_mapping.parse(data=translated_mapping_string, format="ttl") - assert compare.isomorphic(expected_mapping, translated_mapping) \ No newline at end of file + if compare.isomorphic(expected_mapping, translated_mapping): + assert expected_mapping_string == translated_mapping_string + else: + assert False \ No newline at end of file From 41c2747242b7d9fe2c7c932af9ca6ba9e328cb51 Mon Sep 17 00:00:00 2001 From: David Chaves Date: Mon, 8 May 2023 19:16:29 +0200 Subject: [PATCH 4/8] adding citation --- CITATION.cff | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 CITATION.cff diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 0000000..dc1c3ea --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,21 @@ +title: "Yatter: Translating YARRRML into easy-to-read [R2]RML mappings" +license: Apache-2.0 +authors: + - family-names: Chaves-Fraga + given-names: David + orcid: "http://orcid.org/0000-0003-3236-2789" +cff-version: 1.0.0 +preferred-citation: + authors: + - family-names: Iglesias-Molina + given-names: Ana + - family-names: Chaves-Fraga + given-names: David + - family-names: Dasoulas + given-names: Ioannnis + - family-names: Dimou + given-names: Anastasia + title: "Human-Friendly RDF Graph Construction: Which one do you chose?" + type: inproceedings + booktitle: ICWE + year: 2023 \ No newline at end of file From 95a201a87e2884929c3af5a42f5ad02567c85d65 Mon Sep 17 00:00:00 2001 From: David Chaves Date: Mon, 8 May 2023 19:20:52 +0200 Subject: [PATCH 5/8] enhance CITATION.cff --- CITATION.cff | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CITATION.cff b/CITATION.cff index dc1c3ea..3318848 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -5,6 +5,10 @@ authors: given-names: David orcid: "http://orcid.org/0000-0003-3236-2789" cff-version: 1.0.0 +version: 1.1.0 +doi: 10.5281/zenodo.7024500 +date-released: 2023-05-05 +url: "https://github.com/oeg-uopm/yatter" preferred-citation: authors: - family-names: Iglesias-Molina @@ -16,6 +20,6 @@ preferred-citation: - family-names: Dimou given-names: Anastasia title: "Human-Friendly RDF Graph Construction: Which one do you chose?" - type: inproceedings + type: conference booktitle: ICWE year: 2023 \ No newline at end of file From bae604b78ab868fbe346f678698caca40cbf3429 Mon Sep 17 00:00:00 2001 From: David Chaves Date: Fri, 23 Jun 2023 12:21:33 +0200 Subject: [PATCH 6/8] solving #63 --- src/yatter/predicateobject.py | 109 +++++++++++------- test/r2rml/INVERSETC-0005/mapping.ttl | 62 ++++++++++ test/r2rml/INVERSETC-0005/mapping.yml | 50 ++++++++ .../INVERSETC-0005/test_inversetc0005.py | 5 +- test/r2rml/YARRRMLTC-0013/mapping.ttl | 4 +- test/r2rml/YARRRMLTC-0013/mapping.yml | 4 +- .../mapping.ttl | 0 .../mapping.yml | 0 .../INVERSETC-0006/test_inversetc0006.py | 0 .../YARRRMLTC-0035/mapping.ttl | 0 .../YARRRMLTC-0035/mapping.yml | 0 .../YARRRMLTC-0035/test_yarrrmltc0035.py | 0 .../YARRRMLTC-0036/mapping.ttl | 0 .../YARRRMLTC-0036/mapping.yml | 0 .../YARRRMLTC-0036/test_yarrrmltc0036.py | 0 .../YARRRMLTC-0037/mapping.ttl | 0 .../YARRRMLTC-0037/mapping.yml | 0 .../YARRRMLTC-0037/test_yarrrmltc0037.py | 0 .../YARRRMLTC-0038/mapping.ttl | 0 .../YARRRMLTC-0038/mapping.yml | 0 .../YARRRMLTC-0038/test_yarrrmltc0038.py | 0 .../YARRRMLTC-0039/mapping.ttl | 0 .../YARRRMLTC-0039/mapping.yml | 0 .../YARRRMLTC-0039/test_yarrrmltc0039.py | 0 .../YARRRMLTC-0040/mapping.ttl | 0 .../YARRRMLTC-0040/mapping.yml | 0 .../YARRRMLTC-0040/test_yarrrmltc0040.py | 0 .../mapping.ttl | 0 .../mapping.yml | 0 .../INVERSETC-0007/test_inversetc0007.py | 31 +++++ 30 files changed, 216 insertions(+), 49 deletions(-) create mode 100644 test/r2rml/INVERSETC-0005/mapping.ttl create mode 100644 test/r2rml/INVERSETC-0005/mapping.yml rename test/{rml-datatype => r2rml}/INVERSETC-0005/test_inversetc0005.py (86%) rename test/rml-datatype/{INVERSETC-0005 => INVERSETC-0006}/mapping.ttl (100%) rename test/rml-datatype/{INVERSETC-0005 => INVERSETC-0006}/mapping.yml (100%) rename test/{rml-language => rml-datatype}/INVERSETC-0006/test_inversetc0006.py (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0035/mapping.ttl (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0035/mapping.yml (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0035/test_yarrrmltc0035.py (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0036/mapping.ttl (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0036/mapping.yml (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0036/test_yarrrmltc0036.py (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0037/mapping.ttl (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0037/mapping.yml (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0037/test_yarrrmltc0037.py (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0038/mapping.ttl (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0038/mapping.yml (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0038/test_yarrrmltc0038.py (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0039/mapping.ttl (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0039/mapping.yml (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0039/test_yarrrmltc0039.py (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0040/mapping.ttl (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0040/mapping.yml (100%) rename test/{rml-target => rml-io}/YARRRMLTC-0040/test_yarrrmltc0040.py (100%) rename test/rml-language/{INVERSETC-0006 => INVERSETC-0007}/mapping.ttl (100%) rename test/rml-language/{INVERSETC-0006 => INVERSETC-0007}/mapping.yml (100%) create mode 100644 test/rml-language/INVERSETC-0007/test_inversetc0007.py diff --git a/src/yatter/predicateobject.py b/src/yatter/predicateobject.py index c883ae4..3c6b4a4 100644 --- a/src/yatter/predicateobject.py +++ b/src/yatter/predicateobject.py @@ -7,6 +7,7 @@ from .mapping import prefixes from ruamel.yaml import YAML + def get_object_access(predicate_object_map): if YARRRML_OBJECT in predicate_object_map: object_access = YARRRML_OBJECT @@ -15,7 +16,8 @@ def get_object_access(predicate_object_map): elif YARRRML_OBJECTS in predicate_object_map: object_access = YARRRML_OBJECTS else: - logger.error("There isn't a valid object key (object, objects, o) correctly specify in PON " + predicate_object_map) + logger.error( + "There isn't a valid object key (object, objects, o) correctly specify in PON " + predicate_object_map) raise Exception("Add or change the key of the object in the indicated POM") return object_access @@ -28,7 +30,8 @@ def get_predicate_access(predicate_object_map): elif YARRRML_PREDICATE in predicate_object_map: predicate_access = YARRRML_PREDICATE else: - logger.error("There isn't a valid predicate key (predicate, predicates, p) correctly specify in PON " + predicate_object_map) + logger.error( + "There isn't a valid predicate key (predicate, predicates, p) correctly specify in PON " + predicate_object_map) raise Exception("Add or change the key of the predicate in the indicated POM") return predicate_access @@ -40,7 +43,7 @@ def get_predicate_object_access(mapping, predicate_object_map): predicate_object_access = YARRRML_PREDICATEOBJECT_SHORTCUT else: predicate_object_access = None - logger.warning("The triples map "+mapping+" does not have predicate object maps defined") + logger.warning("The triples map " + mapping + " does not have predicate object maps defined") return predicate_object_access @@ -64,7 +67,8 @@ def add_predicate_object_maps(data, mapping, mapping_format): pom_text = "\t" + R2RML_PREDICATE_OBJECT_MAP + " [\n" for predicate_object_map in mapping_data.get(key_access_pom): if type(predicate_object_map) is list: - po_template += pom_text + add_predicate_object(data, mapping, predicate_object_map, mapping_format) + "\n" + po_template += pom_text + add_predicate_object(data, mapping, predicate_object_map, + mapping_format) + "\n" else: po_template += pom_text + add_predicate_object(data, mapping, predicate_object_map, mapping_format, get_predicate_access(predicate_object_map), @@ -87,11 +91,11 @@ def get_object_list(predicate_object, object_access): else: for object in object_maps: if YARRRML_LANGUAGE in object: - object_list.append([object[YARRRML_VALUE],object[YARRRML_LANGUAGE]+"~lang"]) + object_list.append([object[YARRRML_VALUE], object[YARRRML_LANGUAGE] + "~lang"]) elif YARRRML_DATATYPE in object: object_list.append([object[YARRRML_VALUE], object[YARRRML_DATATYPE]]) elif YARRRML_TYPE in object: - object_list.append([object[YARRRML_VALUE]+"~"+object[YARRRML_TYPE]]) + object_list.append([object[YARRRML_VALUE] + "~" + object[YARRRML_TYPE]]) elif YARRRML_VALUE in object: if YARRRML_TARGETS in object or YARRRML_FUNCTION in object: if YARRRML_TARGETS in object: @@ -148,7 +152,7 @@ def add_predicate_object(data, mapping, predicate_object, mapping_format=RML_URI elif YARRRML_FUNCTION in pm: pm_value = pm[YARRRML_FUNCTION] execution = True - template += generate_rml_termmap(R2RML_PREDICATE, R2RML_PREDICATE_CLASS, pm_value,"\t\t\t") + 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 + ">") if YARRRML_TARGETS in pm: @@ -166,7 +170,7 @@ def add_predicate_object(data, mapping, predicate_object, mapping_format=RML_URI object_value, "\t\t\t", mapping_format) else: object_map = generate_rml_termmap(R2RML_OBJECT, R2RML_OBJECT_CLASS, - object_value, "\t\t\t", mapping_format) + 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}\"") @@ -177,18 +181,23 @@ def add_predicate_object(data, mapping, predicate_object, mapping_format=RML_URI if types != "error": if types == YARRRML_LANGUAGE: if "$(" in om[1]: - template = template[0:len(template) - 5] + generate_rml_termmap(RML_LANGUAGE_MAP, RML_LANGUAGE_MAP_CLASS, - om[1].replace("~lang",""), "\t\t\t\t", mapping_format) + "\t\t];\n" + template = template[0:len(template) - 5] + generate_rml_termmap(RML_LANGUAGE_MAP, + RML_LANGUAGE_MAP_CLASS, + om[1].replace("~lang", ""), + "\t\t\t\t", + mapping_format) + "\t\t];\n" else: template = template[0:len(template) - 5] + "\t\t\t" + R2RML_LANGUAGE + " \"" \ - + om[1].replace(YARRRML_LANG, "") + "\"\n\t\t];\n" + + om[1].replace(YARRRML_LANG, "") + "\"\n\t\t];\n" elif types == YARRRML_DATATYPE: if "$(" in om[1]: - template = template[0:len(template) - 5] + generate_rml_termmap(RML_DATATYPE_MAP, RML_DATATYPE_MAP_CLASS, - om[1], "\t\t\t\t", mapping_format) + "\t\t];\n" + template = template[0:len(template) - 5] + generate_rml_termmap(RML_DATATYPE_MAP, + RML_DATATYPE_MAP_CLASS, + om[1], "\t\t\t\t", + mapping_format) + "\t\t];\n" else: template = template[0:len(template) - 5] + "\t\t\t" + R2RML_DATATYPE + " " \ - + om[1] + "\n\t\t];\n" + + om[1] + "\n\t\t];\n" elif types == YARRRML_TARGETS: template = template[0:len(template) - 5] + "\t\t\t" + RML_LOGICAL_TARGET + " <" \ + om[1] + ">\n\t\t];\n" @@ -202,9 +211,9 @@ def add_predicate_object(data, mapping, predicate_object, mapping_format=RML_URI if YARRRML_CONDITION in om: template += ref_mapping(data, mapping, om, YARRRML_NON_ASSERTED, STAR_QUOTED, mapping_format) else: - template += generate_rml_termmap(STAR_OBJECT, STAR_CLASS,om, "\t\t\t", mapping_format) + template += generate_rml_termmap(STAR_OBJECT, STAR_CLASS, om, "\t\t\t", mapping_format) else: - template += ref_mapping(data, mapping, om, YARRRML_QUOTED, STAR_QUOTED, mapping_format) + template += ref_mapping(data, mapping, om, YARRRML_QUOTED, STAR_QUOTED, mapping_format) else: if YARRRML_VALUE in om and type(om) is dict: object_value = om.get(YARRRML_VALUE) @@ -217,8 +226,9 @@ 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( + 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, @@ -237,15 +247,13 @@ def add_predicate_object(data, mapping, predicate_object, mapping_format=RML_URI template = template[0:len(template) - 5] + "\t\t\t" + R2RML_TERMTYPE + " " \ + R2RML_LITERAL + "\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" + template = template[0:len(template) - 5] + "\t\t\t" + RML_LOGICAL_TARGET + " <" + om.get( + YARRRML_TARGETS) + ">\n\t\t];\n" if iri: template = template[0:len(template) - 5] + "\t\t\t" + R2RML_TERMTYPE + " " \ + R2RML_IRI + "\n\t\t];\n" - - - for graph in graph_list: graph_value = graph if YARRRML_VALUE in graph: @@ -255,7 +263,6 @@ def add_predicate_object(data, mapping, predicate_object, mapping_format=RML_URI template = template[0:-3] + "\t" + RML_LOGICAL_TARGET + " <" + graph[ YARRRML_TARGETS] + ">\n\t\t];\n" - return template + "\t];" @@ -291,8 +298,8 @@ def ref_mapping(data, mapping, om, yarrrml_key, ref_type_property, mapping_forma if YARRRML_PARAMETERS in condition: list_parameters = condition.get(YARRRML_PARAMETERS) if len(list_parameters) == 2: - child = list_parameters[0][1].replace('"',r'\"').replace("$(", '"').replace(")", '"') - parent = list_parameters[1][1].replace('"',r'\"').replace("$(", '"').replace(")", '"') + child = list_parameters[0][1].replace('"', r'\"').replace("$(", '"').replace(")", '"') + parent = list_parameters[1][1].replace('"', r'\"').replace("$(", '"').replace(")", '"') template += "\t\t\t" + R2RML_JOIN_CONITION + \ " [\n\t\t\t\t" + R2RML_CHILD + " " + child + \ @@ -325,7 +332,7 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): f' WHERE {{ ' \ f'<{mapping_id}> {R2RML_PREDICATE_OBJECT_MAP} ?predicateObjectMap . ' \ f'?predicateObjectMap {R2RML_PREDICATE}|{R2RML_SHORTCUT_PREDICATE} ?predicate .' \ - f'OPTIONAL {{ ?predicate {R2RML_CONSTANT} ?predicateValue . }}' \ + f'OPTIONAL {{ ?predicate {R2RML_TEMPLATE}|{R2RML_COLUMN}|{R2RML_CONSTANT}|{RML_REFERENCE} ?predicateValue . }}' \ f'?predicateObjectMap {R2RML_OBJECT}|{R2RML_SHORTCUT_OBJECT} ?object .' \ f' {{ OPTIONAL {{ ?predicateObjectMap {R2RML_GRAPH} ?graphValue .}}' \ f' }} UNION {{' \ @@ -337,12 +344,12 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): f'OPTIONAL {{ ?object {R2RML_TERMTYPE} ?termtype . }}' \ f'OPTIONAL {{ ?object {R2RML_DATATYPE} ?datatype .}} ' \ f'OPTIONAL {{ ' \ - f' ?object {RML_DATATYPE_MAP} ?datatypeMap .' \ - f' ?datatypeMap {R2RML_TEMPLATE}|{R2RML_CONSTANT}|{RML_REFERENCE} ?datatypeMapValue .}} ' \ + f' ?object {RML_DATATYPE_MAP} ?datatypeMap .' \ + f' ?datatypeMap {R2RML_TEMPLATE}|{R2RML_CONSTANT}|{RML_REFERENCE} ?datatypeMapValue .}} ' \ f'OPTIONAL {{ ?object {R2RML_LANGUAGE} ?language .}} ' \ f'OPTIONAL {{ ' \ - f' ?object {RML_LANGUAGE_MAP} ?languageMap .' \ - f' ?languageMap {R2RML_TEMPLATE}|{R2RML_CONSTANT}|{RML_REFERENCE} ?languageMapValue .}} }} ' \ + 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 .' \ @@ -351,13 +358,20 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): for tm in rdf_mapping.query(query): yarrrml_pom = [] if tm['predicateValue']: - prefix = list({i for i in prefixes if tm['predicateValue'].toPython().startswith(prefixes[i])}) - if len(prefix) > 0: - predicate = tm['predicateValue'].toPython().replace(prefixes[prefix[0]], prefix[0] + ":") - else: - predicate = tm['predicateValue'].toPython() - else: + predicate = tm['predicateValue'].toPython() + elif tm['predicate']: predicate = tm['predicate'].toPython() + else: + logger.error("ERROR: There is POM without predicate map defined") + raise Exception("Review your mapping " + str(mapping_id)) + + prefix = list({i for i in prefixes if predicate.startswith(prefixes[i])}) + if not predicate.startswith("http") and "{" not in predicate: + predicate = '$(' + predicate + ')' + elif "{" in predicate and "}" in predicate: + predicate = predicate.replace('{', '$(').replace('}', ')') + elif prefix: + predicate = tm['predicateValue'].toPython().replace(prefixes[prefix[0]], prefix[0] + ":") if tm['parentTriplesMap']: yarrrml_pom = {'p': predicate, 'o': {'mapping': None, 'condition': @@ -374,18 +388,24 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): datatype = None language = None - if tm['objectValue']: # we have extended objectMap version + if tm['objectValue']: # we have extended objectMap version object = tm['objectValue'].toPython() elif tm['object']: object = tm['object'].toPython() else: - logger.error("There is not object for a given predicate ") - raise Exception("Review your mapping "+str(mapping_id)) + logger.error("There is not object for a given predicate") + raise Exception("Review your mapping " + str(mapping_id)) + + 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] + ":") else: - object.replace('{', '$(').replace('}', ')') + object = object.replace('{', '$(').replace('}', ')') if tm['termtype']: if tm['termtype'] == rdflib.URIRef(R2RML_IRI): @@ -393,7 +413,7 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): if tm['graphValue']: graph_value = add_inverse_graph([tm['graphValue']]) - yarrrml_pom = {'p': predicate,'o': object} + yarrrml_pom = {'p': predicate, 'o': object} yarrrml_pom.update(graph_value) else: yarrrml_pom.append(predicate) @@ -401,6 +421,9 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): if tm['datatype']: datatype = tm['datatype'].toPython() + prefix = list({i for i in prefixes if datatype.startswith(prefixes[i])}) + if prefix: + datatype = datatype.replace(prefixes[prefix[0]], prefix[0] + ":") elif tm['datatypeMapValue']: datatype = tm['datatypeMapValue'] if not datatype.startswith("http"): @@ -408,7 +431,7 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): else: datatype.replace('{', '$(').replace('}', ')') if tm['language']: - language = tm['language'].toPython()+"~lang" + language = tm['language'].toPython() + "~lang" elif tm['languageMapValue']: language = tm['languageMapValue'] if not language.startswith("http"): @@ -432,4 +455,4 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): yarrrml_pom.fa.set_flow_style() yarrrml_poms.append(yarrrml_pom) - return yarrrml_poms \ No newline at end of file + return yarrrml_poms diff --git a/test/r2rml/INVERSETC-0005/mapping.ttl b/test/r2rml/INVERSETC-0005/mapping.ttl new file mode 100644 index 0000000..eac4b7b --- /dev/null +++ b/test/r2rml/INVERSETC-0005/mapping.ttl @@ -0,0 +1,62 @@ +@prefix foaf: . +@prefix ex: . +@prefix rdf: . +@prefix xsd: . +@prefix rr: . +@prefix rml: . +@prefix rdfs: . +@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 "Patient"; + rr:sqlVersion rr:SQL2008 + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "http://example.com/Patient/{ID}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant foaf:Person; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:template "http://example.com/{last_name}"; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:column "LastName"; + rr:datatype xsd:string + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant ex:height; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "http://example.com/{Height}" + ]; + ]. + + diff --git a/test/r2rml/INVERSETC-0005/mapping.yml b/test/r2rml/INVERSETC-0005/mapping.yml new file mode 100644 index 0000000..2d99a82 --- /dev/null +++ b/test/r2rml/INVERSETC-0005/mapping.yml @@ -0,0 +1,50 @@ +prefixes: + brick: https://brickschema.org/schema/Brick# + csvw: http://www.w3.org/ns/csvw# + dc: http://purl.org/dc/elements/1.1/ + dcat: http://www.w3.org/ns/dcat# + dcmitype: http://purl.org/dc/dcmitype/ + dcterms: http://purl.org/dc/terms/ + dcam: http://purl.org/dc/dcam/ + doap: http://usefulinc.com/ns/doap# + foaf: http://xmlns.com/foaf/0.1/ + geo: http://www.opengis.net/ont/geosparql# + odrl: http://www.w3.org/ns/odrl/2/ + org: http://www.w3.org/ns/org# + prof: http://www.w3.org/ns/dx/prof/ + prov: http://www.w3.org/ns/prov# + qb: http://purl.org/linked-data/cube# + schema: https://schema.org/ + sh: http://www.w3.org/ns/shacl# + skos: http://www.w3.org/2004/02/skos/core# + sosa: http://www.w3.org/ns/sosa/ + ssn: http://www.w3.org/ns/ssn/ + time: http://www.w3.org/2006/time# + vann: http://purl.org/vocab/vann/ + void: http://rdfs.org/ns/void# + wgs: https://www.w3.org/2003/01/geo/wgs84_pos# + 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# + xml: http://www.w3.org/XML/1998/namespace + ex: http://example.com/ + rr: http://www.w3.org/ns/r2rml# + rml: http://semweb.mmlab.be/ns/rml# + ql: http://semweb.mmlab.be/ns/ql# + d2rq: http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1# + schema1: http://schema.org/ + formats: http://www.w3.org/ns/formats/ + comp: http://semweb.mmlab.be/ns/rml-compression# + fnml: http://semweb.mmlab.be/ns/fnml# + grel: http://users.ugent.be/~bjdmeest/function/grel.ttl# +mappings: + TriplesMap1_0: + sources: + - table: Patient + queryFormulation: sql2008 + s: http://example.com/Patient/$(ID) + po: + - [rdf:type, foaf:Person] + - [http://example.com/$(last_name), $(LastName), xsd:string] + - [ex:height, http://example.com/$(Height)] diff --git a/test/rml-datatype/INVERSETC-0005/test_inversetc0005.py b/test/r2rml/INVERSETC-0005/test_inversetc0005.py similarity index 86% rename from test/rml-datatype/INVERSETC-0005/test_inversetc0005.py rename to test/r2rml/INVERSETC-0005/test_inversetc0005.py index 5979795..3610479 100644 --- a/test/rml-datatype/INVERSETC-0005/test_inversetc0005.py +++ b/test/r2rml/INVERSETC-0005/test_inversetc0005.py @@ -4,7 +4,7 @@ __license__ = "Apache-2.0" __maintainer__ = "David Chaves-Fraga" __email__ = "david.chaves@upm.es" -__name__ = "INVERSETC-0003 based on YARRRMLTC-0005" +__name__ = "INVERSETC-0005 based on YARRRMLTC-0013" import os @@ -12,6 +12,7 @@ import yatter from rdflib.graph import Graph from deepdiff import DeepDiff +R2RML_URI = 'http://www.w3.org/ns/r2rml#' def test_inversetc0005(): @@ -21,7 +22,7 @@ def test_inversetc0005(): input_mapping = Graph() mapping_path = input_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") - translated_mapping = yaml.load(str(yatter.inverse_translation(mapping_path))) + translated_mapping = yaml.load(str(yatter.inverse_translation(mapping_path, mapping_format=R2RML_URI))) ddiff = DeepDiff(expected_mapping['mappings'], translated_mapping['mappings'], ignore_order=True) diff --git a/test/r2rml/YARRRMLTC-0013/mapping.ttl b/test/r2rml/YARRRMLTC-0013/mapping.ttl index 74f7f3b..2bb3944 100644 --- a/test/r2rml/YARRRMLTC-0013/mapping.ttl +++ b/test/r2rml/YARRRMLTC-0013/mapping.ttl @@ -51,7 +51,7 @@ rr:predicateObjectMap [ rr:predicateMap [ a rr:PredicateMap; - rr:constant ex:firstName; + rml:reference "first_name"; ]; rr:objectMap [ a rr:ObjectMap; @@ -62,7 +62,7 @@ rr:predicateObjectMap [ rr:predicateMap [ a rr:PredicateMap; - rr:constant ex:lastName; + rr:template "http://example.org/{last_name}"; ]; rr:objectMap [ a rr:ObjectMap; diff --git a/test/r2rml/YARRRMLTC-0013/mapping.yml b/test/r2rml/YARRRMLTC-0013/mapping.yml index 3ea4ed6..ec06b2e 100644 --- a/test/r2rml/YARRRMLTC-0013/mapping.yml +++ b/test/r2rml/YARRRMLTC-0013/mapping.yml @@ -12,8 +12,8 @@ mappings: po: - [rdf:type, foaf:Person] - [ex:id, $(ID), xsd:integer] - - [ex:firstName, $(FirstName), xsd:string] - - [ex:lastName, $(LastName), xsd:string] + - [$(first_name), $(FirstName), xsd:string] + - ["http://example.org/$(last_name)", $(LastName), xsd:string] - [ex:gender, $(Sex), xsd:string] - [ex:weight, $(Weight), xsd:float] - [ex:height, $(Height), xsd:float] \ No newline at end of file diff --git a/test/rml-datatype/INVERSETC-0005/mapping.ttl b/test/rml-datatype/INVERSETC-0006/mapping.ttl similarity index 100% rename from test/rml-datatype/INVERSETC-0005/mapping.ttl rename to test/rml-datatype/INVERSETC-0006/mapping.ttl diff --git a/test/rml-datatype/INVERSETC-0005/mapping.yml b/test/rml-datatype/INVERSETC-0006/mapping.yml similarity index 100% rename from test/rml-datatype/INVERSETC-0005/mapping.yml rename to test/rml-datatype/INVERSETC-0006/mapping.yml diff --git a/test/rml-language/INVERSETC-0006/test_inversetc0006.py b/test/rml-datatype/INVERSETC-0006/test_inversetc0006.py similarity index 100% rename from test/rml-language/INVERSETC-0006/test_inversetc0006.py rename to test/rml-datatype/INVERSETC-0006/test_inversetc0006.py diff --git a/test/rml-target/YARRRMLTC-0035/mapping.ttl b/test/rml-io/YARRRMLTC-0035/mapping.ttl similarity index 100% rename from test/rml-target/YARRRMLTC-0035/mapping.ttl rename to test/rml-io/YARRRMLTC-0035/mapping.ttl diff --git a/test/rml-target/YARRRMLTC-0035/mapping.yml b/test/rml-io/YARRRMLTC-0035/mapping.yml similarity index 100% rename from test/rml-target/YARRRMLTC-0035/mapping.yml rename to test/rml-io/YARRRMLTC-0035/mapping.yml diff --git a/test/rml-target/YARRRMLTC-0035/test_yarrrmltc0035.py b/test/rml-io/YARRRMLTC-0035/test_yarrrmltc0035.py similarity index 100% rename from test/rml-target/YARRRMLTC-0035/test_yarrrmltc0035.py rename to test/rml-io/YARRRMLTC-0035/test_yarrrmltc0035.py diff --git a/test/rml-target/YARRRMLTC-0036/mapping.ttl b/test/rml-io/YARRRMLTC-0036/mapping.ttl similarity index 100% rename from test/rml-target/YARRRMLTC-0036/mapping.ttl rename to test/rml-io/YARRRMLTC-0036/mapping.ttl diff --git a/test/rml-target/YARRRMLTC-0036/mapping.yml b/test/rml-io/YARRRMLTC-0036/mapping.yml similarity index 100% rename from test/rml-target/YARRRMLTC-0036/mapping.yml rename to test/rml-io/YARRRMLTC-0036/mapping.yml diff --git a/test/rml-target/YARRRMLTC-0036/test_yarrrmltc0036.py b/test/rml-io/YARRRMLTC-0036/test_yarrrmltc0036.py similarity index 100% rename from test/rml-target/YARRRMLTC-0036/test_yarrrmltc0036.py rename to test/rml-io/YARRRMLTC-0036/test_yarrrmltc0036.py diff --git a/test/rml-target/YARRRMLTC-0037/mapping.ttl b/test/rml-io/YARRRMLTC-0037/mapping.ttl similarity index 100% rename from test/rml-target/YARRRMLTC-0037/mapping.ttl rename to test/rml-io/YARRRMLTC-0037/mapping.ttl diff --git a/test/rml-target/YARRRMLTC-0037/mapping.yml b/test/rml-io/YARRRMLTC-0037/mapping.yml similarity index 100% rename from test/rml-target/YARRRMLTC-0037/mapping.yml rename to test/rml-io/YARRRMLTC-0037/mapping.yml diff --git a/test/rml-target/YARRRMLTC-0037/test_yarrrmltc0037.py b/test/rml-io/YARRRMLTC-0037/test_yarrrmltc0037.py similarity index 100% rename from test/rml-target/YARRRMLTC-0037/test_yarrrmltc0037.py rename to test/rml-io/YARRRMLTC-0037/test_yarrrmltc0037.py diff --git a/test/rml-target/YARRRMLTC-0038/mapping.ttl b/test/rml-io/YARRRMLTC-0038/mapping.ttl similarity index 100% rename from test/rml-target/YARRRMLTC-0038/mapping.ttl rename to test/rml-io/YARRRMLTC-0038/mapping.ttl diff --git a/test/rml-target/YARRRMLTC-0038/mapping.yml b/test/rml-io/YARRRMLTC-0038/mapping.yml similarity index 100% rename from test/rml-target/YARRRMLTC-0038/mapping.yml rename to test/rml-io/YARRRMLTC-0038/mapping.yml diff --git a/test/rml-target/YARRRMLTC-0038/test_yarrrmltc0038.py b/test/rml-io/YARRRMLTC-0038/test_yarrrmltc0038.py similarity index 100% rename from test/rml-target/YARRRMLTC-0038/test_yarrrmltc0038.py rename to test/rml-io/YARRRMLTC-0038/test_yarrrmltc0038.py diff --git a/test/rml-target/YARRRMLTC-0039/mapping.ttl b/test/rml-io/YARRRMLTC-0039/mapping.ttl similarity index 100% rename from test/rml-target/YARRRMLTC-0039/mapping.ttl rename to test/rml-io/YARRRMLTC-0039/mapping.ttl diff --git a/test/rml-target/YARRRMLTC-0039/mapping.yml b/test/rml-io/YARRRMLTC-0039/mapping.yml similarity index 100% rename from test/rml-target/YARRRMLTC-0039/mapping.yml rename to test/rml-io/YARRRMLTC-0039/mapping.yml diff --git a/test/rml-target/YARRRMLTC-0039/test_yarrrmltc0039.py b/test/rml-io/YARRRMLTC-0039/test_yarrrmltc0039.py similarity index 100% rename from test/rml-target/YARRRMLTC-0039/test_yarrrmltc0039.py rename to test/rml-io/YARRRMLTC-0039/test_yarrrmltc0039.py diff --git a/test/rml-target/YARRRMLTC-0040/mapping.ttl b/test/rml-io/YARRRMLTC-0040/mapping.ttl similarity index 100% rename from test/rml-target/YARRRMLTC-0040/mapping.ttl rename to test/rml-io/YARRRMLTC-0040/mapping.ttl diff --git a/test/rml-target/YARRRMLTC-0040/mapping.yml b/test/rml-io/YARRRMLTC-0040/mapping.yml similarity index 100% rename from test/rml-target/YARRRMLTC-0040/mapping.yml rename to test/rml-io/YARRRMLTC-0040/mapping.yml diff --git a/test/rml-target/YARRRMLTC-0040/test_yarrrmltc0040.py b/test/rml-io/YARRRMLTC-0040/test_yarrrmltc0040.py similarity index 100% rename from test/rml-target/YARRRMLTC-0040/test_yarrrmltc0040.py rename to test/rml-io/YARRRMLTC-0040/test_yarrrmltc0040.py diff --git a/test/rml-language/INVERSETC-0006/mapping.ttl b/test/rml-language/INVERSETC-0007/mapping.ttl similarity index 100% rename from test/rml-language/INVERSETC-0006/mapping.ttl rename to test/rml-language/INVERSETC-0007/mapping.ttl diff --git a/test/rml-language/INVERSETC-0006/mapping.yml b/test/rml-language/INVERSETC-0007/mapping.yml similarity index 100% rename from test/rml-language/INVERSETC-0006/mapping.yml rename to test/rml-language/INVERSETC-0007/mapping.yml diff --git a/test/rml-language/INVERSETC-0007/test_inversetc0007.py b/test/rml-language/INVERSETC-0007/test_inversetc0007.py new file mode 100644 index 0000000..88ce9ca --- /dev/null +++ b/test/rml-language/INVERSETC-0007/test_inversetc0007.py @@ -0,0 +1,31 @@ +__author__ = "David Chaves-Fraga" +__credits__ = ["David Chaves-Fraga"] + +__license__ = "Apache-2.0" +__maintainer__ = "David Chaves-Fraga" +__email__ = "david.chaves@upm.es" +__name__ = "INVERSETC-0003 based on YARRRMLTC-0005" + + +import os +from ruamel.yaml import YAML +import yatter +from rdflib.graph import Graph +from deepdiff import DeepDiff + + +def test_inversetc0007(): + yaml = YAML(typ='safe', pure=True) + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.yml')) as file: + expected_mapping = yaml.load(file) + + input_mapping = Graph() + mapping_path = input_mapping.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.ttl'), format="ttl") + translated_mapping = yaml.load(str(yatter.inverse_translation(mapping_path))) + + ddiff = DeepDiff(expected_mapping['mappings'], translated_mapping['mappings'], ignore_order=True) + + if ddiff: + assert False + else: + assert True \ No newline at end of file From 6200c81ffe93094438f512432244048c0b5aded6 Mon Sep 17 00:00:00 2001 From: Ioannis Dasoulas <49875599+TheRazorace@users.noreply.github.com> Date: Wed, 28 Jun 2023 11:54:38 +0200 Subject: [PATCH 7/8] Add files via upload --- .../IMTC001/mappings-new.rml.ttl | 42 ++++++++ test/rml-in-memory/IMTC001/mappings.rml.ttl | 43 ++++++++ test/rml-in-memory/IMTC001/mappings.yml | 23 +++++ .../IMTC002/mappings-new.rml.ttl | 36 +++++++ test/rml-in-memory/IMTC002/mappings.rml.ttl | 37 +++++++ test/rml-in-memory/IMTC002/mappings.yml | 20 ++++ .../IMTC003/mappings-new.rml.ttl | 36 +++++++ test/rml-in-memory/IMTC003/mappings.rml.ttl | 37 +++++++ test/rml-in-memory/IMTC003/mappings.yml | 18 ++++ .../IMTC004/mappings-new.rml.ttl | 42 ++++++++ test/rml-in-memory/IMTC004/mappings.rml.ttl | 43 ++++++++ test/rml-in-memory/IMTC004/mappings.yml | 23 +++++ .../IMTC005/mappings-new.rml.ttl | 37 +++++++ test/rml-in-memory/IMTC005/mappings.rml.ttl | 38 ++++++++ test/rml-in-memory/IMTC005/mappings.yml | 18 ++++ .../IMTC006/mappings-new.rml.ttl | 95 ++++++++++++++++++ test/rml-in-memory/IMTC006/mappings.rml.ttl | 96 ++++++++++++++++++ test/rml-in-memory/IMTC006/mappings.yml | 33 +++++++ .../IMTC007/mappings-new.rml.ttl | 96 ++++++++++++++++++ test/rml-in-memory/IMTC007/mappings.rml.ttl | 97 +++++++++++++++++++ test/rml-in-memory/IMTC007/mappings.yml | 33 +++++++ .../IMTC008/mappings-new.rml.ttl | 88 +++++++++++++++++ test/rml-in-memory/IMTC008/mappings.rml.ttl | 89 +++++++++++++++++ test/rml-in-memory/IMTC008/mappings.yml | 28 ++++++ 24 files changed, 1148 insertions(+) create mode 100644 test/rml-in-memory/IMTC001/mappings-new.rml.ttl create mode 100644 test/rml-in-memory/IMTC001/mappings.rml.ttl create mode 100644 test/rml-in-memory/IMTC001/mappings.yml create mode 100644 test/rml-in-memory/IMTC002/mappings-new.rml.ttl create mode 100644 test/rml-in-memory/IMTC002/mappings.rml.ttl create mode 100644 test/rml-in-memory/IMTC002/mappings.yml create mode 100644 test/rml-in-memory/IMTC003/mappings-new.rml.ttl create mode 100644 test/rml-in-memory/IMTC003/mappings.rml.ttl create mode 100644 test/rml-in-memory/IMTC003/mappings.yml create mode 100644 test/rml-in-memory/IMTC004/mappings-new.rml.ttl create mode 100644 test/rml-in-memory/IMTC004/mappings.rml.ttl create mode 100644 test/rml-in-memory/IMTC004/mappings.yml create mode 100644 test/rml-in-memory/IMTC005/mappings-new.rml.ttl create mode 100644 test/rml-in-memory/IMTC005/mappings.rml.ttl create mode 100644 test/rml-in-memory/IMTC005/mappings.yml create mode 100644 test/rml-in-memory/IMTC006/mappings-new.rml.ttl create mode 100644 test/rml-in-memory/IMTC006/mappings.rml.ttl create mode 100644 test/rml-in-memory/IMTC006/mappings.yml create mode 100644 test/rml-in-memory/IMTC007/mappings-new.rml.ttl create mode 100644 test/rml-in-memory/IMTC007/mappings.rml.ttl create mode 100644 test/rml-in-memory/IMTC007/mappings.yml create mode 100644 test/rml-in-memory/IMTC008/mappings-new.rml.ttl create mode 100644 test/rml-in-memory/IMTC008/mappings.rml.ttl create mode 100644 test/rml-in-memory/IMTC008/mappings.yml diff --git a/test/rml-in-memory/IMTC001/mappings-new.rml.ttl b/test/rml-in-memory/IMTC001/mappings-new.rml.ttl new file mode 100644 index 0000000..d48e50d --- /dev/null +++ b/test/rml-in-memory/IMTC001/mappings-new.rml.ttl @@ -0,0 +1,42 @@ +@prefix insta: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rml:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "output_dataframe"; + sd:hasDataTransformation [ + sd:hasSoftwareRequirements "pandas>=1.1.0"; + sd:hasSourceCode [ + sd:programmingLanguage "Python3.9"; + ]; + ]; + ]; + rml:referenceFormulation ql:DataFrame; + ]; + rml:subjectMap [ + a rml:SubjectMap; + rml:template "http://instagram.com/data/user{Id}"; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant rdf:type; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:constant insta:User; + ]; + ]. + +ql:DataFrame a rml:ReferenceFormulation; + kg4di:definedBy "Pandas". \ No newline at end of file diff --git a/test/rml-in-memory/IMTC001/mappings.rml.ttl b/test/rml-in-memory/IMTC001/mappings.rml.ttl new file mode 100644 index 0000000..ab5a0bf --- /dev/null +++ b/test/rml-in-memory/IMTC001/mappings.rml.ttl @@ -0,0 +1,43 @@ +@prefix insta: . +@prefix rr: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "output_dataframe"; + sd:hasDataTransformation [ + sd:hasSoftwareRequirements "pandas>=1.1.0"; + sd:hasSourceCode [ + sd:programmingLanguage "Python3.9"; + ]; + ]; + ]; + rml:referenceFormulation ql:DataFrame; + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "http://instagram.com/data/user{Id}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant insta:User; + ]; + ]. + +ql:DataFrame a rml:ReferenceFormulation; + kg4di:definedBy "Pandas". \ No newline at end of file diff --git a/test/rml-in-memory/IMTC001/mappings.yml b/test/rml-in-memory/IMTC001/mappings.yml new file mode 100644 index 0000000..e236f5e --- /dev/null +++ b/test/rml-in-memory/IMTC001/mappings.yml @@ -0,0 +1,23 @@ +prefixes: + insta: "http://instagram.com/data/" + rr: "http://www.w3.org/ns/r2rml#" + rml: "http://semweb.mmlab.be/ns/rml#" + 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#" + foaf: "http://xmlns.com/foaf/0.1/" + sd: "https://w3id.org/okn/o/sd/" + kg4di: "https://w3id.org/kg4di/" + +mappings: + df_map: + sources: + access: $(output_dataframe) + referenceFormulation: DataFrame + structureDefiner: Pandas + softwareSpecification: + programmingLanguage: Python3.9 + softwareRequirements: “pandas>=1.1.0” + s: http://instagram.com/data/user{Id} + po: + - [a, insta:User] \ No newline at end of file diff --git a/test/rml-in-memory/IMTC002/mappings-new.rml.ttl b/test/rml-in-memory/IMTC002/mappings-new.rml.ttl new file mode 100644 index 0000000..1a44182 --- /dev/null +++ b/test/rml-in-memory/IMTC002/mappings-new.rml.ttl @@ -0,0 +1,36 @@ +@prefix insta: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rml:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "output_dataframe"; + ]; + rml:referenceFormulation ql:DataFrame; + ]; + rml:subjectMap [ + a rml:SubjectMap; + rml:template "http://instagram.com/data/user{Id}"; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant rdf:type; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:constant insta:User; + ]; + ]. + +ql:DataFrame a rml:ReferenceFormulation; + kg4di:definedBy "Pandas". \ No newline at end of file diff --git a/test/rml-in-memory/IMTC002/mappings.rml.ttl b/test/rml-in-memory/IMTC002/mappings.rml.ttl new file mode 100644 index 0000000..6eb2920 --- /dev/null +++ b/test/rml-in-memory/IMTC002/mappings.rml.ttl @@ -0,0 +1,37 @@ +@prefix insta: . +@prefix rr: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "output_dataframe"; + ]; + rml:referenceFormulation ql:DataFrame; + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "http://instagram.com/data/user{Id}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant insta:User; + ]; + ]. + +ql:DataFrame a rml:ReferenceFormulation; + kg4di:definedBy "Pandas". \ No newline at end of file diff --git a/test/rml-in-memory/IMTC002/mappings.yml b/test/rml-in-memory/IMTC002/mappings.yml new file mode 100644 index 0000000..cbb281c --- /dev/null +++ b/test/rml-in-memory/IMTC002/mappings.yml @@ -0,0 +1,20 @@ +prefixes: + insta: "http://instagram.com/data/" + rr: "http://www.w3.org/ns/r2rml#" + rml: "http://semweb.mmlab.be/ns/rml#" + 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#" + foaf: "http://xmlns.com/foaf/0.1/" + sd: "https://w3id.org/okn/o/sd/" + kg4di: "https://w3id.org/kg4di/" + +mappings: + df_map: + sources: + access: $(output_dataframe) + referenceFormulation: DataFrame + structureDefiner: Pandas + s: http://instagram.com/data/user{Id} + po: + - [a, insta:User] \ No newline at end of file diff --git a/test/rml-in-memory/IMTC003/mappings-new.rml.ttl b/test/rml-in-memory/IMTC003/mappings-new.rml.ttl new file mode 100644 index 0000000..1a44182 --- /dev/null +++ b/test/rml-in-memory/IMTC003/mappings-new.rml.ttl @@ -0,0 +1,36 @@ +@prefix insta: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rml:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "output_dataframe"; + ]; + rml:referenceFormulation ql:DataFrame; + ]; + rml:subjectMap [ + a rml:SubjectMap; + rml:template "http://instagram.com/data/user{Id}"; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant rdf:type; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:constant insta:User; + ]; + ]. + +ql:DataFrame a rml:ReferenceFormulation; + kg4di:definedBy "Pandas". \ No newline at end of file diff --git a/test/rml-in-memory/IMTC003/mappings.rml.ttl b/test/rml-in-memory/IMTC003/mappings.rml.ttl new file mode 100644 index 0000000..6eb2920 --- /dev/null +++ b/test/rml-in-memory/IMTC003/mappings.rml.ttl @@ -0,0 +1,37 @@ +@prefix insta: . +@prefix rr: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "output_dataframe"; + ]; + rml:referenceFormulation ql:DataFrame; + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "http://instagram.com/data/user{Id}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant insta:User; + ]; + ]. + +ql:DataFrame a rml:ReferenceFormulation; + kg4di:definedBy "Pandas". \ No newline at end of file diff --git a/test/rml-in-memory/IMTC003/mappings.yml b/test/rml-in-memory/IMTC003/mappings.yml new file mode 100644 index 0000000..3928ada --- /dev/null +++ b/test/rml-in-memory/IMTC003/mappings.yml @@ -0,0 +1,18 @@ +prefixes: + insta: "http://instagram.com/data/" + rr: "http://www.w3.org/ns/r2rml#" + rml: "http://semweb.mmlab.be/ns/rml#" + 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#" + foaf: "http://xmlns.com/foaf/0.1/" + sd: "https://w3id.org/okn/o/sd/" + kg4di: "https://w3id.org/kg4di/" + +mappings: + df_map: + sources: + - [$(output_dataframe)~Pandas-DataFrame] + s: http://instagram.com/data/user{Id} + po: + - [a, insta:User] \ No newline at end of file diff --git a/test/rml-in-memory/IMTC004/mappings-new.rml.ttl b/test/rml-in-memory/IMTC004/mappings-new.rml.ttl new file mode 100644 index 0000000..2779035 --- /dev/null +++ b/test/rml-in-memory/IMTC004/mappings-new.rml.ttl @@ -0,0 +1,42 @@ +@prefix insta: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rml:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "output_dict"; + sd:hasDataTransformation [ + sd:hasSourceCode [ + sd:programmingLanguage "Python3.9"; + ]; + ]; + ]; + rml:referenceFormulation ql:Dictionary; + rml:iterator "$.users[*]"; + ]; + rml:subjectMap [ + a rml:SubjectMap; + rml:template "http://instagram.com/data/user{id}"; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant rdf:type; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:constant insta:User; + ]; + ]. + +ql:Dictionary a rml:ReferenceFormulation; + kg4di:definedBy "Python". \ No newline at end of file diff --git a/test/rml-in-memory/IMTC004/mappings.rml.ttl b/test/rml-in-memory/IMTC004/mappings.rml.ttl new file mode 100644 index 0000000..34c6e92 --- /dev/null +++ b/test/rml-in-memory/IMTC004/mappings.rml.ttl @@ -0,0 +1,43 @@ +@prefix insta: . +@prefix rr: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "output_dict"; + sd:hasDataTransformation [ + sd:hasSourceCode [ + sd:programmingLanguage "Python3.9"; + ]; + ]; + ]; + rml:referenceFormulation ql:Dictionary; + rml:iterator "$.users[*]"; + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "http://instagram.com/data/user{id}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant insta:User; + ]; + ]. + +ql:Dictionary a rml:ReferenceFormulation; + kg4di:definedBy "Python". \ No newline at end of file diff --git a/test/rml-in-memory/IMTC004/mappings.yml b/test/rml-in-memory/IMTC004/mappings.yml new file mode 100644 index 0000000..80c8c15 --- /dev/null +++ b/test/rml-in-memory/IMTC004/mappings.yml @@ -0,0 +1,23 @@ +prefixes: + insta: "http://instagram.com/data/" + rr: "http://www.w3.org/ns/r2rml#" + rml: "http://semweb.mmlab.be/ns/rml#" + 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#" + foaf: "http://xmlns.com/foaf/0.1/" + sd: "https://w3id.org/okn/o/sd/" + kg4di: "https://w3id.org/kg4di/" + +mappings: + dict_map: + sources: + access: $(output_dict) + referenceFormulation: Dictionary + structureDefiner: Python + iterator: $.users[*] + softwareSpecification: + programmingLanguage: Python3.9 + s: http://instagram.com/data/user{Id} + po: + - [a, insta:User] \ No newline at end of file diff --git a/test/rml-in-memory/IMTC005/mappings-new.rml.ttl b/test/rml-in-memory/IMTC005/mappings-new.rml.ttl new file mode 100644 index 0000000..3953d07 --- /dev/null +++ b/test/rml-in-memory/IMTC005/mappings-new.rml.ttl @@ -0,0 +1,37 @@ +@prefix insta: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rml:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "output_dict"; + ]; + rml:referenceFormulation ql:Dictionary; + rml:iterator "$.users[*]"; + ]; + rml:subjectMap [ + a rml:SubjectMap; + rml:template "http://instagram.com/data/user{id}"; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant rdf:type; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:constant insta:User; + ]; + ]. + +ql:Dictionary a rml:ReferenceFormulation; + kg4di:definedBy "Python". \ No newline at end of file diff --git a/test/rml-in-memory/IMTC005/mappings.rml.ttl b/test/rml-in-memory/IMTC005/mappings.rml.ttl new file mode 100644 index 0000000..a80e050 --- /dev/null +++ b/test/rml-in-memory/IMTC005/mappings.rml.ttl @@ -0,0 +1,38 @@ +@prefix insta: . +@prefix rr: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "output_dict"; + ]; + rml:referenceFormulation ql:Dictionary; + rml:iterator "$.users[*]"; + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "http://instagram.com/data/user{id}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant insta:User; + ]; + ]. + +ql:Dictionary a rml:ReferenceFormulation; + kg4di:definedBy "Python". \ No newline at end of file diff --git a/test/rml-in-memory/IMTC005/mappings.yml b/test/rml-in-memory/IMTC005/mappings.yml new file mode 100644 index 0000000..38ed3f3 --- /dev/null +++ b/test/rml-in-memory/IMTC005/mappings.yml @@ -0,0 +1,18 @@ +prefixes: + insta: "http://instagram.com/data/" + rr: "http://www.w3.org/ns/r2rml#" + rml: "http://semweb.mmlab.be/ns/rml#" + 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#" + foaf: "http://xmlns.com/foaf/0.1/" + sd: "https://w3id.org/okn/o/sd/" + kg4di: "https://w3id.org/kg4di/" + +mappings: + dict_map: + sources: + - [$(output_dict)~Python-Dictionary, "$.users[*]"] + s: http://instagram.com/data/user{Id} + po: + - [a, insta:User] \ No newline at end of file diff --git a/test/rml-in-memory/IMTC006/mappings-new.rml.ttl b/test/rml-in-memory/IMTC006/mappings-new.rml.ttl new file mode 100644 index 0000000..ecc798e --- /dev/null +++ b/test/rml-in-memory/IMTC006/mappings-new.rml.ttl @@ -0,0 +1,95 @@ +@prefix insta: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rml:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "variable1"; + sd:hasDataTransformation [ + sd:hasSoftwareRequirements "pandas>=1.1.0"; + sd:hasSourceCode [ + sd:programmingLanguage "Python3.9"; + ]; + ]; + ]; + rml:referenceFormulation ql:DataFrame; + ]; + rml:subjectMap [ + a rml:SubjectMap; + rml:template "http://instagram.com/data/user{Id}"; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant rdf:type; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:constant insta:User; + ]; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant insta:username; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:reference "Username"; + ]; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant insta:name; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:template "{Name} {Surname}"; + rml:datatype rdfs:Literal + ]; + ]. + + + a rml:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "variable2"; + sd:hasDataTransformation [ + sd:hasSoftwareRequirements "pandas>=1.1.0"; + sd:hasSourceCode [ + sd:programmingLanguage "Python3.9"; + ]; + ]; + ]; + rml:referenceFormulation ql:DataFrame; + ]; + rml:subjectMap [ + a rml:SubjectMap; + rml:template "http://instagram.com/data/user{Id}"; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant insta:followersNumber; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:reference "Followers"; + ]; + ]. + +ql:DataFrame a rml:ReferenceFormulation; + kg4di:definedBy "Pandas". \ No newline at end of file diff --git a/test/rml-in-memory/IMTC006/mappings.rml.ttl b/test/rml-in-memory/IMTC006/mappings.rml.ttl new file mode 100644 index 0000000..5415dbb --- /dev/null +++ b/test/rml-in-memory/IMTC006/mappings.rml.ttl @@ -0,0 +1,96 @@ +@prefix insta: . +@prefix rr: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "variable1"; + sd:hasDataTransformation [ + sd:hasSoftwareRequirements "pandas>=1.1.0"; + sd:hasSourceCode [ + sd:programmingLanguage "Python3.9"; + ]; + ]; + ]; + rml:referenceFormulation ql:DataFrame; + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "http://instagram.com/data/user{Id}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant insta:User; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant insta:username; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "Username"; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant insta:name; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "{Name} {Surname}"; + rr:datatype rdfs:Literal + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "variable2"; + sd:hasDataTransformation [ + sd:hasSoftwareRequirements "pandas>=1.1.0"; + sd:hasSourceCode [ + sd:programmingLanguage "Python3.9"; + ]; + ]; + ]; + rml:referenceFormulation ql:DataFrame; + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "http://instagram.com/data/user{Id}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant insta:followersNumber; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "Followers"; + ]; + ]. + +ql:DataFrame a rml:ReferenceFormulation; + kg4di:definedBy "Pandas". \ No newline at end of file diff --git a/test/rml-in-memory/IMTC006/mappings.yml b/test/rml-in-memory/IMTC006/mappings.yml new file mode 100644 index 0000000..78ff649 --- /dev/null +++ b/test/rml-in-memory/IMTC006/mappings.yml @@ -0,0 +1,33 @@ +prefixes: + insta: "http://instagram.com/data/" + rr: "http://www.w3.org/ns/r2rml#" + rml: "http://semweb.mmlab.be/ns/rml#" + 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#" + foaf: "http://xmlns.com/foaf/0.1/" + sd: "https://w3id.org/okn/o/sd/" + kg4di: "https://w3id.org/kg4di/" + +mappings: + + df_map: + sources: + - access: $(variable1) + referenceFormulation: DataFrame + structureDefiner: Pandas + softwareSpecification: + programmingLanguage: Python3.9 + softwareRequirements: “pandas>=1.1.0” + - access: $(variable2) + referenceFormulation: DataFrame + structureDefiner: Pandas + softwareSpecification: + programmingLanguage: Python3.9 + softwareRequirements: “pandas>=1.1.0” + s: http://instagram.com/data/user{Id} + po: + - [a, insta:User] + - [insta:username, $(Username)] + - [insta:name, "$(Name) $(Surname)"] + - [insta:followersNumber, $(Followers)] diff --git a/test/rml-in-memory/IMTC007/mappings-new.rml.ttl b/test/rml-in-memory/IMTC007/mappings-new.rml.ttl new file mode 100644 index 0000000..9e4fb4e --- /dev/null +++ b/test/rml-in-memory/IMTC007/mappings-new.rml.ttl @@ -0,0 +1,96 @@ +@prefix insta: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rml:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "variable1"; + sd:hasDataTransformation [ + sd:hasSourceCode [ + sd:programmingLanguage "Python3.9"; + ]; + ]; + ]; + rml:referenceFormulation ql:Dictionary; + rml:iterator "$.users[*]"; + ]; + rml:subjectMap [ + a rml:SubjectMap; + rml:template "http://instagram.com/data/user{Id}"; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant rdf:type; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:constant insta:User; + ]; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant insta:username; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:reference "Username"; + ]; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant insta:name; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:template "{Name} {Surname}"; + rml:datatype rdfs:Literal + ]; + ]. + + + a rml:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "variable2"; + sd:hasDataTransformation [ + sd:hasSourceCode [ + sd:programmingLanguage "Python3.9"; + ]; + ]; + ]; + rml:referenceFormulation ql:Dictionary; + rml:iterator "$.followers[*]"; + ]; + rml:subjectMap [ + a rml:SubjectMap; + rml:template "http://instagram.com/data/user{Id}"; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant insta:follows; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:template "http://instagram.com/data/user{Follows}"; + rml:termType rml:IRI + ]; + ]. + +ql:Dictionary a rml:ReferenceFormulation; + kg4di:definedBy "Python". diff --git a/test/rml-in-memory/IMTC007/mappings.rml.ttl b/test/rml-in-memory/IMTC007/mappings.rml.ttl new file mode 100644 index 0000000..54c6afe --- /dev/null +++ b/test/rml-in-memory/IMTC007/mappings.rml.ttl @@ -0,0 +1,97 @@ +@prefix insta: . +@prefix rr: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "variable1"; + sd:hasDataTransformation [ + sd:hasSourceCode [ + sd:programmingLanguage "Python3.9"; + ]; + ]; + ]; + rml:referenceFormulation ql:Dictionary; + rml:iterator "$.users[*]"; + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "http://instagram.com/data/user{Id}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant insta:User; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant insta:username; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "Username"; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant insta:name; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "{Name} {Surname}"; + rr:datatype rdfs:Literal + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "variable2"; + sd:hasDataTransformation [ + sd:hasSourceCode [ + sd:programmingLanguage "Python3.9"; + ]; + ]; + ]; + rml:referenceFormulation ql:Dictionary; + rml:iterator "$.followers[*]"; + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "http://instagram.com/data/user{Id}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant insta:follows; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "http://instagram.com/data/user{Follows}"; + rr:termType rr:IRI + ]; + ]. + +ql:Dictionary a rml:ReferenceFormulation; + kg4di:definedBy "Python". diff --git a/test/rml-in-memory/IMTC007/mappings.yml b/test/rml-in-memory/IMTC007/mappings.yml new file mode 100644 index 0000000..bc5ec84 --- /dev/null +++ b/test/rml-in-memory/IMTC007/mappings.yml @@ -0,0 +1,33 @@ +prefixes: + insta: "http://instagram.com/data/" + rr: "http://www.w3.org/ns/r2rml#" + rml: "http://semweb.mmlab.be/ns/rml#" + 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#" + foaf: "http://xmlns.com/foaf/0.1/" + sd: "https://w3id.org/okn/o/sd/" + kg4di: "https://w3id.org/kg4di/" + +mappings: + + df_map: + sources: + - access: $(variable1) + referenceFormulation: Dictionary + structureDefiner: Python + iterator: $.users[*] + softwareSpecification: + programmingLanguage: Python3.9 + - access: $(variable2) + referenceFormulation: Dictionary + structureDefiner: Python + iterator: $.followers[*] + softwareSpecification: + programmingLanguage: Python3.9 + s: http://instagram.com/data/user{Id} + po: + - [a, insta:User] + - [insta:username, $(Username)] + - [insta:name, "$(Name) $(Surname)"] + - [insta:follows, http://instagram.com/data/user${Follows}~iri] diff --git a/test/rml-in-memory/IMTC008/mappings-new.rml.ttl b/test/rml-in-memory/IMTC008/mappings-new.rml.ttl new file mode 100644 index 0000000..d66c7f2 --- /dev/null +++ b/test/rml-in-memory/IMTC008/mappings-new.rml.ttl @@ -0,0 +1,88 @@ +@prefix insta: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rml:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "variable1"; + sd:hasDataTransformation [ + sd:hasSourceCode [ + sd:programmingLanguage "Python3.9"; + ]; + ]; + ]; + rml:referenceFormulation ql:Dictionary; + rml:iterator "$.users[*]"; + ]; + rml:subjectMap [ + a rml:SubjectMap; + rml:template "http://instagram.com/data/user{Id}"; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant rdf:type; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:constant insta:User; + ]; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant insta:username; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:reference "Username"; + ]; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant insta:name; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:template "{Name} {Surname}"; + rml:datatype rdfs:Literal + ]; + ]. + + + a rml:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "followers.json"; + rml:referenceFormulation ql:JSONPath; + rml:iterator "$.followers[*]"; + ]; + rml:subjectMap [ + a rml:SubjectMap; + rml:template "http://instagram.com/data/user{Id}"; + ]; + rml:predicateObjectMap [ + rml:predicateMap [ + a rml:PredicateMap; + rml:constant insta:follows; + ]; + rml:objectMap [ + a rml:ObjectMap; + rml:template "http://instagram.com/data/user{Follows}"; + rml:termType rml:IRI + ]; + ]. + +ql:Dictionary a rml:ReferenceFormulation; + kg4di:definedBy "Python". diff --git a/test/rml-in-memory/IMTC008/mappings.rml.ttl b/test/rml-in-memory/IMTC008/mappings.rml.ttl new file mode 100644 index 0000000..e64944a --- /dev/null +++ b/test/rml-in-memory/IMTC008/mappings.rml.ttl @@ -0,0 +1,89 @@ +@prefix insta: . +@prefix rr: . +@prefix rml: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix sd: . +@prefix kg4di: . + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source [ + a sd:DatasetSpecification; + sd:name "variable1"; + sd:hasDataTransformation [ + sd:hasSourceCode [ + sd:programmingLanguage "Python3.9"; + ]; + ]; + ]; + rml:referenceFormulation ql:Dictionary; + rml:iterator "$.users[*]"; + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "http://instagram.com/data/user{Id}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant rdf:type; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:constant insta:User; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant insta:username; + ]; + rr:objectMap [ + a rr:ObjectMap; + rml:reference "Username"; + ]; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant insta:name; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "{Name} {Surname}"; + rr:datatype rdfs:Literal + ]; + ]. + + + a rr:TriplesMap; + + rml:logicalSource [ + a rml:LogicalSource; + rml:source "followers.json"; + rml:referenceFormulation ql:JSONPath; + rml:iterator "$.followers[*]"; + ]; + rr:subjectMap [ + a rr:SubjectMap; + rr:template "http://instagram.com/data/user{Id}"; + ]; + rr:predicateObjectMap [ + rr:predicateMap [ + a rr:PredicateMap; + rr:constant insta:follows; + ]; + rr:objectMap [ + a rr:ObjectMap; + rr:template "http://instagram.com/data/user{Follows}"; + rr:termType rr:IRI + ]; + ]. + +ql:Dictionary a rml:ReferenceFormulation; + kg4di:definedBy "Python". diff --git a/test/rml-in-memory/IMTC008/mappings.yml b/test/rml-in-memory/IMTC008/mappings.yml new file mode 100644 index 0000000..ce19422 --- /dev/null +++ b/test/rml-in-memory/IMTC008/mappings.yml @@ -0,0 +1,28 @@ +prefixes: + insta: "http://instagram.com/data/" + rr: "http://www.w3.org/ns/r2rml#" + rml: "http://semweb.mmlab.be/ns/rml#" + 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#" + foaf: "http://xmlns.com/foaf/0.1/" + sd: "https://w3id.org/okn/o/sd/" + kg4di: "https://w3id.org/kg4di/" + +mappings: + + df_map: + sources: + - access: $(variable1) + referenceFormulation: Dictionary + structureDefiner: Python + iterator: $.users[*] + softwareSpecification: + programmingLanguage: Python3.9 + - source: [followersperson.json~jsonpath, "$.followers[*]"] + s: http://instagram.com/data/user{Id} + po: + - [a, insta:User] + - [insta:username, $(Username)] + - [insta:name, "$(Name) $(Surname)"] + - [insta:follows, http://instagram.com/data/user${Follows}~iri] From c35a8a7d7822ac8d22987813119ffaee6648e26e Mon Sep 17 00:00:00 2001 From: Ioannis Dasoulas <49875599+TheRazorace@users.noreply.github.com> Date: Wed, 28 Jun 2023 11:56:18 +0200 Subject: [PATCH 8/8] Create Description.md --- test/rml-in-memory/Description.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/rml-in-memory/Description.md diff --git a/test/rml-in-memory/Description.md b/test/rml-in-memory/Description.md new file mode 100644 index 0000000..2003f2c --- /dev/null +++ b/test/rml-in-memory/Description.md @@ -0,0 +1,18 @@ +# In-Memory YARRRML +Syntax proposal test cases for in-memory YARRRML. + +IMTC001: Pandas dataframe as source + +IMTC002: Pandas dataframe as source without specifying software characteristics + +IMTC003: Pandas dataframe as source without specifying software characteristics - short version + +IMTC004: Python dictionary as source + +IMTC005: Python dictionary as source without specifying software characteristics - short version + +IMTC006: Multiple Pandas dataframes as sources + +IMTC007: Multiple Python dictionaries as sources + +IMTC008: Combination of in-memory and localy stored source