/** * Return a multiunion, initialized with the given graphs. */ public MultiUnion createMultiUnion(Iterator<Graph> graphs) { return new MultiUnion(graphs); }
public static Graph unwrapUnionGraphs(Graph graph) { if (graph != null && graph instanceof MultiUnion) { List<Graph> subGraphs = ((MultiUnion)graph).getSubGraphs(); if (subGraphs == null || subGraphs.isEmpty()) { return ((MultiUnion)graph).getBaseGraph(); } } return graph; } }
/** * <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 ); }
/** * Creates an includes Model for a given input Model. * The includes Model is the union of the input Model will all graphs linked via * sh:include (or owl:imports), transitively. * @param model the Model to create the includes Model for * @param graphURI the URI of the named graph represented by Model * @return a Model including the semantics */ public static Model createIncludesModel(Model model, String graphURI) { Set<Graph> graphs = new HashSet<Graph>(); Graph baseGraph = model.getGraph(); addIncludes(baseGraph, graphURI, graphs, new HashSet<String>()); if(graphs.size() == 1) { return model; } else { MultiUnion union = new MultiUnion(graphs.iterator()); union.setBaseGraph(baseGraph); return ModelFactory.createModelForGraph(union); } }
@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 ); }
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() ); 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() );
Graph g2 = graphWith( "x p y; z p a" ); // intersects with g1 MultiUnion m = new MultiUnion( new Graph[] {g0, g1} ); int m0 = m.size(); m.add( triple( "a q b" ) ); assertEquals( "m.size should have increased by one", m0 + 1, m.size() ); assertEquals( "g0.size should have increased by one", s0 + 1, g0.size() ); assertEquals( "g1 size should be constant", s1, g1.size() ); m.setBaseGraph( g1 ); m0 = m.size(); m.add( triple( "a1 q b1" )); assertEquals( "m.size should have increased by one", m0 + 1, m.size() ); assertEquals( "g0 size should be constant", s0, g0.size() ); assertEquals( "g1.size should have increased by one", s1 + 1, g1.size() ); m.setBaseGraph( g2 );
public void testDelete() { Graph g0 = graphWith( "x p y" ); Graph g1 = graphWith( "x p z; z p zz" ); // disjoint with g0 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 ); }
public static Graph getBaseGraph(Graph graph) { Graph baseGraph = graph; while(baseGraph instanceof MultiUnion) { baseGraph = ((MultiUnion)baseGraph).getBaseGraph(); } return baseGraph; }
private void addImportedGraphs( FileManager fm, Set<String> loading, StmtIterator oit, MultiUnion g ) { while (oit.hasNext()) { String path = getObjectURI( oit.nextStatement() ); if (loading.add( path )) g.addGraph( graphFor( fm, loading, path ) ); } }
/** * <p> * Answer the sub-graphs of this model. A sub-graph is defined as a graph that * is used to contain the triples from an imported document. * </p> * * @return A list of sub graphs for this ontology model */ @Override public List<Graph> getSubGraphs() { return getUnionGraph().getSubGraphs(); }
/** * <p> * Remove the given model as one of the sub-models of the enclosed ontology union model. * </p> * * @param model A sub-model to remove * @param rebind If true, rebind any associated inferencing engine to the new data (which * may be an expensive operation) */ @Override public void removeSubModel( Model model, boolean rebind ) { Graph subG = model.getGraph(); getUnionGraph().removeGraph( subG ); // note that it may be the base graph of the given model that was added // originally if (subG instanceof MultiUnion) { // we need to get the base graph when removing a ontmodel getUnionGraph().removeGraph( ((MultiUnion) subG).getBaseGraph() ); } if (rebind) { rebind(); } }
/** A MultiUnion graph should have a MultiUnionStatisticsHandler, and that handler should point right back to that graph. */ public void testMultiUnionHasMultiUnionStatisticsHandler() { MultiUnion mu = new MultiUnion(); GraphStatisticsHandler sh = mu.getStatisticsHandler(); assertInstanceOf( MultiUnionStatisticsHandler.class, sh ); assertSame( mu, ((MultiUnionStatisticsHandler) sh).getUnion() ); }
public void testContains() { Graph g0 = graphWith( "x p y" ); Graph g1 = graphWith( "x p z; z p zz" ); // disjoint with g0 MultiUnion m = new MultiUnion( new Graph[] {g0, g1} ); assertTrue( "m should contain triple", m.contains( triple( "x p y "))); assertTrue( "m should contain triple", m.contains( triple( "x p z "))); assertTrue( "m should contain triple", m.contains( triple( "z p zz "))); assertFalse( "m should not contain triple", m.contains( triple( "zz p z "))); }
@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 ); }
/** * Creates an includes Model for a given input Model. * The includes Model is the union of the input Model will all graphs linked via * sh:include (or owl:imports), transitively. * @param model the Model to create the includes Model for * @param graphURI the URI of the named graph represented by Model * @return a Model including the semantics */ public static Model createIncludesModel(Model model, String graphURI) { Set<Graph> graphs = new HashSet<Graph>(); Graph baseGraph = model.getGraph(); addIncludes(baseGraph, graphURI, graphs, new HashSet<String>()); if(graphs.size() == 1) { return model; } else { MultiUnion union = new MultiUnion(graphs.iterator()); union.setBaseGraph(baseGraph); return ModelFactory.createModelForGraph(union); } }
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() ); 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() );
Graph g2 = graphWith( "x p y; z p a" ); // intersects with g1 MultiUnion m = new MultiUnion( new Graph[] {g0, g1} ); int m0 = m.size(); m.add( triple( "a q b" ) ); assertEquals( "m.size should have increased by one", m0 + 1, m.size() ); assertEquals( "g0.size should have increased by one", s0 + 1, g0.size() ); assertEquals( "g1 size should be constant", s1, g1.size() ); m.setBaseGraph( g1 ); m0 = m.size(); m.add( triple( "a1 q b1" )); assertEquals( "m.size should have increased by one", m0 + 1, m.size() ); assertEquals( "g0 size should be constant", s0, g0.size() ); assertEquals( "g1.size should have increased by one", s1 + 1, g1.size() ); m.setBaseGraph( g2 );
public void testDelete() { Graph g0 = graphWith( "x p y" ); Graph g1 = graphWith( "x p z; z p zz" ); // disjoint with g0 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 ); }
public static Graph getBaseGraph(Graph graph) { Graph baseGraph = graph; while(baseGraph instanceof MultiUnion) { baseGraph = ((MultiUnion)baseGraph).getBaseGraph(); } return baseGraph; }