digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.65k stars 195 forks source link

dbPedia endpoint uses @context that jsonld.js cannot parse #463

Open flyon opened 2 years ago

flyon commented 2 years ago

I'm playing around with querying dbPedia. I'm filling in a DESCRIBE query from the web SPARQL interface and I set the format to JSON-LD (with context).

This is the resulting URL. In the browser it shows me a plain json-ld result.

If I make the same request from my application with fetch and parse the json result with jsonld I get the following error:

jsonld.SyntaxError: Invalid JSON-LD syntax; term in form of IRI must expand to definition.
    at Object.../core/node_modules/jsonld/lib/context.js.api.createTermDefinition (context.js:632)
    at ../core/node_modules/jsonld/lib/context.js.api.process (context.js:371)
    at async ../core/node_modules/jsonld/lib/expand.js.api.expand (expand.js:211)
    at async Function.jsonld.expand (jsonld.js:325)
    at async Function.jsonld.toRDF (jsonld.js:671)

When I inspect I see that termIRI !== id where termIRI is netIncomehttp://dbpedia.org/datatype/polishZłoty" and id is http://dbpedia.org/ontology/netIncome

The strange context value with a text followed by a URI is because dbPedia uses a context entry for each property in the result, and when the property is used with multiple datatypes, it creates multiple contexts for each.

In this case jsonld breaks at the following key-value pair in @context:

 "netIncomehttp://dbpedia.org/datatype/polishZłoty": { "@id": "http://dbpedia.org/ontology/netIncome", "@type": "http://dbpedia.org/datatype/polishZłoty" },

I notice it uses both an @id and a @type, is this part of the standard? and is it supported? Or is it the special characters that break things?