Search in sources :

Example 1 with Quad

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;
        }
    };
}
Also used : Quad(org.apache.jena.sparql.core.Quad) BindingInputStream(org.apache.jena.sparql.engine.binding.BindingInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) BindingOutputStream(org.apache.jena.sparql.engine.binding.BindingOutputStream) SinkQuadOutput(org.apache.jena.riot.out.SinkQuadOutput) LangNQuads(org.apache.jena.riot.lang.LangNQuads) SerializationFactory(org.apache.jena.atlas.data.SerializationFactory) Tokenizer(org.apache.jena.riot.tokens.Tokenizer)

Example 2 with Quad

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);
    }
}
Also used : Quad(org.apache.jena.sparql.core.Quad)

Example 3 with Quad

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));
}
Also used : Quad(org.apache.jena.sparql.core.Quad) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 4 with Quad

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);
}
Also used : Quad(org.apache.jena.sparql.core.Quad)

Example 5 with Quad

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));
}
Also used : Quad(org.apache.jena.sparql.core.Quad) Tokenizer(org.apache.jena.riot.tokens.Tokenizer) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Aggregations

Quad (org.apache.jena.sparql.core.Quad)161 Test (org.junit.Test)91 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)49 Node (org.apache.jena.graph.Node)36 BaseTest (org.apache.jena.atlas.junit.BaseTest)32 Triple (org.apache.jena.graph.Triple)25 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)14 Update (org.apache.jena.update.Update)14 QuadWritable (org.apache.jena.hadoop.rdf.types.QuadWritable)12 ResultSet (java.sql.ResultSet)8 ArrayList (java.util.ArrayList)8 TripleWritable (org.apache.jena.hadoop.rdf.types.TripleWritable)7 Var (org.apache.jena.sparql.core.Var)7 LongWritable (org.apache.hadoop.io.LongWritable)6 UpdateDataDelete (org.apache.jena.sparql.modify.request.UpdateDataDelete)6 UpdateDataInsert (org.apache.jena.sparql.modify.request.UpdateDataInsert)6 Element (org.apache.jena.sparql.syntax.Element)6 Graph (org.apache.jena.graph.Graph)5 BasicPattern (org.apache.jena.sparql.core.BasicPattern)4 IOException (java.io.IOException)3