Search in sources :

Example 1 with MultiUnion

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

the class OntModelImpl method generateGraph.

/**
     * <p>Helper method to the constructor, which interprets the spec and generates an appropriate
     * graph for this model</p>
     * @param spec The model spec to interpret
     * @param base The base model, or null
     */
private static Graph generateGraph(OntModelSpec spec, Graph base) {
    // create a empty union graph
    MultiUnion u = new MultiUnion();
    u.addGraph(base);
    u.setBaseGraph(base);
    Reasoner r = spec.getReasoner();
    // if we have a reasoner in the spec, bind to the union graph and return
    return r == null ? (Graph) u : r.bind(u);
}
Also used : Reasoner(org.apache.jena.reasoner.Reasoner) MultiUnion(org.apache.jena.graph.compose.MultiUnion)

Example 2 with MultiUnion

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

the class UnionModelAssembler method openEmptyModel.

@Override
protected Model openEmptyModel(Assembler a, Resource root, Mode mode) {
    checkType(root, JA.UnionModel);
    MultiUnion union = new MultiUnion();
    union.addGraph(getRootModel(a, root, mode));
    addSubModels(a, root, union, mode);
    return ModelFactory.createModelForGraph(union);
}
Also used : MultiUnion(org.apache.jena.graph.compose.MultiUnion)

Example 3 with MultiUnion

use of org.apache.jena.graph.compose.MultiUnion 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 4 with MultiUnion

use of org.apache.jena.graph.compose.MultiUnion 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 5 with MultiUnion

use of org.apache.jena.graph.compose.MultiUnion 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)

Aggregations

MultiUnion (org.apache.jena.graph.compose.MultiUnion)15 Graph (org.apache.jena.graph.Graph)9 AbstractTestGraph (org.apache.jena.graph.test.AbstractTestGraph)8 GraphStatisticsHandler (org.apache.jena.graph.GraphStatisticsHandler)1 Model (org.apache.jena.rdf.model.Model)1 InfGraph (org.apache.jena.reasoner.InfGraph)1 Reasoner (org.apache.jena.reasoner.Reasoner)1