RMLio / rmlmapper-java

The RMLMapper executes RML rules to generate high quality Linked Data from multiple originally (semi-)structured data sources
http://rml.io
MIT License
144 stars 61 forks source link

Conditions at Subjects #210

Closed pabloalarconm closed 10 months ago

pabloalarconm commented 1 year ago

Hi!

I'm trying to create a YARRRML template that contains a condition in which: if the data source column named value_id in the CSV contains "null" as value in the data cell, create a URL based on other columns like: this:$(pid)_$(uniqid)_Output. If it does not contain "null", use this value (it will be a URL) from this value_id column.

The solution I found was to use functions equal and idlab-fn:notEqual. This solution seems to work perfectly at predicateobjects every time I want to perform this function at objects. But, this function seems not to work with subjects. Based on the documentation, subjects accepts both functions, value and parameters (ref and ref2), so it seems it should work in my case, but it doesnt.

I will send you two YARRRML template and one CSV that fits with both templates. Each template contains the functions in different places: yarrrml_1.yaml has the functions at the predicateobjects and works, the second template, yarrrml_2.yaml contains the same functions in the subjects and doesn't work.

Could you tell what changes do I need in yarrrml_2 to obtain same functionality but in subjects and I achieved in yarrrml_1 for `predicateobjects? Thank you so much, truly appreciated.

yarrrml_1

mapping:
  test:
    po:
        - p: sio:SIO_000229
          o:
            - value: this:$(pid)_$(uniqid)_Output
              type: iri
              condition:
                function: equal
                parameters:
                  - [str1, $(value_id)]
                  - [str2, "null"]
            - value: $(value_id)
              type: iri
              condition:
                function: idlab-fn:notEqual
                parameters:
                  - [grel:valueParameter, $(value_id)]
                  - [grel:valueParameter2, "null"]
    graph: this:$(pid)_Context
    sources:
    - source_cde_test
    subjects: this:$(pid)_$(uniqid)_Process
prefixes:
  obo: http://purl.obolibrary.org/obo/
  rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
  rdfs: http://www.w3.org/2000/01/rdf-schema#
  sio: https://sio.semanticscience.org/resource/
  this: http://my_example.com/
  xsd: http://www.w3.org/2001/XMLSchema#
  grel: http://users.ugent.be/~bjdmeest/function/grel.ttl#
  idlab-fn: http://example.com/idlab/function/

sources:
  source_cde_test:
    access: data.csv
    iterator: $
    referenceFormulation: csv

yarrrml_2

mapping:
  test:
    graph: this:$(uniqid)_Context
    predicateobject:

    - objects:
        type: xsd:integer
        value: $(uniqid)
      predicate: sio:SIO_000300

    sources:
    - source_cde_test

    subjects:
      - value: this:$(pid)_$(uniqid)_Output
        condition:
          function: equal
          parameters:
            - [str1, $(value_id)]
            - [str2, "null"]
      - value: $(value_id)
        condition:
          function: idlab-fn:notEqual
          parameters:
            - [grel:valueParameter, $(value_id)]
            - [grel:valueParameter2, "null"]

prefixes:
  obo: http://purl.obolibrary.org/obo/
  rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
  rdfs: http://www.w3.org/2000/01/rdf-schema#
  sio: https://sio.semanticscience.org/resource/
  this: http://my_example.com/
  xsd: http://www.w3.org/2001/XMLSchema#
  grel: http://users.ugent.be/~bjdmeest/function/grel.ttl#
  idlab-fn: http://example.com/idlab/function/

sources:
  source_cde_test:
    access: data.csv
    iterator: $
    referenceFormulation: csv

data.csv

pid,uniqid,value_id
3246543214,33654,http://www.orpha.net/ORDO/Orphanet_93552
3246543214,33655,null
3246543214,33656,null
3246543214,33657,null
3246543214,33658,http://www.orpha.net/ORDO/Orphanet_93552
3246543214,33659,null
3246543214,33660,null

Results obtained from yarrrml_1 and data.csv

<http://my_example.com/3246543214_33654_Process> <https://sio.semanticscience.org/resource/SIO_000229> <http://www.orpha.net/ORDO/Orphanet_93552> <http://my_example.com/3246543214_Context>.
<http://my_example.com/3246543214_33655_Process> <https://sio.semanticscience.org/resource/SIO_000229> <http://my_example.com/3246543214_33655_Output> <http://my_example.com/3246543214_Context>.
<http://my_example.com/3246543214_33656_Process> <https://sio.semanticscience.org/resource/SIO_000229> <http://my_example.com/3246543214_33656_Output> <http://my_example.com/3246543214_Context>.
<http://my_example.com/3246543214_33657_Process> <https://sio.semanticscience.org/resource/SIO_000229> <http://my_example.com/3246543214_33657_Output> <http://my_example.com/3246543214_Context>.
<http://my_example.com/3246543214_33658_Process> <https://sio.semanticscience.org/resource/SIO_000229> <http://www.orpha.net/ORDO/Orphanet_93552> <http://my_example.com/3246543214_Context>.
<http://my_example.com/3246543214_33659_Process> <https://sio.semanticscience.org/resource/SIO_000229> <http://my_example.com/3246543214_33659_Output> <http://my_example.com/3246543214_Context>.
<http://my_example.com/3246543214_33660_Process> <https://sio.semanticscience.org/resource/SIO_000229> <http://my_example.com/3246543214_33660_Output> <http://my_example.com/3246543214_Context>.
DylanVanAssche commented 1 year ago

Hi!

I think you need to put on a mapping level for subjects, see https://rml.io/yarrrml/spec/#conditions

DylanVanAssche commented 10 months ago

Closing as assumed resolved since no response for several months. Please re-open if you still have issues with this. Thanks!