RMLio / RML-Mapper

Generate High Quality Linked Data from multiple originally (semi-)structured data (legacy)
http://RML.io
52 stars 20 forks source link

objects in an array in objects in an array #47

Closed justin2004 closed 3 years ago

justin2004 commented 3 years ago

note that i am not concerned about using correct properties yet. i am just concerned with structure.

characters.json:

{
  "characters": [
    {
      "id": "0",
      "firstname": "Ash",
      "items":[ {"id":10,"name":"gloves", "weight":340},
                {"id":11,"name":"sword", "weight":44400}
      ]
    },
    {
      "id": "1",
      "firstname": "Misty",
      "items":[ {"id":12,"name":"gloves", "weight":340},
                {"id":13,"name":"mittens", "weight":300},
                {"id":14,"name":"hat", "weight":800}
      ]
    }
  ]
}

rml:

@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <http://example.org/rules/> .
@prefix ex: <http://example.org/example/> .
@prefix schema: <http://schema.org/> .
@prefix dbo: <http://dbpedia.org/ontology/> .

:LogicalSource a rml:logicalSource ;
    rml:source "characters.json";
    rml:referenceFormulation ql:JSONPath;
    rml:iterator "$.characters[*]" .

:CharactersTriplesMap a rr:TriplesMap;
  rml:logicalSource :LogicalSource .

:CharactersTriplesMap rr:subjectMap [
  rr:template "http://example.org/character/{id}" ;
].

:CharactersTriplesMap rr:predicateObjectMap [
  rr:predicate rdf:type;
  rr:objectMap [
   rr:constant schema:Person
 ]
].

:CharactersTriplesMap rr:predicateObjectMap [
  rr:predicate schema:hasPossessions;
  rr:objectMap [
   rr:parentTriplesMap :TriplesMapItems;
   rr:joinCondition [
                     rr:child  "id"; 
                     rr:parent "id"; 
                    ]
 ]
].

####################

:TriplesMapItems a rr:TriplesMap ;
   rml:logicalSource [
    rml:source "characters.json";
    rml:referenceFormulation ql:JSONPath;
    rml:iterator "$.characters[*]" ] .

:TriplesMapItems rr:subjectMap [
        rr:template "http://characters.com/posessions/char/{id}/possessions/"; 
].

:TriplesMapItems rr:predicateObjectMap [
  rr:predicate rdf:type;
  rr:objectMap [
   rr:constant schema:Collection
               ] 
].

:TriplesMapItems rr:predicateObjectMap [
  rr:predicate schema:contains;
  rr:objectMap [
   rr:parentTriplesMap :TriplesMapItemsContents;
   rr:joinCondition [
                     rr:child  "items[0].id"; 
                     rr:parent "id"; 
                    ]
 ]
].

##########

:TriplesMapItemsContents a rr:TriplesMap ;
   rml:logicalSource [
    rml:source "characters.json";
    rml:referenceFormulation ql:JSONPath;
    rml:iterator "$.characters[*].items[*]" ] .

:TriplesMapItemsContents rr:subjectMap [
        rr:template "http://characters.com/items/{id}"; 
].

:TriplesMapItemsContents rr:predicateObjectMap [
  rr:predicate dbo:name;
  rr:objectMap [
    rml:reference "name"
  ]
].

which produces the triples i expect:

<http://characters.com/items/10> <http://dbpedia.org/ontology/name> "gloves".
<http://characters.com/items/11> <http://dbpedia.org/ontology/name> "sword".
<http://characters.com/items/12> <http://dbpedia.org/ontology/name> "gloves".
<http://characters.com/items/13> <http://dbpedia.org/ontology/name> "mittens".
<http://characters.com/items/14> <http://dbpedia.org/ontology/name> "hat".
<http://characters.com/posessions/char/0/possessions/> <http://schema.org/contains> <http://characters.com/items/10>.
<http://characters.com/posessions/char/0/possessions/> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Collection>.
<http://characters.com/posessions/char/1/possessions/> <http://schema.org/contains> <http://characters.com/items/12>.
<http://characters.com/posessions/char/1/possessions/> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Collection>.
<http://example.org/character/0> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person>.
<http://example.org/character/0> <http://schema.org/hasPossessions> <http://characters.com/posessions/char/0/possessions/>.
<http://example.org/character/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person>.
<http://example.org/character/1> <http://schema.org/hasPossessions> <http://characters.com/posessions/char/1/possessions/>.

but notice i had to hardcode to the 0th item:

                     rr:child  "items[0].id"; 

i can manually iterate like:

                     rr:child  "items[1].id"; 

and

                     rr:child  "items[2].id"; 

and it works as expected.

but if i want to do them all at once:

                     rr:child  "items[*].id"; 

then i lose the ?s http://schema.org/contains ?o matching triples:

<http://characters.com/items/10> <http://dbpedia.org/ontology/name> "gloves".
<http://characters.com/items/11> <http://dbpedia.org/ontology/name> "sword".
<http://characters.com/items/12> <http://dbpedia.org/ontology/name> "gloves".
<http://characters.com/items/13> <http://dbpedia.org/ontology/name> "mittens".
<http://characters.com/items/14> <http://dbpedia.org/ontology/name> "hat".
<http://characters.com/posessions/char/0/possessions/> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Collection>.
<http://characters.com/posessions/char/1/possessions/> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Collection>.
<http://example.org/character/0> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person>.
<http://example.org/character/0> <http://schema.org/hasPossessions> <http://characters.com/posessions/char/0/possessions/>.
<http://example.org/character/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person>.
<http://example.org/character/1> <http://schema.org/hasPossessions> <http://characters.com/posessions/char/1/possessions/>.
justin2004 commented 3 years ago

oh, i just saw this:

This repository remains available as legacy.

i'll find the new repo.

justin2004 commented 3 years ago

opened this instead https://github.com/RMLio/rmlmapper-java/issues/93