Search in sources :

Example 16 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestConcurrentAccess method mrswGraph5.

@Test
public void mrswGraph5() {
    Dataset d = TDBFactory.createDataset();
    Model m = d.getNamedModel("http://example");
    GraphUtil.addInto(m.getGraph(), buildGraph());
    Resource r = m.createResource("x");
    ExtendedIterator<Statement> iter1 = m.listStatements(r, null, (RDFNode) null);
    while (iter1.hasNext()) iter1.next();
    Triple t = SSE.parseTriple("(<y> <p> 99)");
    m.getGraph().delete(t);
    iter1.hasNext();
}
Also used : Triple(org.apache.jena.graph.Triple) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 17 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestConcurrentAccess method mrswGraph4.

@Test(expected = ConcurrentModificationException.class)
public void mrswGraph4() {
    Model m = create().getDefaultModel();
    Resource r = m.createResource("x");
    ExtendedIterator<Statement> iter1 = m.listLiteralStatements(r, null, 1);
    assertNotNull(iter1.next());
    // and now the iterator has implicitly finished.
    Triple t = SSE.parseTriple("(<y> <p> 99)");
    m.getGraph().add(t);
    // Bad - modification of the dataset occurred.
    iter1.hasNext();
}
Also used : Triple(org.apache.jena.graph.Triple) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 18 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestConcurrentAccess method mrswGraph2.

@Test(expected = ConcurrentModificationException.class)
public void mrswGraph2() {
    Model m = create().getDefaultModel();
    Resource r = m.createResource("x");
    ExtendedIterator<Statement> iter1 = m.listStatements(r, null, (RDFNode) null);
    assertNotNull(iter1.next());
    Triple t = SSE.parseTriple("(<y> <p> 99)");
    m.getGraph().add(t);
    // Bad
    iter1.hasNext();
}
Also used : Triple(org.apache.jena.graph.Triple) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 19 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class ModelHelper method statements.

// /**
// * Create an array of Statements parsed from a semi-separated string.
// *
// * @param lockModel
// * a model to serve as a statement factory
// * @param facts
// * a sequence of semicolon-separated "S P O" facts
// * @return a Statement[] of the (S P O) statements from the string
// */
// public static Statement[] statements(Model m, String facts) {
// ArrayList<Statement> sl = new ArrayList<Statement>();
// StringTokenizer st = new StringTokenizer(facts, ";");
// while (st.hasMoreTokens())
// sl.add(statement(m, st.nextToken()));
// return sl.toArray(new Statement[sl.size()]);
// }
/**
	 * Create an array of Statements parsed from a semi-separated string.
	 * 
	 * @param facts
	 *            a sequence of semicolon-separated "S P O" facts
	 * @return a Statement[] of the (S P O) statements from the string
	 */
public static Statement[] statements(String facts) {
    ArrayList<Statement> sl = new ArrayList<>();
    StringTokenizer st = new StringTokenizer(facts, ";");
    while (st.hasMoreTokens()) sl.add(statement(st.nextToken()));
    return sl.toArray(new Statement[sl.size()]);
}
Also used : StringTokenizer(java.util.StringTokenizer) Statement(org.apache.jena.rdf.model.Statement) ArrayList(java.util.ArrayList)

Example 20 with Statement

use of org.apache.jena.rdf.model.Statement 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

Statement (org.apache.jena.rdf.model.Statement)37 Model (org.apache.jena.rdf.model.Model)17 Resource (org.apache.jena.rdf.model.Resource)14 Test (org.junit.Test)9 StmtIterator (org.apache.jena.rdf.model.StmtIterator)7 ArrayList (java.util.ArrayList)6 BaseTest (org.apache.jena.atlas.junit.BaseTest)6 Triple (org.apache.jena.graph.Triple)6 RDFNode (org.apache.jena.rdf.model.RDFNode)4 Property (org.apache.jena.rdf.model.Property)3 IOException (java.io.IOException)2 Dataset (org.apache.jena.query.Dataset)2 TextIndexException (org.apache.jena.query.text.TextIndexException)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 Files.createTempFile (java.nio.file.Files.createTempFile)1 Path (java.nio.file.Path)1