use of org.apache.jena.graph.Graph in project jena by apache.
the class AbstractTestGraph2 method remove_01.
@Test
public void remove_01() {
Graph g = emptyGraph();
Triple t1 = triple(s1, p1, o1);
g.add(t1);
g.remove(any, any, any);
assertEquals(0, g.size());
returnGraph(g);
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class AbstractTestGraph2 method graph_add_delete_03.
@Test
public void graph_add_delete_03() {
Graph g = emptyGraph();
Triple t = triple(s1, p1, o1);
// Add twice, delete once => empty
g.add(t);
g.add(t);
g.delete(t);
assertEquals(0, g.size());
assertFalse("g contains t", g.contains(t));
returnGraph(g);
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class AbstractTestGraph2 method graph_add_03.
@Test
public void graph_add_03() {
Graph g = emptyGraph();
// SPO twice -- as different nodes.
Node ns1 = NodeFactoryExtra.parseNode("<ex:s>");
Node np1 = NodeFactoryExtra.parseNode("<ex:p>");
Node no1 = NodeFactoryExtra.parseNode("<ex:o>");
Node ns2 = NodeFactoryExtra.parseNode("<ex:s>");
Node np2 = NodeFactoryExtra.parseNode("<ex:p>");
Node no2 = NodeFactoryExtra.parseNode("<ex:o>");
Triple t1 = triple(ns1, np1, no1);
Triple t2 = triple(ns2, np2, no2);
g.add(t1);
g.add(t2);
assertEquals(1, g.size());
assertTrue(g.contains(t1));
assertTrue(g.contains(t2));
assertTrue(g.contains(ns1, np1, no1));
returnGraph(g);
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class TestFindLiterals method aTest.
public static TestFindLiterals aTest(final String graph, final int size, final String search, final String results) {
return new TestFindLiterals("TestFindLiterals: graph {" + graph + "} size " + size + " search " + search + " expecting {" + results + "}") {
@Override
public void runBare() {
Graph g = graphWith(graph);
Node literal = NodeCreateUtils.create(search);
//
assertEquals("graph has wrong size", size, g.size());
Set<Node> got = g.find(Node.ANY, Node.ANY, literal).mapWith(t -> t.getObject()).toSet();
assertEquals(nodeSet(results), got);
}
};
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class TestIntersection method testDelete.
public void testDelete() {
Graph l = graphWith("r A s; x R y");
Graph r = graphWith("x R y; p S q");
Intersection isec = new Intersection(l, r);
assertIsomorphic(graphWith("x R y"), isec);
// removing non-contained triples is a no-op
isec.delete(triple("r A s"));
assertIsomorphic(graphWith("r A s; x R y"), l);
isec.delete(triple("p S q"));
assertIsomorphic(graphWith("x R y; p S q"), r);
// removing a contained triple removes it from the left operand
isec.delete(triple("x R y"));
assertIsomorphic(graphWith(""), isec);
assertIsomorphic(graphWith("r A s"), l);
assertIsomorphic(graphWith("x R y; p S q"), r);
}
Aggregations