<!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>Graphity: generic processor for declarative Linked Data applications</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Martynas Jusevičius</string-name>
          <email>martynas@graphity.org</email>
        </contrib>
      </contrib-group>
      <abstract>
        <p>In this paper we describe a novel approach to read-write Linked Data design. By combining URI-to-query mapping with SPIN, XSLT, and RDF/POST, many advanced Web application features can be implemented declaratively. Such architecture is standard-compliant and provides a rapid way to build life-science Linked Data apps from reusable components.</p>
      </abstract>
      <kwd-group>
        <kwd>Life sciences</kwd>
        <kwd>Linked Data</kwd>
        <kwd>Declarative</kwd>
        <kwd>Web Applications</kwd>
        <kwd>RDF</kwd>
        <kwd>SPARQL</kwd>
        <kwd>Graphity</kwd>
        <kwd>SPIN</kwd>
        <kwd>XSLT</kwd>
        <kwd>Linked Data Platform</kwd>
        <kwd>REST</kwd>
        <kwd>OWL</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>Graphity</p>
    </sec>
    <sec id="sec-2">
      <title>1. Introduction</title>
      <p>
        The volume of life-science related RDF data is set to grow [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. Data publishers
providing Linked Data access often choose to develop new software, which is costly.
Usability expectations are high. We address these issues with a novel software design
that makes the components reusable and the development rapid by reducing the
functionality into simple operations on semantic data.
      </p>
      <p>
        In Graphity [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], we implemented a declarative approach which maps read-write
Linked Data HTTP access to SPARQL operations on RDF stores. The W3C has done
related work based on XML [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], but has not applied it to RDF. The Linked Data
Platform [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] has similar aims, but lacks the mapping to SPARQL.
      </p>
    </sec>
    <sec id="sec-3">
      <title>2. Approach</title>
      <p>In RESTful applications, resources that share the same URI structure usually share
the same representation pattern. In our case, the representation is RDF, with views
defined in SPARQL. Let us consider a simple Linked Data request, to which the
server responds with a query result:
GET &lt;resource&gt; → DESCRIBE &lt;resource&gt;</p>
      <p>We can generalize this into a mapping between resource URIs and SPARQL
queries by using templates of the form:
/{path} → DESCRIBE ?this</p>
      <p>Special query variable ?this stands for the request URI that matches the
template. A collection of such mappings is application-specific and called a sitemap.</p>
    </sec>
    <sec id="sec-4">
      <title>3. Implementation</title>
      <p>Each application instance embeds a processor, which interprets the sitemap on each
HTTP request and executes queries on a SPARQL endpoint. No domain-specific
object layer is present: the triplestore acts as an MVC model via HTTP, while the
processor is the controller, and XSLT is the optional view layer. All components
operate on RDF natively and directly.
1.1</p>
      <sec id="sec-4-1">
        <title>Sitemap and templates</title>
        <p>
          Resource template is an OWL class, which maps a URI template to a SPARQL
query. For that we use regex-like JAX-RS syntax [
          <xref ref-type="bibr" rid="ref5">5</xref>
          ] and SPIN RDF [
          <xref ref-type="bibr" rid="ref6">6</xref>
          ] syntax,
respectively:
gp:Resource a owl:Class, gp:Template ;
rdfs:subClassOf foaf:Document ;
gp:uriTemplate "/{path: .*}" ;
spin:query gp:Describe .
gp:Describe a sp:Describe, sp:Query ;
sp:text """DESCRIBE ?this"""^^xsd:string .
        </p>
        <p>This example shows a catch-all URI template mapped to a default query. In
realworld applications both the URI templates and the queries are more specialized. The
query forms are limited to DESCRIBE and CONSTRUCT, as the required result is
RDF graph.
1.2</p>
      </sec>
      <sec id="sec-4-2">
        <title>Processing model</title>
        <p>Each request URI is first matched against the set of URI templates in the sitemap,
using the JAX-RS precedence algorithm. ?this in the query of the matching
template is bound to request URI. The query is then executed on the endpoint, and the
result is returned as the representation of the requested resource. If no template
matches, 404 Not Found is returned.</p>
        <p>It is often useful to arrange resources in a hierarchical fashion. Folders and files in
the filesystem is well known example. We implement this using container resources
that have children resources. Container queries must contain SELECT subqueries to
provide paginated access to its children by dynamically setting LIMIT and OFFSET
modifiers. Ordering is implemented using ORDER BY. Default modifier values are
specified in the resource template and overridden by request query parameter values:
&lt;#Container&gt; a owl:Class, gp:Template ;
gp:limit 20 ;
gp:offset 100 ;
gp:orderBy "title"^^xsd:string .</p>
        <p>Previous/next page resources are added to container responses automatically,
following the REST principles:
1.3</p>
      </sec>
      <sec id="sec-4-3">
        <title>Representations</title>
        <p>Representations should be available in all RDF serializations supported by the
underlying I/O framework via content negotiation. The processor must select
bestmatching media type based on the Accept header of the request.</p>
        <p>The application can produce non-RDF representations, including binary. (X)HTML
output is achieved via XSLT transformation of RDF/XML, server- and client-side.
Layout modes can be configured per resource template.</p>
        <p>Caching can also be configured per resource template:
&lt;#CachedDocument&gt; a owl:Class, gp:Template ;</p>
        <p>gp:cacheControl "public, max-age=86400" .
1.4</p>
      </sec>
      <sec id="sec-4-4">
        <title>Data input</title>
        <p>
          POST HTTP request to a container is used to create a new child resource, while
PUT is used to replace existing representation. The update is done using SPARQL
Update template attached to resource template using spin:update property.
However, Graph Store Protocol [
          <xref ref-type="bibr" rid="ref7">7</xref>
          ] is often more convenient .
        </p>
        <p>Blank nodes in the request RDF payload are skolemized. For example, building
URI for node with dct:identifier value 42 and URI template
/books/{identifier} yields /books/42. Unmatched bnodes are left
untouched.</p>
        <p>
          Quality of the incoming data is controlled using SPIN constraints [
          <xref ref-type="bibr" rid="ref8">8</xref>
          ]. If the data is
invalid, an error response is returned to the client and no further processing is done.
        </p>
        <p>
          A common, but still problematic use case in read-write Linked Data applications is
retrieving user input natively as RDF. Luckily, that is covered by RDF/POST [
          <xref ref-type="bibr" rid="ref9">9</xref>
          ].
        </p>
      </sec>
      <sec id="sec-4-5">
        <title>Access control</title>
        <p>
          Access control can be implemented using the W3C ACL ontology [
          <xref ref-type="bibr" rid="ref10">10</xref>
          ]. Graphity
provides a transparent filter that authorizes each request using an ASK SPARQL query
for public or authenticated agent access.
        </p>
        <p>User accounts and authorizations are stored in a RDF repository separately from
the domain data, prohibiting the end-users from modifying them. The filter has access
to both of them by means of federation (the SERVICE SPARQL keyword).</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>4. Conclusions</title>
      <p>The architecture of a generic processor interpreting declarative application-specific
sitemaps enables a new way to reuse application components without writing new
software. It is also very scalable, as the system is stateless and functional.</p>
      <p>Core Web application functionality such as URI routing, data representation and
input, and access control can be implemented using standard RDF/OWL constructs
only. Such apps can run on different processors and platforms, can be imported,
merged, forked, managed collaboratively, transformed, queried etc.</p>
      <p>
        The Graphity processor is open-source and works with any SPARQL 1.1
triplestore. The commercial platform layer provides multi-tenant functionality and has
been successfully used to build rich Linked Data applications for product information
management [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ] and library data [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ].
      </p>
      <p>
        Our goal is to formalize this approach as a W3C submission. We invite you to join
the discussion at the W3C Declarative Linked Data Apps Community Group [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ].
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>S.</given-names>
            <surname>Jupp</surname>
          </string-name>
          et al.
          <article-title>The EBI RDF Platform: Linked Open Data for the Life Sciences</article-title>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>2. Graphity. http://graphityhq.com</mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>Declarative</given-names>
            <surname>Web Applications Current Status</surname>
          </string-name>
          , http://www.w3.org/standards/techs/dwa
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <source>Linked Data Platform</source>
          <volume>1</volume>
          .0. http://www.w3.org/TR/ldp/
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5. The @
          <article-title>Path Annotation and URI Path Templates</article-title>
          . http://docs.oracle.com/cd/E19798- 01/
          <fpage>821</fpage>
          -1841/6nmq2cp26/index.html
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>6. SPIN - Modeling Vocabulary. http://spinrdf.org/spin.html</mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          <article-title>7. SPARQL 1.1 Graph Store HTTP Protocol</article-title>
          . http://www.w3.org/TR/sparql11-http-rdfupdate/
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          <article-title>8. The Data Quality Constraints Library Language Reference</article-title>
          . http://semwebquality.org/ontologies/dq-constraints
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>9. RDF/POST Encoding for RDF. http://www.lsrn.org/semweb/rdfpost.html</mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>10. WebAccessControl. http://www.w3.org/wiki/WebAccessControl</mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>11. NXP Data, http://data.nxp.com</mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>12. De Danske Aviser. http://dedanskeaviser.dk</mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          13.
          <string-name>
            <surname>Declarative Linked Data Apps</surname>
            <given-names>CG</given-names>
          </string-name>
          , http://www.w3.org/community/declarative-apps/
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>