<!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>
      <journal-title-group>
        <journal-title>D. Arndt);</journal-title>
      </journal-title-group>
      <issn pub-type="ppub">1613-0073</issn>
    </journal-meta>
    <article-meta>
      <title-group>
        <article-title>SiN3: Scalable Inferencing</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Dörthe Arndt</string-name>
          <email>doerthe.arndt@tu-dresden.de</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>William Van Woensel</string-name>
          <email>wvanwoen@uottawa.ca</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Dominik Tomaszuk</string-name>
          <email>d.tomaszuk@uwb.edu.pl</email>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Computational Logic group, Technische Universität Dresden</institution>
          ,
          <addr-line>Dresden</addr-line>
          ,
          <country country="DE">Germany</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Telfer School of Management, University of Ottawa</institution>
          ,
          <addr-line>Ottawa, ON</addr-line>
          ,
          <country country="CA">Canada</country>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>University of Bialystok</institution>
          ,
          <addr-line>Bialystok„</addr-line>
          <country country="PL">Poland</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>1806</year>
      </pub-date>
      <volume>000</volume>
      <fpage>0</fpage>
      <lpage>0002</lpage>
      <abstract>
        <p>SPARQL is a widely used and well-established standard in the Semantic Web to eficiently query explicitly stated RDF data. However, the authors (and others before us) suggest that this ignores the full potential of the language: when used recursively, CONSTRUCT queries can serve as fully-fledged rules allowing for reasoning over the data. For this purpose, we present SiN3, a tool that translates SPARQL queries to Notation3 (N3) rules; an N3-compliant reasoner (such as eye) can then recursively generate inferences from RDF data. We provide a demo that uses CONSTRUCT queries to infer the need for Zika screening, based on the Turtle HL7 FHIR notation. We show that a reasoning-based approach, compared to standard SPARQL, makes such use cases more eficient, as rule-based reasoning is optimized for recursively generating inferences; and easier to implement, as only one execution run is necessary to apply interdependent queries, and supporting queries can be used to modularize the code. We compare the performance of SiN3 with SpinRDF, which supports reasoning over the SPIN serialization of SPARQL but is an order of magnitude slower on our test data. SiN3 thus enables eficient reasoning using SPARQL</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>CEUR</p>
      <p>ceur-ws.org
CONSTRUCT
queries, opening the door for scalable Semantic Web reasoning using a well-known semantic formalism.</p>
    </sec>
    <sec id="sec-2">
      <title>1. Introduction</title>
      <p>
        The query language SPARQL [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] is a well-established standard in the Semantic Web: it provides
an easy-to-learn syntax—especially for people used to databases—together with a lot of useful
features like filter functions, aggregation, and property paths to extract information from RDF
graphs. This information is then typically provided to the user in table form (S E L E C T ) or in
an RDF graph (C O N S T R U C T ). However, even in the latter case, C O N S T R U C T queries are not applied
recursively, that is, queries do not act on each others’ results. We aim to change this situation
by providing SiN3 (Sparql in N3), a tool that translates SPARQL queries to Notation3 (N3) [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], a
rule language for the Semantic Web. Subsequently, reasoners like eye [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] or jen31, which are
(D. Tomaszuk)
CEUR
Workshop
Proceedings
designed for scalable reasoning, can infer new data based on C O N S T R U C T queries. Using SiN3,
complex use cases—such as our Zika use case, which involves many logical steps—become
easier and more eficient to implement: (i) modularity: each step can be encapsulated in an
individual query, and its results can be re-used by other queries. This is in contrast to a single
monolithic query with likely code duplication, or ad-hoc application code executing multiple
queries and manually tying the results together (e.g., with a query being executed for all results
of another query in a for-loop); (ii) expressivity: instead of using “vanilla” N3, features provided
by SPARQL (e.g., property paths, aggregation), which have proven to be very useful, are directly
available in SiN3; (iii) performance: rule-based reasoning is optimized for recursively deriving
new information, with the eye N3 reasoner [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] being state-of-the-art and having been used in
many projects since 2006; (iv) Web-compatibility: SiN3 acts on and produces RDF graphs.
      </p>
      <p>
        The idea of using SPARQL recursively is not new and has been investigated before. Polleres
[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] translated the—back then—upcoming standard SPARQL 1.0 into Datalog to better understand
the complexity of the language; a (blank node-free) recursive extension of SPARQL is discussed.
Similarly, Kostylev et al. [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] investigated how diferent restrictions (e.g., lack of blank nodes) of
recursive CONSTRUCT queries relate to existing logical frameworks; they proposed a recursive
extension of SPARQL resembling that of SQL. Atzori et al. [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] and Reutter et al. [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] take a
more practical approach by adding to SPARQL (respectively) a recursion function, which can
be called within a SPARQL query to execute a given query string; and a recursion operator,
which calculates the fixed point-based recursion results of given queries. The aim of our work
difers from the approaches above in the sense that we want to ofer a practical tool, enabling
the user who is more familiar with SPARQL to make use of N3 logic, its features (e.g., recursive
reasoning, range of built-ins) and N3 rules written by third parties. As a secondary goal, we
wanted to show that the built-in functions of the logic [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] are strong enough to cover SPARQL.
      </p>
      <p>
        Section 2 provides a use case that illustrates the usefulness of our work. The example is
available in our demonstrator2 and git repo [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]. Section 3 provides an in-depth discussion of
the implementation. Finally, in Section 4, we present the conclusion, summarize key findings,
and discuss future research directions.
      </p>
    </sec>
    <sec id="sec-3">
      <title>2. Use Case: Zika Screening using HL7 FHIR</title>
      <p>
        As an example, we consider a case in which we query patient data in an electronic health
record (EHR). The data is represented in HL7 FHIR3, an interoperability standard for EHR
that ofers an RDF representation (Turtle syntax) and allows covering detailed information
about—among other things—health conditions, test results, and personal data. In Listing 1 we
display an extract of such data4: patient : p 0 has condition : p o _ p r e g n which is a pregnancy
(terminology code 77386006). We observe that the information about the patient and condition
is structured in a rather complex way, as it relies on many nested blank nodes, and the relation
between concepts is expressed by the fact that the id value of the patient (line 1) is the same
as the condition’s subject’s reference value (line 3). This pattern of expressing relationships is
2https://n3-editor.herokuapp.com/n3/spin3/s/CT3InugS
3http://build.fhir.org/rdf
4Namespaces are omitted for brevity.
typical for HL7 FHIR, but similar constructs can also be found in many other RDF vocabularies,
such as Bio2RDF [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ].
      </p>
      <p>
        We implemented the CDC testing guidance for Zika5 using SPARQL C O N S T R U C T queries.
Our queries, based on the EHR, determine whether a patient should be tested for Zika. The
recommendation relies on diferent factors such as pregnancy, relevant symptoms, recent travel
to Zika areas, or sexual contacts with residents or travelers to Zika areas. To illustrate the
modularity ofered by SiN3, we encapsulate the aforementioned relationship pattern (i.e., shared
id and reference values) in an individual C O N S T R U C T query, so other queries can more easily refer
to a patient’s observations and conditions (Listing 2). As a result, other queries can simply refer
to the triple pattern ? p u t : h a s ? r instead of having to repeat the query’s W H E R E clause, as would
be the case in standard SPARQL. Secondly, being a resident of, or having traveled to, a Zika
area (a list of 92 countries) should be checked multiple times, i.e., for the patient as well as their
recent sexual partners. We similarly encapsulate the checks for residence and travel status of
any individual within two separate C O N S T R U C T queries, so they do not have to be repeated each
time. We refer to our git repository for the full code for the Zika use case [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ].
      </p>
    </sec>
    <sec id="sec-4">
      <title>3. SPARQL-in-N3 Reasoning Implementation</title>
      <p>
        To implement a recursive version of SPARQL C O N S T R U C T queries, we translate SPARQL queries to
N3 [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], due to (a) the variety of built-ins that N3 provides [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], e.g., supporting scoped
negationas-failure to implement aggregation; (b) support for the production of new blank nodes, which
is crucial for many cases (such as our Zika use case), and (c) tooling support for the language.
      </p>
      <p>
        Figure 1 illustrates the overall workflow. In SiN3 rule translation, the input CONSTRUCT
queries are first translated into SPIN code [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ], an RDF representation of SPARQL, using
SpinRDF [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ]. Next, we translate this SPIN code into N3 query rules, i.e., N3 rules that implement
5https://www.cdc.gov/zika/hc-providers/testing-guidance.html
the C O N S T R U C T queries; this is done by executing the aux.n3 and query.n3 code on the SPIN code
using an N3 reasoner. We point out that this step is only needed when first creating or modifying
the CONSTRUCT queries, or when using SiN3 interactively (such as our demonstrator). In SiN3
rule execution, the N3 query rules are executed on the input N3 data using an N3 reasoner,
together with runtime.n3 (needed for property paths), which yields N3 reasoning results.
      </p>
      <p>Note that, for the input CONSTRUCT queries file, queries currently should be separated by a
dot and newline character. Further, we allow marking queries as filters: by adding the keyword
# @ f i l t e r right before a query, only the results of the particular query will appear in the output;
all other construct queries are still recursively applied.</p>
      <p>
        In order to get a first indication of the performance of SiN3, we compared our reasoning times
with those of SpinRDF [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ], which also ofers a fixpoint-style algorithm to generate inferences
from SPIN code. We ran SiN3 and SpinRDF on the Zika use case presented in the previous
section. We modified one C O N S T R U C T query introducing new blank nodes as this is not supported
by SpinRDF. On a Macbook Pro with Apple M1 Pro, 32Gb RAM and 1Tb SSD (OS Ventura 13.4.1),
averaging over 10 runs, generating SPIN code took avg. 420ms; for SiN3, generating N3 query
rules took avg. 93ms, and executing N3 query rules took avg. 81ms; for SpinRDF, reasoning
over the SPIN code took avg. 645ms. We thus found that SiN3, leveraging the state-of-the-art
eye reasoner [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], was an order of magnitude faster than SpinRDF, while providing the same
results. This result has to be interpreted with care: SPIN is a complex language – it does not
only cover SPARQL but also a modeling vocabulary [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ] – and the SpinRDF reasoner was likely
not optimized for use cases as presented here. Thus, a preliminary conclusion is that, for the
recursive application of C O N S T R U C T queries as presented here, SiN3 is a better choice.
      </p>
    </sec>
    <sec id="sec-5">
      <title>4. Conclusion</title>
      <p>In this demo paper, we have presented SiN3, a tool that unlocks the full potential of SPARQL by
enabling recursive application of C O N S T R U C T queries using Notation3 rules. While SPARQL is
widely used for querying RDF data on the Semantic Web, its potential as a language for complex
reasoning has often been overlooked. By translating SPARQL queries into Notation3 rules, SiN3
allows scalable N3-compliant reasoners, such as EYE, to generate inferences recursively from
RDF data. We demonstrated the efectiveness of SiN3 through a demo that utilized C O N S T R U C T
queries to infer the need for Zika screening based on the HL7 FHIR notation.</p>
      <p>
        Future work includes extending the feature support of our tool (currently, solution modifiers
and federated querying are not covered), more extensive testing, and an extension towards
supporting other languages like for example, SWRL (e.g., via SWRL2SPIN [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ]). We also plan to
investigate whether SiN3 could be used to embed SPARQL expressions in N3 [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ]. We see this
as a first step to finally establish rule-based inferencing as a first-class citizen in the Semantic
Web.
      </p>
    </sec>
    <sec id="sec-6">
      <title>Acknowledgments</title>
      <p>Dörthe Arndt was supported by funding from BMBF within projects KIMEDS (grant no.
GW0552B) and M/EDGE (grant no. 16ME0529).</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>S.</given-names>
            <surname>Harris</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Seaborne</surname>
          </string-name>
          , SPARQL
          <volume>1</volume>
          .
          <article-title>1 Query Language</article-title>
          ,
          <source>W3C Recommendation, W3C</source>
          ,
          <year>2013</year>
          . https://www.w3.org/TR/2013/REC-sparql11
          <string-name>
            <surname>-</surname>
          </string-name>
          query-20130321/.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>W.</given-names>
            <surname>Van Woensel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Arndt</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.-A.</given-names>
            <surname>Champin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Tomaszuk</surname>
          </string-name>
          , G. Kellogg,
          <source>Notation3 Language, W3C Community Group Report, W3C</source>
          ,
          <year>2023</year>
          . https://w3c.github.io/N3/reports/20230703/.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>R.</given-names>
            <surname>Verborgh</surname>
          </string-name>
          , J. De Roo,
          <article-title>Drawing conclusions from linked data on the web: The eye reasoner</article-title>
          ,
          <source>IEEE Software 32</source>
          (
          <year>2015</year>
          )
          <fpage>23</fpage>
          -
          <lpage>27</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>A.</given-names>
            <surname>Polleres</surname>
          </string-name>
          ,
          <article-title>From SPARQL to rules (and back)</article-title>
          ,
          <source>in: Proceedings of the 16th international conference on World Wide Web</source>
          ,
          <year>2007</year>
          , pp.
          <fpage>787</fpage>
          -
          <lpage>796</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>E.</given-names>
            <surname>Kostylev</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Reutter</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Ugarte</surname>
          </string-name>
          , Construct queries in SPARQL,
          <source>in: 18th International Conference on Database Theory (ICDT</source>
          <year>2015</year>
          ),
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>M.</given-names>
            <surname>Atzori</surname>
          </string-name>
          ,
          <article-title>Computing recursive SPARQL queries</article-title>
          ,
          <source>in: 2014 IEEE International Conference on Semantic Computing, IEEE</source>
          ,
          <year>2014</year>
          , pp.
          <fpage>258</fpage>
          -
          <lpage>259</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>J.</given-names>
            <surname>Reutter</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Soto</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Vrgoč</surname>
          </string-name>
          , Recursion in
          <string-name>
            <surname>SPARQL</surname>
          </string-name>
          ,
          <source>Semantic Web</source>
          <volume>12</volume>
          (
          <year>2021</year>
          )
          <fpage>711</fpage>
          -
          <lpage>740</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <surname>W. Van Woensel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Hochstenbach</surname>
          </string-name>
          , Notation3 Builtin Functions,
          <source>W3C Community Group Report, W3C</source>
          ,
          <year>2023</year>
          . https://w3c.github.io/N3/reports/20230703/builtins.html.
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>D.</given-names>
            <surname>Arndt</surname>
          </string-name>
          , SiN3: Git repository,
          <year>2023</year>
          . https://github.com/doerthe/SPARQL-to-N3.
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>F.</given-names>
            <surname>Belleau</surname>
          </string-name>
          , M.
          <article-title>-</article-title>
          <string-name>
            <surname>A. Nolin</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          <string-name>
            <surname>Tourigny</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          <string-name>
            <surname>Rigault</surname>
            ,
            <given-names>J. Morissette,</given-names>
          </string-name>
          <article-title>Bio2rdf: towards a mashup to build bioinformatics knowledge systems</article-title>
          ,
          <source>Journal of biomedical informatics 41</source>
          (
          <year>2008</year>
          )
          <fpage>706</fpage>
          -
          <lpage>716</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>H.</given-names>
            <surname>Knublauch</surname>
          </string-name>
          , SPIN - SPARQL Syntax,
          <source>W3C Member Submission, W3C</source>
          ,
          <year>2011</year>
          . http://www. w3.org/Submission/2011/SUBM-spin-sparql-
          <volume>20110222</volume>
          /.
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <surname>M. J. Andy</surname>
            <given-names>Seaborne</given-names>
          </string-name>
          , Spinrdf,
          <year>2019</year>
          . https://github.com/spinrdf/spinrdf.
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <given-names>H.</given-names>
            <surname>Knublauch</surname>
          </string-name>
          , SPIN - Modeling
          <string-name>
            <surname>Vocabulary</surname>
          </string-name>
          ,
          <source>W3C Member Submission, W3C</source>
          ,
          <year>2011</year>
          . http: //www.w3.org/Submission/2011/SUBM-spin-modeling-
          <volume>20110222</volume>
          /.
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <given-names>N.</given-names>
            <surname>Bassiliades</surname>
          </string-name>
          ,
          <article-title>SWRL2SPIN: Converting swrl to spin</article-title>
          , in: RuleML+ RR (Supplement),
          <year>2018</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <given-names>M.</given-names>
            <surname>Farnbauer-Schmidt</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Charpenay</surname>
          </string-name>
          ,
          <string-name>
            <surname>A. Harth,</surname>
          </string-name>
          <article-title>N3x: Notation3 with SPARQL expressions</article-title>
          ,
          <source>in: European Semantic Web Conference</source>
          , Springer,
          <year>2020</year>
          , pp.
          <fpage>79</fpage>
          -
          <lpage>83</lpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>