/** * Return a new inference graph which is a clone of the current graph * together with an additional set of data premises. The default * implementation loses ALL partial deductions so far. Some subclasses * may be able to a more efficient job. */ public InfGraph cloneWithPremises(Graph premises) { MultiUnion union = new MultiUnion(); Graph raw = getRawGraph(); union.addGraph( raw ); union.setBaseGraph( raw ); union.addGraph( premises ); Graph schema = getSchemaGraph(); if (schema != null) { if (schema instanceof BaseInfGraph) { BaseInfGraph ischema = (BaseInfGraph)schema; Graph sschema = ischema.getSchemaGraph(); if (sschema != null) union.addGraph( sschema ); Graph rschema = ischema.getRawGraph(); if (rschema != null) union.addGraph( rschema ); } } return getReasoner().bind(union); }
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 ) ); } }
/** * Return a new inference graph which is a clone of the current graph * together with an additional set of data premises. The default * implementation loses ALL partial deductions so far. Some subclasses * may be able to a more efficient job. */ public InfGraph cloneWithPremises(Graph premises) { MultiUnion union = new MultiUnion(); Graph raw = getRawGraph(); union.addGraph( raw ); union.setBaseGraph( raw ); union.addGraph( premises ); Graph schema = getSchemaGraph(); if (schema != null) { if (schema instanceof BaseInfGraph) { BaseInfGraph ischema = (BaseInfGraph)schema; Graph sschema = ischema.getSchemaGraph(); if (sschema != null) union.addGraph( sschema ); Graph rschema = ischema.getRawGraph(); if (rschema != null) union.addGraph( rschema ); } } return getReasoner().bind(union); }
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> * Add the given model as one of the sub-models of the enclosed ontology union model. * <strong>Note</strong> that if <code>model</code> is a composite model (i.e. an * {@link OntModel} or {@link InfModel}), the model and all of its submodels will * be added to the union of sub-models of this model. If this is <strong>not</strong> required, * callers should explicitly add only the base model: * </p> * <pre> * parent.addSubModel( child.getBaseModel(), true ); * </pre> * * @param model A sub-model to add * @param rebind If true, rebind any associated inferencing engine to the new data (which * may be an expensive operation) */ @Override public void addSubModel( Model model, boolean rebind ) { getUnionGraph().addGraph( model.getGraph() ); if (rebind) { rebind(); } }
/** * <p> * Add the given model as one of the sub-models of the enclosed ontology union model. * <strong>Note</strong> that if <code>model</code> is a composite model (i.e. an * {@link OntModel} or {@link InfModel}), the model and all of its submodels will * be added to the union of sub-models of this model. If this is <strong>not</strong> required, * callers should explicitly add only the base model: * </p> * <pre> * parent.addSubModel( child.getBaseModel(), true ); * </pre> * * @param model A sub-model to add * @param rebind If true, rebind any associated inferencing engine to the new data (which * may be an expensive operation) */ @Override public void addSubModel( Model model, boolean rebind ) { getUnionGraph().addGraph( model.getGraph() ); if (rebind) { rebind(); } }
/** * <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 ); }
/** * <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 ); }
private void initDefaultModel() throws GraphNotFoundException { if(defaultGraphs.isEmpty()) { defaultModel = super.getDefaultModel(); } else { if(defaultGraphs.size() == 1) { String defaultGraphURI = defaultGraphs.iterator().next(); defaultModel = getNamedModel(defaultGraphURI); if(defaultModel == null) { throw new GraphNotFoundException("Named graph " + defaultGraphURI + " not found"); } } else { MultiUnion multiUnion = JenaUtil.createMultiUnion(); for(String graphURI : defaultGraphs) { Model model = getNamedModel(graphURI); if(model == null) { throw new GraphNotFoundException("Named graph " + graphURI + " not found"); } multiUnion.addGraph(model.getGraph()); } defaultModel = ModelFactory.createModelForGraph(multiUnion); } } }
@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 ); }
private void initDefaultModel() throws GraphNotFoundException { if(defaultGraphs.isEmpty()) { defaultModel = super.getDefaultModel(); } else { if(defaultGraphs.size() == 1) { String defaultGraphURI = defaultGraphs.iterator().next(); defaultModel = getNamedModel(defaultGraphURI); if(defaultModel == null) { throw new GraphNotFoundException("Named graph " + defaultGraphURI + " not found"); } } else { MultiUnion multiUnion = JenaUtil.createMultiUnion(); for(String graphURI : defaultGraphs) { Model model = getNamedModel(graphURI); if(model == null) { throw new GraphNotFoundException("Named graph " + graphURI + " not found"); } multiUnion.addGraph(model.getGraph()); } defaultModel = ModelFactory.createModelForGraph(multiUnion); } } }
@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 ); }
private void addSubModels( Assembler a, Resource root, MultiUnion union, Mode mode ) { for (StmtIterator it = root.listProperties( JA.subModel ); it.hasNext();) { Resource resource = getResource( it.nextStatement() ); union.addGraph( a.openModel( resource, mode ).getGraph() ); } }
private void addSubModels( Assembler a, Resource root, MultiUnion union, Mode mode ) { for (StmtIterator it = root.listProperties( JA.subModel ); it.hasNext();) { Resource resource = getResource( it.nextStatement() ); union.addGraph( a.openModel( resource, mode ).getGraph() ); } }
public void testModel() { Graph g0 = graphWith( "x p y" ); MultiUnion u = new MultiUnion( new Graph[] {g0} ); Model m = ModelFactory.createModelForGraph( u ); assertEquals( "Model size not correct", 1, m.size() ); Graph g1 = graphWith( "x p z; z p zz" ); // disjoint with g0 u.addGraph( g1 ); assertEquals( "Model size not correct", 3, m.size() ); // adds one more statement to the model m.read( getFileName("ontology/list0.rdf") ); assertEquals( "Model size not correct", 4, m.size() ); // debug m.write( System.out ); }
public void testModel() { Graph g0 = graphWith( "x p y" ); MultiUnion u = new MultiUnion( new Graph[] {g0} ); Model m = ModelFactory.createModelForGraph( u ); assertEquals( "Model size not correct", 1, m.size() ); Graph g1 = graphWith( "x p z; z p zz" ); // disjoint with g0 u.addGraph( g1 ); assertEquals( "Model size not correct", 3, m.size() ); // adds one more statement to the model m.read( getFileName("ontology/list0.rdf") ); assertEquals( "Model size not correct", 4, m.size() ); // debug m.write( System.out ); }