From 9b2a0f448c49ddc35fc155a87c8661d04079dc96 Mon Sep 17 00:00:00 2001 From: dachafra Date: Wed, 8 Jan 2025 13:51:13 +0100 Subject: [PATCH] solving problems with in_memory --- src/yatter/__init__.py | 7 +++--- src/yatter/normalization.py | 35 ++++++++++++++++++++------- src/yatter/predicateobject.py | 4 +-- src/yatter/source.py | 1 + test/r2rml/INVERSETC-0005/mapping.yml | 2 +- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/yatter/__init__.py b/src/yatter/__init__.py index 97fe4f6..2807873 100644 --- a/src/yatter/__init__.py +++ b/src/yatter/__init__.py @@ -19,14 +19,14 @@ def translate(yarrrml_data, mapping_format=RML_URI): rml_mapping.extend(generate_database_connections(yarrrml_data, external_sources)) rml_mapping.extend(add_logical_targets(yarrrml_data, external_targets)) rml_mapping.extend(add_functions(yarrrml_data)) - + external_references = [] try: mappings, mapping_format = get_non_asserted_mappings(yarrrml_data, mapping_format) for mapping in yarrrml_data.get(YARRRML_MAPPINGS): if mapping_format == R2RML_URI: source_list = add_table(yarrrml_data, mapping) else: - source_list = add_source(yarrrml_data, mapping, external_sources) + source_list, external_references = add_source(yarrrml_data, mapping, external_sources) subject_list = add_subject(yarrrml_data, mapping, mapping_format) pred = add_predicate_object_maps(yarrrml_data, mapping, mapping_format) it = 0 @@ -40,7 +40,8 @@ def translate(yarrrml_data, mapping_format=RML_URI): rml_mapping[len(rml_mapping) - 1] = rml_mapping[len(rml_mapping) - 1][:-2] rml_mapping.append(".\n\n\n") it = it + 1 - external_refs = list(dict.fromkeys(external_refs)) + + external_refs = list(dict.fromkeys(external_references)) for ref in external_refs: rml_mapping.append(ref) diff --git a/src/yatter/normalization.py b/src/yatter/normalization.py index 5587c18..c9de671 100644 --- a/src/yatter/normalization.py +++ b/src/yatter/normalization.py @@ -94,17 +94,34 @@ def expand_source_item(source): if isinstance(source, list): if len(source) == 2 and isinstance(source[0], str) and '~' in source[0]: access, reference = source[0].split('~') - return { - YARRRML_ACCESS: access, - YARRRML_REFERENCE_FORMULATION: reference, - YARRRML_ITERATOR: source[1] - } + if '-' in reference: + reference = reference.split('-') + return { + YARRRML_ACCESS: access, + YARRRML_REFERENCE_FORMULATION: reference[1], + YARRRML_STRUCTURE_DEFINER: reference[0], + YARRRML_ITERATOR: source[1] + } + else: + return { + YARRRML_ACCESS: access, + YARRRML_REFERENCE_FORMULATION: reference, + YARRRML_ITERATOR: source[1] + } elif len(source) == 1 and isinstance(source[0], str) and '~' in source[0]: access, reference = source[0].split('~') - return { - YARRRML_ACCESS: access, - YARRRML_REFERENCE_FORMULATION: reference - } + if '-' in reference: + reference = reference.split('-') + return { + YARRRML_ACCESS: access, + YARRRML_REFERENCE_FORMULATION: reference[1] , + YARRRML_STRUCTURE_DEFINER: reference[0], + } + else: + return { + YARRRML_ACCESS: access, + YARRRML_REFERENCE_FORMULATION: reference, + } elif isinstance(source, dict): for key, val in source.items(): if isinstance(val, list) and len(val) == 2 and '~' in val[0]: diff --git a/src/yatter/predicateobject.py b/src/yatter/predicateobject.py index 9cf70f1..8819282 100644 --- a/src/yatter/predicateobject.py +++ b/src/yatter/predicateobject.py @@ -201,7 +201,7 @@ def ref_mapping(data, mapping, om, yarrrml_key, ref_type_property, mapping_forma else: if mapping_format == STAR_URI: object = STAR_OBJECT - source_list = add_source(data, mapping_join) + source_list, external_references = add_source(data, mapping_join) number_joins_rml = len(subject_list) * len(source_list) for i in range(number_joins_rml): @@ -259,7 +259,7 @@ def ref_cc_mapping(data, mapping, om, yarrrml_key, ref_type_property, mapping_fo else: if mapping_format == STAR_URI: object = STAR_OBJECT - source_list = add_source(data, mapping_join) + source_list, external_references = add_source(data, mapping_join) number_joins_rml = len(subject_list) * len(source_list) for i in range(number_joins_rml): diff --git a/src/yatter/source.py b/src/yatter/source.py index d3d921b..cfd4d58 100644 --- a/src/yatter/source.py +++ b/src/yatter/source.py @@ -12,6 +12,7 @@ def add_source(data, mapping, external_sources={}): ";\n\t\t" + RML_SOURCE + " " final_list = [] sources = data.get(YARRRML_MAPPINGS).get(mapping).get(YARRRML_SOURCES) + external_references_list = [] for source in sources: db_identifier = mapping for external_Source in external_sources: diff --git a/test/r2rml/INVERSETC-0005/mapping.yml b/test/r2rml/INVERSETC-0005/mapping.yml index 2d99a82..8a4a4da 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] - - [http://example.com/$(last_name), $(LastName), xsd:string] + - [ex:$(last_name), $(LastName), xsd:string] - [ex:height, http://example.com/$(Height)]