/** Return the number of triples in the inferred graph */ @Override public int graphBaseSize() { checkOpen(); if (!isPrepared) { prepare(); } int baseSize = fdata.getGraph().size(); int dedSize = fdeductions.getGraph().size(); // System.err.println( ">> BasicForwardRuleInfGraph::size = " + baseSize + "(base) + " + dedSize // + "(deductions)" ); return baseSize + dedSize; }
/** * Create the graph used to hold the deductions. Can be overridden by subclasses that need special * purpose graph implementations here. Assumes the graph underlying fdeductions and associated * SafeGraph wrapper can be reused if present thus enabling preservation of listeners. */ protected Graph createDeductionsGraph() { if (fdeductions != null) { Graph dg = fdeductions.getGraph(); if (dg != null) { // Reuse the old graph in order to preserve any listeners safeDeductions.getBulkUpdateHandler().removeAll(); return dg; } } Graph dg = Factory.createGraphMem(style); safeDeductions = new SafeGraph(dg); return dg; }
/** Removes the triple t (if possible) from the set belonging to this graph. */ @Override public void performDelete(Triple t) { version++; if (fdata != null) { Graph data = fdata.getGraph(); if (data != null) { data.delete(t); } } if (isPrepared) { fdeductions.getGraph().delete(t); } }
/** * Adds a set of precomputed triples to the deductions store. These do not, themselves, fire any * rules but provide additional axioms that might enable future rule firing when real data is * added. Used to implement bindSchema processing in the parent Reasoner. * * @return return true if the rule set has also been loaded */ protected boolean preloadDeductions(Graph preloadIn) { Graph d = fdeductions.getGraph(); BasicForwardRuleInfGraph preload = (BasicForwardRuleInfGraph) preloadIn; // If the rule set is the same we can reuse those as well if (preload.rules == rules) { // Load raw deductions for (Iterator<Triple> i = preload.find(null, null, null); i.hasNext(); ) { d.add(i.next()); } engine.setRuleStore(preload.engine.getRuleStore()); return true; } else { return false; } }
/** * Internals of findWithContinuation implementation which allows control over functor filtering. */ private ExtendedIterator<Triple> findWithContinuation( TriplePattern pattern, Finder continuation, boolean filter) { checkOpen(); if (!isPrepared) prepare(); 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; } }
/** Assert a new triple in the deduction graph, bypassing any processing machinery. */ public void silentAdd(Triple t) { fdeductions.getGraph().add(t); }