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