use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class TestTextTDB method textDB_2.
@Test
public void textDB_2() {
// Check text query and union graph
Dataset ds = create();
ds.getContext().set(TDB.symUnionDefaultGraph, true);
Quad quad = SSE.parseQuad("(<g> <s> rdfs:label 'foo')");
ds.asDatasetGraph().add(quad);
String qs = StrUtils.strjoinNL("PREFIX text: <http://jena.apache.org/text#>", "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>", "SELECT *", "{ ?s text:query 'foo' ;", " rdfs:label 'foo'", "}");
Query q = QueryFactory.create(qs);
QueryExecution qexec = QueryExecutionFactory.create(q, ds);
ResultSet rs = qexec.execSelect();
List<QuerySolution> x = Iter.toList(rs);
assertEquals(1, x.size());
}
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);
}
Aggregations