Included in the Theseus release is an API that allows you to easily incorporate Theseus functionality into your existing Java applications. Using the Theseus API involves calling a special library function with a plan (in plaintext or in a file) and input data (in plaintext or as Relation objects) and then unwrapping its output.
To use the Theseus API, you simply need to do the following:
As an example, consider the following code:
import theseus.api.AttrList;
import theseus.api.LoadedPlan;
import theseus.api.Relation;
import theseus.api.RelationList;
import theseus.api.Theseus;
import theseus.api.Tuple;
import java.io.StringReader;
/*
* A very simple example of using the Theseus API
*/
public class Example
{
public static void main(String[] args)
{
try {
String plan = "PLAN p { INPUT: stream s1, stream s2 "+
"OUTPUT: stream s3 BODY { union (s1, s2 : s3) } }";
RelationList inRel = new RelationList();
Relation cur;
AttrList aLst1 = new AttrList("name char");
cur = new Relation("s1", aLst1);
cur.addTuple(new Tuple(aLst1, "Lucy"));
cur.addTuple(new Tuple(aLst1, "Ricky"));
inRel.addRelation(cur);
AttrList aLst2 = new AttrList("name char");
cur = new Relation("s2", aLst2);
cur.addTuple(new Tuple(aLst2, "Fred"));
cur.addTuple(new Tuple(aLst2, "Ethel"));
inRel.addRelation(cur);
Theseus th = new Theseus();
LoadedPlan lp = th.loadPlan(new StringReader(plan));
RelationList outRel = th.executePlan(lp, inRel);
if (outRel != null) {
for (int j=0; j<outRel.size(); j++) {
System.out.println(outRel.getRelation(j));
}
}
th.shutdown();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
|
name=[p_i1_s3], attrs=[name char], values=[Ethel, Lucy, Fred, Ricky] |
The complete code for this example can be found in the "src" directory of your Theseus installation.