Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Other tools have problems with JSON-LD output files #214

Open
fbartusch opened this issue Dec 18, 2023 · 12 comments
Open

Other tools have problems with JSON-LD output files #214

fbartusch opened this issue Dec 18, 2023 · 12 comments

Comments

@fbartusch
Copy link

Hi,

I'm trying to use JSON-LD output files with Apache Jena tools like riot (e.g. converting .jsonld to .ttl).
But riot and also JSON-LD Playground have problems with ProvToolbox' output.

Here is a minimal example:

{
  "@context" : [ {
    "xsd" : "http://www.w3.org/2001/XMLSchema#",
    "prov" : "http://www.w3.org/ns/prov#",
    "exa" : "https://example.com/"
  }, "http://openprovenance.org/prov.jsonld" ],
  "@graph" : [ {
    "@type" : "prov:Entity",
    "@id" : "exa:anatomy-img1",
    "prov:label" : [ {
      "@value" : "anatomy_img1"
    } ]
  } ]
}

I'm using

riot complains:

$ riot  --output=Turtle test.jsonld
07:31:58 ERROR riot            :: There was a problem encountered loading a remote context [code=LOADING_REMOTE_CONTEXT_FAILED]

Here is the problem inside the JSON-LD playground

I found that the external context (I hope this term is correct, I'm not experienced with the format) http://openprovenance.org/prov.jsonld causes the problem. When removed both tools don't complain:
working JSON-LD playground

If the external context is replaced with https://json-ld.org/contexts/person.jsonld, it also works.
The replacement doesn't makes sense, it's just an example that the linked JSON-LD file http://openprovenance.org/prov.jsonld somehow breaks other tools.

Kind Regards,
Felix

@lucmoreau
Copy link
Owner

lucmoreau commented Dec 18, 2023 via email

@fbartusch
Copy link
Author

Same problem with https.
I think both tools I tested (Apache Jena's riot and the JSON-LD playground) expect that the content type returned from the context is application/ld+json.

But the content type of http://openprovenance.org/prov.jsonld is text/html.

$ curl -s -I http://openprovenance.org/prov.jsonld | grep -i "^Content-Type:"
Content-Type: text/html

$ curl -s -I https://json-ld.org/contexts/person.jsonld | grep -i "^Content-Type:"
Content-Type: application/ld+json

@lucmoreau
Copy link
Owner

lucmoreau commented Dec 18, 2023

@fbartusch thanks for identifying the origin of the problem

@trungdong is this something you could fix on openprovenance.org?

@fbartusch
Copy link
Author

I stumbled upon another problem and hope it's ok to add it here, as it's the same topic:

ProvToolbox currently produces this JSON-LD where the prov prefix is missing from some elements. The effect is, that other tools omit these information when they parse the file.
The example here is for Generation. In my more elaborated use case I can see the problem also for Membership, Derivation, Association, and Usage. Maybe it's also present for other elements that I don't use.

{
  "@context" : [ {
    "prov" : "http://www.w3.org/ns/prov#",
    "exa" : "https://example.com/"
  } ],
  "@graph" : [
    {
    "@type" : "prov:Generation",
    "entity" : "exa:generatedFile",
    "activity" : "exa:ProgramExecution"
  } ]
}

When I convert this into Turtle format (again with Apache Jena riot tool), the entity and activity information is lost. There is only a blank node:

_:b0   a       prov:Generation .

The example in the JSON-LD Playground: click

When I add the prov prefix to entity and activity, it behaves like expected:

{
  "@context" : [ {
    "prov" : "http://www.w3.org/ns/prov#",
    "exa" : "https://example.com/"
  } ],
  "@graph" : [
    {
    "@type" : "prov:Generation",
      "prov:entity" : "exa:generatedFile",
      "prov:activity" : "exa:ProgramExecution"
  } ]
}

Converting yields:

_:b    a              prov:Generation ;
        prov:activity  "exa:ProgramExecution" ;
        prov:entity    "exa:generatedFile" .

The example in the JSON-LD Playground: click

@fbartusch
Copy link
Author

Missclick, sorry. I didn't want to close it with the last comment ...

@fbartusch fbartusch reopened this Dec 20, 2023
@lucmoreau
Copy link
Owner

I think that's because the context has not been loaded by the tool properly. You will see that http://openprovenance.org/prov.jsonld contains the following declarations.

    "entity": { "@id": "prov:entity", "@type": "@id" },
    "activity": { "@id": "prov:activity", "@type": "@id" },
    "agent": { "@id": "prov:agent", "@type": "@id" },

@lucmoreau
Copy link
Owner

I now realise that this was an old version of the prov-jsonld context.

The definition of prov-jsonld can be found at https://openprovenance.org/prov-jsonld/.

The prov-jsonld context is accessible from https://openprovenance.org/prov-jsonld/context.json and is served with the application/json type.

The development branch has got a fix, and it will be included in the next release of ProvToolbox.

If you update the context by hand, does it fix the issue you are having with your tool?

@fbartusch
Copy link
Author

If you update the context by hand, does it fix the issue you are having with your tool?
No, unfortunately not.

I found a solution now. I took your context.json and converted it to context.jsonld.
I put the new context into a local webserver that returns the file with the MIME Type application/ld+json. 'The conversion tool now converts my files without complaining and the results looks like expected.
Maybe you can use that file on your server?
context.jsonld
Python script for my local webserver
Context used in my jsonld file

@trungdong
Copy link
Contributor

@fbartusch thanks for identifying the origin of the problem

@trungdong is this something you could fix on openprovenance.org?

I have fixed the MIME type.

$ curl -s -I -L http://openprovenance.org/prov.jsonld                                                                                                                                                           
HTTP/1.1 301 Moved Permanently
Server: nginx/1.24.0
Date: Wed, 03 Jan 2024 12:52:52 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: https://openprovenance.org/prov.jsonld

HTTP/2 200 
server: nginx/1.24.0
date: Wed, 03 Jan 2024 12:52:52 GMT
content-type: application/ld+json
content-length: 1896
last-modified: Thu, 09 Aug 2018 20:56:13 GMT
...

@trungdong
Copy link
Contributor

The prov-jsonld context is accessible from https://openprovenance.org/prov-jsonld/context.json and is served with the application/json type.

The development branch has got a fix, and it will be included in the next release of ProvToolbox.

I would advise against changing the canonical context's location to https://openprovenance.org/prov-jsonld/context.json since we will not be able to serve it with the correct MIME type, i.e. application/ld+json (without also serving other JSON files with this MIME type).

We can instead update the file at http://openprovenance.org/prov.jsonld with the latest, accurate content.

@lucmoreau
Copy link
Owner

lucmoreau commented Jan 3, 2024 via email

@trungdong
Copy link
Contributor

I've made a symlink at /prov-jsonld/context.jsonld pointing to /prov-jsonld/context.json

$ curl -s -I -L http://openprovenance.org/prov-jsonld/context.jsonld
HTTP/1.1 301 Moved Permanently
Server: nginx/1.24.0
Date: Tue, 09 Jan 2024 14:38:28 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: https://openprovenance.org/prov-jsonld/context.jsonld

HTTP/2 200 
server: nginx/1.24.0
date: Tue, 09 Jan 2024 14:38:28 GMT
content-type: application/ld+json
content-length: 4703
last-modified: Mon, 23 Mar 2020 15:34:15 GMT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants