<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Terp: Syntax for OWL-friendly SPARQL queries</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Evren Sirin</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Blazej Bulka</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Michael Smith</string-name>
          <email>msmithg@clarkparsia.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Clark &amp; Parsia, LLC</institution>
          ,
          <addr-line>Washington, DC</addr-line>
          ,
          <country country="US">USA</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>Web Ontology Language (OWL) [5] can be seen as an extension of Resource Description Framework (RDF). The primary exchange syntax for OWL is RDF/XML, and every OWL ontology can be represented as an RDF graph. But there is no standard query language speci cally for OWL ontologies. The most commonly used Semantic Web query language is SPARQL [7], which is intended to be used for RDF. Roughly speaking, SPARQL is speci ed as queries matching RDF graphs with simple RDF entailment. However, it allows this de nition to be extended to OWL entailment. A semantics for SPARQL compatible with OWL DL has been de ned in SPARQL-DL [8] and a similar formalization of OWL-compatible SPARQL semantics is being developed by the W3C's SPARQL Working Group as part of SPARQL 1.1.1 The semantics extension of SPARQL allows one to query OWL ontologies and get the expected results with respect to OWL entailments. However, writing SPARQL queries that involve complex OWL expressions ranges from challenging to unpleasant because SPARQL query syntax is based on Turtle [1], which isn't intended for OWL. SPARQL queries against OWL data have to encode the RDF serialization of OWL expressions: these queries are typically verbose, di cult to write, and di cult to understand. In this paper we present Terp, a new syntax that combines Turtle and Manchester syntaxes to provide maximum legibility and conciseness when querying OWL with SPARQL. More precisely, Terp syntax allows class, property, and data range expressions, expressed in Manchester syntax, to be used inside SPARQL queries. In this paper, we provide examples to demonstrate how Terp reuses existing features from well-known syntaxes to make SPARQL queries of OWL data more concise and more legible.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>SPARQL syntax provides many Turtle-derived shortcuts for writing concise
queries. Such features are especially useful for instance queries. The following
query against Wine ontology2 shows several feature of the SPARQL syntax.3
1 http://www.w3.org/TR/sparql11-entailment/
2 http://www.w3.org/TR/2004/REC-owl-guide-20040210/wine.rdf
3 We omit pre x declarations in SPARQL queries due to space constraints.</p>
      <p>SELECT ?wine ?flavor WHERE {
?wine a :FrenchWine , :RedWine ;</p>
      <p>:hasFlavor ?flavor
}</p>
      <p>Ex. 1. [SPARQL] Find the avors of red wines produced in France.</p>
      <p>This query uses several Turtle shortcuts: 1. the Turtle keyword a instead of
rdf:type qname, 2. object lists separated by comma when subject and predicate
of triples is the same, and 3. predicate-object lists separated by semi-colon when
only the subject of triples is the same.</p>
      <p>But the shortcuts provided by Turtle are inadequate when OWL expressions
are used inside SPARQL queries.4 The following example shows the e ect of
using simple OWL constructs such as intersection and cardinality restrictions.</p>
      <p>SELECT ?wine WHERE {
?wine a [ owl:intersectionOf (
wine:Wine
[ owl:onProperty wine:madeFromGrape ;</p>
      <p>owl:minCardinality 2
])]
}</p>
      <p>Ex. 2. [SPARQL] Find wine instances that are made of at least two grapes.</p>
      <p>Example 2 is very verbose even though it uses Turtle's bnode and list
shortcuts. And the OWL keywords are mixed with the domain elements making it
harder to read the query.</p>
      <p>
        Manchester syntax [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] is commonly used for concisely writing OWL
expressions. It was originally designed to express class expressions in OWL 1 and then
later extended to write entire OWL 2 ontologies. It is used in RDF/OWL editors
such as Protege 4 and TopBraid Composer.
      </p>
      <p>Terp extends SPARQL syntax by allowing class, property, and data range
expressions expressed in Manchester syntax to be used in queries. The following
example shows how this combination results in a much more concise query.</p>
      <p>SELECT ?wine WHERE {</p>
      <p>?wine a ( wine:Wine and wine:madeFromGrape min 2 )
}</p>
      <p>Ex. 3. [Terp] Example 2 written in Terp syntax.</p>
      <p>Terp is designed to support everything in SPARQL syntax, including all
of the abbreviations of Turtle, to which it adds Manchester syntax features to
represent OWL expressions. The following example shows a valid Terp query
that uses several features of SPARQL and Manchester syntaxes.</p>
      <p>The grammar for Terp can be found online.5 This grammar is nearly an
exact merge of SPARQL grammar with Manchester syntax grammar. As a result,
4 This isn't really a criticism of Turtle's design, since representing OWL constructs
compactly was not a Turtle design desideratum.
5 http://clark-parsia.svn.cvsdude.com/pellet-devel/tags/release-2.1.0/
query/antlr/SparqlOwl.g</p>
      <p>SELECT ?mealCourse ?label WHERE {
?mealCourse rdfs:subClassOf
food:MealCourse ,
food:hasDrink some (wine:Wine and</p>
      <p>wine:hasBody value wine:Full)
OPTIONAL {</p>
      <p>?mealCourse rdfs:label ?label
}</p>
      <p>FILTER ( ?mealCourse != owl:Nothing )
}</p>
      <p>
        ORDER BY ?label
Ex. 4. [Terp] Find meal courses that go with full-bodied wines, optionally nd the
associated label. Filter owl:Nothing from results and order by labels.
Manchester syntax expressions can appear in the subject and object position of
SPARQL triple patterns. Ultimately, any Terp query can be translated to pure
SPARQL queries in a straight-forward way by using the translation rules for
Manchester syntax [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ].6
      </p>
      <p>There are a few cases where ambiguity arises due to the combination of
grammars. For example, the use of parentheses to indicates lists in SPARQL and
nesting in Manchester syntax. If the ambiguity cannot be resolved by the context,
Terp grammar assumes the SPARQL intention, primarily because SPARQL is
known to more people (or so we reasonably assume) than Manchester.</p>
    </sec>
    <sec id="sec-2">
      <title>3 Implementation</title>
      <p>Experimental Terp support is available in Pellet version 2.1.7 The Pellet
distribution contains many more examples of Terp queries. Terp can be used from
the Pellet command-line to execute queries written in Terp syntax. Terp can
also be accessed programmatically: it reads Terp queries and generates standard
SPARQL queries that can be executed by any OWL-aware SPARQL endpoint.
4</p>
    </sec>
    <sec id="sec-3">
      <title>Related Work</title>
      <p>There have been several e orts to create a query language for OWL.
SPARQLAS8 is one example where OWL functional syntax with variables and
Manchester syntax like abbreviations is used to encode queries. Similar to Terp, there
is a well-de ned translation from SPARQLAS queries to pure SPARQL.
SPARQLAS certainly makes writing OWL expressions easier than in standard SPARQL;
however, it supports only conjunctive queries without any SPARQL operators
(i.e., UNION, OPTIONAL, or FILTER).</p>
      <p>
        OWLLink [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] protocol provides a query language that is intended to be used
for OWL. The OWLLink core provides a set of general requests, called basic
6 Manchester syntax de nes a mapping to OWL 2 functional syntax for which an RDF
mapping is de ned.
7 http://clarkparsia.com/pellet
8 http://code.google.com/p/twouse/wiki/SPARQLAS
asks, for retrieving entailments and a query extension for more complex union of
conjunctive queries. There is both a functional syntax and XML syntax binding
for these queries. However, OWLLink is not designed to improve the concision
or legibility of SPARQL queries for OWL.
      </p>
      <p>
        SQWRL (Semantic Query-enhanced Web Rule Language) [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] is another query
language for OWL; it's based on human-readable syntax of SWRL [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. In
principle, the SWRL speci cation allows class expressions in human-readable syntax,
but there is no formal grammar about how this can be done. SWRL syntax is
only suitable for instance queries and schema queries need to be handled by
SQWRL built-in function extensions.
5
      </p>
    </sec>
    <sec id="sec-4">
      <title>Conclusions and Future Work</title>
      <p>In this paper, we provide a brief description of Terp syntax which allows
using Manchester syntax expressions in SPARQL for concise and readable OWL
queries. Terp is mainly intended to be easy to read and write for humans. Since
Terp queries can be translated to SPARQL queries, this syntax can be used in
conjunction with standard SPARQL Protocol to communicate with SPARQL
endpoints, since the translation can be done on either client or server side. Terp
can be useful even if SPARQL queries are auto-generated through a UI,
especially when those queries need to be inspected or debugged by people.</p>
      <p>Terp syntax is still evolving and there are several OWL 2 features such as
negative property assertions and axiom annotations that it does not provide
syntactic shortcuts. Furthermore, there are several extensions possible for Terp
such as allowing Manchester syntax keywords in predicate position (e.g. use
equivalentTo to replace owl:equivalentClass and owl:equivalentProperty)
or additional syntactic sugar for some frequently used OWL 2 constructs.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>D.</given-names>
            <surname>Beckett</surname>
          </string-name>
          and
          <string-name>
            <given-names>T.</given-names>
            <surname>Berners-Lee. Turtle - Terse RDF Triple Language. W3C Team Submission</surname>
          </string-name>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>M.</given-names>
            <surname>Horridge</surname>
          </string-name>
          and
          <string-name>
            <given-names>P. F.</given-names>
            <surname>Patel-Schneider</surname>
          </string-name>
          .
          <article-title>OWL 2 web ontology language manchester syntax</article-title>
          . W3C Working Group Note,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>I.</given-names>
            <surname>Horrocks</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P. F.</given-names>
            <surname>Patel-Schneider</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Boley</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Tabet</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Grosof</surname>
          </string-name>
          , and
          <string-name>
            <given-names>M.</given-names>
            <surname>Dean</surname>
          </string-name>
          .
          <article-title>SWRL: A semantic web rule language combining OWL and RuleML</article-title>
          .
          <source>W3C</source>
          ,
          <year>2004</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>T.</given-names>
            <surname>Liebig</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Luther</surname>
          </string-name>
          , and
          <string-name>
            <given-names>O.</given-names>
            <surname>Noppens</surname>
          </string-name>
          .
          <article-title>The OWLlink Protocol</article-title>
          .
          <source>In Proc. of 6th OWL: Experiences and Directions Workshop (OWLED2009)</source>
          ,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>B.</given-names>
            <surname>Motik</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P. F.</given-names>
            <surname>Patel-Schneider</surname>
          </string-name>
          , and
          <string-name>
            <surname>B. Parsia.</surname>
          </string-name>
          <article-title>OWL 2 web ontology language structural speci cation and functional-style syntax</article-title>
          .
          <source>W3C Recommendation</source>
          ,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>M. J. O'Connor and A. K. Das. SQWRL:</surname>
          </string-name>
          <article-title>A Query Language for OWL</article-title>
          .
          <source>In Proc. of 6th OWL: Experiences and Directions Workshop (OWLED2009)</source>
          ,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>E.</given-names>
            <surname>Prud</surname>
          </string-name>
          <article-title>'hommeaux and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Seaborne. SPARQL Query</surname>
          </string-name>
          <article-title>Language for RDF</article-title>
          .
          <source>W3C Recommendation</source>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <given-names>E.</given-names>
            <surname>Sirin</surname>
          </string-name>
          and
          <string-name>
            <given-names>B.</given-names>
            <surname>Parsia</surname>
          </string-name>
          .
          <article-title>SPARQL-DL: SPARQL Query for OWL-DL</article-title>
          .
          <source>In Proc. of 3rd OWL: Experiences and Directions Workshop (OWLED2007)</source>
          ,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>