use of org.apache.jena.graph.Triple in project jena by apache.
the class TestLPBRuleEngine method testSaturateTabledGoals.
@Test
public void testSaturateTabledGoals() throws Exception {
final int MAX = 1024;
// Set the cache size very small just for this test
System.setProperty("jena.rulesys.lp.max_cached_tabled_goals", "" + MAX);
try {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, ty, C1));
List<Rule> rules = Rule.parseRules("[r1: (?x p ?t) <- (?x rdf:type C1), makeInstance(?x, p, C2, ?t)]" + "[r2: (?t rdf:type C2) <- (?x rdf:type C1), makeInstance(?x, p, C2, ?t)]");
FBRuleInfGraph infgraph = (FBRuleInfGraph) createReasoner(rules).bind(data);
LPBRuleEngine engine = getEngineForGraph(infgraph);
assertEquals(0, engine.activeInterpreters.size());
assertEquals(0, engine.tabledGoals.size());
// Let's ask about lots of unknown subjects
for (int i = 0; i < MAX * 128; i++) {
Node test = NodeFactory.createURI("test" + i);
ExtendedIterator<Triple> it = infgraph.find(test, ty, C2);
assertFalse(it.hasNext());
it.close();
}
// Let's see how many were cached
assertEquals(MAX, engine.tabledGoals.size());
// and no leaks of activeInterpreters (this will happen if we forget
// to call hasNext above)
assertEquals(0, engine.activeInterpreters.size());
} finally {
System.clearProperty("jena.rulesys.lp.max_cached_tabled_goals");
}
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class GraphLocation method clearGraph.
public void clearGraph() {
if (graph != null) {
Iterator<Triple> iter = graph.find(Node.ANY, Node.ANY, Node.ANY);
List<Triple> triples = Iter.toList(iter);
for (Triple t : triples) graph.delete(t);
}
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class BasicPattern method toString.
@Override
public String toString() {
IndentedLineBuffer out = new IndentedLineBuffer();
SerializationContext sCxt = SSE.sCxt(SSE.getPrefixMapString());
boolean first = true;
for (Triple t : triples) {
if (!first)
out.print("\n");
else
first = false;
// Adds (triple ...)
// SSE.write(buff.getIndentedWriter(), t) ;
out.print("(");
WriterNode.outputPlain(out, t, sCxt);
out.print(")");
}
out.flush();
return out.toString();
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class BasicPattern method equiv.
public boolean equiv(BasicPattern other, NodeIsomorphismMap isoMap) {
if (this.triples.size() != other.triples.size())
return false;
for (int i = 0; i < this.triples.size(); i++) {
Triple t1 = get(i);
Triple t2 = other.get(i);
if (!Iso.tripleIso(t1, t2, isoMap))
return false;
}
return true;
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class GraphView method graphBaseFind.
@Override
protected ExtendedIterator<Triple> graphBaseFind(Node s, Node p, Node o) {
if (Quad.isUnionGraph(gn))
return graphUnionFind(s, p, o);
Node g = graphNode(gn);
Iterator<Triple> iter = GLib.quads2triples(dsg.find(g, s, p, o));
return WrappedIterator.createNoRemove(iter);
}
Aggregations