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
147 stars 61 forks source link

JSONPath support for "step" expression on array slice #133

Closed JohannesLipp closed 2 years ago

JohannesLipp commented 2 years ago

I need to select every n-th element from a JSON array, but it seems that the JSONPath array slice expression "step" is not supported. An example would be [0:10:2] to select every other element in the range 0-9.

Input JSON: { "array": [0,1,2,3,4,5,6,7,8,9] }

RML mapping:

@prefix :     <http://example.org/> .
@prefix ql:   <http://semweb.mmlab.be/ns/ql#>.
@prefix rml:  <http://semweb.mmlab.be/ns/rml#>.
@prefix rr:   <http://www.w3.org/ns/r2rml#>.
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .

:Map
    a rr:TriplesMap ;
    rml:logicalSource [
        rml:source               "/src/main/resources/ex.json" ;
        rml:referenceFormulation ql:JSONPath ;
        rml:iterator             "$" ] ;

    rr:subjectMap [ rr:termType rr:BlankNode ] ;

    rr:predicateObjectMap [rr:predicate :hasEntry; rr:objectMap [rml:reference "array[0:10:2]"; rr:datatype xsd:integer]] .

Actual output:

@prefix : <http://example.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

_:0 :hasEntry 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 .

Expected output:

@prefix : <http://example.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

_:0 :hasEntry 0, 2, 4, 6, 8 .

Is there anything we can do about this? Thank you very much in advance!

DylanVanAssche commented 2 years ago

Hi @JohannesLipp !

Thank you for your interest in RML and our tools! The JSONPath specification you refer to is still a draft at IETF which was recently being established from https://goessner.net/articles/JsonPath/. The JSONPath library inside the RMLMapper does not support the new specification yet and therefore not the array slice expression.

You may be able to workaround this issue using FnO functions. The RMLMapper supports a default set of functions, but you can also add your own functions. You can find the default set of functions at: https://rml.io/docs/rmlmapper/default-functions/

If you still have any questions, feel free to reach out!

no-response[bot] commented 2 years ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

JohannesLipp commented 2 years ago

Hi @DylanVanAssche thank you very much for your quick reply! We investigated FnO functions in the RML Mapper and successfully implemented these in other use-cases, but: We evaluated the required effort for the JSON indexing as too high, so we actually changed the format of our input files to enable easy processing via default RML JSON-path.

Concretely, we split the list in the input file into two lists containing every other element. Thank you anyway! 🦀