querying rdf rdfs owl
play

Querying RDF, RDFS, OWL Partially adapted from Lee Feigenbaum and - PowerPoint PPT Presentation

Querying RDF, RDFS, OWL Partially adapted from Lee Feigenbaum and Olaf Hartigs slides What is a Graph Query Language? A Graph Query language should allow us to Retrieve any query-specified portion of some graph data Create a new


  1. Querying RDF, RDFS, OWL Partially adapted from Lee Feigenbaum and Olaf Hartig’s slides

  2. What is a Graph Query Language?  A Graph Query language should allow us to  Retrieve any query-specified portion of some graph data  Create a new graph by combining different pieces of retrieved subgraphs in a query-specified way  Compute a set of graph properties  Diameter  Distance between two nodes  Centrality of nodes  …  We will discuss SPARQL  Standard RDF Query Language  SPARQL only allows us to do a few of the operations an ideal graph query language should

  3. Example Graph

  4. A Single Variable Graph Pattern <http://eve/> foaf:interest ?x ?x http://xtech.2008.org

  5. SELECT Returns Bindings select ?x, ?y where {?x foaf:interest ?y} ?x ?y <htttp://eve/> http://xtech.org <htttp://bob/> http://www2008.org <htttp://alice> http://www2008.org

  6. Basic Graph Patterns  What has Alice written?  BGP AND {?x dc:creator http://alice/ . ?x dc:title ?y} {?x dc:creator http://alice/; Turtle syntax dc:title ?y}  Who has common interests?  BGP {?x foaf:interest ?y . ?z foaf:interest ?y }  Matching Literals http://alice/ hasAge 29^^xsd:integer  Consider the data http://alice/ hasPet “cat”@en  Will it match  {?x hasPet “cat”} ?  {?x hasAge 29} ?

  7. Structure of a SPARQL Query PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dc: <http://purl.org/dc/elements/1.1/> . SELECT ?x, ?z, ?y FROM <http://example.org/Hackers> WHERE { {?x dc:creator ?z . ?x dc:title ?y} } ORDER BY ?y  Prologue:  Prefix definitions are references in the query  No period (“.”) character to separate (as in N3 )  If we said PREFIX : http://example.org/Hackers  We could drop the FROM clause  We have to say :?x etc.

  8. Structure of a SPARQL Query PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dc: <http://purl.org/dc/elements/1.1/> . SELECT ?x, ?z, ?y FROM <http://example.org/Hackers> WHERE { {?x dc:creator ?z . Graph Pattern (not only BGP) ?x dc:title ?y} } ORDER BY ?y  Result form specification:  SELECT, DESCRIBE, CONSTRUCT, or ASK  SELECT: - Variable list or asterisk (“*”) character for all  DISTINCT for disjoint results

  9. Structure of a SPARQL Query PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dc: <http://purl.org/dc/elements/1.1/> . SELECT ?x, ?z, ?y FROM <http://example.org/Hackers> WHERE { {?x dc:creator ?z . ?x dc:title ?y } ORDER BY ?y  Dataset specification:  Specify the datasets to be queried  FROM and FROM NAMED clauses (each with a URI)  When multiple datasets are specified, the system assumes an RDF merge of the two graphs  FROM NAMED is discussed later

  10. Structure of a SPARQL Query PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dc: <http://purl.org/dc/elements/1.1/> . SELECT ?x, ?z, ?y FROM <http://example.org/Hackers> WHERE { {?x dc:creator ?z . ?x dc:title ?y} } ORDER BY ?y  Solution modifiers:  Modify the result set, but not the single results  ORDER BY, LIMIT, or OFFSET  LIMIT gets a query-specified number of results  OFFSET k gets results starting from the k -th result record

  11. Graph Patterns in SPARQL  Basic graph pattern (BGP)  Optional graph pattern  Union graph pattern  (Constraints)  Graph graph pattern  Group graph pattern

  12. More on BGPs  Using Blank Nodes in Queries  Blank nodes in graph patterns act as variables , not as references to specific blank nodes in the data being queried .  Permitted as subject and object of a triple pattern  Non-selectable variables  Indicated either as _:abc or as [ ] _:b50 dc:creator ?x. [ dc:creator ?x ] dc:title ?title _:b50 dc:title ?title ?x blog:comment _:b57 . ?x blog_comment [ dc:title ?title ] . _:b57 dc:title ?title .  Blank node identifiers can appear in query results

  13. Optional Graph Patterns  Who commented on “ trouble_with_bob ”? select ?p, ?t where {Trouble_with_bob blog:comment ?y . ?y dc:creator ?p . ?y dc:title ?t}  Does not report eve select ?p, ?t where {Trouble_with_bob blog:comment ?y . ?y dc:creator ?p . optional {?y dc:title ?t} }  Reports eve

  14. Union Graph Patterns  Who is interested in the conferences Xtech 2008 OR WWW 2008? select ?x where { {?x foaf:interest http://xTech2008/} UNION {?x foaf:interest http://www2008/} }  Union patterns are used to query for alternatives select ?x, ?y where { {John foaf:interest ?x } UNION {John likes ?y} }

  15. Constraints – Filters  Constraints filter solutions  Keyword FILTER followed by expression  Filter expressions contain operators and functions select ?y ?y where { _b20 dc:title ?y Alice Rules filter regex(?y “rule”) }

  16. Built-in Constraints  Unary Operators

  17. Filter Example  Find me all landlocked countries with a population greater than 15 million with the highest population country first. PREFIX type: <http://dbpedia.org/class/yago/> PREFIX prop: <http://dbpedia.org/property/> SELECT ?country_name ?population WHERE { ?country a type:LandlockedCountries ; rdfs:label ?country_name ; prop:populationEstimate ?population . FILTER (?population > 15000000 && langMatches(lang(?country_name), "EN")) . } ORDER BY DESC(?population)  Try this at http://dbpedia.org/sparql

  18. Homework from DBPedia  Find everything about the country whose name is Afghanistan in language English  everything means all properties of the country  Who is Barak Obama?  Where is Greece?  What is the capital of Nepal?  What is the area of work of Albert Einstein?  How is India related to “Indira Gandhi”?

  19. Group Graph Patterns  Consider the query  Groups break up a graph PREFIX type: <http://dbpedia.org/class/yago/> PREFIX prop: <http://dbpedia.org/property/> pattern into SELECT ?country_name ?population multiple pieces WHERE { such that filters { ?country a type:LandlockedCountries ; can be applied rdfs:label ?country_name ; to each piece prop:populationEstimate ?population . Group 1 and joint filters FILTER (?population > 15000000 && langMatches(lang(?country_name), "EN")) can be applied } across groups { ?place prop:establishedDate ?y . FILTER (?y > 1980) Group 2 }. Filter on Group 1 and Group 2 FILTER (?country = ?place) } ORDER BY DESC(?population)

  20. Negation with SPARQL Filters <rdf:Description  Find cities in the UK rdf:about="http://dbpedia.org/resource/Manchester"> < rdf:type whose name is not rdf:resource="http://schema.org/City"/> </rdf:Description> Manchester. <rdf:Description PREFIX prop: rdf:about="http://dbpedia.org/resource/Manchester"> <http://dbpedia.org/property/> < dbpprop:subdivisionName xmlns:dbpprop="http://dbpedia.org/property/" SELECT DISTINCT ?x xml:lang ="en">United WHERE { Kingdom</dbpprop:subdivisionName> ?x a <http://schema.org/City>. </rdf:Description> ?x rdfs:label ?city. <rdf:Description FILTER (str(?city) != rdf:about="http://dbpedia.org/resource/Manchester"> < rdfs:labe l xml:lang ="zh"> 曼 彻 斯特 "Manchester") . ?x prop:subdivisionName ?y. </rdfs:label> FILTER(str(?y) = "United Kingdom"). </rdf:Description> <rdf:Description } ORDER BY desc(?x) rdf:about="http://dbpedia.org/resource/Manchester"> < rdfs:labe l xml:lang ="nl">Manchester</rdfs:label> </rdf:Description>

  21. Negation with SPARQL Filters x http://dbpedia.org/resource/Stoke-on-Trent http://dbpedia.org/resource/Sheffield http://dbpedia.org/resource/Portsmouth http://dbpedia.org/resource/Plymouth http://dbpedia.org/resource/Newcastle_upon_Tyne Is this result http://dbpedia.org/resource/Manchester What is this? incorrect? http://dbpedia.org/resource/Kingston_upon_Hull http://dbpedia.org/resource/Hamilton,_Bermuda http://dbpedia.org/resource/Edinburgh http://dbpedia.org/resource/City_of_Sunderland http://dbpedia.org/resource/City_of_Salford http://dbpedia.org/resource/City_of_Lancaster http://dbpedia.org/resource/City_of_Carlisle http://dbpedia.org/resource/City_of_Bradford http://dbpedia.org/resource/Bristol http://dbpedia.org/resource/Brades http://dbpedia.org/resource/Birmingham

  22. Negation in SPARQL Filters (contd.)  Desired behavior: A logic exercise p  q  not r Negation by Failure q  s  Negation as failure is q  t t  a non-monotonic inference is p true? rule in logic programming, used to PREFIX prop: <http://dbpedia.org/property/> derive predicate not(p) SELECT distinct ?x from failure to WHERE { ?x a <http://schema.org/City>. derive predicate p ?x prop:subdivisionName ?y.  First try to satisfy the predicate FILTER(str(?y) = "United Kingdom"). OPTIONAL{?x rdfs:label ?city. p , and test if you failed. If you FILTER (str(?city) = "Manchester")}. did, declare the result as FILTER(!bound(?city)) satisfying not(p) } ORDER BY desc(?x)

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend