Search in sources :

Example 1 with Intersection

use of org.apache.jena.graph.compose.Intersection in project jena by apache.

the class IntersectionTest method testDeleteDoesNotUpdateR.

@ContractTest
public void testDeleteDoesNotUpdateR() {
    Graph L = graphWith("a pings b; b pings c; c pings a");
    Graph R = graphWith("c pings a; b pings c; x captures y");
    Graph join = new Intersection(L, R);
    GraphUtil.deleteFrom(L, R);
    assertIsomorphic("R should not change", graphWith("c pings a; b pings c; x captures y"), R);
    assertIsomorphic(graphWith("a pings b"), L);
}
Also used : Intersection(org.apache.jena.graph.compose.Intersection) Graph(org.apache.jena.graph.Graph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 2 with Intersection

use of org.apache.jena.graph.compose.Intersection 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);
}
Also used : Intersection(org.apache.jena.graph.compose.Intersection) Graph(org.apache.jena.graph.Graph)

Example 3 with Intersection

use of org.apache.jena.graph.compose.Intersection in project jena by apache.

the class TestIntersection method testIntersectionReflectsChangesToOperands.

public void testIntersectionReflectsChangesToOperands() {
    Graph l = graphWith("x R y");
    Graph r = graphWith("p S q");
    Intersection isec = new Intersection(l, r);
    assertIsomorphic(graphWith(""), isec);
    // add to the left what is already in the right
    l.add(triple("p S q"));
    assertIsomorphic(graphWith("p S q"), isec);
    // add to the right what is already in the left
    r.add(triple("x R y"));
    assertIsomorphic(graphWith("p S q; x R y"), isec);
    // add to a single graph is not reflected
    l.add(triple("p S o"));
    r.add(triple("x R z"));
    assertIsomorphic(graphWith("p S q; x R y"), isec);
    // remove from the left
    l.delete(triple("x R y"));
    assertIsomorphic(graphWith("p S q"), isec);
    // remove from the right
    r.delete(triple("p S q"));
    assertIsomorphic(graphWith(""), isec);
}
Also used : Intersection(org.apache.jena.graph.compose.Intersection) Graph(org.apache.jena.graph.Graph)

Example 4 with Intersection

use of org.apache.jena.graph.compose.Intersection in project jena by apache.

the class IntersectionTest method testIntersection.

@ContractTest
public void testIntersection() {
    Graph g1 = graphWith("x R y; p R q");
    Graph g2 = graphWith("r Foo s; x R y");
    Intersection i = new Intersection(g1, g2);
    assertContains("Intersection", "x R y", i);
    assertOmits("Intersection", i, "p R q");
    assertOmits("Intersection", i, "r Foo s");
    if (i.size() != 1)
        fail("oops: size of intersection is not 1");
    i.add(triple("cats eat cheese"));
    assertContains("Intersection.L", "cats eat cheese", g1);
    assertContains("Intersection.R", "cats eat cheese", g2);
}
Also used : Intersection(org.apache.jena.graph.compose.Intersection) Graph(org.apache.jena.graph.Graph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 5 with Intersection

use of org.apache.jena.graph.compose.Intersection in project jena by apache.

the class TestIntersection method testAdd.

public void testAdd() {
    Graph l = graphWith("x R y");
    Graph r = graphWith("p S q");
    Intersection isec = new Intersection(l, r);
    assertIsomorphic(graphWith(""), isec);
    isec.add(triple("r A s"));
    assertIsomorphic(graphWith("r A s"), isec);
    assertIsomorphic(graphWith("x R y; r A s"), l);
    assertIsomorphic(graphWith("p S q; r A s"), r);
    isec.add(triple("x R y"));
    assertIsomorphic(graphWith("r A s; x R y"), isec);
    assertIsomorphic(graphWith("x R y; r A s"), l);
    assertIsomorphic(graphWith("p S q; r A s; x R y"), r);
    isec.add(triple("p S q"));
    assertIsomorphic(graphWith("p S q; r A s; x R y"), isec);
    assertIsomorphic(graphWith("p S q; r A s; x R y"), l);
    assertIsomorphic(graphWith("p S q; r A s; x R y"), r);
}
Also used : Intersection(org.apache.jena.graph.compose.Intersection) Graph(org.apache.jena.graph.Graph)

Aggregations

Graph (org.apache.jena.graph.Graph)5 Intersection (org.apache.jena.graph.compose.Intersection)5 ContractTest (org.xenei.junit.contract.ContractTest)2