<!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>SPARQL-LD: A SPARQL Extension for Fetching and Querying Linked Data</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>Computer Science Department, University of Crete, Greece, and Institute of Computer Science</institution>
          ,
          <addr-line>FORTH-ICS</addr-line>
          ,
          <country country="GR">Greece</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>SPARQL is a standard query language for retrieving and manipulating RDF data. However, the majority of SPARQL implementations require the data to be available in advance, i.e., to exist in main memory or in a RDF repository (accessible through a SPARQL endpoint). Nonetheless, Linked Data exists in the Web in various forms; even an HTML Web page can contain RDF data through RDFa, or RDF data may be dynamically created by a Web Service. In this paper, we propose and demonstrate an extension of SPARQL 1.1, called SPARQL-LD, that allows to directly and exibly exploit this wealth of data. SPARQL-LD allows to fetch, query and integrate in the same SPARQL query: i) data coming from online RDF or JSON-LD les, ii) data coming from dereferenceable URIs, iii) data embedded in Web pages as RDFa, iv) data that is dynamically created by Web Services, and v) data coming by querying other endpoints. A distinctive characteristic of this extension is that it enables to fetch and query even data in datasets returned by a portion of the query, i.e. discovered at query-execution time.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        Linked Data [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] provides a publishing paradigm in which data can be a first
class citizen of the Web. Linked Data exists in various forms: in RDF/XML
(e.g. through dereferenceable URIs), as Notation3 (N3) or Turtle files, as
JSONLD files [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], in HTML Web pages as RDFa [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], even a Web Service may
create RDF data dynamically (at request time). SPARQL [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] is a standard query
language for retrieving and manipulating RDF data. Although most SPARQL
implementations require the data to be available in advance (in main memory or
in a repository), the specification of SPARQL allows to directly query an RDF
dataset accessible on the Web (in a standard format) and identifiable by an IRI
through the operators FROM/FROM NAMED and GRAPH. However, this has an
important limitation: it requires knowing in advance the IRI of the dataset and
having declared it in the FROM NAMED clause. Thus, an IRI coming from partial
results (that get bound after executing an initial query fragment) cannot be used
in the GRAPH operator as the dataset to run a portion of the query. Furthermore,
although RDFa and JSON-LD are W3C standards that are exploited by an
ever-increasing number of publishers, we have not managed to find a SPARQL
implementation that can directly query such RDF data. In addition, using the
1 SELECT DISTINCT ?authorURI (count(distinct ?paper) AS ?numOfPapers)
2 (count(distinct ?series) AS ?numOfDiffConfs) WHERE {
3 SERVICE &lt;http://users.ics.forth.gr/~fafalios/&gt; {
4 ?p &lt;http://purl.org/dc/terms/creator&gt; ?authorURI }
5 SERVICE ?authorURI { ?paper &lt;http://purl.org/dc/elements/1.1/creator&gt; ?authorURI }
6 SERVICE &lt;http://dblp.l3s.de/d2r/sparql&gt; {
7 ?p2 &lt;http://purl.org/dc/elements/1.1/creator&gt; ?authorURI .
8 ?p2 &lt;http://swrc.ontoware.org/ontology#series&gt; ?series }
9 } GROUP BY ?authorURI ORDER BY ?numOfPapers
service operator of SPARQL 1.1 Federated Query [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ], we can invoke a portion
of a query against a remote RDF repository. However, service requires the IRI
to be the address of a SPARQL endpoint, thus one cannot exploit it for querying
RDF data accessible on the Web but not available through an endpoint.
      </p>
      <p>In this paper, we propose and demonstrate an extension of SPARQL, called
SPARQL-LD (from Linked Data), that overcomes the aforementioned limitations
enhancing thereby the flexibility of the language. SPARQL-LD extends the
applicability of the service operator enabling to fetch and query any Web source
containing RDF data (even RDF data that is created dynamically, e.g. by
RESTful Web APIs). SPARQL-LD does not require to have declared the named graphs,
thus one can even query a dataset returned by a portion of the query, i.e. its IRI
is derived at query execution time. Fig. 1 illustrates an example of a query that
can be answered by SPARQL-LD. The query returns all co-authors of P. Fafalios
(1st author of this paper) together with the number of their publications and
the number of distinct conferences in which they have a publication. Notice that
this query combines and integrates: i) data embedded in a Web page as RDFa
(lines 3-4), ii) data coming from dereferenceable IRIs derived at query-execution
time (line 5), and iii) data coming by querying another endpoint (lines 6-8).</p>
      <p>For answering the above query with the original SPARQL, one must
download and load to a repository the triples that are contained in the Web page (line
3) as well as the triples regarding the publications of all co-authors (line 5),
considering of course that these triples are not available through an endpoint. The
problem may become unfeasible if these resources are derived at query-execution
time, i.e. in case we are unaware of their IRIs at query-writing time. On the
contrary, using SPARQL-LD and exploiting the Linked Data principles, such different
types of resources can be directly queried without needing to retain a repository.</p>
      <p>Note also that the proposed extension is actually a generalization of SPARQL
in the sense that every query that can be answered by the original SPARQL can
be also answered by SPARQL-LD. Specifically, if the IRI given to the service
operator corresponds to a SPARQL endpoint, then it works exactly as the
original SPARQL (the remote endpoint evaluates the query and returns the result).
Otherwise, instead of returning an error (and no bindings), it tries to fetch and
query the triples that may exist in the given resource.</p>
      <p>
        Related Works. SPARQL-LD offers a method to execute queries over the Web of
Linked Data. Such approaches can be classified in three categories: query
federation (integrated and transparent access to distributed sources, e.g. the DARQ
engine [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]), data centralization (query service over a collection of data copied and
transformed from different sources, e.g. the MarineTLO-based Warehouse [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ]),
SPARQL-LD: A SPARQL Extension for Fetching and Querying Linked Data
and link traversal (discover data related to IRIs given in the query, e.g. the work
by Hartig et al. [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ]). The functionality offered by SPARQL-LD complements and
can be used in combination to the aforementioned approaches.
2
      </p>
    </sec>
    <sec id="sec-2">
      <title>SPARQL-LD: SPARQL 1.1 Federated Query Extension</title>
      <p>
        The service operator of SPARQL 1.1 (service a P ) is defined (in [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]) as a
graph pattern P evaluated in the SPARQL endpoint specified by the IRI a,
while (service ?X P ) is defined by assigning to the variable ?X all the IRIs (of
endpoints) coming from partial results, i.e. that get bound after executing an
initial query fragment. The idea behind SPARQL-LD is to enable the evaluation
of a graph pattern P not absolutely in a SPARQL endpoint a, but generally in
an RDF graph Gr specified by a Web Resource r. Thus, now an IRI given to
the service operator can also be the dereferenceable IRI of a resource, the Web
page of an entity (e.g. of a person), an ontology (OWL), Turtle or N3 file, etc. If
the IRI is not the address of a SPARQL endpoint, the RDF data that may exist
in the resource are fetched at real-time and queried for the graph pattern P .
Implementation. SPARQL-LD has been implemented using Apache Jena. Jena is
an open source Java framework for building Semantic Web applications (http://
jena.apache.org/). Specifically, we have extended Jena 2.13 ARQ component.
ARQ is a query engine for Jena that supports SPARQL 1.1. The implementation
is available as open source1. An endpoint that realizes SPARQL-LD (and that also
includes several query examples) has been deployed for experimentation2.
      </p>
      <p>
        The implementation can be described through the following process: we first
check if the IRI corresponds to a SPARQL endpoint by submitting the ASK query
“ASK f?x ?y ?zg”. In case we get a valid answer, we continue just like the
default query federation approach, i.e. the corresponding graph pattern (query)
is submitted to the endpoint. In case we do not get a valid answer, it means
that the IRI is not the address of an endpoint. Then, we read the content type
header field of the IRI by opening an HTTP connection and setting the value
application/rdf+xml to the ACCEPT request header. Now, according to the
returned content type, we fetch and query the corresponding triples. For the case of
HTML Web pages (the content type is text/html or application/xhtml+xml),
we try to fetch and query the RDF triples that may be embedded in the Web
page as RDFa. If the Web page does not contain any RDF data, the query
returns no bindings. For reading possible RDF triples in a Web page, we
exploit the Semargl framework [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] which also offers integration with Jena. The
implementation also allows to read and query JSON-LD files.
      </p>
      <p>Optimizations. We adopt the following optimization techniques for saving both
time for the user side and load for the server side.
-Index of known endpoints. We have seen that, compared to the original service
operator, the only additional cost is the time to run an ASK query (which is in
average less than 200 ms). To eliminate this cost, we keep a small index with
the IRIs of known endpoints (like DBpedia’s) and of endpoints that have been
1 https://github.com/fafalios/sparql-ld
2 http://users.ics.forth.gr/~fafalios/sparql-ld-endpoint.html
already checked. Thereby, if the service IRI exists in the index, the query is
directly forwarded to the endpoint, otherwise an ASK query is first submitted.
-Request-scope caching of the retrieved dataset(s). A SPARQL query may contain
multiple service invocations against the same Web resource. In such cases,
fetching and loading repeatedly the same resource triples costs both in time and
in computer resources. To avoid this, for a submitted query we use a
requestscope cache of datasets that have been already fetched. Thereby, in each new
service invocation, we first check if the corresponding IRI exists in the cache in
order to avoid re-fetching its triples. The cache is cleared after query execution.
Demonstration. The ISWC’15 participants will have the opportunity to
experiment with SPARQL-LD for several query scenarios including: parameterize and
call a named entity extraction Web service at query-execution time, query Web
pages containing RDFa, query dereferenceable IRIs that derive at query-execution
time, query ontologies, query JSOL-LD, N3 and N-Triples les.</p>
    </sec>
    <sec id="sec-3">
      <title>Conclusion</title>
      <p>We have proposed SPARQL-LD, a SPARQL 1.1 extension that allows to directly
fetch and query RDF data from heterogeneous sources via service calls. Using
SPARQL-LD one can even query a dataset coming from query’s partial results,
i.e. identified at query-execution time. Such a functionality motivates Web
publishers to enrich their documents with RDF since it makes their data directly
accessible via SPARQL (without needing to set up an endpoint), while it also
enables the direct exploitation of RDF data that is created dynamically (e.g. by
RESTful Web applications). In future, we will study query planning approaches
and more optimization techniques aiming to reduce the transfer of data between
server/endpoint and remote sources.</p>
      <p>Acknowledgements. This work was partially supported by DIACHRON (FP7-ICT,
2013-2016) and BlueBridge (H2020 Research Infrastructures, 2015-2018).</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          <article-title>1. A JSON-based Serialization for Linked Data</article-title>
          . http://www.w3.org/TR/json-ld/.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <source>RDFa Core 1</source>
          .1. http://www.w3.org/TR/2015/REC-rdfa-core-
          <volume>20150317</volume>
          /.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>Semargl</given-names>
            <surname>Framework</surname>
          </string-name>
          . https://github.com/levkhomich/semargl.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          <article-title>4. SPARQL 1.1 Query Language (W3C)</article-title>
          . http://www.w3.org/TR/sparql11-query/.
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>SPARQL</given-names>
            <surname>Federated</surname>
          </string-name>
          <article-title>Query</article-title>
          . http://www.w3.org/TR/sparql11-federated-query.
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>C.</given-names>
            <surname>Bizer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Heath</surname>
          </string-name>
          , and
          <string-name>
            <given-names>T.</given-names>
            <surname>Berners-Lee</surname>
          </string-name>
          .
          <article-title>Linked Data-The Story So Far</article-title>
          .
          <source>International Journal on Semantic Web and Information Systems (IJSWIS)</source>
          ,
          <volume>5</volume>
          (
          <issue>3</issue>
          ),
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>C.</given-names>
            <surname>Buil-Aranda</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Arenas</surname>
          </string-name>
          ,
          <string-name>
            <given-names>O.</given-names>
            <surname>Corcho</surname>
          </string-name>
          ,
          <article-title>and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Polleres</surname>
          </string-name>
          .
          <article-title>Federating queries in SPARQL 1.1: Syntax, Semantics and Evaluation</article-title>
          .
          <source>Web Semantics: Science, Services and Agents on the World Wide Web</source>
          ,
          <volume>18</volume>
          (
          <issue>1</issue>
          ):1{
          <fpage>17</fpage>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <given-names>O.</given-names>
            <surname>Hartig</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Bizer</surname>
          </string-name>
          , and
          <string-name>
            <given-names>J.-C.</given-names>
            <surname>Freytag</surname>
          </string-name>
          .
          <article-title>Executing SPARQL Queries over the Web of Linked Data</article-title>
          .
          <source>The Semantic Web-ISWC</source>
          <year>2009</year>
          ,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <given-names>B.</given-names>
            <surname>Quilitz</surname>
          </string-name>
          and
          <string-name>
            <given-names>U.</given-names>
            <surname>Leser</surname>
          </string-name>
          .
          <article-title>Querying distributed RDF data sources with SPARQL</article-title>
          .
          <source>In 5th European/Extended Semantic Web Conference (ESWC'08)</source>
          . Springer,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <given-names>Y.</given-names>
            <surname>Tzitzikas</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Alloca</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Bekiari</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Marketakis</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Fafalios</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Doerr</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Minadakis</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Patkos</surname>
          </string-name>
          , and
          <string-name>
            <given-names>L.</given-names>
            <surname>Candela</surname>
          </string-name>
          .
          <article-title>Integrating Heterogeneous and Distributed Information about Marine Species through a Top Level Ontology</article-title>
          .
          <source>In MTSR</source>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>