Last active
August 29, 2015 14:10
-
-
Save edsu/65b70aba97214c154da4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import json | |
import rdflib | |
from rdflib.plugin import register, Parser, Serializer | |
register('json-ld', Serializer, 'rdflib_jsonld.serializer', 'JsonLDSerializer') | |
ex = rdflib.Namespace("http://example.com/ns#") | |
g = rdflib.ConjunctiveGraph() | |
u0 = rdflib.URIRef("http://example.com/list") | |
u1 = rdflib.BNode() | |
u2 = rdflib.BNode() | |
u3 = rdflib.BNode() | |
u4 = rdflib.BNode() | |
g.add((u0, ex.hasStuff, u1)) | |
g.add((u1, rdflib.RDF.type, rdflib.RDF.List)) | |
g.add((u1, rdflib.RDF.first, u2)) | |
g.add((u2, rdflib.RDF.value, rdflib.Literal(1))) | |
g.add((u1, rdflib.RDF.rest, u3)) | |
g.add((u3, rdflib.RDF.type, rdflib.RDF.List)) | |
g.add((u3, rdflib.RDF.first, u4)) | |
g.add((u4, rdflib.RDF.value, rdflib.Literal(2))) | |
g.add((u3, rdflib.RDF.rest, rdflib.RDF.nil)) | |
context = { | |
"ex": "http://example.com/ns#", | |
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", | |
"ex:hasStuff": { | |
"@container": "@list" | |
} | |
} | |
jsonld = json.loads(g.serialize(format='json-ld', context=context)) | |
print json.dumps(jsonld, indent=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://bitbucket.org/westurner/bobcat/src/tip/bobcat/__init__.py?at=default
https://github.com/westurner/healthref/blob/gh-pages/healthref.py#L176