Search in sources :

Example 11 with Triple

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");
    }
}
Also used : Triple(org.apache.jena.graph.Triple) FBRuleInfGraph(org.apache.jena.reasoner.rulesys.FBRuleInfGraph) FBRuleInfGraph(org.apache.jena.reasoner.rulesys.FBRuleInfGraph) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) Rule(org.apache.jena.reasoner.rulesys.Rule) Test(org.junit.Test)

Example 12 with Triple

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);
    }
}
Also used : Triple(org.apache.jena.graph.Triple)

Example 13 with Triple

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();
}
Also used : SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) Triple(org.apache.jena.graph.Triple) IndentedLineBuffer(org.apache.jena.atlas.io.IndentedLineBuffer)

Example 14 with Triple

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;
}
Also used : Triple(org.apache.jena.graph.Triple)

Example 15 with Triple

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);
}
Also used : Triple(org.apache.jena.graph.Triple) Node(org.apache.jena.graph.Node)

Aggregations

Triple (org.apache.jena.graph.Triple)406 Test (org.junit.Test)139 Node (org.apache.jena.graph.Node)95 BaseTest (org.apache.jena.atlas.junit.BaseTest)66 Graph (org.apache.jena.graph.Graph)54 Quad (org.apache.jena.sparql.core.Quad)25 TriplePath (org.apache.jena.sparql.core.TriplePath)22 ArrayList (java.util.ArrayList)20 StatsMatcher (org.apache.jena.sparql.engine.optimizer.StatsMatcher)19 Var (org.apache.jena.sparql.core.Var)17 TripleWritable (org.apache.jena.hadoop.rdf.types.TripleWritable)15 TriplePattern (org.apache.jena.reasoner.TriplePattern)13 Op (org.apache.jena.sparql.algebra.Op)13 BasicPattern (org.apache.jena.sparql.core.BasicPattern)13 Model (org.apache.jena.rdf.model.Model)12 TransitiveGraphCache (org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache)11 LongWritable (org.apache.hadoop.io.LongWritable)10 InfGraph (org.apache.jena.reasoner.InfGraph)10 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)10 QuadWritable (org.apache.jena.hadoop.rdf.types.QuadWritable)8