Skip to content

objects in an array in objects in an array #93

Open
@justin2004

Description

@justin2004

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/>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions