RDFlib: access a triple store in 5 lines of code


/ Published in: Python
Save to your folder(s)

Note that in the example the 'sleepycat' backend is used ( Oracle Berkeley DB, which requires the ''bsddb3'' python bindings). If you don't have that installed you can just remove that directive and the triples will be loaded in memory.....


Copy this code and paste it in your HTML
  1. ed@rorty:~$ python
  2. Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
  3. [GCC 4.4.1] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> import rdflib
  6. >>> graph = rdflib.Graph('Sleepycat')
  7. >>> graph.open('my-store', create=True)
  8. >>> graph.parse('http://dbpedia.org/resource/Semantic_Web')
  9. >>> for object in graph.objects(predicate=rdflib.namespace.OWL.sameAs):
  10. ... print object
  11. ...
  12. http://dbpedia.org/resource/Semantic_Web
  13. http://rdf.freebase.com/ns/guid.9202a8c04000641f8000000000039a20

URL: http://www.semanticoverflow.com/questions/75/which-tools-and-libraries-do-you-use-to-develop-semantic-web-applications

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.