use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class SerializationFactoryFinder method quadSerializationFactory.
public static SerializationFactory<Quad> quadSerializationFactory() {
return new SerializationFactory<Quad>() {
@Override
public Sink<Quad> createSerializer(OutputStream out) {
return new SinkQuadOutput(out, null, NodeToLabel.createBNodeByLabelEncoded());
}
@Override
public Iterator<Quad> createDeserializer(InputStream in) {
Tokenizer tokenizer = TokenizerFactory.makeTokenizerASCII(in);
ParserProfile profile = RiotLib.createParserProfile(RiotLib.factoryRDF(LabelToNode.createUseLabelEncoded()), ErrorHandlerFactory.errorHandlerNoWarnings, IRIResolver.createNoResolve(), false);
LangNQuads parser = new LangNQuads(tokenizer, profile, null);
return parser;
}
@Override
public long getEstimatedMemorySize(Quad item) {
// TODO
return 0;
}
};
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class StreamOps method sendQuadsToStream.
/** Set quads to a StreamRDF - does not call .start/.finish */
public static void sendQuadsToStream(Iterator<Quad> iter, StreamRDF dest) {
for (; iter.hasNext(); ) {
Quad q = iter.next();
dest.quad(q);
}
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class TestParserFactory method trig_02.
@Test
public void trig_02() {
String s = "<g> { <x> <p> <q> }";
CatchParserOutput sink = parseCapture(s, Lang.TRIG);
assertEquals(1, sink.startCalled);
assertEquals(1, sink.finishCalled);
assertEquals(0, sink.triples.size());
assertEquals(1, sink.quads.size());
Quad q = SSE.parseQuad("(<http://base/g> <http://base/x> <http://base/p> <http://base/q>)");
assertEquals(q, last(sink.quads));
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class TestPipedRDFIterators method test_streamed_quads.
private void test_streamed_quads(int bufferSize, final int generateSize, boolean fair) throws InterruptedException, ExecutionException, TimeoutException {
final PipedRDFIterator<Quad> it = new PipedRDFIterator<>(bufferSize, fair);
final PipedQuadsStream out = new PipedQuadsStream(it);
// Create a runnable that will generate quads
Runnable genQuads = new Runnable() {
@Override
public void run() {
out.start();
// Generate quads
for (int i = 1; i <= generateSize; i++) {
Quad q = new Quad(org.apache.jena.graph.NodeFactory.createURI("http://graph"), org.apache.jena.graph.NodeFactory.createBlankNode(), org.apache.jena.graph.NodeFactory.createURI("http://predicate"), NodeFactoryExtra.intToNode(i));
out.quad(q);
}
out.finish();
return;
}
};
// Create a runnable that will consume quads
Callable<Integer> consumeQuads = 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(genQuads);
Future<Integer> result = executor.submit(consumeQuads);
Integer count = 0;
try {
count = result.get(10, TimeUnit.SECONDS);
} catch (TimeoutException e) {
// Check that it wasn't the producer thread erroring that caused us
// to time out
genResult.get();
// It wasn't so throw the original error
throw e;
}
Assert.assertEquals(generateSize, (int) count);
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class TestParserFactory method nquads_01.
@Test
public void nquads_01() {
{
String s = "<x> <p> <q> <g> .";
CatchParserOutput sink = parseCapture(s, Lang.NQ);
assertEquals(1, sink.startCalled);
assertEquals(1, sink.finishCalled);
assertEquals(0, sink.triples.size());
assertEquals(1, sink.quads.size());
Quad q = SSE.parseQuad("(<g> <x> <p> <q>)");
assertEquals(q, last(sink.quads));
}
// Old style, deprecated.
Tokenizer tokenizer = TokenizerFactory.makeTokenizerString("<x> <p> <q> <g>.");
CatchParserOutput sink = new CatchParserOutput();
ParserProfile x = makeParserProfile(IRIResolver.createNoResolve(), null, false);
LangRIOT parser = RiotParsers.createParserNQuads(tokenizer, sink, x);
parser.parse();
assertEquals(1, sink.startCalled);
assertEquals(1, sink.finishCalled);
assertEquals(0, sink.triples.size());
assertEquals(1, sink.quads.size());
Quad q = SSE.parseQuad("(<g> <x> <p> <q>)");
assertEquals(q, last(sink.quads));
}
Aggregations