1 / 29

Semantic Web

Semantic Web. Chapter 7. SPARQL: Query Language for RDF. PREFIX ex: <http://example.org/> SELECT ?title ?author WHERE { ?book ex:publishedBy <someone>. ?book ex:title ?title. ?book ex:author ?author }. Example result (Select result). Group patterns. { {?pattern thatIs <uri/simple> }

trevor
Download Presentation

Semantic Web

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Semantic Web Chapter 7

  2. SPARQL: Query Language for RDF PREFIX ex: <http://example.org/> SELECT ?title ?author WHERE { ?book ex:publishedBy <someone>. ?book ex:title ?title. ?book ex:author ?author }

  3. Example result (Select result)

  4. Group patterns { {?pattern thatIs <uri/simple> } {} ?code usingPattern ?pattern }

  5. OPTIONAL pattern Not required for a match Creates bindings if it occurs. OPTIONAL { ?book ex:author ?author} Unbound fields are left empty in the result.

  6. UNION pattern {group} UNION {group} Match if either group (or both) is a match. {?book ex:author ?author . } UNION {?book ex:writer ? author .}

  7. Data values Untyped, untyped and typed forms of "a string" is different. Some types may have semantics to evaluate equality between them. "041"^int == "41"^int == "41"^double

  8. Filters Extra conditions for accepting a particular variable assignment. Boolean statements (or error). FILTER (?price < 100) Scope of rule is the containing group.

  9. Comparison operators =, >, <= ....etc Works according to the semantics of the compared types. Gives errors for incompatible comparisons.

  10. Special operators BOUND isURI isBLANK isLITERAL STR LANG DATATYPE sameTERM(A,B) langMACHES(A,B) REGEX(A;B)

  11. Boolean and arithmetic operators &&, ||, !, +, -, *, / These are quite familiar.

  12. Result formats SELECT => table CONSTRUCT => rdf graph DESCRIBE => for browsing ASK => boolean

  13. Modifiers ORDER BY => sorting LIMIT OFFSET => result pruning DISTINCT => removes duplicates

  14. Semantics and Algebra of SPARQL • SPARQL Algebra: • "a system of clearly computational operations which can be used to calculate the results of a query" • VERY similar to SQL

  15. Translating queries to algebra • We distinguish operators that describe graph patterns from those describing solution sequence modifiers • Graph pattern operators: • Basic Graph Patterns (BGP) • Join (Conjunctions) • LeftJoin (Optional Condition) • Filter • Union • Each returns the result of the subquery it describes

  16. Translating queries to algebra • An example query: { ?book ex:price ?price . FILTER(?price < 15) OPTIONAL {?book ex:title ?title . } { ?book ex: author ex: Shakespeare . } UNION { ?book ex:author ex:Marlowe . } }

  17. Translating queries to algebra • Step one: Expand all abbreviations, and all simple graph patterns (triples) are expressed with BGP • Step two: Occurrences of UNION are marked with the operator Union • Step three: Group graph patterns are resolved from inside to outside: Join, Filter and LeftJoin • If Sub-Expressions are OPTIONAL Filter(F, A) • R := LeftJoin(R, A, F) • if SE is OPTIONAL A • R := LeftJoin(R, A, true) • Otherwise • R := Join(R, SE) • Z denotes no condition or variable binding • Our BGP-s are denoted Z, for example

  18. Translating queries to algebra • Applying these rules on example: Filter((?price < 15) Join( LeftJoin( Join(Z, BGP(?book <example.org/price> ?price.)), Join(Z, BGP(?book <example.org/title> ?title.)), true ), Union(Join(Z, BGP(?book <example.org/author> <example.org/Shakespeare>.)), Join(Z, BGP(?book <example.org/author> <example.org/Marlowe>.))) ))

  19. Calculations in SPARQL Algebra • All these operators return query results • These partial results are denoted with µ-s. • Read the book for understanding calculations with these ... • One result is that Z is neutral with respect to Join

  20. Calculations in SPARQL algebra • Which simplifies a bit: Filter((?price < 15) Join( LeftJoin( BGP(?book <example.org/price> ?price.), BGP(?book <example.org/title> ?title.), true ), Union(BGP(?book <example.org/author> <example.org/Shakespeare>.), BGP(?book <example.org/author> <example.org/Marlowe>.))) ))

  21. Operators for modifiers • Order By, Project, Distinct, Slice can only be done on the final result

  22. Conjunctive Queries for OWL DL • SPARQL: Query language for RDF graphs • RDFS and OWL not directly supported • OWL DL can be interpreted as graphs, BUT: • OWL DL Ontologies describe many interpretations • OWL DL interpretations may comprise an infinite number of elements

  23. Conjunctive Queries for OWL DL • Conjunctive queries is a query formalism for OWL DL that MIGHT serve as a basis for a SPARQL for OWL extension

  24. Conjunctive queries • Mainly follows first-order logic syntax: • Book(x) ^ publishedBy(x,CRCPress) ^ Author(x,y) • Allowed atoms: • C(e) or ¬C(e). C is a class, e is a variable • R(e,f). R is a property name, e/f variables/name • Note: ¬R(e,f) not allowed • Applying negation: • Adding axiom to knowledge base: • ¬R(e,f) ≡ ¬(∃R{e})(f) • Book(x)^¬(∃publishedBy{CRCPress})(x)^Author(x,y)

  25. Variables • Distinguished Variables: • Free variables that we know must exist, but we may not have the knowledge of what/who it is • Book(a) (a is a book)Book⊆ ∃author.⊤ (every book has an author) • This knowledge base has no solution for Book(x) ^ author(x, y) • We know of no y-s that can be returned • Non-Distinguished Variables: • Bound variables, useful for querying concrete instances, or asking for the existence of an element • ∃x.(author(x, y) ^ Book(x))

  26. Conjunctive Queries and SPARQL • Different, different, but same: • Consider the atom R(e, f) as a triple <e, R, f> • conjunction of atoms describe a graph structure

  27. Conjunctive Queries and SPARQL • ... but different • CQs lack features like OPTIONAL and UNION • Only SPARQL allows disjunction • SPARQL allows variables in place of property names, CQ have syntactic restrictions of first order logic

  28. Conjunctive Queries and SPARQL • Different usage of variables • SPARQL represents placeholders in queries by variables or blank nodes • Not all variables need to be part of result in SPARQL • CQ use Distinguished and Non-Distinguished variables • Summarized by two features: • Anonymous values: Can the variable take values for which no concrete ID is known? • Output: Will the variable appear in the result?

  29. Conjunctive Queries and SPARQL • Major difference is between SPARQL variables and Distinguished Variables • Latter is restricted to elements with concrete names • Thus, semantic approach from SPARQL leads to all entailed elements having to be returned • Strongest technical reason as to why no official extension from SPARQL to OWL DL exists

More Related