comake / rmlmapper-js

MIT License
5 stars 0 forks source link

Cannot read properties of undefined (reading '@id') #6

Open Melchyore opened 1 year ago

Melchyore commented 1 year ago

Hello!

(I opened the same issue in RocketRML repository, but I think it's not maintained anymore)

I'm facing a weird problem. I have an RML generated by Matey that I want to try on RocketRML (and this package, locally), however, whenever I submit the input + RML to generate N-Tripples (RDF), I get the following error: TypeError: Cannot read properties of undefined (reading '@id')

This is the RML

@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix map: <http://mapping.example.com/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix sd: <http://www.w3.org/ns/sparql-service-description#> .
@prefix v: <http://rdf.data-vocabulary.org/#> .
@prefix odrl: <http://www.w3.org/ns/odrl/2/> .
@prefix occe: <https://w3id.org/occe/> .
@prefix dpv: <https://w3id.org/dpv#> .
@prefix obo: <http://purl.obolibrary.org/obo/> .
@prefix this: <https://example.com/> .

map:map_policy_000 rml:logicalSource map:source_000 ;
    rdf:type rr:TriplesMap ;
    rdfs:label "policy" ;
    rr:predicateObjectMap map:pom_000, map:pom_001, map:pom_002, map:pom_003 ;
    rr:subjectMap map:s_000 .

map:map_rule_000 rml:logicalSource map:source_001 ;
    rdf:type rr:TriplesMap ;
    rdfs:label "rule" ;
    rr:predicateObjectMap map:pom_004, map:pom_005, map:pom_006, map:pom_007 ;
    rr:subjectMap map:s_001 .

map:map_rule_action_000 rml:logicalSource map:source_002 ;
    rdf:type rr:TriplesMap ;
    rdfs:label "rule_action" ;
    rr:predicateObjectMap map:pom_008, map:pom_009 ;
    rr:subjectMap map:s_002 .

map:map_rule_action_refinement_000 rml:logicalSource map:source_003 ;
    rdf:type rr:TriplesMap ;
    rdfs:label "rule_action_refinement" ;
    rr:predicateObjectMap map:pom_010, map:pom_011, map:pom_012, map:pom_013, map:pom_014, map:pom_015, map:pom_016 ;
    rr:subjectMap map:s_003 .

map:om_000 rml:reference "type" ;
    rdf:type rr:ObjectMap ;
    rr:termType rr:IRI .

map:om_001 rml:reference "uid" ;
    rdf:type rr:ObjectMap ;
    rr:termType rr:IRI .

map:om_002 rml:reference "profile" ;
    rdf:type rr:ObjectMap ;
    rr:termType rr:IRI .

map:om_003 rdf:type rr:ObjectMap ;
    rr:template "https://example.com/{uniqid}_rule" ;
    rr:termType rr:IRI .

map:om_004 rml:reference "rule_target" ;
    rdf:type rr:ObjectMap ;
    rr:termType rr:IRI .

map:om_005 rml:reference "rule_assigner" ;
    rdf:type rr:ObjectMap ;
    rr:termType rr:IRI .

map:om_006 rml:reference "rule_assignee" ;
    rdf:type rr:ObjectMap ;
    rr:termType rr:IRI .

map:om_007 rdf:type rr:ObjectMap ;
    rr:template "https://example.com/{uniqid}_rule_action" ;
    rr:termType rr:IRI .

map:om_008 rml:reference "rule_action" ;
    rdf:type rr:ObjectMap ;
    rr:termType rr:IRI .

map:om_009 rdf:type rr:ObjectMap ;
    rr:template "https://example.com/{uniqid}_rule_action_refinement" ;
    rr:termType rr:IRI .

map:om_010 rml:reference "rule_action_refinement_lo" ;
    rdf:type rr:ObjectMap ;
    rr:termType rr:IRI .

map:om_011 rml:reference "rule_action_refinement_o" ;
    rdf:type rr:ObjectMap ;
    rr:termType rr:IRI .

map:om_012 rml:reference "rule_action_refinement_ro_value_iri" ;
    rdf:type rr:ObjectMap ;
    rr:termType rr:IRI .

map:om_013 rml:reference "rule_action_refinement_ro_value_date" ;
    rdf:type rr:ObjectMap ;
    rr:datatype xsd:date ;
    rr:termType rr:Literal .

map:om_014 rml:reference "rule_action_refinement_ro_value_string" ;
    rdf:type rr:ObjectMap ;
    rr:datatype xsd:string ;
    rr:termType rr:Literal .

map:om_015 rml:reference "rule_action_refinement_ro_value_float" ;
    rdf:type rr:ObjectMap ;
    rr:datatype xsd:float ;
    rr:termType rr:Literal .

map:om_016 rml:reference "rule_action_refinement_unit" ;
    rdf:type rr:ObjectMap ;
    rr:termType rr:IRI .

map:pm_000 rdf:type rr:PredicateMap ;
    rr:constant rdf:type .

map:pm_001 rdf:type rr:PredicateMap ;
    rr:constant odrl:uid .

map:pm_002 rdf:type rr:PredicateMap ;
    rr:constant odrl:profile .

map:pm_003 rml:reference "rule_type" ;
    rdf:type rr:PredicateMap .

map:pm_004 rdf:type rr:PredicateMap ;
    rr:constant odrl:target .

map:pm_005 rdf:type rr:PredicateMap ;
    rr:constant odrl:assigner .

map:pm_006 rdf:type rr:PredicateMap ;
    rr:constant odrl:assignee .

map:pm_007 rdf:type rr:PredicateMap ;
    rr:constant odrl:action .

map:pm_008 rdf:type rr:PredicateMap ;
    rr:constant rdf:value .

map:pm_009 rdf:type rr:PredicateMap ;
    rr:constant odrl:refinement .

map:pm_010 rdf:type rr:PredicateMap ;
    rr:constant odrl:leftOperand .

map:pm_011 rdf:type rr:PredicateMap ;
    rr:constant odrl:operator .

map:pm_012 rdf:type rr:PredicateMap ;
    rr:constant odrl:rightOperand .

map:pm_013 rdf:type rr:PredicateMap ;
    rr:constant odrl:rightOperand .

map:pm_014 rdf:type rr:PredicateMap ;
    rr:constant odrl:rightOperand .

map:pm_015 rdf:type rr:PredicateMap ;
    rr:constant odrl:rightOperand .

map:pm_016 rdf:type rr:PredicateMap ;
    rr:constant odrl:unit .

map:pom_000 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_000 ;
    rr:predicateMap map:pm_000 .

map:pom_001 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_001 ;
    rr:predicateMap map:pm_001 .

map:pom_002 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_002 ;
    rr:predicateMap map:pm_002 .

map:pom_003 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_003 ;
    rr:predicateMap map:pm_003 .

map:pom_004 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_004 ;
    rr:predicateMap map:pm_004 .

map:pom_005 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_005 ;
    rr:predicateMap map:pm_005 .

map:pom_006 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_006 ;
    rr:predicateMap map:pm_006 .

map:pom_007 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_007 ;
    rr:predicateMap map:pm_007 .

map:pom_008 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_008 ;
    rr:predicateMap map:pm_008 .

map:pom_009 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_009 ;
    rr:predicateMap map:pm_009 .

map:pom_010 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_010 ;
    rr:predicateMap map:pm_010 .

map:pom_011 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_011 ;
    rr:predicateMap map:pm_011 .

map:pom_012 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_012 ;
    rr:predicateMap map:pm_012 .

map:pom_013 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_013 ;
    rr:predicateMap map:pm_013 .

map:pom_014 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_014 ;
    rr:predicateMap map:pm_014 .

map:pom_015 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_015 ;
    rr:predicateMap map:pm_015 .

map:pom_016 rdf:type rr:PredicateObjectMap ;
    rr:objectMap map:om_016 ;
    rr:predicateMap map:pm_016 .

map:rules_000 <http://rdfs.org/ns/void#exampleResource> map:map_policy_000, map:map_rule_000, map:map_rule_action_000, map:map_rule_action_refinement_000 ;
    rdf:type <http://rdfs.org/ns/void#Dataset> .

map:s_000 rml:reference "uid" ;
    rdf:type rr:SubjectMap .

map:s_001 rdf:type rr:SubjectMap ;
    rr:template "https://example.com/{uniqid}_rule" .

map:s_002 rdf:type rr:SubjectMap ;
    rr:template "https://example.com/{uniqid}_rule_action" .

map:s_003 rdf:type rr:SubjectMap ;
    rr:template "https://example.com/{uniqid}_rule_action_refinement" .

map:source_000 rml:referenceFormulation ql:CSV ;
    rml:source "input" ;
    rdf:type rml:LogicalSource .

map:source_001 rml:referenceFormulation ql:CSV ;
    rml:source "input" ;
    rdf:type rml:LogicalSource .

map:source_002 rml:referenceFormulation ql:CSV ;
    rml:source "input" ;
    rdf:type rml:LogicalSource .

map:source_003 rml:referenceFormulation ql:CSV ;
    rml:source "input" ;
    rdf:type rml:LogicalSource .

CSV data

type,uid,profile,rule_type,rule_action,rule_target,rule_assigner,rule_assignee,rule_action_refinement_lo,rule_action_refinement_o,rule_action_refinement_ro_value_iri,rule_action_refinement_ro_value_string,rule_action_refinement_ro_value_date,rule_action_refinement_ro_value_float,rule_action_refinement_unit,rule_assignee_refinement_lo,rule_assignee_refinement_o,rule_assignee_refinement_ro_value_iri,rule_assignee_refinement_ro_value_string,rule_assignee_refinement_ro_value_date,rule_assignee_refinement_ro_value_float,rule_assignee_refinement_unit,rule_target_refinement_lo,rule_target_refinement_o,rule_target_refinement_ro_value_iri,rule_target_refinement_ro_value_string,rule_target_refinement_ro_value_date,rule_target_refinement_ro_value_float,rule_target_refinement_unit,rule_constraint_lo,rule_constraint_o,rule_constraint_ro_value_iri,rule_constraint_ro_value_string,rule_constraint_ro_value_date,rule_constraint_ro_value_float,rule_constraint_unit,permission_duty_target,permission_duty_action,permission_duty_action_refinement_lo,permission_duty_action_refinement_o,permission_duty_action_refinement_ro_value_iri,permission_duty_action_refinement_ro_value_string,permission_duty_action_refinement_ro_value_date,permission_duty_action_refinement_ro_value_float,permission_duty_action_refinement_unit,permission_duty_constraint_lo,permission_duty_constraint_o,permission_duty_constraint_ro_value_iri,permission_duty_constraint_ro_value_string,permission_duty_constraint_ro_value_date,permission_duty_constraint_ro_value_float,permission_duty_constraint_unit,prohibition_remedy_action,prohibition_remedy_target,uniqid
odrl:Offer,https://example.com/policy:01,https://w3id.org/occe/,odrl:Permission,occe:reIdentify,https://example.com/asset_1,https://example.com/Data_Center_1,https://example.com/John,occe:notMediatedBy,odrl:eq,https://example.com/Data_Center_1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,32000090
odrl:Offer,https://example.com/policy:02,https://w3id.org/occe/,odrl:Permission,occe:reIdentify,https://example.com/asset_2,https://example.com/Data_Center_2,https://example.com/Sarah,occe:notMediatedBy,odrl:eq,https://example.com/Data_Center_2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,60949991

Can you help me, please?

adlerfaulkner commented 1 year ago

Hello! Happy to help.

First, when running your example, I'm seeing an error that the rr prefix is not defined in the mapping you provided. So add @prefix rr: <http://www.w3.org/ns/r2rml#> . to the top of your mapping file.

After fixing that, I can replicate the error you are experiencing. This error comes from the fact that you have PredicateMaps with no rr:constant. I see that you are trying to define the value of the PredicateMaps using an rml:reference to your data (eg. map:pm_003). Unfortunately, RocketRML (and thus this library) does not (yet) have support for reference valued PredicateMaps. I'm not sure why the original authors didn't support references and templates for PredicateMaps. Hopefully I'll have time soon to do more refactoring and add those as features here.

adlerfaulkner commented 1 year ago

Also, I can't find any tests specifically for using a reference in a PredicateMap in the RML Test Cases so maybe the creators and early implementers didn't expect it to be used that way (ie. they assumed data sources wouldn't have URIs in them to use as predicates in generated rdf?)

Melchyore commented 1 year ago

@adlerfaulkner Thank you for your answers! In fact, the RML rules are generated based on a YARRRML template on Matey. So I just write YARRRML and RML is generated automatically. Unfortunately, I'm not really an expert with RML rules, that's why I raised this issue. It would be really awesome to support RML rules generated by Matey.

Thanks again!