Open algrebe opened 8 years ago
I tried parsing the rdfa using rdflib, and then serializing with json-ld.
import rdflib
g = rdflib.Graph()
g.load("input.rdfa", format="rdfa")
with open("output.jsonld", "w") as fp:
fp.write(g.serialize(format="json-ld", indent=4))
cat output.jsonld
[
{
"@id": "http://schema.org/CreativeWork",
"@type": [
"http://www.w3.org/2000/01/rdf-schema#Class"
],
"http://purl.org/dc/terms/source": [
{
"@id": "http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_rNews"
}
],
"http://www.w3.org/2000/01/rdf-schema#comment": [
{
"@value": "The most generic kind of creative work, including books, movies, photographs, software programs, etc."
}
],
"http://www.w3.org/2000/01/rdf-schema#label": [
{
"@value": "CreativeWork"
}
],
"http://www.w3.org/2000/01/rdf-schema#subClassOf": [
{
"@id": "http://schema.org/Thing"
}
]
},
{
"@id": "http://schema.org/WebPage",
"@type": [
"http://www.w3.org/2000/01/rdf-schema#Class"
],
"http://www.w3.org/2000/01/rdf-schema#comment": [
{
"@value": "A web page. Every web page is implicitly assumed to be declared to be of type WebPage, so the various properties about that webpage, such as <code>breadcrumb</code> may be used. We recommend explicit declaration if these properties are specified, but if they are found outside of an itemscope, they will be assumed to be about the page."
}
],
"http://www.w3.org/2000/01/rdf-schema#label": [
{
"@value": "WebPage"
}
],
"http://www.w3.org/2000/01/rdf-schema#subClassOf": [
{
"@id": "http://schema.org/CreativeWork"
}
]
}
]
Parsing the above output.jsonld
works perfectly fine. The difference between this and the original jsonld I've posted is the @context
and @graph
.
When defining the context somewhere else, and specifying it in each of the objects in the list using @context
, it still works -
[
{
"@context": "schema.context",
"@id": "schema:CreativeWork",
"@type": "rdfs:Class",
"dcterms:source": {
"@id": "http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_rNews"
},
"rdfs:comment": "The most generic kind of creative work, including books, movies, photographs, software programs, etc.",
"rdfs:label": "CreativeWork",
"rdfs:subClassOf": {
"@id": "schema:Thing"
}
},
{
"@context": "schema.context",
"@id": "schema:WebPage",
"@type": "rdfs:Class",
"rdfs:comment": "A web page. Every web page is implicitly assumed to be declared to be of type WebPage, so the various properties about that webpage, such as <code>breadcrumb</code> may be used. We recommend explicit declaration if these properties are specified, but if they are found outside of an itemscope, they will be assumed to be about the page.",
"rdfs:label": "WebPage",
"rdfs:subClassOf": {
"@id": "schema:CreativeWork"
}
}
]
How can I avoid writing @context
in each of the objects ?
Currently experiencing similar trouble in parsing some json-ld making use of "@graph" to attach a common "@context" to a list of identically structured objects.
Similar problem here also. Cannot parse back the serialized json-ld (serialized by rdflib-jsonld).
It seems to work when using ConjunctiveGraph instead of Graph.
@fserena
ConjunctiveGraph works!
I created g=ConjunctiveGraph
and it now works perfectly fine
Example 61 from https://www.w3.org/TR/json-ld/ gives an empty graph for me, even with ConjunctiveGraph
.
Maybe this helps: I got it working, only when I stopped using the method-result chaining shortcut syntax:
foo = ConjunctiveGraph() bar = foo.parse(data=mydoor, format='json-ld') foo.serialize()
This works. However the object "bar" returned from calling 'parse' is the wrong/empty graph, so we can't chain the expressions together with ConjunctiveGraph().parse(etc...).
Maybe this helps: I got it working, only when I stopped using the method-result chaining shortcut syntax:
foo = ConjunctiveGraph() bar = foo.parse(data=mydoor, format='json-ld') foo.serialize()
This works. However the object "bar" returned from calling 'parse' is the wrong/empty graph, so we can't chain the expressions together with ConjunctiveGraph().parse(etc...).
Thanks, It's work fine for me! Don't use the chain expressions together with ConjunctiveGraph().parse(etc...).
I tried converting the following rdfa to jsonld on rdf translator.
The result was the following -
However, when I try to load this json-ld using the following