filip26 / titanium-json-ld

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

Difference in behavior when using embedded vs. referenced context #379

Open rorlic opened 21 hours ago

rorlic commented 21 hours ago

Describe the bug The @base is handled differently when referencing a context vs. when embedding a context. When using an embedded context containing a @base, it is used - as expected - for creating a valid URI from relative properties and values. However, when referencing the same context, it seems that the @base is not used, resulting in different behavior.

To Reproduce In order to easy showcase the issue I use the latest Jena (5.2.0) command line tools which according to the Jena developers now use titanium.

Example files:

Pre-requisites:

Steps to reproduce the behavior:

  1. run riot with the embedded context example: riot --base=http://should-not-happen.org embedded-context.jsonld this results in:
    <https://example.com/id/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/#something> .
    <https://example.com/id/1> <http://example.com/#property> "anything" .
    <https://example.com/id/1> <http://www.w3.org/2000/01/rdf-schema#label> "A simple document" .
  2. run riot with the referenced context example: riot --base=http://should-not-happen.org referenced-context.jsonld this results in:
    <https://example.com/id/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://should-not-happen.org#something> .
    <https://example.com/id/1> <http://should-not-happen.org#property> "anything" .
    <https://example.com/id/1> <http://www.w3.org/2000/01/rdf-schema#label> "A simple document" .

Expected behavior I would expect that both would return the same result as it should not make any difference if the context is embedded or referenced. Am I correct in my assumption or am I missing something here?

rorlic commented 21 hours ago

FYI: the JSON-LD playground produces the same result for both examples:

<https://example.com/id/1> <http://example.com/#property> "anything" .
<https://example.com/id/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/#something> .
<https://example.com/id/1> <http://www.w3.org/2000/01/rdf-schema#label> "A simple document" .
rorlic commented 17 hours ago

The referenced context is as follows:

{
  "@context": {
    "@base": "http://example.com/",
    "@vocab": "#",
    "label": "http://www.w3.org/2000/01/rdf-schema#label"
  }
}

The root cause of the problem is the relative "@vocab": "#" and can be fixed by prepending it with the @base value, i.e. "@vocab": "http://example.com/#". Unfortunately, we do not always have control over the context so a fix in Titanium would be appreciated.