Generating condition-based rdf:type triples using YARRRML mapping

234 Views Asked by At

I’m working on an implementation that requires assigning rdf:type based upon a value in the data.

Example:

ID,Species
1,Rat
2,Eagle

ID-1 should be assigned type as "Animal" and ID-2 should be assigned type as "Bird".

I’m stuck with the conditional mapping. I tried this YARRRML mapping:

  - p: a
    o: 
        value: http://example.com/Animal
        condition:
            function: idlab-fn:equal
            parameters:
                - [grel:valueParameter, $(Species)]
                - [grel:valueParameter2, "Rat"]
1

There are 1 best solutions below

0
On

The problem might be that the condition is defined at the object instead of one level higher (see https://rml.io/yarrrml/spec/#conditions), the following seems to work (tested on Matey)

prefixes:
 ex: "http://example.com/"
 idlab-fn: "http://example.com/idlab/function/"
 grel: "http://users.ugent.be/~bjdmeest/function/grel.ttl#"

mappings:
  person:
    sources:
      - ['test.csv~csv']
    s: http://example.com/$(ID)
    po:
      - p: rdf:type
        o: ex:Animal~iri
        condition:
          function: idlab-fn:equal
          parameters:
            - [grel:valueParameter, "Rat"]
            - [grel:valueParameter2, $(Species)]
      - [ex:name, $(Species)]