rdflib-jsonld icon indicating copy to clipboard operation
rdflib-jsonld copied to clipboard

use the default namespaces in generating context for json-ld output from rdflib

Open satra opened this issue 8 years ago • 4 comments

import rdflib as rl
g = rl.Graph()
g.bind('ex', 'http://example.org/')
g.bind('ex2', 'http://example2.org/')
g.add((rl.term.URIRef('http://example.org/a'), rl.RDF.type, rl.term.URIRef('http://example2.org/a')))
print(g.serialize(format='turtle').decode())
print(g.serialize(format='json-ld').decode())

returns

@prefix ex: <http://example.org/> .
@prefix ex2: <http://example2.org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:a a ex2:a .

and

[
  {
    "@id": "http://example.org/a",
    "@type": [
      "http://example2.org/a"
    ]
  }
]

it would be nice if the default prefixes could automatically be used for generating the context internally.

satra avatar Oct 17 '16 14:10 satra

It's actually very simple to provide it yourself using the namespaces() function on Graph:

import rdflib
g = rdflib.Graph()
g.load('http://www.w3.org/People/Berners-Lee/card.rdf')
# set the context to a dictionary construction from g.namespaces():
print g.serialize(format='json-ld', context=dict(g.namespaces()))

I'm not arguing for or against making this default behavior (it already is in other namespaced formats), but it is very simple to do on your own.

jpmccu avatar May 08 '18 13:05 jpmccu

Issue #95 has been closed because this one (#43) was running, and this one is closed because the #95 references it.......... and the context still has to be put manually... sad.

Swannbm avatar Oct 06 '18 20:10 Swannbm

@Swannbm Wrong, this issue is still open.

akuckartz avatar Oct 06 '18 20:10 akuckartz

.....oh.... Forgive me please, I thought it was closed by cmaumet in 2016. Still new on Github.

Swannbm avatar Oct 07 '18 07:10 Swannbm