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

Function composition in subject URI template #231

Closed namedgraph closed 7 months ago

namedgraph commented 7 months ago

This YARRRML generates RML in Matey but does not generate any RDF using the default data.json with persons:

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

mappings:
  person:
    sources:
      - ['data.json~jsonpath', '$.persons[*]']
    s:
      function: grel:array_join
      parameters:
        - [ grel:p_array_a, "https://example.org/" ]
        - parameter: grel:p_array_a
            value:
              function: grel:string_md5
              parameters:
                - [ grel:valueParameter, $(firstname)]
    po:
      - [a, foaf:Person]

What are we doing wrong?

bjdmeest commented 7 months ago

the indentation of value was wrong, creating bogus RML, you can try below

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

mappings:
  person:
    sources:
      - ['data.json~jsonpath', '$.persons[*]']
    s:
      function: grel:array_join
      parameters:
        - [ grel:p_array_a, "https://example.org/" ]
        - parameter: grel:p_array_a
          value:
            function: grel:string_md5
            parameters:
              - [ grel:valueParameter, $(firstname)]
    po:
      - [a, foaf:Person]
namedgraph commented 7 months ago

Thank you!

namedgraph commented 7 months ago

Hmm.. I tried applying the same logic to graph but it does not seem to work:

    graph:
      function: grel:array_join
      parameters:
        - [ grel:p_array_a, "bridgestone-qualifications:" ]
        - parameter: grel:p_array_a
          value:
            function: grel:string_md5
            parameters:
              - [ grel:valueParameter, $(label) ]

I get "Could not generate RML rules." in Matey.

namedgraph commented 7 months ago

This is the yarrrml-parser error:

TypeError: mapping.graphs.forEach is not a function
    at expandTargetsInMapping (/opt/homebrew/lib/node_modules/@rmlio/yarrrml-parser/lib/expander.js:239:20)
    at expandMappings (/opt/homebrew/lib/node_modules/@rmlio/yarrrml-parser/lib/expander.js:57:9)
    at expand (/opt/homebrew/lib/node_modules/@rmlio/yarrrml-parser/lib/expander.js:36:3)
    at RMLGenerator.convert (/opt/homebrew/lib/node_modules/@rmlio/yarrrml-parser/lib/abstract-generator.js:60:30)
    at Object.<anonymous> (/opt/homebrew/lib/node_modules/@rmlio/yarrrml-parser/bin/parser.js:107:23)
    at Module._compile (node:internal/modules/cjs/loader:1233:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12) {
  code: 'INVALID_YARRRML'
}
bjdmeest commented 7 months ago

That's probably a small bug of the parser, we'll fix it, but in the meantime I think you can just put the graph object in an a array:

graph:
  - function: grel:array_join
    parameters:
      - [ grel:p_array_a, "bridgestone-qualifications:" ]
      - parameter: grel:p_array_a
        value:
          function: grel:string_md5
          parameters:
            - [ grel:valueParameter, $(label) ]
bjdmeest commented 7 months ago

tracking in https://github.com/RMLio/yarrrml-parser/issues/206

namedgraph commented 7 months ago

Thanks, this works.