Skip to content

Commit

Permalink
Merge pull request #61 from oeg-upm/dev
Browse files Browse the repository at this point in the history
Solving some issues and geomappings support
  • Loading branch information
dachafra authored May 5, 2023
2 parents 689a24c + 08a7d16 commit c16d5e8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/yatter/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@
'csv': 'CSV',
'json': 'JSONPath',
'xpath': 'XPath',
'jsonpath': 'JSONPath'
'jsonpath': 'JSONPath',
"shp": "SHP"
}

YARRRML_DATABASES_DRIVER = {
Expand Down
4 changes: 3 additions & 1 deletion src/yatter/mapping.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .import *
prefixes = {}


def add_mapping(mapping, mappings, it):
Expand All @@ -11,6 +12,7 @@ def add_mapping(mapping, mappings, it):


def add_prefix(data):
global prefixes
template = []
common_prefixes = []
if YARRRML_PREFIXES in data:
Expand Down Expand Up @@ -121,5 +123,5 @@ def get_non_asserted_mappings(yarrrml_data, mapping_format):
def merge_mapping_section_by_key(key,yarrrml_list):
output = {key:{}}
for yarrrml_mapping in yarrrml_list:
output[key] = output[key] | yarrrml_mapping
output[key] = output[key] | yarrrml_mapping
return output
17 changes: 12 additions & 5 deletions src/yatter/predicateobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from .source import get_initial_sources, add_source, add_table
from .subject import add_subject
from .termmap import generate_rml_termmap, check_type
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
Expand Down Expand Up @@ -143,7 +143,7 @@ def add_predicate_object(data, mapping, predicate_object, mapping_format=RML_URI
for pm in predicate_list:
pm_value = pm
execution = False
if YARRRML_VALUE in pm:
if YARRRML_VALUE in pm and type(pm) is dict:
pm_value = pm[YARRRML_VALUE]
elif YARRRML_FUNCTION in pm:
pm_value = pm[YARRRML_FUNCTION]
Expand All @@ -165,8 +165,13 @@ 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)
else:
template += generate_rml_termmap(R2RML_OBJECT, R2RML_OBJECT_CLASS,
object_map = generate_rml_termmap(R2RML_OBJECT, R2RML_OBJECT_CLASS,
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}\"")

template += object_map
if len(om) == 2:
types = check_type(om[1])
if types != "error":
Expand Down Expand Up @@ -201,7 +206,7 @@ def add_predicate_object(data, mapping, predicate_object, mapping_format=RML_URI
else:
template += ref_mapping(data, mapping, om, YARRRML_QUOTED, STAR_QUOTED, mapping_format)
else:
if YARRRML_VALUE in om:
if YARRRML_VALUE in om and type(om) is dict:
object_value = om.get(YARRRML_VALUE)
else:
object_value = om
Expand Down Expand Up @@ -311,7 +316,9 @@ def add_inverse_pom(mapping_id, rdf_mapping, classes, prefixes):
yarrrml_poms = []
yaml = YAML()
for c in classes:
yarrrml_poms.append(['rdf:type', c.toPython()])
yarrrml_pom = yaml.seq(['rdf:type', c.toPython()])
yarrrml_pom.fa.set_flow_style()
yarrrml_poms.append(yarrrml_pom)

query = f'SELECT ?predicate ?predicateValue ?object ?objectValue ?termtype ?datatype ?datatypeMapValue ' \
f'?language ?languageMapValue ?parentTriplesMap ?child ?parent ?graphValue' \
Expand Down
9 changes: 5 additions & 4 deletions src/yatter/source.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import re
import rdflib
from .constants import *
Expand Down Expand Up @@ -85,7 +86,7 @@ def add_source_simplified(mapping, source):
source_rdf = ""
file_path = re.sub("~.*", "", source[0])
reference_formulation = source[0].split('~')[1]
source_extension = file_path.split('.')[1]
source_extension = os.path.splitext(file_path)[1].replace(".","")
ref_formulation_rml = YARRRML_REFERENCE_FORMULATIONS[reference_formulation]

if switch_in_reference_formulation(reference_formulation) != source_extension:
Expand Down Expand Up @@ -170,9 +171,7 @@ def database_source(mapping, source, db_identifier):

def switch_in_reference_formulation(value):
value = value.lower()
if value == "csv":
switcher = value
elif "json" in value:
if "json" in value:
if "path" in value:
switcher = "json"
else:
Expand All @@ -182,6 +181,8 @@ def switch_in_reference_formulation(value):
switcher = "xml"
else:
switcher = "xpath"
else:
switcher = value
return switcher


Expand Down
2 changes: 1 addition & 1 deletion src/yatter/subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def add_subject(data, mapping, mapping_format):
subject_termmap = generate_rml_termmap(STAR_SUBJECT, R2RML_SUBJECT_CLASS, individual_subject, "\t\t")
else:
subject_value = individual_subject
if YARRRML_VALUE in individual_subject:
if YARRRML_VALUE in individual_subject and type(individual_subject) is dict:
subject_value = individual_subject.get(YARRRML_VALUE)
elif YARRRML_FUNCTION in individual_subject:
subject_value = individual_subject.get(YARRRML_FUNCTION)
Expand Down
2 changes: 1 addition & 1 deletion src/yatter/termmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def generate_rml_termmap(rml_property, rml_class, text, identation, mapping_form
term_map = get_termmap_type(text, mapping_format)
if term_map == R2RML_TEMPLATE:
text = generate_rml_template(text)
text = text.replace('"',r'\"')
text = text.replace('"', r'\"')
elif term_map == RML_REFERENCE or term_map == R2RML_COLUMN:
text = text.replace("$(", "").replace(")", "")
text = text.replace('"', r'\"')
Expand Down

0 comments on commit c16d5e8

Please sign in to comment.