/** * Return the schema graph, if any, bound into this inference graph. */ @Override public Graph getSchemaGraph() { return fschema.getGraph(); }
/** * Replace the underlying data graph for this inference graph and start any * inferences over again. This is primarily using in setting up ontology imports * processing to allow an imports multiunion graph to be inserted between the * inference graph and the raw data, before processing. * @param data the new raw data graph */ @Override public synchronized void rebind(Graph data) { fdata = new FGraph(data); isPrepared = false; }
if (fdata != null) data = fdata.getGraph(); Graph oldDeductions = (fdeductions).getGraph(); oldDeductions.clear(); } else { fdeductions = new FGraph( createDeductionsGraph() ); FGraph finserts = new FGraph(inserts); dataSource = FinderUtil.cascade(fdata, finserts); dataFind = FinderUtil.cascade(dataFind, finserts); Graph rawPreload = ((InfGraph)schemaGraph).getRawGraph(); if (rawPreload != null) { dataFind = FinderUtil.cascade(dataFind, new FGraph(rawPreload));
/** * Internals of findWithContinuation implementation which allows control * over functor filtering. */ private ExtendedIterator<Triple> findWithContinuation(TriplePattern pattern, Finder continuation, boolean filter) { checkOpen(); this.requirePrepared(); ExtendedIterator<Triple> result = null; if (fdata == null) { result = fdeductions.findWithContinuation(pattern, continuation); } else { if (continuation == null) { result = fdata.findWithContinuation(pattern, fdeductions); } else { result = fdata.findWithContinuation(pattern, FinderUtil.cascade(fdeductions, continuation) ); } } if (filter && filterFunctors) { return result.filterDrop(Functor.acceptFilter); } else { return result; } }
/** * Return the raw RDF data Graph being processed (i.e. the argument * to the Reasonder.bind call that created this InfGraph). */ @Override public Graph getRawGraph() { return fdata.getGraph(); }
/** * Constructor * @param data the raw data file to be augmented with entailments * @param reasoner the engine, with associated tbox data, whose find interface * can be used to extract all entailments from the data. */ public BaseInfGraph(Graph data, Reasoner reasoner) { super( ); this.fdata = new FGraph( data ); this.reasoner = reasoner; }
/** * Create a continuation object which is a cascade of two * continuation objects. * @param first the first Graph/Finder to try * @param second the second Graph/Finder to try */ public static Finder cascade(Finder first, Finder second) { if (first == null || (first instanceof FGraph && ((FGraph)first).getGraph() == null)) return second; if (second == null || (second instanceof FGraph && ((FGraph)second).getGraph() == null)) return first; return new Cascade(first, second); }
/** * Replace the underlying data graph for this inference graph and start any * inferences over again. This is primarily using in setting up ontology imports * processing to allow an imports multiunion graph to be inserted between the * inference graph and the raw data, before processing. * @param data the new raw data graph */ @Override public void rebind(Graph data) { fdata = new FGraph( data ); rebind(); }
/** * Return the schema graph, if any, bound into this inference graph. */ @Override public Graph getSchemaGraph() { if (tbox == null) return null; if (tbox instanceof FGraph) { return ((FGraph)tbox).getGraph(); } else { throw new ReasonerException("Transitive reasoner got into an illegal state"); } }
/** * Extracts all of the subClass and subProperty declarations from * the given schema/tbox and caches the resultant graphs. * It can only be used once, can't stack up multiple tboxes this way. * This limitation could be lifted - the only difficulty is the need to * reprocess all the earlier tboxes if a new subPropertyOf subPropertyOf * subClassOf is discovered. * @param tbox schema containing the property and class declarations */ @Override public Reasoner bindSchema(Graph tbox) throws ReasonerException { return bindSchema(new FGraph(tbox)); }
/** * Assert a new triple in the deduction graph, bypassing any processing machinery. */ @Override public void silentAdd(Triple t) { fdeductions.getGraph().add(t); }
/** * Replace the underlying data graph for this inference graph and start any * inferences over again. This is primarily using in setting up ontology imports * processing to allow an imports multiunion graph to be inserted between the * inference graph and the raw data, before processing. * @param data the new raw data graph */ @Override public synchronized void rebind(Graph data) { engine.checkSafeToUpdate(); fdata = new FGraph(data); this.setPreparedState(false); }
/** Answer true iff this graph is empty. [Used to be in QueryHandler, but moved in here because it's a more primitive operation.] */ @Override public boolean isEmpty() { return fdata.getGraph().isEmpty(); }
/** * Extracts all of the subClass and subProperty declarations from * the given schema/tbox and caches the resultant graphs. * It can only be used once, can't stack up multiple tboxes this way. * This limitation could be lifted - the only difficulty is the need to * reprocess all the earlier tboxes if a new subPropertyOf subPropertyOf * subClassOf is discovered. * @param tbox schema containing the property and class declarations */ @Override public Reasoner bindSchema(Model tbox) throws ReasonerException { return bindSchema(new FGraph(tbox.getGraph())); }
/** * Assert a new triple in the deduction graph, bypassing any processing machinery. */ @Override public void silentAdd(Triple t) { fdeductions.getGraph().add(t); }
/** * Constructor. Create a new backward inference graph to process * the given data. The parent reasoner supplies the ruleset and * any additional schema graph. * * @param reasoner the parent reasoner * @param ruleStore the indexed set of rules to use * @param data the data graph to be processed * @param schema optional precached schema (use null if not required) */ public LPBackwardRuleInfGraph(Reasoner reasoner, LPRuleStore ruleStore, Graph data, Graph schema) { super(data, reasoner); if (schema != null) { fschema = new FGraph(schema); } engine = new LPBRuleEngine(this, ruleStore); tempNodecache = new TempNodeCache(this); }
/** * Perform any initial processing and caching. This call is optional. Most * engines either have negligable set up work or will perform an implicit * "prepare" if necessary. The call is provided for those occasions where * substantial preparation work is possible (e.g. running a forward chaining * rule system) and where an application might wish greater control over when * this prepration is done. */ @Override public synchronized void prepare() { if (this.isPrepared()) return; fdeductions = new FGraph( Factory.createGraphMem() ); extractAxioms(); dataFind = fdata; if (fdeductions != null) { dataFind = FinderUtil.cascade(dataFind, fdeductions); } if (fschema != null) { dataFind = FinderUtil.cascade(dataFind, fschema); } this.setPreparedState(true); }
/** * Free all resources, any further use of this Graph is an error. */ @Override public void close() { if (!closed) { fdata.getGraph().close(); fdata = null; super.close(); } }
/** * Perform any initial processing and caching. This call is optional. Most * engines either have negligable set up work or will perform an implicit * "prepare" if necessary. The call is provided for those occasions where * substantial preparation work is possible (e.g. running a forward chaining * rule system) and where an application might wish greater control over when * this prepration is done. */ @Override public synchronized void prepare() { if (this.isPrepared()) return; this.setPreparedState(true); // initilize the deductions graph fdeductions = new FGraph( createDeductionsGraph() ); boolean rulesLoaded = false; if (schemaGraph != null) { rulesLoaded = preloadDeductions(schemaGraph); } if (rulesLoaded) { engine.fastInit(fdata); } else { engine.init(true, fdata); } }