anuzzolese / pyrml

pyRML is a Python based engine for processing RML files. The RDF Mapping Language (RML) is a mapping language defined to express customized mapping rules from heterogeneous data structures and serializations to the RDF data model. RML is defined as a superset of the W3C-standardized mapping language R2RML, aiming to extend its applicability and broaden its scope, adding support for data in other structured formats.
Apache License 2.0
33 stars 12 forks source link

AttributeError: tripleMap #14

Open MicheleMallia opened 2 months ago

MicheleMallia commented 2 months ago

Hi,

I am using your library to perform transformations between structured data. I used yatter to do the conversion from yaml to RML, but once I use your library to get the RDF I get this error:

Traceback (most recent call last):
  File "C:\Users\Michele Mallia\Lavoro\H2IOSC\Dev\yarrrml-parser-yatter\script.py", line 16, in <module>
    rdf_graph = rml_converter.convert(rml_file_path)
  File "C:\Users\Michele Mallia\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrml\pyrml_mapper.py", line 135, in convert
    triple_mappings = RMLParser.parse(rml_mapping)
  File "C:\Users\Michele Mallia\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrml\pyrml_mapper.py", line 47, in parse
    return TripleMappings.from_rdf(g)
  File "C:\Users\Michele Mallia\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrml\pyrml_core.py", line 1660, in from_rdf
    return set([TripleMappings.__build(g, row) for row in qres])
  File "C:\Users\Michele Mallia\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrml\pyrml_core.py", line 1660, in <listcomp>
    return set([TripleMappings.__build(g, row) for row in qres])
  File "C:\Users\Michele Mallia\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrml\pyrml_core.py", line 1668, in __build       
    predicate_object_maps = PredicateObjectMap.from_rdf(g, row.tm)
  File "C:\Users\Michele Mallia\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrml\pyrml_core.py", line 778, in from_rdf
    return list(map(lmbd(g), qres))
  File "C:\Users\Michele Mallia\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrml\pyrml_core.py", line 777, in <lambda>
    lmbd = lambda graph : lambda row :  PredicateObjectMap.__build(graph, row)
  File "C:\Users\Michele Mallia\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrml\pyrml_core.py", line 784, in __build
    predicates = PredicateBuilder.build(g, row.pom)
  File "C:\Users\Michele Mallia\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrml\pyrml_core.py", line 695, in build
    predicates += PredicateMap.from_rdf(g, predicate_ref)
  File "C:\Users\Michele Mallia\AppData\Local\Programs\Python\Python39\lib\site-packages\pyrml\pyrml_core.py", line 655, in from_rdf
    pm = PredicateMap(row.tripleMap, row.map, row.termType, row.predicateMap)
  File "C:\Users\Michele Mallia\AppData\Local\Programs\Python\Python39\lib\site-packages\rdflib\query.py", line 124, in __getattr__
    raise AttributeError(name)
AttributeError: tripleMap

This is the structure of RML file:

@prefix ex: <http://example.com/>.
@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 xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix ql: <http://semweb.mmlab.be/ns/ql#>.
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix schema: <http://schema.org/>.
@prefix formats: <http://www.w3.org/ns/formats/>.
@prefix comp: <http://semweb.mmlab.be/ns/rml-compression#>.
@prefix void: <http://rdfs.org/ns/void#>.
@prefix fnml: <http://semweb.mmlab.be/ns/fnml#>.
@prefix grel: <http://users.ugent.be/~bjdmeest/function/grel.ttl#>.
@base <http://example.com/ns#>.

<person_0> a rr:TriplesMap;

    rml:logicalSource [
        a rml:LogicalSource;
        rml:source "data.json";
        rml:referenceFormulation ql:JSONPath;
        rml:iterator "$.persons[*]";
    ];
    rr:subjectMap [
        a rr:SubjectMap;
        rr:template "http://example.com/{firstname}";
    ];
    rr:predicateObjectMap [
        rr:predicateMap [
            a rr:PredicateMap;
            rr:constant rdf:type;
        ];
        rr:objectMap [
            a rr:ObjectMap;
            rr:constant foaf:Person;
        ];
    ];
    rr:predicateObjectMap [
        rr:predicateMap [
            a rr:PredicateMap;
            rr:constant ex:name;
        ];
        rr:objectMap [
            a rr:ObjectMap;
            rml:reference "firstname";
        ];
    ].

Thank you in advance.

anuzzolese commented 2 months ago

Hi @MicheleMallia,

can you provide me with an example of the JSON file you use as input?

MicheleMallia commented 2 months ago

Hi @anuzzolese,

Thank you for the quick response.

I took my cue from Matey's examples, I was currently doing a simple test with the “people” example, which has a data.json file that has this structure:

{
    "persons": [
        {
            "firstname": "John",
            "lastname": "Doe"
        },
        {
            "firstname": "Jane",
            "lastname": "Smith"
        },
        {
            "firstname": "Sarah",
            "lastname": "Bladinck"
        }
    ]
}

And a mapping file that has this structure:

prefixes:
 ex: "http://example.com/"

mappings:
  person:
    sources:
      - ['data.json~jsonpath', '$.persons[*]']
    s: http://example.com/$(firstname)
    po:
      - [a, foaf:Person]
      - [ex:name, $(firstname)]
MicheleMallia commented 2 months ago

I use Python 3.10