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

Wrong implementation of JsonPath #79

Closed Sealdolphin closed 3 years ago

Sealdolphin commented 3 years ago

Hi,

I recently came across a possible bug:

My JSON architecture looks like this:

{
  "elementStore": [
    {
      "type" : "type1",
      "elements": [
        {
          "ord": "first"
        },
    {
          "ord": "second"
        },
        {
          "ord": "third"
        }
      ]
    },
{
      "type": "type2",
      "elements": [
        {
          "ord": "first2"
        },
    {
          "ord": "second2"
        },
        {
          "ord": "third2"
        }
      ]
    }
}

And I tried to extract the different element ordinals (ord) with the help of JSONPath. My RML fragment:

<#elementsMap> a rr:TriplesMap;

    rml:logicalSource [ 
        rml:source "<my JSON file>";
        rml:referenceFormulation ql:JSONPath;
        rml:iterator "$.elementStore[*]";
    ];

    rr:subjectMap [ 
        rr:template "/{.elements[*].ord}";
        rr:class mm:ordinal;
    ];

I expected that the result should include all three elements however, I only got the first one

pheyvaer commented 3 years ago

Hi @Sealdolphin

Can you explain what the expected result is in terms of RDF?

Sealdolphin commented 3 years ago

Hi, yes, although I think I found the problem in the source code.

Expected output:

<http://example.com/first> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com#ordinal>.
<http://example.com/second> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com#ordinal>.
<http://example.com/third> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com#ordinal>.
<http://example.com/first2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com#ordinal>.
<http://example.com/second2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com#ordinal>.
<http://example.com/third2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com#ordinal>.

Actual output:

<http://example.com/first> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com#ordinal>.
<http://example.com/first2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com#ordinal>.

UPDATE: I looked it again, and it's not the line I first linked.. linking again

Sealdolphin commented 3 years ago

@pheyvaer is it intended behavior, or should it return all possible JSONPath records as subjects?

pheyvaer commented 3 years ago

I would expect the RML to be something like this to get the RDF you want

<#elementsMap> a rr:TriplesMap;

    rml:logicalSource [ 
        rml:source "<my JSON file>";
        rml:referenceFormulation ql:JSONPath;
        rml:iterator "$.elementStore[*].elements[*]";
    ];

    rr:subjectMap [ 
        rr:template "{ord}";
        rr:class mm:ordinal;
    ];

And this because your subjects are in the elements array and not in the elementStore array. Well at least not directly.

Sealdolphin commented 3 years ago

I would expect the RML to be something like this to get the RDF you want

Thanks for the fast response. This mapping does work indeed, however this way I cannot access any other property of the objects in the elementStore (besides elements). Is there a way to make my mapping work, or do I want to use the RMLMapper inherently the wrong way?

I thought that while the JSONPath evaluator parses my JSONPath correctly, that would be the same result in the case of here.

UPDATE: To be precise, my problem is, that JSONPath does not have ancestor operator and with RMLMapper I can only use previously defined subjects as objects (with parentTriplesMap), but not the other way around. So unless I change my whole data structure, I cannot read it the RMLMapper, or can I?

pheyvaer commented 3 years ago

Hi @Sealdolphin

Yeah, the problem is that JSONPath is limited in that regard and at the moment there is not other reference formulation available for JSON and thus also not implemented in the RMLMapper. Preprocessing the JSON structure to work around this issue is the best option at the moment. We have done this too before in the past.

no-response[bot] commented 3 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.