Skip to content

Commit

Permalink
Added language map
Browse files Browse the repository at this point in the history
  • Loading branch information
eiglesias34 committed May 10, 2022
1 parent eea976e commit 6735592
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ You can easily customize your own configurations from the set of features that S

## Version
```
4.4.4.1
4.5
```

## RML-Test Cases
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.4.4.1
4.5
93 changes: 87 additions & 6 deletions rdfizer/rdfizer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ def mapping_parser(mapping_file):
?_predicate_object_map rr:objectMap ?_object_map .
?_object_map rr:template ?object_template .
OPTIONAL {?_object_map rr:termType ?term .}
OPTIONAL {?_object_map rml:languageMap ?language_map.
?language_map rml:reference ?language_value.}
OPTIONAL {
?_object_map rr:datatype ?object_datatype .
}
Expand All @@ -628,6 +630,8 @@ def mapping_parser(mapping_file):
?_predicate_object_map rr:objectMap ?_object_map .
?_object_map rml:reference ?object_reference .
OPTIONAL { ?_object_map rr:language ?language .}
OPTIONAL {?_object_map rml:languageMap ?language_map.
?language_map rml:reference ?language_value.}
OPTIONAL {?_object_map rr:termType ?term .}
OPTIONAL {
?_object_map rr:datatype ?object_datatype .
Expand Down Expand Up @@ -719,11 +723,11 @@ def mapping_parser(mapping_file):
predicate_map = tm.PredicateMap("None", "None", "None")

if result_predicate_object_map.object_constant is not None:
object_map = tm.ObjectMap("constant", str(result_predicate_object_map.object_constant), str(result_predicate_object_map.object_datatype), "None", "None", result_predicate_object_map.term, result_predicate_object_map.language)
object_map = tm.ObjectMap("constant", str(result_predicate_object_map.object_constant), str(result_predicate_object_map.object_datatype), "None", "None", result_predicate_object_map.term, result_predicate_object_map.language,result_predicate_object_map.language_value)
elif result_predicate_object_map.object_template is not None:
object_map = tm.ObjectMap("template", str(result_predicate_object_map.object_template), str(result_predicate_object_map.object_datatype), "None", "None", result_predicate_object_map.term, result_predicate_object_map.language)
object_map = tm.ObjectMap("template", str(result_predicate_object_map.object_template), str(result_predicate_object_map.object_datatype), "None", "None", result_predicate_object_map.term, result_predicate_object_map.language,result_predicate_object_map.language_value)
elif result_predicate_object_map.object_reference is not None:
object_map = tm.ObjectMap("reference", str(result_predicate_object_map.object_reference), str(result_predicate_object_map.object_datatype), "None", "None", result_predicate_object_map.term, result_predicate_object_map.language)
object_map = tm.ObjectMap("reference", str(result_predicate_object_map.object_reference), str(result_predicate_object_map.object_datatype), "None", "None", result_predicate_object_map.term, result_predicate_object_map.language,result_predicate_object_map.language_value)
elif result_predicate_object_map.object_parent_triples_map is not None:
if predicate_map.value + " " + str(result_predicate_object_map.object_parent_triples_map) not in join_predicate:
join_predicate[predicate_map.value + " " + str(result_predicate_object_map.object_parent_triples_map)] = {"predicate":predicate_map, "childs":[str(result_predicate_object_map.child_value)], "parents":[str(result_predicate_object_map.parent_value)], "triples_map":str(result_predicate_object_map.object_parent_triples_map)}
Expand All @@ -732,15 +736,15 @@ def mapping_parser(mapping_file):
join_predicate[predicate_map.value + " " + str(result_predicate_object_map.object_parent_triples_map)]["parents"].append(str(result_predicate_object_map.parent_value))
join = False
elif result_predicate_object_map.object_constant_shortcut is not None:
object_map = tm.ObjectMap("constant shortcut", str(result_predicate_object_map.object_constant_shortcut), "None", "None", "None", result_predicate_object_map.term, result_predicate_object_map.language)
object_map = tm.ObjectMap("constant shortcut", str(result_predicate_object_map.object_constant_shortcut), "None", "None", "None", result_predicate_object_map.term, result_predicate_object_map.language,result_predicate_object_map.language_value)
else:
object_map = tm.ObjectMap("None", "None", "None", "None", "None", "None", "None")
object_map = tm.ObjectMap("None", "None", "None", "None", "None", "None", "None", "None")
if join:
predicate_object_maps_list += [tm.PredicateObjectMap(predicate_map, object_map,predicate_object_graph)]
join = True
if join_predicate:
for jp in join_predicate.keys():
object_map = tm.ObjectMap("parent triples map", join_predicate[jp]["triples_map"], str(result_predicate_object_map.object_datatype), join_predicate[jp]["childs"], join_predicate[jp]["parents"],result_predicate_object_map.term, result_predicate_object_map.language)
object_map = tm.ObjectMap("parent triples map", join_predicate[jp]["triples_map"], str(result_predicate_object_map.object_datatype), join_predicate[jp]["childs"], join_predicate[jp]["parents"],result_predicate_object_map.term, result_predicate_object_map.language,result_predicate_object_map.language_value)
predicate_object_maps_list += [tm.PredicateObjectMap(join_predicate[jp]["predicate"], object_map,predicate_object_graph)]

current_triples_map = tm.TriplesMap(str(result_triples_map.triples_map_id), str(result_triples_map.data_source), subject_map, predicate_object_maps_list, ref_form=str(result_triples_map.ref_form), iterator=str(result_triples_map.iterator), tablename=str(result_triples_map.tablename), query=str(result_triples_map.query))
Expand Down Expand Up @@ -995,6 +999,15 @@ def semantify_xml(triples_map, triples_map_list, output_file_descriptor, csv_fil
object[i] = "\"" + object[i] + "\""
if predicate_object_map.object_map.datatype is not None:
object[i] = "\"" + object[i][1:-1] + "\"" + "^^<{}>".format(predicate_object_map.object_map.datatype)
elif predicate_object_map.object_map.language is not None:
if "spanish" in predicate_object_map.object_map.language or "es" in predicate_object_map.object_map.language :
object[i] += "@es"
elif "english" in predicate_object_map.object_map.language or "en" in predicate_object_map.object_map.language :
object[i] += "@en"
elif len(predicate_object_map.object_map.language) == 2:
object[i] += "@"+predicate_object_map.object_map.language
elif predicate_object_map.object_map.language_map is not None:
object[i] += "@" + string_substitution_xml(predicate_object_map.object_map.language_map, ".+", child, "object", triples_map.iterator, parent_map, namespace)[1:-1]
else:
if predicate_object_map.object_map.term is None:
object = "<" + object + ">"
Expand All @@ -1004,6 +1017,15 @@ def semantify_xml(triples_map, triples_map_list, output_file_descriptor, csv_fil
object = "\"" + object + "\""
if predicate_object_map.object_map.datatype is not None:
object = "\"" + object[1:-1] + "\"" + "^^<{}>".format(predicate_object_map.object_map.datatype)
elif predicate_object_map.object_map.language is not None:
if "spanish" in predicate_object_map.object_map.language or "es" in predicate_object_map.object_map.language :
object += "@es"
elif "english" in predicate_object_map.object_map.language or "en" in predicate_object_map.object_map.language :
object += "@en"
elif len(predicate_object_map.object_map.language) == 2:
object += "@"+predicate_object_map.object_map.language
elif predicate_object_map.object_map.language_map is not None:
object += "@" + string_substitution_xml(predicate_object_map.object_map.language_map, ".+", child, "object", triples_map.iterator, parent_map, namespace)[1:-1]
elif predicate_object_map.object_map.mapping_type == "reference":
object = string_substitution_xml(predicate_object_map.object_map.value, ".+", child, "object", triples_map.iterator, parent_map, namespace)
if object is not None:
Expand All @@ -1022,6 +1044,8 @@ def semantify_xml(triples_map, triples_map_list, output_file_descriptor, csv_fil
object[i] += "@en"
elif len(predicate_object_map.object_map.language) == 2:
object[i] += "@"+predicate_object_map.object_map.language
elif predicate_object_map.object_map.language_map is not None:
object[i] += "@"+ string_substitution_xml(predicate_object_map.object_map.language_map, ".+", child, "object", triples_map.iterator, parent_map, namespace)[1:-1]
elif predicate_object_map.object_map.term is not None:
if "IRI" in predicate_object_map.object_map.term:
if " " not in object:
Expand All @@ -1043,6 +1067,8 @@ def semantify_xml(triples_map, triples_map_list, output_file_descriptor, csv_fil
object += "@en"
elif len(predicate_object_map.object_map.language) == 2:
object += "@"+predicate_object_map.object_map.language
elif predicate_object_map.object_map.language_map is not None:
object += "@"+ string_substitution_xml(predicate_object_map.object_map.language_map, ".+", child, "object", triples_map.iterator, parent_map, namespace)[1:-1]
elif predicate_object_map.object_map.term is not None:
if "IRI" in predicate_object_map.object_map.term:
if " " not in object:
Expand Down Expand Up @@ -1484,6 +1510,15 @@ def semantify_file_array(triples_map, triples_map_list, delimiter, output_file_d
object = "\"" + string_substitution(predicate_object_map.object_map.value, "{(.+?)}", row, "object",ignore, triples_map.iterator) + "\""
if predicate_object_map.object_map.datatype is not None:
object = "\"" + object[1:-1] + "\"" + "^^<{}>".format(predicate_object_map.object_map.datatype)
elif predicate_object_map.object_map.language is not None:
if "spanish" in predicate_object_map.object_map.language or "es" in predicate_object_map.object_map.language :
object += "@es"
elif "english" in predicate_object_map.object_map.language or "en" in predicate_object_map.object_map.language :
object += "@en"
elif len(predicate_object_map.object_map.language) == 2:
object += "@"+predicate_object_map.object_map.language
elif predicate_object_map.object_map.language_map is not None:
object += "@" + string_substitution(predicate_object_map.object_map.language_map, ".+", row, "object",ignore, triples_map.iterator)[1:-1]
except TypeError:
object = None
elif predicate_object_map.object_map.mapping_type == "reference":
Expand Down Expand Up @@ -1868,6 +1903,15 @@ def semantify_json(triples_map, triples_map_list, delimiter, output_file_descrip
object = "\"" + string_substitution_json(predicate_object_map.object_map.value, "{(.+?)}", data, "object",ignore, iterator) + "\""
if predicate_object_map.object_map.datatype is not None:
object = "\"" + object[1:-1] + "\"" + "^^<{}>".format(predicate_object_map.object_map.datatype)
elif predicate_object_map.object_map.language is not None:
if "spanish" in predicate_object_map.object_map.language or "es" in predicate_object_map.object_map.language :
object += "@es"
elif "english" in predicate_object_map.object_map.language or "en" in predicate_object_map.object_map.language :
object += "@en"
elif len(predicate_object_map.object_map.language) == 2:
object += "@"+predicate_object_map.object_map.language
elif predicate_object_map.object_map.language_map is not None:
object += "@" + string_substitution_json(predicate_object_map.object_map.language_map, ".+", data, "object",ignore, iterator)[1:-1]
except TypeError:
object = None
elif predicate_object_map.object_map.mapping_type == "reference":
Expand All @@ -1891,6 +1935,8 @@ def semantify_json(triples_map, triples_map_list, delimiter, output_file_descrip
object_list[i] += "@en"
elif len(predicate_object_map.object_map.language) == 2:
object_list[i] += "@"+predicate_object_map.object_map.language
elif predicate_object_map.object_map.language_map is not None:
object_list[i] += "@"+ string_substitution_json(predicate_object_map.object_map.language_map, ".+", data, "object",ignore, iterator)[1:-1]
elif predicate_object_map.object_map.term is not None:
if "IRI" in predicate_object_map.object_map.term:
if " " not in object_list[i]:
Expand Down Expand Up @@ -1920,6 +1966,8 @@ def semantify_json(triples_map, triples_map_list, delimiter, output_file_descrip
object += "@en"
elif len(predicate_object_map.object_map.language) == 2:
object += "@"+predicate_object_map.object_map.language
elif predicate_object_map.object_map.language_map is not None:
object += "@"+ string_substitution_json(predicate_object_map.object_map.language_map, ".+", data, "object",ignore, iterator)[1:-1]
elif predicate_object_map.object_map.term is not None:
if "IRI" in predicate_object_map.object_map.term:
if " " not in object:
Expand Down Expand Up @@ -2525,6 +2573,15 @@ def semantify_file(triples_map, triples_map_list, delimiter, output_file_descrip
object = "\"" + string_substitution(predicate_object_map.object_map.value, "{(.+?)}", row, "object",ignore, triples_map.iterator) + "\""
if predicate_object_map.object_map.datatype is not None:
object = "\"" + object[1:-1] + "\"" + "^^<{}>".format(predicate_object_map.object_map.datatype)
elif predicate_object_map.object_map.language is not None:
if "spanish" in predicate_object_map.object_map.language or "es" in predicate_object_map.object_map.language :
object += "@es"
elif "english" in predicate_object_map.object_map.language or "en" in predicate_object_map.object_map.language :
object += "@en"
elif len(predicate_object_map.object_map.language) == 2:
object += "@"+predicate_object_map.object_map.language
elif predicate_object_map.object_map.language_map is not None:
object += "@" + string_substitution(predicate_object_map.object_map.language_map, ".+", row, "object",ignore, triples_map.iterator)[1:-1]
except TypeError:
object = None
elif predicate_object_map.object_map.mapping_type == "reference":
Expand All @@ -2543,6 +2600,8 @@ def semantify_file(triples_map, triples_map_list, delimiter, output_file_descrip
object += "@en"
elif len(predicate_object_map.object_map.language) == 2:
object += "@"+predicate_object_map.object_map.language
elif predicate_object_map.object_map.language_map is not None:
object += "@"+ string_substitution(predicate_object_map.object_map.language_map, ".+", row, "object",ignore, triples_map.iterator)[1:-1]
elif predicate_object_map.object_map.term is not None:
if "IRI" in predicate_object_map.object_map.term:
if " " not in object:
Expand Down Expand Up @@ -3139,6 +3198,15 @@ def semantify_mysql(row, row_headers, triples_map, triples_map_list, output_file
object = "\"" + string_substitution_array(predicate_object_map.object_map.value, "{(.+?)}", row, row_headers, "object",ignore) + "\""
if predicate_object_map.object_map.datatype is not None:
object = "\"" + object[1:-1] + "\"" + "^^<{}>".format(predicate_object_map.object_map.datatype)
elif predicate_object_map.object_map.language is not None:
if "spanish" in predicate_object_map.object_map.language or "es" in predicate_object_map.object_map.language :
object += "@es"
elif "english" in predicate_object_map.object_map.language or "en" in predicate_object_map.object_map.language :
object += "@en"
elif len(predicate_object_map.object_map.language) == 2:
object += "@"+predicate_object_map.object_map.language
elif predicate_object_map.object_map.language_map is not None:
object += "@" + string_substitution_array(predicate_object_map.object_map.language_map, ".+", row, row_headers, "object",ignore)[1:-1]
except TypeError:
object = None
elif predicate_object_map.object_map.mapping_type == "reference":
Expand All @@ -3157,6 +3225,8 @@ def semantify_mysql(row, row_headers, triples_map, triples_map_list, output_file
object += "@en"
elif len(predicate_object_map.object_map.language) == 2:
object += "@"+predicate_object_map.object_map.language
elif predicate_object_map.object_map.language_map is not None:
object += "@"+ string_substitution_array(predicate_object_map.object_map.language_map, ".+", row, row_headers, "object",ignore)[1:-1]
elif predicate_object_map.object_map.term is not None:
if "IRI" in predicate_object_map.object_map.term:
if " " not in object:
Expand Down Expand Up @@ -3833,6 +3903,15 @@ def semantify_postgres(row, row_headers, triples_map, triples_map_list, output_f
object = "\"" + string_substitution_postgres(predicate_object_map.object_map.value, "{(.+?)}", row, row_headers, "object",ignore) + "\""
if predicate_object_map.object_map.datatype is not None:
object = "\"" + object[1:-1] + "\"" + "^^<{}>".format(predicate_object_map.object_map.datatype)
elif predicate_object_map.object_map.language is not None:
if "spanish" in predicate_object_map.object_map.language or "es" in predicate_object_map.object_map.language :
object += "@es"
elif "english" in predicate_object_map.object_map.language or "en" in predicate_object_map.object_map.language :
object += "@en"
elif len(predicate_object_map.object_map.language) == 2:
object += "@"+predicate_object_map.object_map.language
elif predicate_object_map.object_map.language_map is not None:
object += "@" + string_substitution_postgres(predicate_object_map.object_map.language_map, ".+", row, row_headers, "object",ignore)[1:-1]
except TypeError:
object = None
elif predicate_object_map.object_map.mapping_type == "reference":
Expand All @@ -3851,6 +3930,8 @@ def semantify_postgres(row, row_headers, triples_map, triples_map_list, output_f
object += "@en"
elif len(predicate_object_map.object_map.language) == 2:
object += "@"+predicate_object_map.object_map.language
elif predicate_object_map.object_map.language_map is not None:
object += "@"+ string_substitution_postgres(predicate_object_map.object_map.language_map, ".+", row, row_headers, "object",ignore)[1:-1]
elif predicate_object_map.object_map.term is not None:
if "IRI" in predicate_object_map.object_map.term:
if " " not in object:
Expand Down
Loading

0 comments on commit 6735592

Please sign in to comment.