Search in sources :

Example 6 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class TestParserFactory method turtle_01.

@Test
public void turtle_01() {
    // Verify the excected outoput works.
    {
        String s = "<x> <p> <q> .";
        CatchParserOutput sink = parseCapture(s, Lang.TTL);
        assertEquals(1, sink.startCalled);
        assertEquals(1, sink.finishCalled);
        assertEquals(1, sink.triples.size());
        assertEquals(0, sink.quads.size());
        Triple t = SSE.parseTriple("(<http://base/x> <http://base/p> <http://base/q>)");
        assertEquals(t, last(sink.triples));
    }
    // Old style, deprecated.
    Tokenizer tokenizer = TokenizerFactory.makeTokenizerString("<x> <p> <q> .");
    CatchParserOutput sink = new CatchParserOutput();
    ParserProfile maker = makeParserProfile(IRIResolver.create("http://base/"), null, true);
    LangRIOT parser = RiotParsers.createParserTurtle(tokenizer, sink, maker);
    parser.parse();
    assertEquals(1, sink.startCalled);
    assertEquals(1, sink.finishCalled);
    assertEquals(1, sink.triples.size());
    assertEquals(0, sink.quads.size());
    assertEquals(SSE.parseTriple("(<http://base/x> <http://base/p> <http://base/q>)"), last(sink.triples));
}
Also used : Triple(org.apache.jena.graph.Triple) Tokenizer(org.apache.jena.riot.tokens.Tokenizer) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 7 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class TestLangTrig method trig_11.

@Test
public void trig_11() {
    DatasetGraph dsg = parse("@prefix ex:  <http://example/> .", "{ ex:s ex:p 123 }");
    assertEquals(1, dsg.getDefaultGraph().size());
    Triple t = dsg.getDefaultGraph().find(null, null, null).next();
    Triple t2 = SSE.parseTriple("(<http://example/s> <http://example/p> 123)");
}
Also used : Triple(org.apache.jena.graph.Triple) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 8 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class TestLangTrig method trig_10.

// Need to check we get resolved URIs.
//{ parse("{ <x> <p> <q> }") ; }
@Test
public //{ parse("{ <x> <p> <q> }") ; }
void trig_10() {
    DatasetGraph dsg = parse("{ <x> <p> <q> }");
    assertEquals(1, dsg.getDefaultGraph().size());
    Triple t = dsg.getDefaultGraph().find(null, null, null).next();
    Triple t2 = SSE.parseTriple("(<http://base/x> <http://base/p> <http://base/q>)");
    assertEquals(t2, t);
}
Also used : Triple(org.apache.jena.graph.Triple) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 9 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class TestGraphsDataBag method delete_1.

@Test(expected = DeleteDeniedException.class)
public void delete_1() {
    Triple t = SSE.parseTriple("(<x> <p> 'ZZZ')");
    distinct.add(t);
    distinct.delete(t);
}
Also used : Triple(org.apache.jena.graph.Triple) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 10 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class TestLPBRuleEngine method testTabledGoalsLeak.

@Test
public void testTabledGoalsLeak() throws Exception {
    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());
    ExtendedIterator<Triple> it = infgraph.find(a, ty, C1);
    it.close();
    // how many were cached
    assertEquals(1, engine.tabledGoals.size());
    // and no leaks of activeInterpreters
    assertEquals(0, engine.activeInterpreters.size());
    // Now ask again:
    it = infgraph.find(a, ty, C1);
    it.close();
    // if it was a cache hit, no change here:
    assertEquals(1, engine.tabledGoals.size());
    assertEquals(0, engine.activeInterpreters.size());
    //the cached generator should not have any consumingCP left
    for (Generator generator : engine.tabledGoals.asMap().values()) {
        assertEquals(0, generator.consumingCPs.size());
    }
}
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) Rule(org.apache.jena.reasoner.rulesys.Rule) Test(org.junit.Test)

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