Terp: An OWL-friendly SPARQL

4,559 views

Published on

Terp is a SPARQL syntax that makes querying OWL ontologies much easier.

Published in: Technology, Business
2 Comments
2 Likes
Statistics
Notes
No Downloads
Views
Total views
4,559
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
78
Comments
2
Likes
2
Embeds 0
No embeds

No notes for slide

Terp: An OWL-friendly SPARQL

  1. 1. Terp: Syntax for OWL-friendly SPARQL queries Evren Sirin, Blazej Bulka and Michael Smith Clark & Parsia, LLC
  2. 2. Who are we? • Clark & Parsia is a semantic software startup o HQ in Washington, DC & office in Boston • Provides software development and integration services • Specializing in Semantic Web, web services, and advanced AI technologies for federal and enterprise customers http://clarkparsia.com/ Twitter: @candp
  3. 3. Motivation • Make it easy to read and write queries for OWL ontologies • Allow both schema and instance queries • Without inventing a completely new query language • Not hard to learn
  4. 4. Querying OWL • The most commonly used Semantic Web query language is SPARQL • SPARQL intended for RDF • Semantics based on pattern matching over RDF graphs • Semantics extensions possible via entailment regimes • SPARQL-DL extension [OWLED 2008 paper] • SPARQL 1.1 entailment regime [SPARQL WG]
  5. 5. Simple SPARQL Query • Query: Find the flavors of red French wines PREFIX rdf: <http://...> PREFIX wine: <http://...> SELECT ?wine ?flavor { ?wine rdf:type wine:FrenchWine . ?wine rdf:type wine:RedWine . ?wine wine:hasFlavor ?flavor . }
  6. 6. SPARQL Abbreviations • Query: Find the flavors of red French wines PREFIX wine: <http://...> SELECT ?wine ?flavor { ?wine a wine:FrenchWine , wine:RedWine ; wine:hasFlavor ?flavor . }
  7. 7. SPARQL Abbreviations • Query: Find the flavors of red French wines PREFIX wine: <http://...> SELECT ?wine ?flavor { ?wine a wine:FrenchWine , wine:RedWine ; wine:hasFlavor ?flavor . } Turtle keyword a instead of rdf:type
  8. 8. SPARQL Abbreviations • Query: Find the flavors of red French wines PREFIX wine: <http://...> Object lists separated by comma SELECT ?wine ?flavor { ?wine a wine:FrenchWine , wine:RedWine ; wine:hasFlavor ?flavor . } Turtle keyword a instead of rdf:type
  9. 9. SPARQL Abbreviations • Query: Find the flavors of red French wines PREFIX wine: <http://...> Object lists separated by comma SELECT ?wine ?flavor { ?wine a wine:FrenchWine , wine:RedWine ; wine:hasFlavor ?flavor . } Turtle keyword a Predicate-object instead of rdf:type lists separated by semi-colon
  10. 10. SPARQL Abbreviations • Query: Find the flavors of red French wines PREFIX wine: <http://...> Object lists separated by comma SELECT ?wine ?flavor { ?wine a wine:FrenchWine , wine:RedWine ; wine:hasFlavor ?flavor . } Turtle keyword a Predicate-object instead of rdf:type lists separated by semi-colon • Result: a concise query
  11. 11. OWL over RDF • RDF knows about triples (and only triples) • OWL has many different constructs • Class/property/data expressions, axioms, etc. • Triple-based representation of OWL can be • verbose • unintuitive • hard to read or understand
  12. 12. SPARQL over OWL • Query: Find wines that are made of at least two grapes SELECT ?wine ?flavor { ?wine a [ owl:intersectionOf ( wine:Wine [ a owl:Restriction ; owl:onProperty wine:madeFromGrape ; owl:minCardinality 2 ])] }
  13. 13. SPARQL over OWL • Query: Find wines that are made of at least two grapes SELECT ?wine ?flavor { ?wine a [ owl:intersectionOf ( RDF List wine:Wine abbreviation [ a owl:Restriction ; owl:onProperty wine:madeFromGrape ; owl:minCardinality 2 ])] }
  14. 14. SPARQL over OWL • Query: Find wines that are made of at least two grapes SELECT ?wine ?flavor { ?wine a [ owl:intersectionOf ( RDF List wine:Wine abbreviation Bnode [ a owl:Restriction ; abbreviation owl:onProperty wine:madeFromGrape ; owl:minCardinality 2 ])] }
  15. 15. SPARQL over OWL • Query: Find wines that are made of at least two grapes SELECT ?wine ?flavor { ?wine a [ owl:intersectionOf ( RDF List wine:Wine abbreviation Bnode [ a owl:Restriction ; abbreviation owl:onProperty wine:madeFromGrape ; owl:minCardinality 2 ])] } • Result: less than ideal (no OWL shortcuts)
  16. 16. We have a syntax for that! • Pick the OWL syntax suitable for you
  17. 17. We have a syntax for that! • Pick the OWL syntax suitable for you • I want a formal syntax: Use Functional Syntax
  18. 18. We have a syntax for that! • Pick the OWL syntax suitable for you • I want a formal syntax: Use Functional Syntax • I want a syntax that plays nicely with XQuery and XML schema: Use OWL/XML syntax
  19. 19. We have a syntax for that! • Pick the OWL syntax suitable for you • I want a formal syntax: Use Functional Syntax • I want a syntax that plays nicely with XQuery and XML schema: Use OWL/XML syntax • I want to write OWL expressions easily: Use Manchester Syntax
  20. 20. We have a syntax for that! • Pick the OWL syntax suitable for you • I want a formal syntax: Use Functional Syntax • I want a syntax that plays nicely with XQuery and XML schema: Use OWL/XML syntax • I want to write OWL expressions easily: Use Manchester Syntax • I want a triple-friendly syntax: Use Turtle syntax
  21. 21. We have a syntax for that! • Pick the OWL syntax suitable for you • I want a formal syntax: Use Functional Syntax • I want a syntax that plays nicely with XQuery and XML schema: Use OWL/XML syntax • I want to write OWL expressions easily: Use Manchester Syntax • I want a triple-friendly syntax: Use Turtle syntax • I don’t need your help: Use RDF/XML syntax
  22. 22. Terp Syntax • Combine Turtle with Manchester syntax • Use Manchester syntax for expressing class, property, or datatype expressions • Manchester syntax expressions can appear in subject or object position of triples SELECT ?wine ?flavor { ?wine a ( wine:Wine and wine:madeFromGrape min 2 ) }
  23. 23. Complex Terp Example • Query: Find meal courses that go with full-bodied wines, if exists return the associated label; order results by labels but don’t include owl:Nothing. SELECT ?wine ?flavor { ?mealCourse rdfs:subClassOf food:MealCourse , food:hasDrink some ( wine:Wine and wine:hasBody value wine:Full ) OPTIONAL { ?mealCourse rdfs:label ?label } FILTER ( ?mealCourse != owl:Nothing ) } ORDER BY rdfs:label
  24. 24. Terp Grammar • Merge SPARQL grammar with Manchester syntax grammar • Keep all the syntax features of SPARQL • A few cases where ambiguity arises • Ex: Parentheses are used for lists in SPARQL and for nesting in Manchester syntax • Try to resolve ambiguity by the context • Assume SPARQL intent otherwise
  25. 25. Implementation • Terp parser implemented in Pellet and available as of version 2.1 • Integrated through Jena ARQ architecture • Can translate any Terp query to regular SPARQL syntax • Can be used programmatically or through CLI
  26. 26. Possible Extensions • Allow Manchester syntax in predicate position • Ex: Use equivalentTo instead of owl:equivalentClass and owl:equivalentProperty • Support for additional OWL 2 constructs • Ex: Negative property assertions, axiom annotations • More syntactic sugar for frequently used OWL features
  27. 27. Questions?

×