From d8dff7a655a4f59a1b1f6f019150f29a5eece136 Mon Sep 17 00:00:00 2001 From: eiglesias34 Date: Tue, 10 Sep 2024 17:01:35 +0200 Subject: [PATCH] Fixed issue with constants in object map --- README.md | 2 +- VERSION | 2 +- rdfizer/rdfizer/__init__.py | 11 ++++++----- rdfizer/rdfizer/functions.py | 15 ++++++++++++++- rdfizer/rdfizer/semantify.py | 11 ++++++----- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 685ee22..9813edb 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ You can easily customize your own configurations from the set of features that S ## Version ``` -4.7.4.9 +4.7.4.10 ``` ## RML-Test Cases diff --git a/VERSION b/VERSION index 0a8d53b..373605f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.7.4.9 \ No newline at end of file +4.7.4.10 \ No newline at end of file diff --git a/rdfizer/rdfizer/__init__.py b/rdfizer/rdfizer/__init__.py index 536bf96..3384b03 100755 --- a/rdfizer/rdfizer/__init__.py +++ b/rdfizer/rdfizer/__init__.py @@ -2153,6 +2153,7 @@ def mapping_parser(mapping_file): result_predicate_object_map.datatype_value, "None") predicate_object_maps_list += [ tm.PredicateObjectMap(join_predicate[jp]["predicate"], object_map, predicate_object_graph)] + predicate_object_maps_list = remove_duplicate_po(predicate_object_maps_list) if result_triples_map.url_source is not None: if result_triples_map.delimiter is not None: url_source = str(result_triples_map.url_source)[7:] if str(result_triples_map.url_source)[:7] == "file://" else str(result_triples_map.url_source) @@ -2608,7 +2609,7 @@ def semantify_xml(triples_map, triples_map_list, output_file_descriptor): predicate = None if predicate_object_map.object_map.mapping_type == "constant" or predicate_object_map.object_map.mapping_type == "constant shortcut": - if "/" in predicate_object_map.object_map.value: + if "http" in predicate_object_map.object_map.value: object = "<" + predicate_object_map.object_map.value + ">" else: object = "\"" + predicate_object_map.object_map.value + "\"" @@ -3597,7 +3598,7 @@ def semantify_json(triples_map, triples_map_list, delimiter, output_file_descrip predicate = None if predicate_object_map.object_map.mapping_type == "constant" or predicate_object_map.object_map.mapping_type == "constant shortcut": - if "/" in predicate_object_map.object_map.value: + if "http" in predicate_object_map.object_map.value: object = "<" + predicate_object_map.object_map.value + ">" else: object = "\"" + predicate_object_map.object_map.value + "\"" @@ -4801,7 +4802,7 @@ def semantify_file(triples_map, triples_map_list, delimiter, output_file_descrip predicate = None if predicate_object_map.object_map.mapping_type == "constant" or predicate_object_map.object_map.mapping_type == "constant shortcut": - if "/" in predicate_object_map.object_map.value: + if "http" in predicate_object_map.object_map.value: object = "<" + predicate_object_map.object_map.value + ">" else: object = "\"" + predicate_object_map.object_map.value + "\"" @@ -6411,7 +6412,7 @@ def semantify_mysql(row, row_headers, triples_map, triples_map_list, output_file predicate = None if predicate_object_map.object_map.mapping_type == "constant" or predicate_object_map.object_map.mapping_type == "constant shortcut": - if "/" in predicate_object_map.object_map.value: + if "http" in predicate_object_map.object_map.value: object = "<" + predicate_object_map.object_map.value + ">" else: object = "\"" + predicate_object_map.object_map.value + "\"" @@ -7301,7 +7302,7 @@ def semantify_postgres(row, row_headers, triples_map, triples_map_list, output_f predicate = None if predicate_object_map.object_map.mapping_type == "constant" or predicate_object_map.object_map.mapping_type == "constant shortcut": - if "/" in predicate_object_map.object_map.value: + if "http" in predicate_object_map.object_map.value: object = "<" + predicate_object_map.object_map.value + ">" else: object = "\"" + predicate_object_map.object_map.value + "\"" diff --git a/rdfizer/rdfizer/functions.py b/rdfizer/rdfizer/functions.py index ceb59e4..9403e98 100644 --- a/rdfizer/rdfizer/functions.py +++ b/rdfizer/rdfizer/functions.py @@ -1903,4 +1903,17 @@ def condition_separetor(string): condition_field = string.split("[") field = condition_field[1][:len(condition_field[1])-1].split("=")[0] value = condition_field[1][:len(condition_field[1])-1].split("=")[1] - return field, value \ No newline at end of file + return field, value + +def remove_duplicate_po(po_list): + unique_list = [] + for po in po_list: + if unique_list == []: + unique_list.append(po) + else: + for po_unique in unique_list: + if po.predicate_map.value == po_unique.predicate_map.value and po.object_map.value == po_unique.object_map.value: + break + else: + unique_list.append(po) + return unique_list \ No newline at end of file diff --git a/rdfizer/rdfizer/semantify.py b/rdfizer/rdfizer/semantify.py index 47ee069..1de27f8 100755 --- a/rdfizer/rdfizer/semantify.py +++ b/rdfizer/rdfizer/semantify.py @@ -2153,6 +2153,7 @@ def mapping_parser(mapping_file): result_predicate_object_map.datatype_value, "None") predicate_object_maps_list += [ tm.PredicateObjectMap(join_predicate[jp]["predicate"], object_map, predicate_object_graph)] + predicate_object_maps_list = remove_duplicate_po(predicate_object_maps_list) if result_triples_map.url_source is not None: if result_triples_map.delimiter is not None: url_source = str(result_triples_map.url_source)[7:] if str(result_triples_map.url_source)[:7] == "file://" else str(result_triples_map.url_source) @@ -2608,7 +2609,7 @@ def semantify_xml(triples_map, triples_map_list, output_file_descriptor): predicate = None if predicate_object_map.object_map.mapping_type == "constant" or predicate_object_map.object_map.mapping_type == "constant shortcut": - if "/" in predicate_object_map.object_map.value: + if "http" in predicate_object_map.object_map.value: object = "<" + predicate_object_map.object_map.value + ">" else: object = "\"" + predicate_object_map.object_map.value + "\"" @@ -3597,7 +3598,7 @@ def semantify_json(triples_map, triples_map_list, delimiter, output_file_descrip predicate = None if predicate_object_map.object_map.mapping_type == "constant" or predicate_object_map.object_map.mapping_type == "constant shortcut": - if "/" in predicate_object_map.object_map.value: + if "http" in predicate_object_map.object_map.value: object = "<" + predicate_object_map.object_map.value + ">" else: object = "\"" + predicate_object_map.object_map.value + "\"" @@ -4801,7 +4802,7 @@ def semantify_file(triples_map, triples_map_list, delimiter, output_file_descrip predicate = None if predicate_object_map.object_map.mapping_type == "constant" or predicate_object_map.object_map.mapping_type == "constant shortcut": - if "/" in predicate_object_map.object_map.value: + if "http" in predicate_object_map.object_map.value: object = "<" + predicate_object_map.object_map.value + ">" else: object = "\"" + predicate_object_map.object_map.value + "\"" @@ -6411,7 +6412,7 @@ def semantify_mysql(row, row_headers, triples_map, triples_map_list, output_file predicate = None if predicate_object_map.object_map.mapping_type == "constant" or predicate_object_map.object_map.mapping_type == "constant shortcut": - if "/" in predicate_object_map.object_map.value: + if "http" in predicate_object_map.object_map.value: object = "<" + predicate_object_map.object_map.value + ">" else: object = "\"" + predicate_object_map.object_map.value + "\"" @@ -7301,7 +7302,7 @@ def semantify_postgres(row, row_headers, triples_map, triples_map_list, output_f predicate = None if predicate_object_map.object_map.mapping_type == "constant" or predicate_object_map.object_map.mapping_type == "constant shortcut": - if "/" in predicate_object_map.object_map.value: + if "http" in predicate_object_map.object_map.value: object = "<" + predicate_object_map.object_map.value + ">" else: object = "\"" + predicate_object_map.object_map.value + "\""