<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to TripleStoreConnector</title><link>https://sourceforge.net/p/arcomem/wiki/TripleStoreConnector/</link><description>Recent changes to TripleStoreConnector</description><atom:link href="https://sourceforge.net/p/arcomem/wiki/TripleStoreConnector/feed" rel="self"/><language>en</language><lastBuildDate>Wed, 19 Feb 2014 00:42:24 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/arcomem/wiki/TripleStoreConnector/feed" rel="self" type="application/rss+xml"/><item><title>TripleStoreConnector modified by John Arcoman</title><link>https://sourceforge.net/p/arcomem/wiki/TripleStoreConnector/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="the-triple-store-connector"&gt;The Triple Store Connector&lt;/h1&gt;
&lt;p&gt;The Arcomem framework has an interface for connecting, reading and writing&lt;br /&gt;
to triple stores. The &lt;a class="" href="../apidocs/eu/arcomem/framework/rdf/TripleStoreConnector"&gt;TripleStoreConnector&lt;/a&gt;&lt;br /&gt;
interface defines a few very simple methods for reading and writing triples to&lt;br /&gt;
the chosen triple-store.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;query( sparql )&lt;/code&gt;: Takes a SPARQL query and runs it against the triple-store. The&lt;br /&gt;
    method will return an OpenRDF &lt;code&gt;QueryResult&lt;/code&gt; object.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;writeTriple( triple )&lt;/code&gt;: Takes a OpenRDF &lt;code&gt;Statement&lt;/code&gt; and writes it to the triple-store.&lt;br /&gt;
    Note that the writing of triples may be buffered.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;writeRDFDocument( docStream, format )&lt;/code&gt;: Takes an &lt;code&gt;InputStream&lt;/code&gt; which contains an RDF&lt;br /&gt;
    document in the given &lt;code&gt;RDFFormat&lt;/code&gt; and imports it into the triple-store.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;resetBuffer()&lt;/code&gt;: Resets any buffers that are being used. Anything in the buffer will be&lt;br /&gt;
    lost unless &lt;code&gt;forceWrite()&lt;/code&gt; has been called first and succeeded.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;forceWrite()&lt;/code&gt;: Forces a flush from the buffer into the output triple-store.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The interface enforces subclasses to take a Hadoop &lt;code&gt;Configuration&lt;/code&gt; object during construction.&lt;br /&gt;
The configuration object will contain information about how to set up the triple-store&lt;br /&gt;
connector.&lt;/p&gt;
&lt;p&gt;There are a number of implementations of this interface for the following triple-stores:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Sesame Memory Connector&lt;/em&gt;: This connector buffers triples into a memory-based&lt;br /&gt;
    triple-store and writes them to either the standard output stream or to a file.&lt;br /&gt;
    Use configuration option &lt;code&gt;SESAME_MEMORY&lt;/code&gt;.&lt;br /&gt;
    (Class: &lt;a class="" href="../apidocs/eu/arcomem/framework/rdf/SesameMemoryTripleStoreConnector"&gt;SesameMemoryTripleStoreConnector&lt;/a&gt;)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Remote Sesame Connector&lt;/em&gt;: This connector reads and writes triples to and from&lt;br /&gt;
    an OpenRDF triple-store. Use configuration open &lt;code&gt;SESAME_REMOTE&lt;/code&gt;.&lt;br /&gt;
    (Class: &lt;a class="" href="../apidocs/eu/arcomem/framework/rdf/SesameRemoteTripleStoreConnector"&gt;SesameRemoteTripleStoreConnector&lt;/a&gt;)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;H2RDF Connector&lt;/em&gt;: This connector implements reading and writing of triples from&lt;br /&gt;
    the Arcomem H2RDF triple-store. Use configuration option &lt;code&gt;H2RDF&lt;/code&gt;.&lt;br /&gt;
    (Class: &lt;a class="" href="../apidocs/eu/arcomem/framework/rdf/H2RDFTripleStoreConnector"&gt;H2RDFTripleStoreConnector&lt;/a&gt;)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here\'s an example of how to create and use a connector:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;org.apache.hadoop.Configuration&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;org.openrdf.model.impl.StatementImpl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;org.openrdf.model.impl.URIUImpl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;org.openrdf.model.impl.LiteralImpl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;eu.arcomem.framework.rdf.TripleStoreConnector&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Create a configuration&lt;/span&gt;
&lt;span class="nx"&gt;Configuration&lt;/span&gt; &lt;span class="n"&gt;conf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;conf.set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;triplestore.connector.class&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;SesameMemoryTripleStoreConnector.class.getName&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Create the connector&lt;/span&gt;
&lt;span class="nx"&gt;TripleStoreConnector&lt;/span&gt; &lt;span class="n"&gt;tsc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;TripleStoreConnector.newConnector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;conf&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Write a triple into the store.&lt;/span&gt;
&lt;span class="nx"&gt;tsc.writeTriple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;StatementImpl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nb"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;URIImpl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;http://example.com/#subject&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nb"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;URIImpl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;http://example.com/#predicate&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nb"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;LiteralImpl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;object&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Query the triple-store&lt;/span&gt;
&lt;span class="nx"&gt;QueryResult&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;BindingSet&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="nx"&gt;tsc.query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;SELECT ?a ?b ?c WHERE (?a ?b ?c.)&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Write the results out&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;results.hasNext&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="nx"&gt;BindingSet&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;results.next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;System.out.println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;b.getBinding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;a&amp;quot;&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;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here we use the &lt;code&gt;TripleStoreConnector.newConnector(conf)&lt;/code&gt; method to create the appropriate&lt;br /&gt;
connector rather than instantiating it directly. This would allow us to configure which&lt;br /&gt;
triple-store to use at runtime rather than compile time, although we don\'t do that in this&lt;br /&gt;
example.&lt;/p&gt;
&lt;p&gt;There is another way to create the connector too. The&lt;br /&gt;
&lt;a class="" href="../apidocs/eu/arcomem/framework/rdf/TripleStoreConnectors"&gt;&lt;code&gt;TripleStoreConnectors&lt;/code&gt;&lt;/a&gt;&lt;br /&gt;
enumerator has all the connectors enumerated. Therefore, it can be also be created as follows:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;TripleStoreConnector&lt;/span&gt; &lt;span class="n"&gt;tsc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;TripleStoreConnectors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SESAME_MEMORY&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This technique is used for configuration of the triple-store connector for an offline-analysis&lt;br /&gt;
phase via the command-line or the configuration file.&lt;br /&gt;
The &lt;code&gt;sample-offline-config.xml&lt;/code&gt; contains an example of how to configure the triple-store&lt;br /&gt;
for offline analysis. The important part is shown below.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="nt"&gt;&amp;lt;tripleStore&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;H2RDF&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;url&amp;gt;&lt;/span&gt;http://test.url&lt;span class="nt"&gt;&amp;lt;/url&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;user&amp;gt;&lt;/span&gt;jon&lt;span class="nt"&gt;&amp;lt;/user&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;table&amp;gt;&lt;/span&gt;the-table&lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/H2RDF&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/tripleStore&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The value of the first child element of the &lt;code&gt;&amp;lt;tripleStore&amp;gt;&lt;/code&gt; configuration&lt;br /&gt;
is the name of the numerator from &lt;code&gt;TripleStoreConnectors&lt;/code&gt;.&lt;br /&gt;
The children elements contain the configuration that is necessary for that&lt;br /&gt;
particular connector.&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:42:24 -0000</pubDate><guid>https://sourceforge.net57bcf4b68e61639dacc44b6890aa615a420137cc</guid></item></channel></rss>