API Reference

From Tupelo Wiki

Table of contents

Resource Description Framework (RDF)

Tupelo 2 provides a simple API (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/rdf/package-summary.html) for constructing and processing RDF (http://www.w3.org/RDF/) data.

Resources and Triples

RDF graphs (http://www.w3.org/TR/rdf-concepts/#section-data-model) consist of statements, each of which is represented by an RDF triple (http://www.w3.org/TR/rdf-concepts/#section-triples). Triples are represented in Tupelo 2 with the Triple (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/rdf/Triple.html) class, which extends the more generic Tuple (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/util/Tuple.html) utility.

Each term in a Triple is a Resource (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/rdf/Resource.html).

Constructing Triples

To construct a URI reference (http://www.w3.org/TR/rdf-concepts/#dfn-URI-reference), use Resource.uriRef (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/rdf/Resource.html#uriRef(java.lang.String)):

Resource subject = Resource.uriRef("http://myuri.org/people/joe");
Resource predicate = Resource.uriRef("http://myuri.org/predicates/hasNickname");

To construct a literal (http://www.w3.org/TR/rdf-concepts/#dfn-literal), use Resource.literal (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/rdf/Resource.html#literal(java.lang.String)):

Resource object = Resource.literal("Mr. RDF");

If you want a typed literal, use the two-argument form:

import static org.tupeloproject.rdf.Vocabulary.Xsd;
...
Resource object = Resource.literal("34",Xsd.POSITIVE_INTEGER);

A Triple can be constructed from Resources:

import static org.tupeloproject.rdf.Vocabulary.Dc;
...
Triple triple = new Triple
  (Resource.uriRef("http://tupeloproject.org"),
   Dc.DESCRIPTION,
   Resource.literal("Tupelo project website");

The Triple class provides a convenience method that attempts to convert Java types to the relevant kinds of Resources:

import static org.tupeloproject.rdf.Vocabulary.Dc;
...
URI website = URI.create("http://tupeloproject.org");
Triple triple1 = Triple.create(website,Dc.DESCRIPTION,"Tupelo project website");
Triple triple2 = Triple.create(website,Dc.DATE,new Date());

Graphs

Unlike other RDF API's such as Jena (http://jena.sourceforge.net/), Tupelo 2's RDF API doesn't provide facilities for manipulating and working with RDF graphs. Instead, Tupelo 2 manages RDF graphs and other kinds of data and metadata using the Context (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/Context.html) abstraction. However, Triples can be managed using ordinary Java collections such as Sets and Maps. Resources are comparable, with URI references preceding literals. Triples are comparable and are sorted by subject first, then predicate, then object.

Blank nodes

Blank node identifiers in RDF are locally scoped in an implementation-dependent way. Since Triples in Tupelo 2 can be used to transport RDF graphs between implementations, Tupelo 2 does not allow blank nodes to be compared unless an application has assigned a globally-unique scope ID (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/rdf/BlankNode.html) to each one. To do this, use BlankNode.setScopeId (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/rdf/BlankNode.html#setScopeId(org.tupeloproject.rdf.UriRef)).

Serialization

Tupelo 2 does not use Java Object Serialization to serialize and deserialize RDF data. Instead, Tupelo 2 provides interfaces to existing implementations of the standard RDF serialization formats.

RDF/XML

To serialize RDF data in RDF/XML (http://www.w3.org/TR/rdf-syntax-grammar/), use org.tupeloproject.jena.Jena (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/jena/Jena.html):

Set<Triple> triplesToWrite = ...
Jena.writeTriples(triplesToWrite, new FileOutputStream(new File("/tmp/foo.xml"));

Deserialization is equally straightforward with Jena:

Set<Triple> triples = Jena.readTriples(new FileInputStream(new File("/tmp/foo.xml"));

Note: Tupelo now contains its own RDF/XML implementation. See the tupelo-kernel module in SVN which contains the new package org.tupeloproject.rdf.xml.

N3

N3 support is also provided by Jena.

Set<Triple> triplesToWrite = ...
JenaContext jc = new JenaContext(triplesToWrite);
jc.writeN3(triplesToWrite, myOutputStream);

Including deserialization:

JenaContext jc = new JenaContext();
jc.readN3(myInputStream);
Set<Triple> triples = jc.getTriples();

N-Triples

To serialize RDF data in N-Triples (http://www.w3.org/TR/rdf-testcases/#ntriples), just use the toString method on each Triple:

Set<Triple> triplesToWrite ...
PrintWriter pw = new PrintWriter(new FileWriter(new File("/tmp/foo.nt"));
for(Triple t : triplesToWrite) {
    pw.println(t);
}

To deserialize N-Triples data, use NTriplesInputStream (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/rdf/ntriples/NTriplesInputStream.html):

NTriplesInputStream ntis = new NTriplesInputStream(new FileInputStream(new File("/tmp/foo.nt")));
for(Triple t : ntis) {
    System.out.println("read: "+t);
}

Contexts

A Context (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/Context.html) represents a logical subset of all the data and metadata in the world, and provides the ability to perform abstract operations against that data and metadata. The Tupelo kernel provides a base Context abstraction and a core set of operations, called Operators (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/Operator.html).

Context abstraction

A Context is a mutable container of data and metadata. Context implementations can perform Operators that either modify or query the state of the Context. A Context can be local and ephemeral (e.g., backed by memory) or persistent (e.g., backed by a database).

Children

Contexts can have any number of children. The Tupelo kernel provides several abstract aggregation models by which a Context delegates operations to its children, including mirroring and merging.

Operators, perform, and late binding

To perform an operation, an Operator is passed to Context's perform method (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/Context.html#perform(org.tupeloproject.kernel.Operator)). This modifies the state of the Context and also potentially of the Operator as well.

Unlike other Java methods, perform uses late binding to locate the most specific implementation for the Operator's runtime type--not necessarily its compile-time type. This is to facilitate dynamic delegation of operations between Contexts.

Operators

Operators (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/Operator.html) are the abstract behaviors that form the Tupelo kernel. Operators are stateful descriptions of actions and the results of actions that are performed by a Context. Currently, Tupelo supports two kinds of Operators: Blob operators and Triple operators.

Blob operators

Blobs are abstract octet (a.k.a. byte) streams, each of which is addressed by a globally-unique URI. Three blob operators are defined in the Tupelo kernel. Blob operators all have a "uri" property identifying the blob; convenience setters and getters for "Subject" that accept a Resource can also be used to set and get this property.

BlobWriter

BlobWriter (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/BlobWriter.html) provides a means for writing octet (a.k.a. byte) streams to a Context.

Properties:

  • uri (URI) - the URI of the blob to write
  • inputStream (InputStream) - the data to write

Usage:

Set the uri property to the blob's URI and the inputStream property to an input stream on the data you want to write to the blob. The stream will be consumed when the BlobWriter is performed, and the Context will be modified so that the data can subsequently be read using a BlobFetcher with the same URI. Tupelo itself doesn't provide any guarantee that the performance of a BlobWriter is atomic, but some Context implementations might.

Example:

BlobWriter bw = new BlobWriter();
bw.setUri(URI.create("urn:foobar"));
bw.setInputStream(new ByteArrayInputStream("Hello, world.\n".getBytes("US-ASCII")));
context.perform(bw);

Context provides a convenience method called read (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/Context.html#read(java.net.URI)) for reading from a blob.

BlobFetcher

BlobFetcher (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/BlobFetcher.html) provides a means of reading octet (a.k.a. byte) streams from a Context.

Properties:

  • uri (URI) - the uri of the blob to fetch
  • inputStream (InputStream) - the data that was fetched

Usage:

Set the uri property to the URI of the blob you want to fetch. After the Context performs the BlobFetcher, either the inputStream property will contain an input stream on the blob's data, or if no blob exists at the given URI, NotFoundException will be thrown.

Example:

BlobFetcher bf = new BlobFetcher();
bf.setUri(URI.create("urn:foobar"));
context.perform(bf);
InputStream is = bf.getInputStream();
... read the data from is ...

BlobRemover

BlobRemover (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/BlobRemover.html) is an operator that breaks the association between a URI and a blob in a Context, so that a subsequent attempt to fetch the blob will throw NotFoundException instead of succeeding. This may release resources associated with the blob (e.g., deleting a file), depending on the Context implementation.

Properties:

  • uri (URI) - the URI of the blob to remove

Usage:

Set the uri property to the URI of the blob you want to remove. The blob will be removed when the BlobRemover is performed.

Example:

BlobRemover br = new BlobRemover();
br.setUri(URI.create("urn:foobar"));
context.perform(br);

Triple operators

Triples are abstract, immutable, atomic descriptions, also known in RDF as statements. The Tupelo kernel defines a number of operations for storing, retrieving, and searching for triples in a Context.

TripleWriter

TripleWriter (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/curent/org/tupeloproject/kernel/TripleWriter.html) provides the ability both to add and remove triples from a Context. It can add and remove any number of triples in a single operation, but Tupelo provides no guarantee that any given Context implementation will perform the operation as a single transaction.

Properties:

  • toAdd (Set<Triple>) - the set of triples to add
  • toRemove (Set<Triple>) - the set of triples to remove

Usage:

Use add (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/TripleWriter.html#add(org.tupeloproject.rdf.Triple)) or addAll (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/TripleWriter.html#addAll(java.util.Collection)) to add triples and the corresponding remove/removeAll methods to remove triples. When perform is called, the toRemove set will be removed and the toAdd set will be added to the Context. No exception will be thrown if the toRemove set contains triples that are not present in the Context.

Example:

import static org.tupeloproject.rdf.Resource.uriRef;
import static org.tupeloproject.rdf.Vocabulary.Foaf;
...
TripleWriter tw = new TripleWriter();
tw.remove(Triple.create(uriRef("urn:person1"),Foaf.NAME,"Jane Smith"));
tw.add(Triple.create(uriRef("urn:person1"),Foaf.NAME,"Jane Doe"));
tw.add(Triple.create(uriRef("urn:person1"),uriRef("http://myns#marriedTo"),uriRef("urn:person2")));
tw.add(Triple.create(uriRef("urn:person2"),Foaf.NAME,"John Doe"));
context.perform(tw);

SubjectRemover

SubjectRemover (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/SubjectRemover.html) allows all triples with a given subject to be removed in a single operation. Although not all Contexts support SubjectRemover, the ones that do generally provide a guarantee that the operation is atomic.

Properties:

  • subject (Resource) - the subject to remove

Usage:

Set the subject property to the subject you want to remove. When perform is called, all triples with that subject will be removed from the Context.

Example:

SubjectRemover sr = new SubjectRemover();
sr.setSubject(Resource.uriRef("urn:theToothFairy"));
context.perform(sr);

TripleIterator

TripleIterator (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/TripleIterator.html) provides a means of iterating over every triple in a Context. For some Contexts (e.g., a triple store with millions of triples in it), this is an absurdly expensive operation, and as a result not all Contexts support this Operator.

Properties:

  • iterator (Iterator<Triple>) - the iterator

Usage:

Construct a TripleIterator and call perform. Then either acquire the iterator and make calls against it, or use a foreach loop.

Example:

TripleIterator ti = new TripleIterator();
context.perform(ti);
System.out.println("Here are the triples:");
for(Triple t : ti) {
    System.out.println(t);
}

Context implements Iterable<Triple> by performing TripleIterator. That means you can use a foreach loop over a Context, but attempting to do so for a Context implementation that does not support TripleIterator will throw an OperatorUnavailableException.

TripleFetcher

TripleFetcher (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/TripleFetcher.html) provides a means of retrieving all triples from a Context that describe the given subject. This is guaranteed to include all triples with that subject, but may also include other related triples, depending on the Context implementation.

Properties:

  • subject (Resource) - the subject whose description to fetch
  • result (Set<Triple>) - the triples that were fetched

Usage:

Set the subject property to the subject whose description you want to fetch. After calling perform, the triples can be retrieved from the result property.

Example:

TripleFetcher tf = new TripleFetcher();
tf.setSubject(Resource.uriRef("http://some.subject"));
context.perform(tf);
// now move the triples to context2
TripleWriter tw = new TripleWriter();
tw.addAll(tf.getResult());
context2.perform(tw);

TripleMatcher

TripleMatcher (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/TripleMatcher.html) provides the ability to find triples that match a given pattern, where a pattern is a 3-tuple each term of which is either a Resource, indicating that a triple must have that Resource in that position to match, or null, meaning that a triple will match regardless of what is in that position. The pattern can be specified either as a Pattern (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/rdf/query/Pattern.html) or as separate subject, predicate, and object properties.

Properties:

  • pattern (Pattern) - the pattern to match
  • subject (Resource) - the subject to match, or null if none
  • predicate (Resource) - the predicate to match, or null if none
  • object (Resource) - the object to match, or null if none
  • result (Set<Triple>) - the matching triples

Usage:

Either set the pattern property or any of the subject, predicate, and object properties. After perform is called, the result property will contain the matching triples.

Example:

TripleMatcher tm = new TripleMatcher();
tm.setSubject(Resource.uriRef("urn:person1"));
tm.setPredicate(Resource.uriRef("http://myns.foo/#hasBrother"));
context.perform(tm);
System.out.printf("Person1 has %d brothers\n",tm.getResult().size());

Unifier

Unifier (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/Unifier.html) provides a means of specifying and executing complex conjunctive queries against a Context. It accepts a list of Patterns (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/rdf/query/Pattern.html) and column names, and finds every set of bindings for unbound variables in the Patterns that results in all the patterns matching triples in the Context. It is effectively equivalent to a simple SPARQL (http://www.w3.org/TR/rdf-sparql-query/) query in which only exact matches and conjunctions are used.

Patterns are 3-tuples where each term is either a Resource or a variable name. If two patterns in the same Unifier share a variable name, any solution must have the same binding in that variable's position in each pattern it occurs in.

Properties:

  • patterns (List<Pattern>) - the patterns to match (i.e., the "where" clause)
  • columnNames (List<String>) - the variables to return in the result table (i.e., the "select" clause)
  • result (Table<Resource>) - the result Table (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/util/Table.html)

Usage:

Set the patterns property or use addPattern to add patterns one at a time. Set the columnNames property to the variables from the patterns that you want returned. After perform is called, iterate over the table to process the results.

Example:

import org.tupeloproject.rdf.Vocabulary.Foaf;
import static org.tupeloproject.rdf.Resource.uriRef;
...
Unifier u = new Unifier();
u.addPattern(new Pattern(uriRef("urn:me"),Foaf.KNOWS,"friend"));
u.addPattern(new Pattern("friend",Foaf.NAME,"friendName"));
u.addPattern(new Pattern("friend",Foaf.KNOWS,"foaf"));
u.addPattern(new Pattern("foaf",Foaf.NAME,"foafName"));
u.setColumnNames("friendName","foafName");
context.perform(u);
for(Tuple<Resource> row : u.getResult()) {
    System.out.printf("I know %s through %s\n",row.get(0),row.get(1));
}

Transformer

Transformer (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/Transformer.html) is like Unifier except that instead of producing a result Table, it produces a set of triples from each solution using a set of "out patterns". Variables in each out pattern are bound to the binding of the same-named variable in each solution. Unbound variables are set to freshly-generated globally-unique RDF resources. Transformer is similar to a simple SWRL (http://www.w3.org/Submission/SWRL/) rule and can be used for some forms of inference, although the in patterns are not recursively matched against the result set and so Transformer cannot for instance be used to compute transitive closure.

Properties:

  • inPatterns (List<Pattern>) - the patterns to unify on
  • outPatterns (List<Pattern>) - the patterns to use to generate triples from each solution
  • result (Set<Triple>) - the resulting triples

Usage:

Set the inPatterns and outPatterns properties, or use addInPattern and addOutPattern to build up the lists of patterns. After performing the Transformer, the resulting triples are available from the result property.

Example:

final Resource HAS_PARENT = Resource.uriRef("http://my.namespace.org/#hasParent");
final Resource HAS_GRANDPARENT = Resource.uriRef("http://my.namespace.org/#hasGrandparent
Transformer t = new Transformer();
t.addInPattern("person",HAS_PARENT,"parent");
t.addInPattern("parent",HAS_PARENT,"gp");
t.addOutPattern("person",HAS_GRANDPARENT,"gp");
context.perform(t);
// put the inferred information back in the context
TripleWriter tw = new TripleWriter();
tw.addAll(t.getResult());
context.perform(tw);

Context implementations

Tupelo provides a number of Context implementations with the goal of enabling interoperability across a variety of data and metadata management scenarios.

Storage and indexing

Tupelo provides support for storing and retrieving triples and blobs.

MemoryContext

MemoryContext stores both triples and blobs in memory. It provides relatively fast implementations of TripleMatcher, Unifier, and Transformer, but it is not especially efficient with respect to memory usage, so is not suitable for managing very large sets of triples. The contents of a MemoryContext are discarded either when it is garbage collected or the JVM terminates, whichever comes first.

Operators supported:

  • BlobWriter
  • BlobReader
  • BlobRemover
  • TripleWriter
  • SubjectRemover
  • TripleIterator
  • TripleFetcher
  • TripleMatcher
  • Unifier
  • Transformer

Usage:

Construct using no-arg constructor. Dispose of by discarding the reference.

FileContext

FileContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/impl/FileContext.html) stores blobs in a local filesystem, and provides the ability to read file metadata using TripleFetcher. Besides performing I/O, FileContext is responsible for mapping between globally-unique URI's and paths in the local filesystem. This is accomplished using a UriMapping (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/util/UriMapping.html).

FileContext has two variants that use different URI mapping strategies.

Operators supported:

  • BlobWriter
  • BlobFetcher
  • BlobRemover
  • TripleFetcher
SimpleFileContext

SimpleFileContext maps URI's to paths by stripping off a specified URI prefix and appending a specified path prefix. As a result it can only perform blob operations on URI's that begin with the specified URI prefix.

Properties:

  • uriPrefix (String) - the URI prefix
  • pathPrefix (String) - the path prefix

Usage:

Set the URI and path prefix. Perform blob operations against any URI with that prefix. To retrieve file metadata, call TripleFetcher, setting the subject to a uriRef with the URI of the blob to get file metadata for. For information about how file metadata is represented in triples, see FileContext.java (http://cvs.ncsa.uiuc.edu/viewcvs.cgi/t2/tupelo-kernel/src/main/java/org/tupeloproject/kernel/impl/FileContext.java?rev=1.23&cvsroot=nladr&only_with_tag=v201&content-type=text/vnd.viewcvs-markup).

Example:

SimpleFileContext sfc = new SimpleFileContext();
sfc.setUriPrefix("tag:foo@bar.edu,2007:");
sfc.setPathPrefix("/tmp/someData/");
// write some data
BlobWriter bw = new BlobWriter();
bw.setUri(URI.create("tag:foo@bar.edu,2007:zow"));
bw.setInputStream(new ByteArrayInputStream("Hello, world.\n".getBytes("US-ASCII")));
sfc.perform(bw);
// get file metadata
TripleFetcher tf = new TripleFetcher();
tf.setSubject(Resource.uriRef("tag:foo@bar.edu,2007:zow"));
sfc.perform(tf);
System.out.println("File metadata:");
for(Triple t : tf.getResult()) {
    System.out.println(t);
}
HashFileContext

HashFileContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/impl/HashFileContext.html) uses a one-way mapping between blob URI's and files based on hashing the URI, and therefore can be used to store blobs with arbitrary URI's (they don't have to begin with a given prefix as with SimpleFileContext).

Properties:

  • directory (File) - the directory in which to store all the data

Usage:

Set the directory property to the directory in which you want to store the data. Use as you would a SimpleFileContext, although without any restriction on the URI prefix.

Example:

HashFileContext hfc = new HashFileContext();
hfc.setDirectory(new File("/tmp/data"), true); // second arg is "create" flag
byte[] data = "This is a test.".getBytes("US-ASCII");
// write one blob
BlobWriter bw = new BlobWriter();
bw.setUri(URI.create("urn:foo"));
bw.setInputStream(new ByteArrayInputStream(data));
hfc.perform(bw);
// now write another blob which does not share a prefix
BlobWriter bw = new BlobWriter();
bw.setUri(URI.create("http://another.uri/foo"));
bw.setInputStream(new ByteArrayInputStream(data));
hfc.perform(bw);

HttpContext

HttpContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/kernel/impl/HttpContext.html) provides BlobReader on the WWW, mapping blob URI's directly to URL's.

Usage:

Use a no-arg constructor and use BlobFetcher to retrieve content from the WWW.

Example:

HttpContext hc = new HttpContext();
BlobFetcher bf = new BlobFetcher();
bf.setUri(URI.create("http://www.google.com/"));
hc.perform(bf);
InputStream googlesHomepage = bf.getInputStream();
...

JenaContext

JenaContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/jena/JenaContext.html#setModel(Model)) provides triple operations on Jena (http://jena.sourceforge.net/) models. In addition to supporting Tupelo operators, JenaContext also provides convenience methods for serializing and deserializing RDF data. Other features of Jena can be accessed directly using the Jena API against the underlying model, which can be retrieved from any JenaContext via the model (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/jena/JenaContext.html#getModel()) property.

Operators supported:

  • TripleWriter
  • SubjectRemover
  • TripleIterator
  • TripleFetcher
  • TripleMatcher
  • Unifier
  • Transformer

Usage:

When constructed with its no-arg constructor, a JenaContext is backed by a new, blank, in-memory Jena model. Alternatively, a JenaContext can be "wrapped" around any Jena model (http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/model/Model.html) using the model (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/jena/JenaContext.html#setModel(Model)) property.

SesameContext

SesameContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/sesame/SesameContext.html) provides triple operations on Sesame 1 (http://www.openrdf.org/).

Operators supported:

  • TripleWriter
  • SubjectRemover
  • TripleIterator
  • TripleFetcher
  • TripleMatcher
  • Unifier
  • Transformer

Usage:

To construct a SesameContext, use SesameContextFactory (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/sesame/SesameContextFactory.html). SesameContextFactory can be used to construct four different kinds of SesameContexts:

  1. In-memory - use getMemoryContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/sesame/SesameContextFactory.html#getMemoryContext(java.lang.String))
  2. HTTP client - use getHttpContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/sesame/SesameContextFactory.html#getHttpContext(java.net.URL,%20java.lang.String,%20java.lang.String,%20java.lang.String))
  3. Direct JDBC - use getJdbcContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/sesame/SesameContextFactory.html#getJdbcContext(java.net.URI,%20java.lang.Class,%20java.lang.String,%20java.lang.String))
  4. RMI - use getRmiContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/sesame/SesameContextFactory.html#getRmiContext(java.net.URI,%20java.lang.String,%20java.lang.String,%20java.lang.String))

Which one to use depends on how your Sesame installation is deployed and configured.

MulgaraContext

MulgaraContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/mulgara/MulgaraContext.html) provides triple operations and direct ITQL access to Mulgara (http://www.mulgara.org/). MulgaraContext is not included in 2.1.0. However it should work with 2.1.0 and will be included in 2.1.1.

Operators supported:

  • TripleWriter
  • SubjectRemover
  • TripleFetcher
  • TripleMatcher
  • Unifier
  • Transformer
  • ItqlOperator (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/mulgara/ItqlOperator.html)

Usage:

Set the modelUri property of a MulgaraContext instance to a URI identical to the URL of the Mulgara model you want to work with. Alternatively, ItqlOperator can be used to issue any legal ITQL query, which could range over a number of models.

MysqlContext

MysqlContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/mysql/MysqlContext.html) provides blob and triple operations backed by a MySQL database. This Context implementation uses its own, generic schema rather than providing a way to map existing MySQL databases to RDF. For that, you can use utilities like ResultSetVisitor (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/sql/ResultSetVisitor.html).

Operators supported:

  • TripleFetcher
  • TripleMatcher
  • Unifier
  • BlobFetcher
  • BlobWriter
  • BlobRemover

Usage:

MysqlContext needs its own "database" in MySQL and when setting it up, you will need create database permission.

Configure a MysqlContext using the setJdbcUrl (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/sql/SqlContext.html#setJdbcUrl(java.lang.String)) method, specifying which database name Tupelo should use. If it's the first time you're using it, call initializeDatabase (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/mysql/MysqlContext.html#initializeDatabase(java.lang.String)) with the database name. Make sure to call close (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/sql/SqlContext.html#close()) to release the database connection when you are done with a MysqlContext.

DerbyContext

DerbyContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/derby/DerbyContext.html) provides blob and triple operations backed by Apache Derby. It is a simple port of MysqlContext and is configured in the same way; you will need to use a JDBC URL that is appropriate for Derby.

DerbyContext has one limitation that MysqlContext doesn't, which is that any blob that is read or written to it needs to fit in the Java heap. We are looking for a solution to this problem.

JournalingContext

The JournalingContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/journaling/JournalingContext.html) adopts a journaling and transactions to ensure all operations are in a consistent state, This involves a two-stage commit strategy: First it takes each write operation and creates a separate transaction for it, then the operation is performed against the backing context. If there is some failure, the operation is retried until it succeeds. This allows for several possible use scenarios, which are detailed Journaling Context Tutorial.

Operators supported:

  • BlobFetcher
  • +BlobRemover
  • +BlobWriter
  • +SubjectRemover
  • +SubjectReplacer
  • Sync
  • Transformer
  • TripleFetcher
  • TripleIterator
  • TripleMatcher
  • +TripleWriter
  • Unifier

+ = the operation is journaled. Otherwise it is sent directly to the backing context.

Usage: Create a new instance passing the backing context. When done, invoke close.

Services and protocols

WebdavContext

WebdavContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/webdav/WebdavContext.html) provides the ability to perform blob and triple operations against WebDAV services. In addition to operations, it also provides support for basic authentication.

Operators supported:

  • BlobWriter
  • BlobFetcher
  • BlobRemover
  • TripleWriter
  • TripleFetcher
  • TripleMatcher (partial)

Usage:

Blob operations should use URI's identical to the URL of the WebDAV resource to be modified. If a BlobWriter is issued on a URI that refers to a WebDAV resource that is in a collection that doesn't exist, that collection will be created in order that the blob can be written.

Triple operations attempt to as closely as possible map WebDAV properties to RDF properties. This is not always possible in the very unlikely case that the URI of an RDF predicate is not convertible to a QName (any URI that ends with a legal NMTOKEN (http://www.w3.org/TR/2006/REC-xml-20060816/#NT-Nmtoken) will work). WebdavContext currently only supports single-valued properties. Also, WebdavContext does not allow a caller to modify DAV-specific properties, which it treats as read-only.

Because of the hierarchical structure of WebDAV repositories, it is impractical to support globally-scoped queries such as the arbitrary triple patterns used in TripleMatcher, Unifier, and Transformer. However, TripleMatcher is supported for some simpler cases, most notably the case in which the subject term of the pattern is bound.

RssContext

RssContext (http://dlt-dev.ncsa.uiuc.edu/javadoc/t2/current/org/tupeloproject/rss/RssContext.html) provides triple reading operations on an RSS 2.0 feed. It also provides utilities for reading RSS feeds from streams. The triples that it produces use a simple vocabulary, and can be easily transformed to another vocabulary using the Transformer operator.

Operators supported:

  • TripleIterator
  • TripleFetcher
  • TripleMatcher
  • Unifier
  • Transformer

Usage:

Set the feedUrl property to the URL of the feed, and use triple reading operators to read triples from the feed.

Aggregation

UnionContext

UnionContext attempts all read operations on all its children, and when possible merges the results (e.g., by concatenating sets of triples together), and executes each write operation against the first child for which it succeeds.

MirrorContext

MirrorContext attempts all blob and triple write operations on all its children, and executes each read operation against the first child for which it succeeds.