The Arcomem framework has an interface for connecting, reading and writing
to triple stores. The TripleStoreConnector
interface defines a few very simple methods for reading and writing triples to
the chosen triple-store.
query( sparql )
: Takes a SPARQL query and runs it against the triple-store. TheQueryResult
object.writeTriple( triple )
: Takes a OpenRDF Statement
and writes it to the triple-store.writeRDFDocument( docStream, format )
: Takes an InputStream
which contains an RDFRDFFormat
and imports it into the triple-store.resetBuffer()
: Resets any buffers that are being used. Anything in the buffer will beforceWrite()
has been called first and succeeded.forceWrite()
: Forces a flush from the buffer into the output triple-store.The interface enforces subclasses to take a Hadoop Configuration
object during construction.
The configuration object will contain information about how to set up the triple-store
connector.
There are a number of implementations of this interface for the following triple-stores:
Sesame Memory Connector: This connector buffers triples into a memory-based
triple-store and writes them to either the standard output stream or to a file.
Use configuration option SESAME_MEMORY
.
(Class: SesameMemoryTripleStoreConnector)
Remote Sesame Connector: This connector reads and writes triples to and from
an OpenRDF triple-store. Use configuration open SESAME_REMOTE
.
(Class: SesameRemoteTripleStoreConnector)
H2RDF Connector: This connector implements reading and writing of triples from
the Arcomem H2RDF triple-store. Use configuration option H2RDF
.
(Class: H2RDFTripleStoreConnector)
Here\'s an example of how to create and use a connector:
import org.apache.hadoop.Configuration; import org.openrdf.model.impl.StatementImpl; import org.openrdf.model.impl.URIUImpl; import org.openrdf.model.impl.LiteralImpl; import eu.arcomem.framework.rdf.TripleStoreConnector; // Create a configuration Configuration conf = new Configuration(); conf.set( "triplestore.connector.class", SesameMemoryTripleStoreConnector.class.getName() ); // Create the connector TripleStoreConnector tsc = TripleStoreConnector.newConnector( conf ); // Write a triple into the store. tsc.writeTriple( new StatementImpl( new URIImpl( "http://example.com/#subject" ), new URIImpl( "http://example.com/#predicate" ), new LiteralImpl( "object" ) ); // Query the triple-store QueryResult<BindingSet> results = tsc.query( "SELECT ?a ?b ?c WHERE (?a ?b ?c.)" ); // Write the results out while( results.hasNext() ) { BindingSet b = results.next(); System.out.println( b.getBinding("a") ); }
Here we use the TripleStoreConnector.newConnector(conf)
method to create the appropriate
connector rather than instantiating it directly. This would allow us to configure which
triple-store to use at runtime rather than compile time, although we don\'t do that in this
example.
There is another way to create the connector too. The
TripleStoreConnectors
enumerator has all the connectors enumerated. Therefore, it can be also be created as follows:
TripleStoreConnector tsc = TripleStoreConnectors.SESAME_MEMORY...
This technique is used for configuration of the triple-store connector for an offline-analysis
phase via the command-line or the configuration file.
The sample-offline-config.xml
contains an example of how to configure the triple-store
for offline analysis. The important part is shown below.
<tripleStore> <H2RDF> <url>http://test.url</url> <user>jon</user> <table>the-table</table> </H2RDF> </tripleStore>
The value of the first child element of the <tripleStore>
configuration
is the name of the numerator from TripleStoreConnectors
.
The children elements contain the configuration that is necessary for that
particular connector.