From b7dc63a01242a49e4c76070c3d68096e7b60ce2f Mon Sep 17 00:00:00 2001 From: dachafra Date: Thu, 13 Jun 2024 18:26:17 +0200 Subject: [PATCH 1/2] allowing non-constant predicates for inverse translation --- src/yatter/__main__.py | 6 ++++-- src/yatter/predicateobject.py | 10 ++++------ test/r2rml/INVERSETC-0005/mapping.yml | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/yatter/__main__.py b/src/yatter/__main__.py index 4b71d8c..5cb9e92 100644 --- a/src/yatter/__main__.py +++ b/src/yatter/__main__.py @@ -5,8 +5,8 @@ from . import translate, inverse_translation, merge_mappings from .constants import * -def write_results(mapping): +def write_results(mapping): if type(mapping) is str: output_file = open(args.output_mapping_path, "w") output_file.write(mapping) @@ -18,6 +18,7 @@ def write_results(mapping): yaml.default_flow_style = False yaml.dump(mapping, f) + def parse_inputs(): input_format = RML_URI yaml = YAML(typ='safe', pure=True) @@ -25,7 +26,8 @@ def parse_inputs(): if args.input_mapping_path.endswith('.yml') or args.input_mapping_path.endswith('.yaml'): with open(args.input_mapping_path) as f: input_data = yaml.load(f) - elif args.input_mapping_path.endswith('.ttl') or args.input_mapping_path.endswith('.rml') or args.input_mapping_path.endswith('.r2rml'): + elif args.input_mapping_path.endswith('.ttl') or args.input_mapping_path.endswith( + '.rml') or args.input_mapping_path.endswith('.r2rml'): input_data = Graph() input_data.parse(args.input_mapping_path, format="turtle") else: diff --git a/src/yatter/predicateobject.py b/src/yatter/predicateobject.py index 7ddb90f..bc2434b 100644 --- a/src/yatter/predicateobject.py +++ b/src/yatter/predicateobject.py @@ -372,15 +372,13 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes): 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: + if not predicate.startswith("http"): predicate = '$(' + predicate + ')' - elif "{" in predicate and "}" in predicate: + elif predicate.startswith("http") and "{" not in predicate: + predicate = find_prefixes(predicate, prefixes) + else: predicate = predicate.replace('{', '$(').replace('}', ')') - elif prefix: - predicate = tm['predicateValue'].toPython().replace(prefixes[prefix[0]], prefix[0] + ":") - predicate = find_prefixes(predicate,prefixes) if tm['parentTriplesMap']: if tm['child']: diff --git a/test/r2rml/INVERSETC-0005/mapping.yml b/test/r2rml/INVERSETC-0005/mapping.yml index 8a4a4da..2d99a82 100644 --- a/test/r2rml/INVERSETC-0005/mapping.yml +++ b/test/r2rml/INVERSETC-0005/mapping.yml @@ -46,5 +46,5 @@ mappings: s: http://example.com/Patient/$(ID) po: - [rdf:type, foaf:Person] - - [ex:$(last_name), $(LastName), xsd:string] + - [http://example.com/$(last_name), $(LastName), xsd:string] - [ex:height, http://example.com/$(Height)] From d1cdabce605f49426ba4cbe8485342cd519d8d7f Mon Sep 17 00:00:00 2001 From: dachafra Date: Wed, 17 Jul 2024 12:36:06 +0200 Subject: [PATCH 2/2] solving #83 --- src/yatter/subject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yatter/subject.py b/src/yatter/subject.py index 3b28037..9934c85 100644 --- a/src/yatter/subject.py +++ b/src/yatter/subject.py @@ -54,7 +54,7 @@ def add_subject(data, mapping, mapping_format): if YARRRML_TARGETS in individual_subject: subject_termmap = subject_termmap[0:-3]+"\t"+RML_LOGICAL_TARGET+" <"+individual_subject[YARRRML_TARGETS]+">\n\t];\n" - if YARRRML_TYPE in individual_subject: + if isinstance(individual_subject, dict) and YARRRML_TYPE in individual_subject: if individual_subject.get(YARRRML_TYPE) == YARRRML_BLANK: subject_termmap = subject_termmap[0:-3] + "\t" + R2RML_TERMTYPE + " " + R2RML_BLANK_NODE +"\n\t];\n"