Presentation is loading. Please wait.

Presentation is loading. Please wait.

RDFLib for your Linked Data Venture Mathew Cherian Oct 12, 2010.

Similar presentations


Presentation on theme: "RDFLib for your Linked Data Venture Mathew Cherian Oct 12, 2010."— Presentation transcript:

1 RDFLib for your Linked Data Venture Mathew Cherian Oct 12, 2010

2 What is it? A python library for working with RDF Contains parsers and serializers for RDF/XML, N3, Ntriples, Turtle, TriX, and RDFa Has graph interface that can be backed by a number of store implementations including MySQL

3 Our Task 1. Look up Tim’s FOAF URI(available at: http://www.w3.org/People/Berners-Lee/card#i) 2. Extract his friends 3. Look at the friends’ FOAF files 4. See where they work 5. Use the workplace URI to query DBpedia for it’s location and/or other labels associated with them 6. Print a list of Tim’s friends, their workplaces and other workplace details

4 Why RDFLib? It is a Python library

5 RDFLib (version 2.4.0) and SPARQLWrapper Ubuntu Search for “rdflib” and sparqlwrapper in Package Manager  Otherwise  www.rdflib.net; http://sparql-wrapper.sourceforge.net/ www.rdflib.nethttp://sparql-wrapper.sourceforge.net/ What you would need and where to get it

6 1: Look up Tim’s FOAF URI from rdflib.Graph import Graph g = Graph() g.parse("http://www.w3.org/People/Berners-Lee/card")

7 2: Extract his friends (their foaf urls) from rdflib import Namespace g.query(' SELECT ?a ?b ?aname ?bname WHERE { ?a foaf:knows ?b. OPTIONAL { ?a foaf:name ?aname. ?b foaf:name ?bname. } }', initNs=dict(foaf=Namespace("http://xmlns.com/foaf/0.1")))

8 3, 4: Look at the friends’ FOAF files and find out where they work f = Graph() f.parse(?b) f.objects(?b, foaf["workplaceHomepage"])

9 from SPARQLWrapper import SPARQLWrapper, JSON h = SPARQLWrapper("http://dbpedia.org/sparql")http://dbpedia.org/sparql h.setQuery(queryString) h.setReturnFormat(JSON) results = h.query().convert() 5: Use the workplace URI to query dbpedia for it’s location and/or other labels associated with them

10 6: Print a list of Tim’s friends, their workplaces and other workplace details for result in results["results"]["bindings"]: print '%s(%s) knows %s(%s) who works at %s, which is based at %s' % (row[0], row[2], row[1], row[3], workplace, result["label"]["value"])


Download ppt "RDFLib for your Linked Data Venture Mathew Cherian Oct 12, 2010."

Similar presentations


Ads by Google