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;
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations