public static Graph getBaseGraph(Graph graph) { Graph baseGraph = graph; while(baseGraph instanceof MultiUnion) { baseGraph = ((MultiUnion)baseGraph).getBaseGraph(); } return baseGraph; }
public static Graph getBaseGraph(Graph graph) { Graph baseGraph = graph; while(baseGraph instanceof MultiUnion) { baseGraph = ((MultiUnion)baseGraph).getBaseGraph(); } return baseGraph; }
public static List<Graph> getSubGraphs(MultiUnion union) { List<Graph> results = new LinkedList<>(); Graph baseGraph = union.getBaseGraph(); if(baseGraph != null) { results.add(baseGraph); } results.addAll(union.getSubGraphs()); return results; }
/** * <p> * Answer the base-graph of this model. The base-graph is the graph that * contains the triples read from the source document for this ontology. * </p> * * @return The base-graph for this ontology model */ public Graph getBaseGraph() { return getUnionGraph().getBaseGraph(); }
/** * <p> * Answer the base-graph of this model. The base-graph is the graph that * contains the triples read from the source document for this ontology. * </p> * * @return The base-graph for this ontology model */ public Graph getBaseGraph() { return getUnionGraph().getBaseGraph(); }
public static List<Graph> getSubGraphs(MultiUnion union) { List<Graph> results = new LinkedList<>(); results.add(union.getBaseGraph()); results.addAll(union.getSubGraphs()); return results; }
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; } }
public static void collectBaseGraphs(Graph graph, Set<Graph> baseGraphs) { if(graph instanceof MultiUnion) { MultiUnion union = (MultiUnion)graph; collectBaseGraphs(union.getBaseGraph(), baseGraphs); for(Object subGraph : union.getSubGraphs()) { collectBaseGraphs((Graph)subGraph, baseGraphs); } } else if(graph != null) { baseGraphs.add(graph); } }
public static void collectBaseGraphs(Graph graph, Set<Graph> baseGraphs) { if(graph instanceof MultiUnion) { MultiUnion union = (MultiUnion)graph; collectBaseGraphs(union.getBaseGraph(), baseGraphs); for(Object subGraph : union.getSubGraphs()) { collectBaseGraphs((Graph)subGraph, baseGraphs); } } else if(graph != null) { baseGraphs.add(graph); } }
/** * Overcomes a design mismatch with Jena: if the base model does not declare a default namespace then the * default namespace of an import is returned - this is not desirable for TopBraid-like scenarios. * @param model the Model to operate on * @param prefix the prefix to get the URI of * @return the URI of prefix */ public static String getNsPrefixURI(Model model, String prefix) { if ("".equals(prefix) && model.getGraph() instanceof MultiUnion) { Graph baseGraph = ((MultiUnion)model.getGraph()).getBaseGraph(); if(baseGraph != null) { return baseGraph.getPrefixMapping().getNsPrefixURI(prefix); } else { return model.getNsPrefixURI(prefix); } } else { return model.getNsPrefixURI(prefix); } }
/** * Overcomes a design mismatch with Jena: if the base model does not declare a default namespace then the * default namespace of an import is returned - this is not desirable for TopBraid-like scenarios. * @param model the Model to operate on * @param prefix the prefix to get the URI of * @return the URI of prefix */ public static String getNsPrefixURI(Model model, String prefix) { if ("".equals(prefix) && model.getGraph() instanceof MultiUnion) { Graph baseGraph = ((MultiUnion)model.getGraph()).getBaseGraph(); if(baseGraph != null) { return baseGraph.getPrefixMapping().getNsPrefixURI(prefix); } else { return model.getNsPrefixURI(prefix); } } else { return model.getNsPrefixURI(prefix); } }
/** * <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(); } }
/** * <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(); } }
public void testCreatesUnionWithBaseModel() { Resource root = resourceInModel( "x rdf:type ja:UnionModel; x ja:subModel A; x ja:rootModel B" ); Assembler a = new UnionModelAssembler(); Model modelA = model( "" ), modelB = model( "" ); Set<Graph> expected = new HashSet<>(); expected.add( modelA.getGraph() ); Assembler mock = new SmudgeAssembler().add( "A", modelA ).add( "B", modelB ); Model m = (Model) a.open( mock, root ); assertInstanceOf( MultiUnion.class, m.getGraph() ); // MultiUnion mu = (MultiUnion) m.getGraph(); assertSame( modelB.getGraph(), mu.getBaseGraph() ); assertEquals( listOfOne( modelA.getGraph() ), mu.getSubGraphs() ); m.add( statement( "a P b" ) ); assertIsoModels( model( "a P b" ), modelB ); } }
public void testCreatesUnionWithBaseModel() { Resource root = resourceInModel( "x rdf:type ja:UnionModel; x ja:subModel A; x ja:rootModel B" ); Assembler a = new UnionModelAssembler(); Model modelA = model( "" ), modelB = model( "" ); Set<Graph> expected = new HashSet<>(); expected.add( modelA.getGraph() ); Assembler mock = new SmudgeAssembler().add( "A", modelA ).add( "B", modelB ); Model m = (Model) a.open( mock, root ); assertInstanceOf( MultiUnion.class, m.getGraph() ); // MultiUnion mu = (MultiUnion) m.getGraph(); assertSame( modelB.getGraph(), mu.getBaseGraph() ); assertEquals( listOfOne( modelA.getGraph() ), mu.getSubGraphs() ); m.add( statement( "a P b" ) ); assertIsoModels( model( "a P b" ), modelB ); } }