Search in sources :

Example 1 with NQUADS

use of org.apache.jena.riot.Lang.NQUADS in project jena by apache.

the class TestInMemDatasetAssembler method directDataLinkToQuads.

@Test
public void directDataLinkToQuads() throws IOException {
    // first make a file of quads to load later
    final Model model = createDefaultModel();
    final Path quads = createTempFile("quadExample", ".nq");
    final Resource quadsURI = model.createResource(quads.toFile().toURI().toString());
    final Resource simpleExample = model.createResource("test:simpleExample");
    simpleExample.addProperty(type, DatasetAssemblerVocab.tDatasetTxnMem);
    simpleExample.addProperty(data, quadsURI);
    final DatasetGraph dsg = createTxnMem().asDatasetGraph();
    model.listStatements().mapWith(Statement::asTriple).mapWith(t -> new Quad(quadsURI.asNode(), t)).forEachRemaining(dsg::add);
    try (OutputStream out = new FileOutputStream(quads.toFile())) {
        write(out, dsg, NQUADS);
    }
    final Dataset dataset = assemble(simpleExample);
    final Model assembledDefaultModel = dataset.getDefaultModel();
    final Model assembledNamedModel = dataset.getNamedModel(quadsURI.getURI());
    assertTrue(assembledDefaultModel.isEmpty());
    assertTrue(assembledNamedModel.contains(assembledNamedModel.createStatement(simpleExample, data, quadsURI)));
}
Also used : Path(java.nio.file.Path) DEFAULT(org.apache.jena.assembler.Mode.DEFAULT) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) JA(org.apache.jena.assembler.JA) Model(org.apache.jena.rdf.model.Model) Statement(org.apache.jena.rdf.model.Statement) NTRIPLES(org.apache.jena.riot.RDFFormat.NTRIPLES) Quad(org.apache.jena.sparql.core.Quad) Resource(org.apache.jena.rdf.model.Resource) MemoryModel(org.apache.jena.assembler.JA.MemoryModel) Path(java.nio.file.Path) Dataset(org.apache.jena.query.Dataset) OutputStream(java.io.OutputStream) DatasetAssemblerVocab.pGraphName(org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab.pGraphName) Iterator(java.util.Iterator) DatasetAssemblerVocab.pNamedGraph(org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab.pNamedGraph) NQUADS(org.apache.jena.riot.Lang.NQUADS) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Test(org.junit.Test) RDFDataMgr.write(org.apache.jena.riot.RDFDataMgr.write) ModelFactory.createDefaultModel(org.apache.jena.rdf.model.ModelFactory.createDefaultModel) Files.createTempFile(java.nio.file.Files.createTempFile) Node(org.apache.jena.graph.Node) DatasetFactory.createTxnMem(org.apache.jena.query.DatasetFactory.createTxnMem) RDF.type(org.apache.jena.vocabulary.RDF.type) CannotConstructException(org.apache.jena.assembler.exceptions.CannotConstructException) JA.data(org.apache.jena.assembler.JA.data) Assert(org.junit.Assert) Quad(org.apache.jena.sparql.core.Quad) Statement(org.apache.jena.rdf.model.Statement) Dataset(org.apache.jena.query.Dataset) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Model(org.apache.jena.rdf.model.Model) MemoryModel(org.apache.jena.assembler.JA.MemoryModel) ModelFactory.createDefaultModel(org.apache.jena.rdf.model.ModelFactory.createDefaultModel) Resource(org.apache.jena.rdf.model.Resource) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Aggregations

FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Files.createTempFile (java.nio.file.Files.createTempFile)1 Path (java.nio.file.Path)1 Iterator (java.util.Iterator)1 JA (org.apache.jena.assembler.JA)1 MemoryModel (org.apache.jena.assembler.JA.MemoryModel)1 JA.data (org.apache.jena.assembler.JA.data)1 DEFAULT (org.apache.jena.assembler.Mode.DEFAULT)1 CannotConstructException (org.apache.jena.assembler.exceptions.CannotConstructException)1 Node (org.apache.jena.graph.Node)1 Dataset (org.apache.jena.query.Dataset)1 DatasetFactory.createTxnMem (org.apache.jena.query.DatasetFactory.createTxnMem)1 Model (org.apache.jena.rdf.model.Model)1 ModelFactory.createDefaultModel (org.apache.jena.rdf.model.ModelFactory.createDefaultModel)1 Resource (org.apache.jena.rdf.model.Resource)1 Statement (org.apache.jena.rdf.model.Statement)1 NQUADS (org.apache.jena.riot.Lang.NQUADS)1 RDFDataMgr.write (org.apache.jena.riot.RDFDataMgr.write)1