filip26 / titanium-json-ld

A JSON-LD 1.1 Processor & API
https://apicatalog.com
Apache License 2.0
134 stars 33 forks source link

Usage of @reverse breaks scoped contexts #248

Closed jakubklimek closed 10 months ago

jakubklimek commented 1 year ago

Describe the bug Usage of @reverse instead of @id prevents parts of scoped context from being interpreted.

To Reproduce Parse this json-ld file as RDF, e.g. through Apache Jena (tested on 4.7.0) and Titanium in LinkedPipes ETL using titanium-json-ld 1.3.1:

{
  "@context": {
    "@version": 1.1,
    "@base": "https://test",
    "xsd": "http://www.w3.org/2001/XMLSchema#",
    "item": {
      "@id": "https://item",
      "@context": {
        "title": {
          "@id": "https://title",
          "@container": "@language"
        },
        "subitems": {
          "@reverse": "https://subitem-of",
          "@context": {
            "subitem": {
              "@id": "https://subitem",
              "@context": {
                "title": {
                  "@id": "https://title",
                  "@container": "@language"
                },
                "description": {
                  "@id": "https://description",
                  "@container": "@language"
                }
              }
            }
          }
        }
      }
    }
  },
  "@graph": [{
    "@id": "item1",
    "@type": "item",
    "subitems": [{
      "@id": "subitem1",
      "@type": "subitem",
      "title": {
        "cs": "title"
      },
      "description": {
        "cs": "description"
      }
  }]
}]
}

The resulting RDF triples are - note the missing title and description:

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

<https://test/item1>  a  <https://item> .

<https://test/subitem1>
        a                     <https://test/subitem> ;
        <https://subitem-of>  <https://test/item1> .

Expected behavior When the same file with @reverse is transformed in JSON-LD playground, the result is:

<https://test/item1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://item> .
<https://test/subitem1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://subitem> .
<https://test/subitem1> <https://description> "description"@cs .
<https://test/subitem1> <https://subitem-of> <https://test/item1> .
<https://test/subitem1> <https://title> "title"@cs .

Additional context When I switch @reverse to @id and use titanium, I get the title and description OK:

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

<https://test/item1>  a       <https://item> ;
        <https://subitem-of>  <https://test/subitem1> .

<https://test/subitem1>
        a                      <https://subitem> ;
        <https://description>  "description"@cs ;
        <https://title>        "title"@cs .
filip26 commented 1 year ago

could be related to https://github.com/w3c/json-ld-api/issues/565

jakubklimek commented 11 months ago

https://github.com/w3c/json-ld-api/issues/565 has been fixed in the meantime.

skodapetr commented 10 months ago

@filip26 What is you position on this issue?

They updated the Editor draft in reaction to https://github.com/w3c/json-ld-api/issues/565, dropping the "return" from 13.7 at https://www.w3.org/TR/json-ld11-api/#create-term-definition. Yet the change remains only in the editor draft. In the associated PR. they also added a new test. Is there a chance to support also the Editors draft in titanium-json-ld, or do you strictly adhere to the last Recommendation?

As the change is small, it should be 2 line change in the TermDefinititionBuilder and adding the new test. I can create a PR.

filip26 commented 10 months ago

@skodapetr if the change does not break existing tests then let's do that. Thank you

filip26 commented 10 months ago

Does there exist a test for this? FYI the included official W3C test suite packaged as zip has not been updated for quite some time.

skodapetr commented 10 months ago

@filip26 Yes, there is a new test in the expansion section associated with the PR. I think this new test should be also included in titanium-json-ld tests. If you agree can you hint preferred way? The tests are part of a zip file with date, should we replace this file with the new content and current date?

filip26 commented 10 months ago

@skodapetr great, I'll sync the json-ld-test-suite-[timestamp].zip. It's made with pom.xml and maven and the resulting jar is renamed to zip then.

filip26 commented 10 months ago

@skodapetr please sync with branch https://github.com/filip26/titanium-json-ld/tree/patch/issue-311 two new tests are failing.