SDM-TIB / SDM-RDFizer

An Efficient RML-Compliant Engine for Knowledge Graph Construction
https://doi.org/10.5281/zenodo.3872103
Apache License 2.0
107 stars 25 forks source link

UnboundLocalError: local variable 'subject_map' referenced before assignment #73

Closed nleguillarme closed 2 years ago

nleguillarme commented 2 years ago

Describe the bug Running rdfizer on a RML file produced with YARRRML Parser raises UnboundLocalError

INFO:rdflib:RDFLib Version: 4.2.2 Traceback (most recent call last): File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/home/leguilln/workspace/KNOWLEDGE_INTEGRATION/inteGraph/rdfizer/rdfizer-env/lib/python3.8/site-packages/rdfizer/main.py", line 44, in semantify(config_path) File "/home/leguilln/workspace/KNOWLEDGE_INTEGRATION/inteGraph/rdfizer/rdfizer-env/lib/python3.8/site-packages/rdfizer/init.py", line 4047, in semantify triples_map_list = mapping_parser(config[dataset_i]["mapping"]) File "/home/leguilln/workspace/KNOWLEDGE_INTEGRATION/inteGraph/rdfizer/rdfizer-env/lib/python3.8/site-packages/rdfizer/init.py", line 593, in mapping_parser 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)) UnboundLocalError: local variable 'subject_map' referenced before assignment

To Reproduce Steps to reproduce the behavior (and resources):

  1. python3 -m rdfizer -c config.ini

Expected behavior Expected the creation of a N-triple file

Additional context Attached are RML mappings and TSV files config.ini.txt mapping.rml.txt taxon.tsv.txt s.tsv.txt

eiglesias34 commented 2 years ago

Hello @nleguillarme,

First of all, thank you for using the SDM-RDFizer.

I check the mapping you sent me and noticed that for the subject maps that are defined as blank nodes are missing a value.

s_001 a rr:SubjectMap.
:map_CONSUMER_000 rr:subjectMap :s_001.
:s_001 rr:termType rr:BlankNode.

Please take note of this example:

@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix ex: <http://example.com/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@base <http://example.com/base/> .

<TriplesMap1>
  a rr:TriplesMap;

  rml:logicalSource [
    rml:source "student.csv";
    rml:referenceFormulation ql:CSV
  ];

  rr:subjectMap [
    rr:template "{Name}";
    rr:termType rr:BlankNode
  ]; 

  rr:predicateObjectMap [ 
    rr:predicate foaf:name; 
    rr:objectMap [
      rml:reference "Name"
    ]
  ].

I hope this solve your problem,

Sincerely, Enrique Iglesias

nleguillarme commented 2 years ago

Hi, thank you for your help. I've just tested by adding templates to my subject maps and it works.

Now, I would like to move from a yarrrml-parser + rmlmapper pipeline to yarrrml-parser + rdfizer and I have two problems :

nleguillarme commented 2 years ago

Hi, do you plan to support blank nodes and TSV files in a future release ?

eiglesias34 commented 2 years ago

Hello again,

First of all, thank you for using the SDM-RDFizer.

Regarding the issue of the Blank Nodes, we follow the semantic defined by R2RML (which is also true for RML):

Triples map must have exactly one subject map that specifies how to generate a subject for each row of the logical table. It may be specified in two ways:

- using the rr:subjectMap property, whose value must be the subject map - using the constant shortcut property rr:subject.

https://www.w3.org/TR/r2rml/#dfn-subject-map

In other words, Blank nodes will only be generated if there is subject map with a defined value with rr:termType rr:BlankNode. Please note that it is not necessary for the value in subject map to be a URL in this case. Follow the example in my previous message.

Regarding the TSV files, I'll update the SDM-RDFizer so that it can transform TSV files some point this week.

Sincerely, Enrique Iglesias

eiglesias34 commented 2 years ago

I updated the SDM-RDFizer so that it can semantify TSV files.

eiglesias34 commented 2 years ago

Hello,

Since the problem has been solved I am going to close this issue.

Thank you again for using the SDM-RDFizer.