Search in sources :

Example 31 with Triple

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

the class container method findContainers.

private static void findContainers(Collection<Node> acc, Graph graph, Node typeNode) {
    ExtendedIterator<Triple> iter = graph.find(Node.ANY, RDF.type.asNode(), typeNode);
    while (iter.hasNext()) {
        Triple t = iter.next();
        Node containerNode = t.getSubject();
        acc.add(containerNode);
    }
}
Also used : Triple(org.apache.jena.graph.Triple) Node(org.apache.jena.graph.Node)

Example 32 with Triple

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

the class TestLangTurtle method turtle_02.

@Test
public void turtle_02() {
    Triple t = parseOneTriple("@base <http://example/> . <s> <p> 123 . ");
    Triple t2 = SSE.parseTriple("(<http://example/s> <http://example/p> 123)");
    assertEquals(t2, t);
}
Also used : Triple(org.apache.jena.graph.Triple) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 33 with Triple

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

the class TestLangTurtle method turtle_01.

@Test
public void turtle_01() {
    Triple t = parseOneTriple("<s> <p> 123 . ");
    Triple t2 = SSE.parseTriple("(<http://base/s> <http://base/p> 123)");
    assertEquals(t2, t);
}
Also used : Triple(org.apache.jena.graph.Triple) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 34 with Triple

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

the class TestPipedRDFIterators method test_streamed_triples_bad.

/**
     * Tests that the iterate copes correctly in the case of hitting a parser
     * error
     * 
     * @param data
     *            Data string (Turtle format) which should be malformed
     * @param expected
     *            Number of valid triples expected to be generated before the
     *            error is hit
     * @throws TimeoutException
     * @throws InterruptedException
     */
private void test_streamed_triples_bad(final String data, int expected) throws TimeoutException, InterruptedException {
    final PipedRDFIterator<Triple> it = new PipedRDFIterator<>();
    final PipedTriplesStream out = new PipedTriplesStream(it);
    // Create a runnable that will try to parse the bad data
    Runnable runParser = new Runnable() {

        @Override
        public void run() {
            Charset utf8 = StandardCharsets.UTF_8;
            ByteArrayInputStream input = new ByteArrayInputStream(data.getBytes(utf8));
            try {
                RDFParser.source(input).lang(Lang.TTL).parse(out);
            } catch (Throwable t) {
            // Ignore the error
            }
            return;
        }
    };
    // Create a runnable that will consume triples
    Callable<Integer> consumeTriples = new Callable<Integer>() {

        @Override
        public Integer call() {
            int count = 0;
            while (it.hasNext()) {
                it.next();
                count++;
            }
            return count;
        }
    };
    // Run the threads
    Future<?> genResult = executor.submit(runParser);
    Future<Integer> result = executor.submit(consumeTriples);
    Integer count = 0;
    try {
        count = result.get(10, TimeUnit.SECONDS);
    } catch (TimeoutException e) {
        // We expect the producer thread to have errored
        try {
            genResult.get();
        } catch (ExecutionException ex) {
            // This is as expected, ignore
            LOGGER.warn("Errored as expected", ex);
        }
        // failure
        throw e;
    } catch (ExecutionException e) {
        // This was not expected
        Assert.fail(e.getMessage());
    }
    // Since the produce thread failed the consumer thread should give the
    // expected count
    Assert.assertEquals(expected, (int) count);
}
Also used : Charset(java.nio.charset.Charset) Triple(org.apache.jena.graph.Triple) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 35 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)

Aggregations

Triple (org.apache.jena.graph.Triple)407 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 Model (org.apache.jena.rdf.model.Model)13 TriplePattern (org.apache.jena.reasoner.TriplePattern)13 Op (org.apache.jena.sparql.algebra.Op)13 BasicPattern (org.apache.jena.sparql.core.BasicPattern)13 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 Resource (org.apache.jena.rdf.model.Resource)9