use of org.apache.jena.graph.Graph in project jena by apache.
the class TestMultiUnion method testGraphSize1.
// public void testDeferredReifier()
// {
// Graph g1 = graphWith( "" ), g2 = graphWith( "" );
// MultiUnion m = new MultiUnion( new Graph[] {g1, g2} );
// m.setBaseGraph( g1 );
// assertSame( m.getReifier(), g1.getReifier() );
// }
public void testGraphSize1() {
Graph g0 = graphWith("x p y");
// disjoint with g0
Graph g1 = graphWith("x p z; z p zz");
// intersects with g1
Graph g2 = graphWith("x p y; z p a");
Graph m01 = new MultiUnion(new Graph[] { g0, g1 });
Graph m10 = new MultiUnion(new Graph[] { g1, g0 });
Graph m12 = new MultiUnion(new Graph[] { g1, g2 });
Graph m21 = new MultiUnion(new Graph[] { g2, g1 });
Graph m02 = new MultiUnion(new Graph[] { g0, g2 });
Graph m20 = new MultiUnion(new Graph[] { g2, g0 });
Graph m00 = new MultiUnion(new Graph[] { g0, g0 });
int s0 = g0.size();
int s1 = g1.size();
int s2 = g2.size();
assertEquals("Size of union of g0 and g1 not correct", s0 + s1, m01.size());
assertEquals("Size of union of g1 and g0 not correct", s0 + s1, m10.size());
assertEquals("Size of union of g1 and g2 not correct", s1 + s2, m12.size());
assertEquals("Size of union of g2 and g1 not correct", s1 + s2, m21.size());
assertEquals("Size of union of g0 and g2 not correct", s0 + s2 - 1, m02.size());
assertEquals("Size of union of g2 and g0 not correct", s0 + s2 - 1, m20.size());
assertEquals("Size of union of g0 with itself not correct", s0, m00.size());
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class TestMultiUnion method testGraphAddSize.
public void testGraphAddSize() {
Graph g0 = graphWith("x p y");
// disjoint with g0
Graph g1 = graphWith("x p z; z p zz");
// intersects with g1
Graph g2 = graphWith("x p y; z p a");
int s0 = g0.size();
int s1 = g1.size();
int s2 = g2.size();
MultiUnion m0 = new MultiUnion(new Graph[] { g0 });
assertEquals("Size of union of g0 not correct", s0, m0.size());
m0.addGraph(g1);
assertEquals("Size of union of g1 and g0 not correct", s0 + s1, m0.size());
m0.addGraph(g2);
assertEquals("Size of union of g0, g1 and g2 not correct", s0 + s1 + s2 - 1, m0.size());
m0.removeGraph(g1);
assertEquals("Size of union of g0 and g2 not correct", s0 + s2 - 1, m0.size());
m0.removeGraph(g0);
assertEquals("Size of union of g2 not correct", s2, m0.size());
// remove again
m0.removeGraph(g0);
assertEquals("Size of union of g2 not correct", s2, m0.size());
m0.removeGraph(g2);
assertEquals("Size of empty union not correct", 0, m0.size());
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class TestMultiUnion method testDelete.
public void testDelete() {
Graph g0 = graphWith("x p y");
// disjoint with g0
Graph g1 = graphWith("x p z; z p zz");
MultiUnion m = new MultiUnion(new Graph[] { g0, g1 });
checkDeleteSizes(1, 2, 3, g0, g1, m);
m.delete(triple("x p y"));
checkDeleteSizes(0, 2, 2, g0, g1, m);
m.delete(triple("x p y"));
checkDeleteSizes(0, 2, 2, g0, g1, m);
m.setBaseGraph(g1);
m.delete(triple("x p z"));
checkDeleteSizes(0, 1, 1, g0, g1, m);
m.delete(triple("z p zz"));
checkDeleteSizes(0, 0, 0, g0, g1, m);
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class TestMultiUnion method testEmptyGraph.
public void testEmptyGraph() {
Graph m = new MultiUnion();
Graph g0 = graphWith("x p y");
assertEquals("Empty model should have size zero", 0, m.size());
assertFalse("Empty model should not contain another graph", m.dependsOn(g0));
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class TestMultiUnionReifier method graph.
private Graph graph(String facts) {
Graph result = Factory.createDefaultGraph();
String[] factArray = facts.split(";");
for (String aFactArray : factArray) {
String fact = aFactArray.trim();
if (fact.equals("")) {
} else if (fact.charAt(0) == '!') {
Triple t = NodeCreateUtils.createTriple(fact.substring(1));
result.add(t);
ReifierStd.reifyAs(result, NodeCreateUtils.create("_r" + ++count), t);
} else if (fact.charAt(0) == '~') {
Triple t = NodeCreateUtils.createTriple(fact.substring(1));
ReifierStd.reifyAs(result, NodeCreateUtils.create("_r" + ++count), t);
} else {
result.add(NodeCreateUtils.createTriple(fact));
}
}
return result;
}
Aggregations