Search in sources :

Example 31 with Statement

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

the class UpdateTest method getAll.

static List<String> getAll(Resource r, Property p) {
    List<String> l = new ArrayList<>();
    ClosableIterator<Statement> cIter = r.listProperties(p);
    for (; cIter.hasNext(); ) {
        Statement stmt = cIter.next();
        String df = stmt.getObject().asResource().getURI();
        l.add(df);
    }
    cIter.close();
    return l;
}
Also used : Statement(org.apache.jena.rdf.model.Statement) ArrayList(java.util.ArrayList)

Example 32 with Statement

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

the class TestModelEvents method testAddSingleStatements.

public void testAddSingleStatements() {
    final Statement S1 = ModelHelper.statement(model, "S P O");
    final Statement S2 = ModelHelper.statement(model, "A B C");
    Assert.assertFalse(SL.has(new Object[] { "add", S1 }));
    model.register(SL);
    model.add(S1);
    SL.assertHas(new Object[] { "add", S1 });
    model.add(S2);
    SL.assertHas(new Object[] { "add", S1, "add", S2 });
    model.add(S1);
    SL.assertHas(new Object[] { "add", S1, "add", S2, "add", S1 });
}
Also used : Statement(org.apache.jena.rdf.model.Statement)

Example 33 with Statement

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

the class TestModelEvents method testTwoListeners.

public void testTwoListeners() {
    final Statement S = ModelHelper.statement(model, "S P O");
    final RecordingModelListener SL1 = new RecordingModelListener();
    final RecordingModelListener SL2 = new RecordingModelListener();
    model.register(SL1).register(SL2);
    model.add(S);
    SL2.assertHas(new Object[] { "add", S });
    SL1.assertHas(new Object[] { "add", S });
}
Also used : Statement(org.apache.jena.rdf.model.Statement) RecordingModelListener(org.apache.jena.rdf.model.test.helpers.RecordingModelListener)

Example 34 with Statement

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

the class TestModelSetOperations method testIntersection.

public void testIntersection() {
    ModelHelper.modelAdd(model, "a P b; w R x");
    ModelHelper.modelAdd(model2, "w R x; y S z");
    final Model im = model.intersection(model2);
    Assert.assertFalse(model.containsAll(model2));
    Assert.assertFalse(model2.containsAll(model));
    Assert.assertTrue(model.containsAll(im));
    Assert.assertTrue(model2.containsAll(im));
    for (final StmtIterator it = im.listStatements(); it.hasNext(); ) {
        final Statement s = it.nextStatement();
        Assert.assertTrue(model.contains(s) && model2.contains(s));
    }
    for (final StmtIterator it = im.listStatements(); it.hasNext(); ) {
        Assert.assertTrue(model.contains(it.nextStatement()));
    }
    for (final StmtIterator it = im.listStatements(); it.hasNext(); ) {
        Assert.assertTrue(model2.contains(it.nextStatement()));
    }
    Assert.assertTrue(model.containsAll(im.listStatements()));
    Assert.assertTrue(model2.containsAll(im.listStatements()));
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model)

Example 35 with Statement

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

the class TestModelSetOperations method testDifference.

public void testDifference() {
    ModelHelper.modelAdd(model, "a P b; w R x");
    ModelHelper.modelAdd(model2, "w R x; y S z");
    final Model dm = model.difference(model2);
    for (final StmtIterator it = dm.listStatements(); it.hasNext(); ) {
        final Statement s = it.nextStatement();
        Assert.assertTrue(model.contains(s) && !model2.contains(s));
    }
    for (final StmtIterator it = model.union(model2).listStatements(); it.hasNext(); ) {
        final Statement s = it.nextStatement();
        Assert.assertEquals(model.contains(s) && !model2.contains(s), dm.contains(s));
    }
    Assert.assertTrue(dm.containsAny(model));
    Assert.assertTrue(dm.containsAny(model.listStatements()));
    Assert.assertFalse(dm.containsAny(model2));
    Assert.assertFalse(dm.containsAny(model2.listStatements()));
    Assert.assertTrue(model.containsAll(dm));
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model)

Aggregations

Statement (org.apache.jena.rdf.model.Statement)38 Model (org.apache.jena.rdf.model.Model)18 Resource (org.apache.jena.rdf.model.Resource)15 Test (org.junit.Test)9 StmtIterator (org.apache.jena.rdf.model.StmtIterator)8 Triple (org.apache.jena.graph.Triple)7 ArrayList (java.util.ArrayList)6 BaseTest (org.apache.jena.atlas.junit.BaseTest)6 RDFNode (org.apache.jena.rdf.model.RDFNode)5 Property (org.apache.jena.rdf.model.Property)4 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