Download
rdf for developers n.
Skip this Video
Loading SlideShow in 5 Seconds..
RDF FOR DEVELOPERS PowerPoint Presentation
Download Presentation
RDF FOR DEVELOPERS

RDF FOR DEVELOPERS

155 Views Download Presentation
Download Presentation

RDF FOR DEVELOPERS

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Paul Groth RDF FOR DEVELOPERS Thanks to Eyal Oren, Stefan Schlobach for slides

  2. Contents • The Web of Data • A Data Model • A Query Language • Query Time… • Building Apps • Exposing Data

  3. Why can’t we query all the information on the Web as a database?

  4. Data Interoperability on the Web Different formats, different structures, different vocabularies, different concepts, different meaning Data should be structured (not ASCII) Structure should be data-oriented (not HTML) Meaning of data should be clear (not XML) Data should have standard APIs (not Flickr) Reusable mappings between data are needed (not XSLT)

  5. What is the Semantic Web? Tim Berners-Lee “There is lots of data we all use every day, and it’s not part of the web. I can see my bank statements on the web, and my photographs, and I can see my appointments in a calendar. But can I see my photos in a calendar to see what I was doing when I took them? Can I see bank statement lines in a calendar? No. Why not? Because we don’t have a web of data. Because data is controlled by applications and each application keeps it to itself.”

  6. The Web of Data

  7. Enrich your data

  8. Standard Data Model • RDF: basic data format (triples form hypergraph) • john likes mary . • isbn:10993 dc:title "The Pelican Brief" . • RDFS : simple schema language (subclass, subproperty) • dc:title rdfs:subPropertyOf rdfs:label . • Jeep isa Car . • OWL: rich schema language (constraints, relations) • likes isa owl:symmetricProperty . • RDF allows interlinked graphs of arbitrary structure • RDFS and OWL allow inferencing of implicit information

  9. Standard API: SPARQL • Query language for RDF • Based on existing ideas (e.g. SQL) • Supported widely • Standard query protocol • How to send a query over HTTP • How to respond over HTTP

  10. RDF BASICS

  11. RDF Data Model: Summary • Resources • Triples • Statements: typed links between triples • May involve literals as property values • Graph • Set of Statements • Interlinked by reusing same URIs acrossed triples

  12. RDF Syntax • Several Different Formats • Standard RDF/XML • NTriples • Turtle

  13. SPARQL

  14. SQL? • Formulate a query on the relational model • students(name, age, address) • Structured Query Language (SQL) SELECT namedata needed FROM studentdata source WHERE age>20data constraint

  15. SPARQL • Standard RDF query language • based on existing ideas • standardised by W3C • widely supported • Standard RDF query protocol • how to send a query over HTTP • how to respond over HTTP

  16. SPARQL Query Syntax • SPARQL uses a select-from-where inspired syntax (like SQL): • select: the entities (variables) you want to return SELECT ?city • from: the data source (RDF dataset) FROM <http://example.org/geo.rdf> • where: the (sub)graph you want to get the information from WHERE {?city geo:areacode “010” .} • Including additional constraints on objects, using operators WHERE {?city geo:areacode ?c. FILTER (?c > 010)} • prologue: namespace information PREFIX geo: <http://example.org/geo.rdf#>

  17. SPARQL Query Syntax PREFIX geo: <http://example.org/geo/> SELECT ?city FROM <http://example.org/geoData.rdf> WHERE {?city geo:areacode ?c . FILTER (?c > 010) }

  18. EuropeanCountry “020”^^xsd:integer hasCapital type ? ? ? SPARQL Graph Patterns • The core of SPARQL • WHERE clause specifies graph pattern • pattern should be matched • pattern can match more than once • Graph pattern: • an RDF graph • with some nodes/edges as variables

  19. Basis: triple patterns • Triples with one/more variables • Turtle syntax • ?X geo:hasCapital geo:Amsterdam • ?X geo:hasCapital ?Y • ?X geo:areacode "020" • ?X ?P ?Y • All of them match this graph: areacode hasCapital Netherlands Amsterdam “020”

  20. Basis: triple pattern • A very basic query PREFIX geo: <http://example.org/geo/> SELECT ?X FROM <http://example.org/geoData.rdf> WHERE { ?X geo:hasCapital ?Y .}

  21. Conjunctions: several patterns • A pattern with several graphs, all must match PREFIX geo: <http://example.org/geo/> SELECT ?X FROM <http://example.org/geoData.rdf> WHERE { {?X geo:hasCapital ?Y } {?Y geo:areacode "020" } } equivalent to PREFIX geo: <http://example.org/geo/> SELECT ?X FROM <http://example.org/geoData.rdf> WHERE { ?X geo:hasCapital ?Y . ?Y geo:areacode "020" . }

  22. Conjunctions: several patterns • A pattern with several graphs, all must match PREFIX geo: <http://example.org/geo/> SELECT ?X FROM <http://example.org/geoData.rdf> WHERE { {?X geo:hasCapital ?Y } {?Y geo:areacode "020" } } equivalent to PREFIX geo: <http://example.org/geo/> SELECT ?X FROM <http://example.org/geoData.rdf> WHERE { ?X geo:hasCapital [ geo:areacode "020" ]. }

  23. Note: Turtle syntax again • ?X geo:name ?Y ; geo:areacode ?Z . • ?X geo:name ?Y . ?X geo:areacode ?Z . • ?country geo:capital [ geo:name “Amsterdam” ] .

  24. Alternative Graphs: UNION • A pattern with several graphs, at least one should match PREFIX geo: <http://example.org/geo/> SELECT ?city WHERE { { ?city geo:name "Parijs"@nl } UNION { ?city geo:name "Paris"@fr .} }

  25. Optional Graphs • RDF is semi-structured • Even when the schema says some object can have a particular property, it may not always be present in the data • Example: persons can have names and email addresses, but Frank is a person without a known email address name person001 “Antoine” email “aisaac@few.vu.nl” name person002 “Frank”

  26. Optional Graphs (2) • “Give me all people with first names, and if known their email address” • An OPTIONAL graph expression is needed PREFIX : <http://example.org/my#> SELECT ?person ?name ?email WHERE { ?person :name ?name . OPTIONAL { ?person :email ?email } }

  27. Testing values of nodes • Tests inFILTERclause have to be validated for matching subgraphs • RDF model-related operators • isLiteral(?aNode) • isURI(?aNode) • STR(?aResource) Interest of STR? SELECT ?X ?N WHERE { ?X ?P ?N . FILTER (STR(?P)="areacode") } • For resources with names only partly known • For literals with unknown language tags

  28. Testing values of nodes • Tests inFILTERclause • Comparison: • ?X <= ?Y, ?Z < 20, ?Z = ?Y, etc. • Arithmetic operators • ?X + ?Y, etc. • String matchingusing regular expressions • REGEX (?X,"netherlands","i") • matches"The Netherlands" PREFIX geo: <http://example.org/geo/> SELECT ?X ?N WHERE { ?X geo:name ?N . FILTER REGEX(STR(?N),"dam") }

  29. Filtering results • Tests in FILTER clause • Boolean combination of these test expressions • && (and), || (or), ! (not) • (?Y > 10 && ?Y < 30) || !REGEX(?Z,"Rott") PREFIX geo: <http://example.org/geo/> SELECT ?X FROM <http://example.org/geo.rdf> WHERE {?X geo:areacode ?Y ; geo:name ?Z . FILTER ((?Y > 10 && ?Y < 30) || !REGEX(STR(?X),"Rott")) }

  30. Boolean comparisons and datatypes • Reminder: RDF has basic datatypes for literals • XML Schema datatypes:xsd:integer, xsd:float, xsd:string, etc. • Datatypes can be used in value comparison • X < “21”^^xsd:integer • and be obtained from literals • DATATYPE(?aLiteral)

  31. Solution modifiers • ORDER BY SELECT ?dog ?ageWHERE { ?dog a Dog ; ?dog :age ?age . } ORDER BY DESC(?age) • LIMITSELECT ?dog ?ageWHERE { ?dog a Dog ; ?dog :age ?age . }ORDER BY ?dogLIMIT 10

  32. SELECT Query Results • SPARQL SELECT queries return solutions that consist of variable bindings • For each variable in the query, it gives a value (or a list of values). • The result is a table, where each column represents a variable and each row a combination of variable bindings

  33. Query result: example • Query: “return all countries with the citiesthey contain, and their areacodes, if known” • Result (as table of bindings): PREFIX geo: <http://example.org/geo/> SELECT ?X ?Y ?Z WHERE { ?X geo:containsCity ?Y. OPTIONAL {?Y geo:areacode ?Z} }

  34. SELECT Query results: format • Query: return all capital cities • Results as an XML document : PREFIX geo: <http://example.org/geo/> SELECT ?X ?Y WHERE { ?X geo:name ?Y .} <sparqlxmlns="http://www.w3.org/2005/sparql-results#"> <head> <variablename="X"/> <variablename="Y"/> </head> <results> <result> <bindingname="X"><uri>http://example.org/Paris</uri></binding> <bindingname="Y"><literal>Paris</literal></binding> </result> <result> <bindingname="X"><uri>http://example.org/Paris</uri></binding> <bindingname="Y"><literalxml:lang="nl">Parijs</literal></binding> </result> ... </results> </sparql> Header Results

  35. Result formats <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="x"/> <variable name="hpage"/> </head> <results> <result> <binding name=”x"> <literal datatype=”…/XMLSchema#integer">30</literal> </binding> <binding name="hpage"> <uri>http://work.example.org/bob/</uri> </binding> </result> </results> </sparql> • RDF/XML • N3 • JSON • TEXT

  36. Query Result forms • SELECT queries return variable bindings • Do we need something else? • Statements from RDF original graph • Data extraction • New statements derived from original data according to a specific need • Data conversion, views over data

  37. SPARQL CONSTRUCT queries • Construct-queries return RDF statements • The query result is either a subgraph of the original graph, or a transformed graph Subgraph query: PREFIX geo: <http://example.org/geo/> CONSTRUCT {?X geo:hasCapital ?Y } WHERE { ?X geo:hasCapital ?Y . ?Y geo:name "Amsterdam" } hasCapital Netherlands Amsterdam

  38. SPARQL CONSTRUCT queries • Construct-queries return RDF statements • The query result is either a subgraph of the original graph, or a transformed graph Transformation query: PREFIX geo: <http://example.org/geo/> PREFIX my: <http://example.org/myNS/> CONSTRUCT {?Y my:inCountry ?X} WHERE { ?X geo:hasCapital ?Y} inCountry Netherlands Amsterdam