<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to DataModel</title><link>https://sourceforge.net/p/arcomem/wiki/DataModel/</link><description>Recent changes to DataModel</description><atom:link href="https://sourceforge.net/p/arcomem/wiki/DataModel/feed" rel="self"/><language>en</language><lastBuildDate>Wed, 19 Feb 2014 00:26:53 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/arcomem/wiki/DataModel/feed" rel="self" type="application/rss+xml"/><item><title>DataModel modified by John Arcoman</title><link>https://sourceforge.net/p/arcomem/wiki/DataModel/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="the-data-model"&gt;The Data Model&lt;/h1&gt;
&lt;p&gt;The ARCOMEM data model is a set of concepts that are links by specific relationships.&lt;br /&gt;
They have been modelled with Protégé and represented as an OWL and RDF ontology&lt;br /&gt;
that is available through the ARCOMEM website.&lt;/p&gt;
&lt;p&gt;&lt;img alt="The ARCOMEM Data Model" src="../arcomem-data-model.png" title="The ARCOMEM Data Model" /&gt;&lt;/p&gt;
&lt;p&gt;The ontology stipulates which relationships are valid for which concepts and&lt;br /&gt;
whether there are any constraints on those relationships. Instances of the&lt;br /&gt;
relationships can be represented as triples. For example, to state that&lt;br /&gt;
a web resource is an image, you would link an instance of a web resource (the subject)&lt;br /&gt;
to an instance of an image (the object) using the &lt;em&gt;hasWebObject&lt;/em&gt; relationship (the predicate):&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;    &lt;span class="nl"&gt;arco:&lt;/span&gt;&lt;span class="n"&gt;webresource1&lt;/span&gt; &lt;span class="n"&gt;arco&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;hasWebObject&lt;/span&gt; &lt;span class="n"&gt;arco&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;image1&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here, the &lt;em&gt;arco:&lt;/em&gt; prefix is shorthand for the base URI of the ontology; that is, the&lt;br /&gt;
full relationship (predicate) URI is actually&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;    &lt;span class="nl"&gt;http:&lt;/span&gt;&lt;span class="c1"&gt;//www.gate.ac.uk/ontologies/arcomem/data-model/hasWebObject.&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;...but that\'s much too long to type!&lt;/p&gt;
&lt;p&gt;Triples like this can be written directly to a knowledge base using a&lt;br /&gt;
&lt;a class="" href="../apidocs/eu/arcomem/framework/rdf/TripleStoreConnector"&gt;&lt;code&gt;TripleStoreConnector&lt;/code&gt;&lt;/a&gt;&lt;br /&gt;
(see the &lt;a class="" href="../TripleStoreConnector"&gt;Triple Store Connectors&lt;/a&gt; section for information&lt;br /&gt;
on creating and using a triple store connector).&lt;/p&gt;
&lt;h2 id="the-data-model-java-classes"&gt;The Data Model Java Classes&lt;/h2&gt;
&lt;p&gt;The data model has been converted (automatically) to Java classes. These Java&lt;br /&gt;
classes provide a means for interacting with instances of the data model.&lt;br /&gt;
They automatically provide the validation, where applicable, and are able to&lt;br /&gt;
be serialized (using the &lt;a class="" href="http://www.openimaj.org/" rel="nofollow"&gt;OpenIMAJ&lt;/a&gt; RDFSerializer)&lt;br /&gt;
into triples compatible with the ontology.&lt;/p&gt;
&lt;p&gt;With these classes it is possible instantiate objects from the data model&lt;br /&gt;
as if they were Java objects and set and get the properties using regular&lt;br /&gt;
getters and setters. These getters and setters may provide validation.&lt;br /&gt;
For example,&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;    &lt;span class="n"&gt;WebResourceImpl&lt;/span&gt; &lt;span class="n"&gt;webResource&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;WebResourceImpl&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;webResource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setURI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="n"&gt;ImageImpl&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;ImageImpl&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setURI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;generateRandomURI&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;webResource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getContainsWebObject&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here we are just creating and setting properties for the top-level image&lt;br /&gt;
web-resources as they arrive at a mapper. We use the getContainsWebObject()&lt;br /&gt;
method to add the image web object to a list of web objects associated with the&lt;br /&gt;
resource because the data-model allows an unrestricted one-to-many&lt;br /&gt;
relation between WebResources and WebObjects, so this is translated into Java&lt;br /&gt;
through the use of Lists.&lt;/p&gt;
&lt;p&gt;To write this information to the triple-store we can utilise the OpenIMAJ&lt;br /&gt;
RDFSerializer class (developed for ARCOMEM) which takes a set of Java classes&lt;br /&gt;
and serialises them to RDF. The data model Java classes have been generated in&lt;br /&gt;
such a way that the serialiser can generate RDF that conforms to the ontology.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;    &lt;span class="c1"&gt;// Write the n-triples to a String (could write to File)&lt;/span&gt;
    &lt;span class="n"&gt;final&lt;/span&gt; &lt;span class="n"&gt;StringWriter&lt;/span&gt; &lt;span class="n"&gt;sw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;StringWriter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// Write to n-triples (could use other writers here)&lt;/span&gt;
    &lt;span class="c1"&gt;// See OpenRDF for the available writers&lt;/span&gt;
    &lt;span class="n"&gt;final&lt;/span&gt; &lt;span class="n"&gt;NTriplesWriter&lt;/span&gt; &lt;span class="n"&gt;tw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;NTriplesWriter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;sw&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Override the addTriple() method in a new RDFSerializer&lt;/span&gt;
    &lt;span class="c1"&gt;// so that it sends the triples to the OpenRDF triple writer&lt;/span&gt;
    &lt;span class="n"&gt;final&lt;/span&gt; &lt;span class="n"&gt;RDFSerializer&lt;/span&gt; &lt;span class="n"&gt;rs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;RDFSerializer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="n"&gt;Override&lt;/span&gt;
        &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;addTriple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;final&lt;/span&gt; &lt;span class="n"&gt;Statement&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;try&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;tw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;handleStatement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;final&lt;/span&gt; &lt;span class="n"&gt;RDFHandlerException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;printStackTrace&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="c1"&gt;// We won’t output the Java class names into the RDF&lt;/span&gt;
    &lt;span class="n"&gt;rs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setOutputClassNames&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Start the RDF writing&lt;/span&gt;
    &lt;span class="n"&gt;tw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;startRDF&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// Start the serializing&lt;/span&gt;
    &lt;span class="n"&gt;rs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;serialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;webResource&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;webResource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getURI&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// End the RDF writing&lt;/span&gt;
    &lt;span class="n"&gt;tw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;endRDF&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// The RDF is now in the sw StringWriter&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The code above sets up an &lt;code&gt;NTriplesWriter&lt;/code&gt; (part of OpenRDF) which will take&lt;br /&gt;
&lt;code&gt;Statement&lt;/code&gt;s (triples) and write valid n-triples.  The &lt;code&gt;RDFSerializer&lt;/code&gt; class&lt;br /&gt;
calls the &lt;code&gt;addTriple(Statement)&lt;/code&gt; method every time it generates a triple when&lt;br /&gt;
serializing the object. This could be sent to a&lt;br /&gt;
&lt;a href="../apidocs/eu/arcomem/framework/rdf/TripleStoreConnector.html#writeTriple%%28org.openrdf.model.Statement%%29"&gt;&lt;code&gt;TripleStoreConnector#writeTriple()&lt;/code&gt;&lt;/a&gt;&lt;br /&gt;
method but in this example we send it to the &lt;code&gt;NTriplesWriter&lt;/code&gt;&lt;br /&gt;
(which itself is writing to a &lt;code&gt;StringWriter&lt;/code&gt;).&lt;/p&gt;
&lt;h2 id="a-note-about-the-uri-scheme-for-resources"&gt;A Note about the URI Scheme for Resources&lt;/h2&gt;
&lt;p&gt;When stored into the HBase, every resource has a key. For web-pages, this key is the URL of the&lt;br /&gt;
web-page, although it may also be other schemes that represent parts of twitter feeds. However,&lt;br /&gt;
this key does not uniquely define a single resource. It actually defines a set of resources. This&lt;br /&gt;
set contists of the content of that URL as it has been crawled at different moments in time.&lt;br /&gt;
&lt;code&gt;http://www.bbc.co.uk/&lt;/code&gt; looks very different now than it did 10 years ago. So, when resources&lt;br /&gt;
are referred to in the knowledge base, it\'s important to know which resource we are talking about.&lt;/p&gt;
&lt;p&gt;So, the ARCOMEM technical team have agreed on a scheme which allows reference to a specific&lt;br /&gt;
versioned resource within a specific crawl database. It is this URI that should be used&lt;br /&gt;
within the triple store for referencing web-resources.&lt;/p&gt;
&lt;p&gt;The scheme is as follows:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="nx"&gt;hbase&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//&amp;lt;table&amp;gt;/&amp;lt;timestamp&amp;gt;/&amp;lt;key&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The scheme (&lt;code&gt;hbase://&lt;/code&gt;) refers to the fact that the data is stored within an hbase. The&lt;br /&gt;
&lt;code&gt;table&lt;/code&gt; is the table name of the crawled data; The &lt;code&gt;timestamp&lt;/code&gt; is the timestamp&lt;br /&gt;
that HBase uses to refer to a specific version; The &lt;code&gt;key&lt;/code&gt; will be the HBase key that identifies the row.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="nl"&gt;hbase:&lt;/span&gt;&lt;span class="c1"&gt;//crawl_data/20121112151302/http://www.bbc.co.uk/&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Until there is a way of globally identifying an HBase instance, there cannot be&lt;br /&gt;
a server portion to the URI, hence this is always empty.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">John Arcoman</dc:creator><pubDate>Wed, 19 Feb 2014 00:26:53 -0000</pubDate><guid>https://sourceforge.neta7e409cfb3b546635856f407ba16f69c14f4f00e</guid></item></channel></rss>