1 10 package com.hp.hpl.jena.reasoner.rulesys.impl.oldCode; 11 12 import com.hp.hpl.jena.reasoner.rulesys.*; 13 import com.hp.hpl.jena.reasoner.rulesys.impl.*; 14 import com.hp.hpl.jena.reasoner.*; 15 import com.hp.hpl.jena.graph.*; 16 17 import java.util.*; 18 19 import com.hp.hpl.jena.util.OneToManyMap; 20 import com.hp.hpl.jena.util.iterator.*; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 34 public class FBLPRuleInfGraph extends FBRuleInfGraph { 35 36 37 protected LPBRuleEngine lpbEngine; 38 39 static Log logger = LogFactory.getLog(FBLPRuleInfGraph.class); 40 41 44 49 public FBLPRuleInfGraph(Reasoner reasoner, Graph schema) { 50 super(reasoner, schema); 51 initLP(schema); 52 } 53 54 60 public FBLPRuleInfGraph(Reasoner reasoner, List rules, Graph schema) { 61 super(reasoner, rules, schema); 62 initLP(schema); 63 } 64 65 72 public FBLPRuleInfGraph(Reasoner reasoner, List rules, Graph schema, Graph data) { 73 super(reasoner, rules, schema, data); 74 initLP(schema); 75 } 76 77 80 private void initLP(Graph schema) { 81 if (schema != null && schema instanceof FBLPRuleInfGraph) { 82 LPRuleStore newStore = new LPRuleStore(); 83 newStore.addAll(((FBLPRuleInfGraph)schema).lpbEngine.getRuleStore()); 84 lpbEngine = new LPBRuleEngine(this, newStore); 85 } else { 86 lpbEngine = new LPBRuleEngine(this); 87 } 88 } 89 90 93 94 101 public boolean processBuiltin(Object clause, Rule rule, BindingEnvironment env) { 102 throw new ReasonerException("Internal error in FBLP rule engine, incorrect invocation of building in rule " + rule); 103 } 104 105 109 public void addBRule(Rule brule) { 110 lpbEngine.addRule(brule); 112 lpbEngine.reset(); 113 } 114 115 119 public void deleteBRule(Rule brule) { 120 lpbEngine.deleteRule(brule); 122 lpbEngine.reset(); 123 } 124 125 128 public void addBRules(List rules) { 129 for (Iterator i = rules.iterator(); i.hasNext(); ) { 130 Rule rule = (Rule)i.next(); 131 lpbEngine.addRule(rule); 133 } 134 lpbEngine.reset(); 135 } 136 137 141 public List getBRules() { 142 return lpbEngine.getAllRules(); 143 } 144 145 148 public void setTabled(Node predicate) { 149 lpbEngine.tablePredicate(predicate); 150 if (traceOn) { 151 logger.info("LP TABLE " + predicate); 152 } 153 } 154 155 158 165 public void rebind() { 166 if (lpbEngine != null) lpbEngine.reset(); 167 isPrepared = false; 168 } 169 170 174 public void setTraceOn(boolean state) { 175 super.setTraceOn(state); 176 lpbEngine.setTraceOn(state); 177 } 178 179 182 public void setDerivationLogging(boolean recordDerivations) { 183 this.recordDerivations = recordDerivations; 184 engine.setDerivationLogging(recordDerivations); 185 lpbEngine.setDerivationLogging(recordDerivations); 186 if (recordDerivations) { 187 derivations = new OneToManyMap(); 188 } else { 189 derivations = null; 190 } 191 } 192 193 197 public long getNRulesFired() { 198 return engine.getNRulesFired(); 199 } 200 201 212 public ExtendedIterator findWithContinuation(TriplePattern pattern, Finder continuation) { 213 checkOpen(); 214 if (!isPrepared) prepare(); 216 ExtendedIterator result = new UniqueExtendedIterator(lpbEngine.find(pattern)); 217 if (continuation != null) { 218 result = result.andThen(continuation.find(pattern)); 219 } 220 return result.filterDrop(Functor.acceptFilter); 221 } 222 223 226 public void reset() { 227 lpbEngine.reset(); 228 isPrepared = false; 229 } 230 231 235 public synchronized void performAdd(Triple t) { 236 fdata.getGraph().add(t); 237 if (useTGCCaching) { 238 if (transitiveEngine.add(t)) isPrepared = false; 239 } 240 if (isPrepared) { 241 engine.add(t); 242 } 243 lpbEngine.reset(); 244 } 245 246 249 public void performDelete(Triple t) { 250 fdata.getGraph().delete(t); 251 if (useTGCCaching) { 252 if (transitiveEngine.delete(t)) { 253 if (isPrepared) { 254 bEngine.deleteAllRules(); 255 } 256 isPrepared = false; 257 } 258 } 259 if (isPrepared) { 260 getDeductionsGraph().delete(t); 261 engine.delete(t); 262 } 263 lpbEngine.reset(); 264 } 265 266 269 274 public void resetLPProfile(boolean enable) { 275 lpbEngine.resetProfile(enable); 276 } 277 278 281 public void printLPProfile() { 282 lpbEngine.printProfile(); 283 } 284 285 } 286 287 288 289 | Popular Tags |