<!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>Optimizing a Semantically Enriched Hypercat-enabled Internet of Things Data Hub (Short Paper)</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Ilias Tachmazidis</string-name>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Sotiris Batsakis</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>John Davies</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Alistair Duke</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Grigoris Antoniou</string-name>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Sandra Stincic Clarke</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>British Telecommunications</institution>
          ,
          <addr-line>Ipswich</addr-line>
          ,
          <country country="UK">UK</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Technical University of Crete</institution>
          ,
          <country country="GR">Greece</country>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>University of Hudders eld</institution>
          ,
          <addr-line>Hudders eld</addr-line>
          ,
          <country country="UK">UK</country>
        </aff>
      </contrib-group>
      <fpage>64</fpage>
      <lpage>71</lpage>
      <abstract>
        <p>Large volumes of data is generated from the increasing number of sensor networks and smart devices. Such data is generated and published in multiple formats, thus highlighting the signi cance of interoperability for the success of what has come to be known as the Internet of Things (IoT). The BT Hypercat Data Hub provides a focal point for the sharing and consumption of available datasets from a wide range of sources. In this work, we present a series of optimizations applied on the BT Hypercat Data Hub that enabled scalable SPARQL query answering over relational databases and an access control mechanism that lters SPARQL results based on user's subscriptions.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        The number of interconnected smart devices is constantly increasing, producing
a huge amount of data that has to be represented and exchanged using common
data formats and protocols that form the Internet of Things (IoT), which is used
in applications such as smart cities. A smart city is based on the use of
technology in order to improve the e ciency, e ectiveness and capability of various city
services, thus improving the quality of the inhabitants' lives [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ]. Such
application area is characterized by the vast variety of the technologies used, the types
and volumes of data, and the services and applications targeted [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. Thus,
developing successful smart city solutions requires the collection and maintenance of
relevant data in the form of IoT data, combined with scalable implementations
and e cient access control mechanisms.
      </p>
      <p>
        Addressing interoperability issues by focusing on how interoperability could
be achieved between data hubs in di erent domains was a major objective for the
development of Hypercat [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], which is a standard for representing and exposing
Internet of Things data hub catalogues [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] over web technologies. In [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], the
semantic enrichment for the core of the Hypercat speci cation, namely an
RDFbased [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] equivalent for a JSON-based catalogue was proposed.
      </p>
      <p>
        The BT Hypercat Data Hub supports access to the enriched data through
a SPARQL endpoint [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] combined with reasoning capabilities and the ability
to combine external data sources using federated queries [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. In [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ], the data in
the BT Hypercat Data Hub is stored in relational databases and since this data
is frequently updated, a dynamic solution based on a mapping from relational
databases to corresponding BT Hypercat Ontology concepts has been adopted.
Thus, instead of copying the existing data into an RDF triplestore, submitted
SPARQL queries are dynamically translated into a set of SQL queries on top of
the existing relational databases.
      </p>
      <p>
        Although this approach was e cient for most querying and reasoning tasks,
scalability for certain queries was limited and certain optimization both on the
relational database schema and the corresponding ontology had to be employed.
In addition, the existing system did not supported an access control mechanism,
which is an important part of related systems [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. In this work, these issues are
addresed, and both optimizations and an access control mechanism are proposed
and implemented, resulting in a scalable, industrial scale IoT system, integrating
Semantic Web technologies and access control.
      </p>
      <p>This work is organized as follows: Section 2 contains background information
about the BT Hypercat Data Hub. Section 3 contains a description of the applied
optimizations to the SPARQL to SQL endpoint which enabled scalable SPARQL
query answering over relational databases. An access control mechanism over the
developed SPARQL endpoints is presented in Section 4, while conclusions and
future work are discussed in Section 5.
2</p>
    </sec>
    <sec id="sec-2">
      <title>BT Hypercat Data Hub</title>
      <p>
        In this section, we describe the basic components of the BT Hypercat Data Hub,
which aggregates and catalogues mulitple IoT data sources and exposes them
via a uniform RESTful API. Figure 1 presents the architecture of the data hub,
more speci cally (for more details readers are referred to [
        <xref ref-type="bibr" rid="ref7 ref9">7,9</xref>
        ]):
{ The BT Hypercat Ontology (see Figure 2) enables the publication of an
RDFbased Hypercat catalogue [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] as well as the translation of data stored in a
relational database into RDF format.
{ RDF Adapters provide internally stored data in N-Triples format following
a systematic generation of URIs.
{ A SPARQL to SQL endpoint enables the dynamic translation of SPARQL
queries into SQL queries, using Ontop4.
{ The BT SPARQL Endpoint queries internally available SPARQL to SQL
endpoints and combines SPARQL results, using Apache Jena5.
{ Federated querying is enabled by providing a Jena endpoint that allows
federated queries over the BT SPARQL Endpoint and SPARQL endpoints
that are available through the Linked Open Data cloud.
3
      </p>
    </sec>
    <sec id="sec-3">
      <title>Optimizing a SPARQL to SQL Endpoint</title>
      <p>The BT Hypercat Data Hub has been successfully deployed as part of two use
cases. The rst being the SimplifAI project, which is aimed at urban tra c
management and control in order to reduce tra c and improve air quality, and
4 http://ontop.inf.unibz.it/
5 https://jena.apache.org/index.html
the second being City Concierge, which is a use case of the CityVerve project
aiming to increase uptake of walking and cycling as a preferred travel mode in
Greater Manchester.</p>
      <p>
        In order to provide the required functionality for both use cases, the SPARQL
to SQL endpoint needed to be optimized, thus ensuring rapid responses.
However, the developed optimizations that are presented in this section, are based on
the assumption that the reader has already some understanding of the internal
functionality of a SPARQL to SQL endpoint (for details see [
        <xref ref-type="bibr" rid="ref7 ref9">7,9</xref>
        ]).
      </p>
      <p>The rst step towards the development of e cient mappings was to optimize
the ontology itself, namely:
{ Restrict class hierarchy only to classes that are used by Ontop for mappings
(faster reasoning, duplicate reduction).
{ Restrict property hierarchy only to properties that are used by Ontop for
mappings (faster reasoning, duplicate reduction).
{ Delete domain and range assertions from properties when each class has a
separate Ontop mapping (duplicate reduction).
{ Study Ontop's reasoning capabilities, for the given ontology, in order to
ensure that reasoning does not lead to SQL plans that generate duplicate
results.</p>
      <p>A thorough investigation of the developed ontology revealed certain ine
ciencies. Thus, the ontology was reduced to a bare minimum (exclusively for
Ontop) in order to prevent duplicates. A close examination of the minimal
ontology showed that the combination of the developed mappings and Ontop's
reasoning capabilities could indeed lead to the unique generation of each RDF
resource.</p>
      <p>Once the unique generation of each RDF resource is ensured, mappings
should be studied for potential ine ciencies in terms of generated SQL plans.
More speci cally, the use of an SQL function (such as TO TIMESTAMP() for
time, unnest() for arrays and ST AsText() for PostGIS geometry) in a given
mapping, is translated into a separate subquery. Such subqueries are ine cient
as they are not indexed and they could lead to unnecessary self-joins over a given
SQL table. Thus, columns representing time or PostGIS geometry need to be
translated into a simpler form (such as character ), while columns representing
arrays need to be stored in a separate SQL table. For example, the following
SQL table:
should be translated into the following SQL tables6:
6 In order to keep the initial database intact, VIEW and MATERIALIZED VIEW
were considered. However, both solutions deteriorate the performance because
Ontop's reasoner is able to retrieve the initial table schema, and thus, each mapping is
translated into a separate subquery (regardless of whether an SQL function is used
or not). In order to overcome this issue, new SQL tables need to be de ned, which</p>
      <sec id="sec-3-1">
        <title>INSERT INTO sparql_feed (id, updated, the_geom) SELECT id, TO_TIMESTAMP(feed.updated) AS updated, ST_AsText(feed.the_geom) AS the_geom FROM feed</title>
      </sec>
      <sec id="sec-3-2">
        <title>INSERT INTO sparql_feed_tag (id, tag) SELECT feed_tag.id, feed_tag.tag FROM (SELECT feed.id, unnest(feed.tag) AS tag FROM feed) AS feed_tag</title>
        <p>Thus, mappings should be based on the SQL tables sparql feed and sparql feed tag
(instead of feed ), hence retrieving each eld without the need for data
translation based on SQL functions. Note that the key of sparql feed is id, while the key
of sparql feed tag is id,tag in order to allow an e cient join operation between
the two tables based on id.</p>
        <p>Based on the following pre xes that are used in order to shorten URIs:
bt-sensors: http://api.bt-hypercat.com/sensors/
bt-hypercat: http://portal.bt-hypercat.com/ontologies/bt-hypercat#
the following mapping maps the data property feed updated of class Feed :
Mapping ID mapping:feed updated
Target (Triple Template) bt-sensors:feeds/fsparql feed.idg
bt-hypercat:feed updated
fsparql feed.updatedg .</p>
        <p>Source (SQL Query) SELECT sparql feed.id, sparql feed.updated</p>
        <p>FROM sparql feed</p>
        <p>Note that the SQL variables that are used in order to generate RDF triples
following the triple template (see Target) should match the columns that belong
to the key (here sparql feed.id ) of the corresponding SQL table. This is important
in order to eliminate self-joins. If the key contains more columns than those used
in the RDF triple pattern to be generated, then self-joins cannot be eliminated
and each mapping for the given table will be translated as a separate subquery.
Allowing self-joins can be manageable for relatively small tables (containing
thousands of rows, provided that the table is indexed), but can be prohibitive
for larger tables (containing millions of rows).</p>
        <p>provide a manually created view over the existing data in a format that allows fast
SPARQL queries.</p>
        <p>Finally, the following guidelines should be taken into consideration in order
to avoid SPARQL queries that lead to excessive SQL query plans (after the
dynamic translation from SPARQL to SQL), namely:
{ Avoid generic triple patterns such as \?s ?p ?o" as they will be translated
using all available mappings (a UNION of all de ned mappings), leading to
an excessive SQL query plan. Thus, the predicate within each triple pattern
should be speci ed.
{ Avoid using DISTINCT as it deteriorates severely performance since the
nal results would be sorted and ltered for unique values at the end of the
SQL query plan.
{ Retrieve speci c Feed s by ltering (namely using FILTER). Restricting the
search space early (e.g., retrieving a feed based on its id) leads to more
e cient SQL query plans.
{ Avoid OPTIONAL as each OPTIONAL is translated into a LEFT OUTER
JOIN. If used, all OPTIONAL should be put at the end of the query in order
to improve query translation.
{ Use LIMIT as limiting the amount of required results could speed up the
query execution.</p>
        <p>By applying the aforementioned optimizations to the BT Hypercat Data Hub,
queries that were unresponsive in the non-optimized system were executed in less
than a second by the optimized system. The optimized system was able to handle
e ciently queries over multiple SQL tables, containing millions of records.
4</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Access Control Mechanism</title>
      <p>An access control mechanism has been implemented for the SPARQL to SQL
endpoint and the SPARQL to SPARQL endpoint while retaining the high level of
performance achieved by the above mentioned optimizations. The proposed
access control mechanism allows user access management at the feed level, namely
if users have access to a feed then they also have access to any information
contained within that feed.</p>
      <p>Access control is enforced in two stages, rst the given query is examined
syntactically. Since the system supports SPARQL 1.0, only a subset of SPARQL
constracts is relevant. Indeed, WHERE is the main point of interest in terms of
enforcing access control. More speci cally, the WHERE clause could contain feed
URIs, de ned as constants, that users have no access to. Consider the following
SPARQL query:
PREFIX hypercat: &lt;http://portal.bt-hypercat.com/ontologies/bt-hypercat#&gt;
BASE &lt;http://api.bt-hypercat.com/&gt;
SELECT ?f1
WHERE f
&lt;sensors/feeds/00000000-0000-0000-0000-000000000001&gt;
hypercat:feed id ?f1.</p>
      <p>Note that this query should be allowed to execute only if users have access to feed
&lt;http://api.bt-hypercat.com/sensors/feeds/00000000-0000-0000-0000-000000000001&gt;.</p>
      <p>In the case that query execution cannot be denied by syntactic analysis, the system
still needs to ensure that users do not have access to results based on variables that
are bound with information from restricted feeds. Consider the following example:
PREFIX hypercat: &lt;http://portal.bt-hypercat.com/ontologies/bt-hypercat#&gt;
SELECT ?f1
WHERE f
?feed hypercat:feed id ?f1.</p>
      <p>?feed hypercat:feed creator ?f2.
g</p>
      <p>It is insu cient to check only returned results (here ?f1 ) since other variables (here
?feed and ?f2 ) might attempt to extract information from feeds that the user has no
access to. Thus, the query is rewritten internally so that the SELECT clause would
contain all variables in the WHERE clause (here ?f1, ?feed and ?f2 ), even though
users will be provided with results only for requested variables (here ?f1 ), provided
that access is allowed (to all variables). Note that results might be combined from
di erent feeds, while in order to access a triple through Ontop either a xed URI
(syntactic analysis) or a variable (result checking over all variables) would be used
within the triple. Moreover, by checking all variables for the given query, manipulating
results through FILTER becomes ine ective.</p>
      <p>Finally, in order to ensure that a given ASK query provides the same level of
access control, after it is syntactically checked for allowed URIs, it is translated into a
SELECT query with LIMIT 1. Thus, the result of an ASK query is true if users have
access to at least one result of the equivalent SELECT query, or false otherwise.</p>
      <p>It is worth mentioning that integrating the access control mechanism to the
optimized system has not a ected the performance of the SPARQL endpoints since query
times remained almost identical regardless of whether the access control mechanism
was enabled or not.
5</p>
    </sec>
    <sec id="sec-5">
      <title>Conclusion</title>
      <p>In this work, a series of applied optimizations to the BT Hypercat Data Hub has been
presented, thus scaling up SPARQL query answering over relational databases. In
addition, an access control mechanism that lters SPARQL results based on user's
subscriptions has been proposed. Both query optimization and access control mechanisms
that were addressed in this work are critical factors for the successful deployment of a
large scale IoT system. Future work includes further semantic enrichment by enabling
GeoSPARQL queries. In addition, spatiotemporal reasoning is a prominent direction
that could provide richer knowledge by combining data coming from both the BT
Hypercat Data Hub and the LOD cloud.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>Pilgrim</given-names>
            <surname>Beart</surname>
          </string-name>
          .
          <source>Hypercat</source>
          <volume>3</volume>
          .00 Speci cation,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Mathieu d'Aquin</surname>
            , John Davies, and
            <given-names>Enrico</given-names>
          </string-name>
          <string-name>
            <surname>Motta</surname>
          </string-name>
          .
          <article-title>Smart cities' data: Challenges and opportunities for semantic technologies</article-title>
          .
          <source>IEEE Internet Computing</source>
          ,
          <volume>19</volume>
          (
          <issue>6</issue>
          ):
          <volume>66</volume>
          {
          <fpage>70</fpage>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>John</given-names>
            <surname>Davies</surname>
          </string-name>
          and Mike Fisher. Internet of Things - Why Now? Jnl Institute of Telecommunications Professionals,
          <volume>7</volume>
          (
          <issue>3</issue>
          ),
          <year>September 2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>Giorgos</given-names>
            <surname>Flouris</surname>
          </string-name>
          , Irini Fundulaki, Maria Michou, and
          <string-name>
            <given-names>Grigoris</given-names>
            <surname>Antoniou</surname>
          </string-name>
          .
          <article-title>Controlling access to rdf graphs</article-title>
          .
          <source>In Future Internet Symposium</source>
          , pages
          <volume>107</volume>
          {
          <fpage>117</fpage>
          . Springer,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>Patrick</given-names>
            <surname>Hayes</surname>
          </string-name>
          .
          <source>RDF Semantics. In W3C Recommendation</source>
          ,
          <year>2004</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Eric</surname>
            <given-names>PrudHommeaux</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Andy Seaborne</surname>
          </string-name>
          , et al.
          <article-title>SPARQL query language for RDF</article-title>
          .
          <source>W3C recommendation</source>
          ,
          <volume>15</volume>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>Ilias</given-names>
            <surname>Tachmazidis</surname>
          </string-name>
          , Sotiris Batsakis, John Davies, Alistair Duke, Mauro Vallati, Grigoris Antoniou, and
          <article-title>Sandra Stincic Clarke. A hypercat-enabled semantic internet of things data hub</article-title>
          .
          <source>In The Semantic Web - 14th International Conference, ESWC</source>
          <year>2017</year>
          , Portoroz, Slovenia, May 28 - June 1,
          <year>2017</year>
          , Proceedings,
          <string-name>
            <surname>Part</surname>
            <given-names>II</given-names>
          </string-name>
          , pages
          <volume>125</volume>
          {
          <fpage>137</fpage>
          ,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Ilias</surname>
            <given-names>Tachmazidis</given-names>
          </string-name>
          , John Davies, Sotiris Batsakis, Grigoris Antoniou, Alistair Duke, and Sandra Stincic Clarke. Hypercat RDF:
          <article-title>Semantic Enrichment for IoT</article-title>
          .
          <source>In Semantic Technology - 6th Joint International Conference, JIST</source>
          <year>2016</year>
          , Singapore, Singapore, November 2-
          <issue>4</issue>
          ,
          <year>2016</year>
          , Revised Selected Papers, pages
          <volume>273</volume>
          {
          <fpage>286</fpage>
          ,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <given-names>Ilias</given-names>
            <surname>Tachmazidis</surname>
          </string-name>
          , Sotiris Batsakis John Davies, Alistair Duke, Mauro Vallati, Grigoris Antoniou, and
          <article-title>Sandra Stincic Clarke. A Hypercat-enabled Semantic Internet of Things Data Hub: Technical Report</article-title>
          . https://arxiv.org/abs/1703.00391,
          <year>March 2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>A.M. Townsend</surname>
          </string-name>
          . Smart Cities:
          <article-title>Big Data, Civic Hackers, and the Quest for a New Utopia</article-title>
          . WW Norton &amp; Company,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>