knowledge-graphrml-rdfontology-mapping

YARRRML: How to link two entities by matching against specific value from JSON


I have a JSON of the following form:

[
  {
    "crew":[
      {
        "id":123,
        "job":"Director",
        "name":"Director Testname",
      },
      {
        "id":456,
        "job":"Screenplay",
        "name":"Crew Testname",
      }
    ],
    "id":789
  }

The "id":862 represents a film. From the crew array I want to create a Directors class. Both should be linked through hasDirector.

My YARRRML.yaml looks like this:

prefixes:
  film: "http://example.com/film#"

mappings:
  films:
    sources:
      - ['data.json~jsonpath', '$.[*]']
    s: film:film$(id)
    po:
      - [a, film:Film]
      - p: film:hasDirector
        o:
          value: film:Director$(crew['?(@.job=="Director")'].id)
          type: iri
    
  
  directors:
    sources:
      - ['data.json~jsonpath', '$[*].crew[?(@.job == "Director")]']
    s: film:Director$(id)
    po:
     - [a, film:Director]
     - [film:fullName, $(name)]

This returns no mappings via hasDirector, but provides all Directors instances. I created through Matey the RML Mapping and with rmlmapper-java I've created the RDF.

Alternatively I've also tried:

 - p: film:hasDirector
    o:
      mapping: directors
      condition:
        function: equal
        parameters:
          - [str1, $(crew.id), s]
          - [str2, "Director", o]

This resulted in all entities in the crew array were linked to film as directors.

Has someone a solution how to fix that?


Solution

  • As for the first way it appears that JSONPath conditions just don't work in YARRRML (or at least I found no way of making them work in the object mapping).

    For the second, you need to use the condition statement, imposing the equality on .job and reporting the .id when a positive match is found:

          - p: f:hasDirector
            o: b:$(crew..id)~iri
            condition:
                function: equal
                parameters:
                  - [str1, $(crew..job), s]
                  - [str2, "Director", o]