Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving #83 and inverse non-constant predicates #84

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/yatter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -18,14 +18,16 @@ 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)
if args.input_mapping_path and args.output_mapping_path:
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:
Expand Down
10 changes: 4 additions & 6 deletions src/yatter/predicateobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
2 changes: 1 addition & 1 deletion src/yatter/subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion test/r2rml/INVERSETC-0005/mapping.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Loading