Search in sources :

Example 71 with Graph

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());
}
Also used : AbstractTestGraph(org.apache.jena.graph.test.AbstractTestGraph) Graph(org.apache.jena.graph.Graph) MultiUnion(org.apache.jena.graph.compose.MultiUnion)

Example 72 with Graph

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());
}
Also used : AbstractTestGraph(org.apache.jena.graph.test.AbstractTestGraph) Graph(org.apache.jena.graph.Graph) MultiUnion(org.apache.jena.graph.compose.MultiUnion)

Example 73 with Graph

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);
}
Also used : AbstractTestGraph(org.apache.jena.graph.test.AbstractTestGraph) Graph(org.apache.jena.graph.Graph) MultiUnion(org.apache.jena.graph.compose.MultiUnion)

Example 74 with Graph

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));
}
Also used : AbstractTestGraph(org.apache.jena.graph.test.AbstractTestGraph) Graph(org.apache.jena.graph.Graph) MultiUnion(org.apache.jena.graph.compose.MultiUnion)

Example 75 with Graph

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

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