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;
}
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 });
}
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 });
}
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()));
}
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));
}
Aggregations