<!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>Ob jects as results from graph queries using an ORM and generated semantic-relational binding</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Marc-Antoine Parent maparent@acm.org</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Interoperability in the Catalyst Consortium</institution>
        </aff>
      </contrib-group>
      <abstract>
        <p>This poster describes a method to expose data in a objectrelational model as linked data. It uses Virtuoso's Linked Data views on relational data to expose and query relational data. As our objectrelational model is evolving, we generate the linked data view definition from augmented ORM declarations. This project has received funding from the European Union's Seventh Framework Programme for research, technological development and demonstration under grant agreement n 6611188.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        The technical partners agreed to use Linked Data technologies for
interoperability, both for its inherent flexibility and because there were relevant standard
ontologies that could be leveraged. We co-designed a format [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] that could
accommodate the model diversity, leveraging a few common ontologies, such as
SIOC, OpenAnnotation, and FOAF; and with equivalences to other relevant
ontologies such as AIF. New ontologies were developed when necessary, for example
for IBIS data. To lower the barrier to entry for partners with limited expertise
with Semantic Web technologies, we agreed on RESTful exchange of JSON-LD
data as the main interchange protocol. Partners with legacy relational models
could enter the ecosystem with simple JSON parsers and generators.
      </p>
      <p>
        The Assembl platform could not follow that simple model: our legacy model
was object-oriented, using SQLAlchemy [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], a Python declarative ORM, with
PostgreSQL. We wanted to use a semantic database rather than a semantic
wrapper on a traditional relational database, so we could display the results
of complex graph queries efficiently. On the other hand, we had a fair amount
of business logic coded at the object layer, which we wanted to leverage; and
the object model was under continuous development, and we did not want to
maintain a semantic-relational wrapper independently.
2
      </p>
    </sec>
    <sec id="sec-2">
      <title>Existing solutions for proxies to data storage</title>
      <p>The first alternatives we rejected were: Pure relational (weakness of
graphoriented queries), pure semantic (relative obscurity of object-semantic tooling
in Python), and partitioning our data between two databases, with the
relationships in a semantic database and the content in a RDBMS (overhead of joining
across database systems).</p>
      <p>When dealing with relational data, Object-Relational Mappings (ORMs) allow
developers to write an object model annotated with mappings to the relational
model. This annotated object model can act as a OO wrapper, or proxy to the
relational model. Many ORMs also allow developers to generate the relational
model from the object model, or more rarely the object model (with relational
annotations) from the relational model through relational introspection. In either
case, we have a single authoritative model, which software engineers also call the
“don’t repeat yourself” (DRY) principle.</p>
      <p>
        With semantic data, we also have object proxies over semantic data11. As with
an ORM, OO code can be annotated with semantic mapping annotations, as with
RDFAlchemy12 or Elmo13) Also similarly, the OO code of those proxys can be
generated from the RDFS or OWL models, as with RdfReactor14 or Jastor15
respectively, and others [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. In the case of dynamic languages like Python, it is
11 http://semanticweb.org/wiki/Tripresso
12 http://www.openvest.com/trac/wiki/RDFAlchemy
13 http://www.openrdf.org/elmo.jsp
14 http://rdfreactor.semweb4j.org/
15 http://jastor.sourceforge.net/
also possible to dynamically translate accessor queries to unchecked RDF access,
as with, for example, SuRF16 or OldMan17.
      </p>
      <p>
        Another bridging technique involves semantic mapping over relational data.
An adapter will use this mapping to act as a semantic proxy. The most
wellknown mapping language is the R2RML standard [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], but Virtuoso offers its
own Linked Data Views syntax [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. Those technologies allow great flexibility,
but require to maintain the semantic-relational mapping in synchrony with the
pre-existing semantic and relational models.
3
      </p>
      <p>Generated semantic-relational binding for Assembl
We opted to use the Virtuoso database and enrich the relational annotation layer
of SQLAlchemy with a semantic layer, with enough information to generate not
only the relational model, but also the semantic mapping. This gives us both
OO and semantic proxies over relational data. Simple traversals are converted
by the ORM into relational queries, while more complex traversals are written as
embedded SPARQL. We can expose the data as a SPARQL endpoint, or export
it as JSON-LD for the benefit of the Catalyst ecosystem.</p>
      <p>We generate Virtuoso linked data view definitions rather than R2RML
mappings (which our annotations would also allow.) This allows us to also exploit
Virtuoso’s capability to embed a SPARQL subquery in a SQL query. Thus, our
code receives ORM objects directly from a SPARQL query, and a single
codebase serves as both an OO and semantic proxy to our data. We still have to keep
this annotation layer up-to-date with both our relational and semantic models,
as in the case of a hand-crafted semantic-relational mapping; but we avoid the
maintainability cost of updating a distinct OO layer.</p>
      <p>The poster18 contains example of data definitions in the object model, and
their translation to a Virtuoso linked data binding.</p>
      <p>Implementation Our semantic annotation layer19 is based on work by William
Waites20 to extend SQLAlchemy with specificities of the Virtuoso SQL dialect.
An extensible introspector visits the classes known to the ORM and obtains the
following information from class and columns annotations: the IRI pattern for
the class; a global condition for the class to be included in the mapping; and
for each database column, a specification needed to define a specific quad in the
Linked data view.</p>
      <p>SQLAlchemy has advanced capability to translate Object-Oriented (OO)
inheritance into complex relational patterns21, so the introspector has to cater to
class definitions spanning many tables, or multiple classes sharing a single table,
16 https://pythonhosted.org/SuRF/
17 https://github.com/oldm/OldMan
18 http://maparent.ca/iswc2014poster.pdf
19 https://github.com/maparent/virtuoso-python
20 http://river.styx.org/ww/2010/10/pyodbc-spasql/index
21 http://docs.sqlalchemy.org/en/rel_0_9/orm/inheritance.html
and generate appropriate bindings. In Assembl, a subclass of the introspector
also allows more quad specifications tied to more than one column, multiple
graphs, global conditions that apply to class patterns, etc.</p>
      <p>Much of the quad specification besides the predicate can be left blank, as
the introspector can be initialized with a default graph, the subject is the class’
subject IRI pattern, and the object is the column to which the quad specification
is attached, which is interpreted to be either a literal or the application of an
IRI pattern which can be inferred from foreign key information.</p>
      <p>The quad specification may also specify a condition of applicability using the
ORM constructs. The condition’s structure is visited to define a coherent set of
table aliases for this condition, which will be used in the linked data binding. A
reference to a column defined in a superclass (which may appear in the object or
condition of the quad specification) will enrich the condition with the appropriate
table join; similarly, a reference to a subclass which does not define its own table
will re-use the appropriate ORM condition.
4</p>
    </sec>
    <sec id="sec-3">
      <title>Open issues</title>
      <p>Having exposed our relational data as linked data, we will next work on
importation of semantic data, and translating it into our relational model. We have
to contend with the fact that open-world semantic data may not conform to
referential integrity constraints defined at the relational layer. Also, because it
is based on SQLAlchemy models, our solution follows its OO model with single
inheritance.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Bayer</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          : Sqlalchemy. In: Brown,
          <string-name>
            <surname>A.</surname>
          </string-name>
          , Wilson, G. (eds.)
          <article-title>The Architecture of Open Source Applications: Elegance, Evolution, and a Few More Fearless Hacks</article-title>
          ., vol.
          <volume>2</volume>
          . Lulu.com (
          <year>2012</year>
          ), http://aosabook.org/en/sqlalchemy.html 2
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>Buckingham</given-names>
            <surname>Shum</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            ,
            <surname>De Liddo</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            ,
            <surname>Klein</surname>
          </string-name>
          ,
          <string-name>
            <surname>M.</surname>
          </string-name>
          :
          <article-title>Dcla meet cida: Collective intelligence deliberation analytics</article-title>
          .
          <source>The Second International Workshop on DiscourseCentric Learning Analytics (Mar</source>
          <year>2014</year>
          ), http://dcla14.files.
          <source>wordpress.com/ 2014/03/dcla14_buckinghamshumdeliddoklein1.pdf 1</source>
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Das</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Sundara</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Cyganiak</surname>
          </string-name>
          , R.: R2rml:
          <article-title>Rdb to rdf mapping language</article-title>
          .
          <source>W3c recommendation, World Wide Web Consortium (September</source>
          <year>2012</year>
          ), http://www. w3.org/TR/2012/REC-r2rml
          <source>-20120927/ 3</source>
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Haynes</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          :
          <article-title>Mapping relational data to rdf with virtuoso's rdf views</article-title>
          .
          <source>Tech. rep., OpenLink Software</source>
          (
          <year>2010</year>
          ), http://virtuoso.openlinksw.
          <source>com/whitepapers/ Mapping%20Relational%20Data%20to%20RDF.pdf 3</source>
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Kalyanpur</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Pastor</surname>
            ,
            <given-names>D.J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Battle</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Padget</surname>
            ,
            <given-names>J.A.</given-names>
          </string-name>
          :
          <article-title>Automatic mapping of owl ontologies into java</article-title>
          . In: Maurer,
          <string-name>
            <given-names>F.</given-names>
            ,
            <surname>Ruhe</surname>
          </string-name>
          ,
          <string-name>
            <surname>G</surname>
          </string-name>
          . (eds.) SEKE. pp.
          <fpage>98</fpage>
          -
          <lpage>103</lpage>
          (
          <year>2004</year>
          )
          <fpage>2</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Parent</surname>
            ,
            <given-names>M.A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Grégoire</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          :
          <article-title>Software architecture and cross-platform interoperability specification</article-title>
          .
          <source>D 3</source>
          .1,
          <string-name>
            <surname>Catalyst-FP7</surname>
          </string-name>
          (
          <year>Mar 2014</year>
          ), http://catalyst-fp7.eu/wpcontent/uploads/2014/03/D3.1-
          <string-name>
            <surname>Software-Architecture-</surname>
          </string-name>
          and
          <article-title>-</article-title>
          <string-name>
            <surname>Cross-</surname>
          </string-name>
          PlatformInteroperability
          <source>-Specification.pdf 2</source>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>