# Test of various things you can do with an RDF schema for definitions. # Using SurfRDF: https://github.com/cosminbasca/surfrdf import rdflib import surf import yaml import os import warnings import parse DATABASE = 'memory' #DATABASE = 'virtuoso' surf.ns.register(baserock='http://baserock.org/definitions/example-schema#') if DATABASE == 'memory': # For testing store = surf.Store(reader='rdflib', writer='rdflib', rdflib_store='IOMemory') elif DATABASE == 'virtuoso': # For importing into Virtuoso database # See: https://pythonhosted.org/SuRF/integration/virtuoso.html # Note that you need to work around a bug in Virtuoso in order to # use this. See https://github.com/RDFLib/rdflib/issues/298 for more # info. Virtuoso expects the url parameter in the SPARQL update # request to be called 'query' rather than 'update'. You can change # this on line 488 of SPARQLWrapper/Wrapper.py of # as a nasty workaround. store = surf.Store(reader='sparql_protocol', writer='sparql_protocol', endpoint='http://localhost:8890/sparql', default_context='http://example.com') session = surf.Session(store) parse.load_all_morphologies(session, store) Cluster = session.get_class(surf.ns.BASEROCK.Cluster) cluster = Cluster.all() for s in cluster: s.load() # hack text = s.serialize('json') import json data = json.loads(text) print json.dumps(data, indent=4) break