Skip to content

How to use the values of a flat array when iterating on it with RML? #95

@vemonet

Description

@vemonet

Hi, I have an issue finding how to properly map flat arrays value to triple subjects when I am iterating on the array with RML

Here is a practical example ((ingredients.json`):

[
  {
    "id": 1,
    "ingredients": [
      "garlic",
      "pepper"
    ]
  },
  {
    "id": 2,
    "ingredients": [
      "salt",
      "tomatoes"
    ]
  }
]

I would like to iterate over the ingredients to create subjects, but I cannot find how to reference the value of the array entries (all documentations and tests I have found provide examples for array containing objects that can then be references by the object key)

Here are the YARRRML mappings, I put ??? as placeholder in the mappings:

prefixes:
  grel: "http://users.ugent.be/~bjdmeest/function/grel.ttl#"
  rdfs: "http://www.w3.org/2000/01/rdf-schema#"
  fo: "http://purl.org/ontology/fo/"
mappings:
  ingredients:
    sources:
      - ['ingredients.json~jsonpath', "$.[*].ingredients[*]"]
    s: fo:ingredient/$(???)
    po:
      - [rdfs:label, $(???)]

Which gives the corresponding RML, using https://rml.io/yarrrml/matey:

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

map:map_ingredients_0 rml:logicalSource map:source_0;
    a rr:TriplesMap;
    rdfs:label "ingredients";
    rr:subjectMap map:s_0;
    rr:predicateObjectMap map:pom_0.
map:om_0 a rr:ObjectMap;
    rml:reference "???";
    rr:termType rr:Literal.
map:pm_0 a rr:PredicateMap;
    rr:constant rdfs:label.
map:pom_0 a rr:PredicateObjectMap;
    rr:predicateMap map:pm_0;
    rr:objectMap map:om_0.
map:s_0 a rr:SubjectMap;
    rr:template "http://purl.org/ontology/fo/ingredient/{???}".
map:source_0 a rml:LogicalSource;
    rml:source "ingredients.json";
    rml:iterator "$.[*].ingredients[*]";
    rml:referenceFormulation ql:JSONPath.

What should be used to reference the actual array value we are iterating on? Instead of $(???) and {???}?

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