Search in sources :

Example 81 with Graph

use of org.apache.jena.graph.Graph 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 82 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class TestDisjointUnion method testRemoveBoth.

public void testRemoveBoth() {
    Graph L = graphWith("x R y; a P b"), R = graphWith("x R y; p Q r");
    Graph du = new DisjointUnion(L, R);
    du.delete(triple("x R y"));
    assertIsomorphic(graphWith("a P b"), L);
    assertIsomorphic(graphWith("p Q r"), R);
}
Also used : Graph(org.apache.jena.graph.Graph) DisjointUnion(org.apache.jena.graph.compose.DisjointUnion)

Example 83 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class TestPackage method suite.

public static TestSuite suite() {
    TestSuite result = new TestSuite();
    GraphModelFactory gmf = new GraphModelFactory() {

        @Override
        Graph getGraph() {
            return new Intersection(Factory.createGraphMem(), Factory.createGraphMem());
        }
    };
    AbstractTestPackage atp = new AbstractTestPackage("Intersection", gmf) {
    };
    for (int i = 0; i < atp.testCount(); i++) {
        result.addTest(atp.testAt(i));
    }
    gmf = new GraphModelFactory() {

        @Override
        Graph getGraph() {
            return new Difference(Factory.createGraphMem(), Factory.createGraphMem());
        }
    };
    atp = new AbstractTestPackage("Difference", gmf) {
    };
    for (int i = 0; i < atp.testCount(); i++) {
        result.addTest(atp.testAt(i));
    }
    gmf = new GraphModelFactory() {

        @Override
        Graph getGraph() {
            return new Union(Factory.createGraphMem(), Factory.createGraphMem());
        }
    };
    atp = new AbstractTestPackage("Union", gmf) {
    };
    for (int i = 0; i < atp.testCount(); i++) {
        result.addTest(atp.testAt(i));
    }
    /* */
    result.addTest(TestDelta.suite());
    result.addTest(TestUnion.suite());
    result.addTest(TestDisjointUnion.suite());
    result.addTest(TestDifference.suite());
    result.addTest(TestIntersection.suite());
    result.addTestSuite(TestUnionStatistics.class);
    result.addTest(TestMultiUnion.suite());
    /* */
    result.addTest(TestPolyadicPrefixMapping.suite());
    return result;
}
Also used : Graph(org.apache.jena.graph.Graph) AbstractTestPackage(org.apache.jena.rdf.model.test.AbstractTestPackage)

Example 84 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class TestUnion method testDelete.

public void testDelete() {
    Graph l = graphWith("x R y; x R z");
    Graph r = graphWith("x R y; p S q");
    Union u = new Union(l, r);
    u.delete(triple("r A s"));
    assertIsomorphic(graphWith("x R y; x R z"), l);
    assertIsomorphic(graphWith("x R y; p S q"), r);
    u.delete(triple("x R z"));
    assertIsomorphic(graphWith("x R y"), l);
    assertIsomorphic(graphWith("x R y; p S q"), r);
    u.delete(triple("p S q"));
    assertIsomorphic(graphWith("x R y"), l);
    assertIsomorphic(graphWith("x R y"), r);
    u.delete(triple("x R y"));
    assertIsomorphic(graphWith(""), l);
    assertIsomorphic(graphWith(""), r);
}
Also used : Graph(org.apache.jena.graph.Graph) Union(org.apache.jena.graph.compose.Union)

Example 85 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class TestDelta method testDeleteGoesToDeletions.

public void testDeleteGoesToDeletions() {
    Graph base = graphWith(DEFAULT_TRIPLES);
    Delta delta = new Delta(base);
    delta.delete(triple("x R y"));
    assertIsomorphic(graphWith(DEFAULT_TRIPLES), base);
    assertIsomorphic(graphWith("x R y"), delta.getDeletions());
    assertIsomorphic(graphWith("p S q"), delta);
}
Also used : AbstractTestGraph(org.apache.jena.graph.test.AbstractTestGraph) Graph(org.apache.jena.graph.Graph) Delta(org.apache.jena.graph.compose.Delta)

Aggregations

Graph (org.apache.jena.graph.Graph)247 Test (org.junit.Test)90 BaseTest (org.apache.jena.atlas.junit.BaseTest)56 Triple (org.apache.jena.graph.Triple)56 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)54 Node (org.apache.jena.graph.Node)46 AbstractTestGraph (org.apache.jena.graph.test.AbstractTestGraph)16 InfGraph (org.apache.jena.reasoner.InfGraph)16 ContractTest (org.xenei.junit.contract.ContractTest)16 Model (org.apache.jena.rdf.model.Model)14 MultiUnion (org.apache.jena.graph.compose.MultiUnion)9 Delta (org.apache.jena.graph.compose.Delta)8 BuilderGraph (org.apache.jena.sparql.sse.builders.BuilderGraph)8 StreamRDF (org.apache.jena.riot.system.StreamRDF)7 PrefixMapping (org.apache.jena.shared.PrefixMapping)7 GraphUnionRead (org.apache.jena.sparql.graph.GraphUnionRead)7 IOException (java.io.IOException)6 Dataset (org.apache.jena.query.Dataset)6 Rule (org.apache.jena.reasoner.rulesys.Rule)6 ConfigTest (org.apache.jena.tdb.ConfigTest)6