AGJenaGraphInterface.java
package com.franz.agjena.examples;
import com.franz.agbase.AllegroGraph;
import com.franz.agbase.AllegroGraphConnection;
import com.franz.agbase.AllegroGraphException;
import com.franz.agbase.examples.AGPaths;
import com.franz.agjena.AllegroGraphGraphMaker;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.GraphMaker;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.graph.test.NodeCreateUtils;
public class AGJenaGraphInterface {
@param
@throws
public static void main(String[] args) throws AllegroGraphException {
showGraph(Graph.emptyGraph);
AllegroGraphConnection ags = new AllegroGraphConnection();
try {
ags.enable();
} catch (Exception e) {
throw new AllegroGraphException("Server connection problem", e);
}
AllegroGraph ts = ags.renew("store", AGPaths.TRIPLE_STORES);
GraphMaker maker = new AllegroGraphGraphMaker(ts);
Graph g = maker.getGraph();
showGraph(g);
Node r = NodeCreateUtils.create( "r" ), s = NodeCreateUtils.create( "s" ), p = NodeCreateUtils.create( "P" );
Triple t1 = Triple.create( r, p, s );
g.add(t1);
showGraph(g);
boolean b = g.contains( t1 );
System.out.println("contains ( t1 ): " + b);
b = g.contains( r, p, Node.ANY );
System.out.println("contains( r, p, Node.ANY ): " + b);
Triple t2 = Triple.create( r, p, s );
b = g.contains( t2 );
System.out.println("contains( t2 ): " + b);
int size = g.find( r, p, Node.ANY ).toList().size();
System.out.println("number found: " + size);
System.out.println("numberOfTriples(): " + ts.numberOfTriples());
ts.closeTripleStore();
ags.disable();
}
public static void showGraph(Graph g) {
System.out.println(g.toString()+": "+g.size()+" triples.");
}
}
Up |
Next