Search in sources :

Example 1 with Triple

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

the class container method execEvaluatedConcrete.

// Ask directly.
private QueryIterator execEvaluatedConcrete(Binding binding, Node containerNode, Node predicate, Node member, ExecutionContext execCxt) {
    QueryIterator input = QueryIterSingleton.create(binding, execCxt);
    Graph graph = execCxt.getActiveGraph();
    QueryIterator qIter = new QueryIterTriplePattern(input, new Triple(containerNode, predicate, member), execCxt);
    return qIter;
}
Also used : Triple(org.apache.jena.graph.Triple) Graph(org.apache.jena.graph.Graph) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Example 2 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 3 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 4 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 5 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)

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