1 10 package com.hp.hpl.jena.reasoner.rulesys.impl.oldCode; 11 12 13 import com.hp.hpl.jena.rdf.model.*; 14 import com.hp.hpl.jena.reasoner.*; 15 import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry; 16 import com.hp.hpl.jena.reasoner.rulesys.Functor; 17 import com.hp.hpl.jena.reasoner.rulesys.Rule; 18 import com.hp.hpl.jena.reasoner.rulesys.Util; 19 import com.hp.hpl.jena.vocabulary.ReasonerVocabulary; 20 import com.hp.hpl.jena.graph.*; 21 22 import java.util.*; 23 24 35 public class FBLPRuleReasoner implements Reasoner { 36 37 38 protected ReasonerFactory factory; 39 40 41 protected List rules; 42 43 44 protected Graph schemaGraph; 45 46 47 protected boolean recordDerivations = false; 48 49 50 protected boolean traceOn = false; 51 52 53 protected static final boolean cachePreload = true; 54 55 56 protected InfGraph preload; 57 58 59 protected Capabilities capabilities; 60 61 66 public FBLPRuleReasoner(List rules) { 67 this.rules = rules; 68 } 69 70 74 public FBLPRuleReasoner(ReasonerFactory factory) { 75 this(null, factory); 76 } 77 78 83 public FBLPRuleReasoner(List rules, ReasonerFactory factory) { 84 this(rules); 85 this.factory = factory; 86 } 87 88 92 protected FBLPRuleReasoner(List rules, Graph schemaGraph, ReasonerFactory factory) { 93 this(rules, factory); 94 this.schemaGraph = schemaGraph; 95 } 96 97 103 public Model getReasonerCapabilities() { 104 if (factory != null) { 105 return factory.getCapabilities(); 106 } else { 107 return null; 108 } 109 } 110 111 117 public void addDescription(Model configSpec, Resource base) { 118 } 120 121 128 public boolean supportsProperty(Property property) { 129 if (factory == null) return false; 130 Model caps = factory.getCapabilities(); 131 Resource root = caps.getResource(factory.getURI()); 132 return caps.contains(root, ReasonerVocabulary.supportsP, property); 133 } 134 135 139 public Reasoner bindSchema(Graph tbox) throws ReasonerException { 140 if (schemaGraph != null) { 141 throw new ReasonerException("Can only bind one schema at a time to an OWLRuleReasoner"); 142 } 143 FBLPRuleInfGraph graph = new FBLPRuleInfGraph(this, rules, getPreload(), tbox); 144 graph.prepare(); 145 FBLPRuleReasoner fbr = new FBLPRuleReasoner(rules, graph, factory); 146 fbr.setDerivationLogging(recordDerivations); 147 fbr.setTraceOn(traceOn); 148 return fbr; 149 } 150 151 155 public Reasoner bindSchema(Model tbox) throws ReasonerException { 156 return bindSchema(tbox.getGraph()); 157 } 158 159 170 public InfGraph bind(Graph data) throws ReasonerException { 171 Graph schemaArg = schemaGraph == null ? getPreload() : (FBLPRuleInfGraph)schemaGraph; 172 FBLPRuleInfGraph graph = new FBLPRuleInfGraph(this, rules, schemaArg); 173 graph.setDerivationLogging(recordDerivations); 174 graph.setTraceOn(traceOn); 175 graph.rebind(data); 176 return graph; 177 } 178 179 183 public void setRules(List rules) { 184 this.rules = rules; 185 preload = null; 186 } 187 188 192 public List getRules() { 193 return rules; 194 } 195 196 200 public synchronized void tablePredicate(Node predicate) { 201 Rule tablePredicateRule = new Rule("", 203 new ClauseEntry[]{ 204 new Functor("table", new Node[] { predicate }) 205 }, 206 new ClauseEntry[]{}); 207 rules.add(tablePredicateRule); 209 } 210 211 214 protected synchronized InfGraph getPreload() { 215 if (cachePreload && preload == null) { 216 preload = (new FBLPRuleInfGraph(this, rules, null)); 217 preload.prepare(); 218 } 219 return preload; 220 } 221 222 230 public void setDerivationLogging(boolean logOn) { 231 recordDerivations = logOn; 232 } 233 234 238 public void setTraceOn(boolean state) { 239 traceOn = state; 240 } 241 242 254 public void setParameter(Property parameter, Object value) { 255 if (parameter.equals(ReasonerVocabulary.PROPderivationLogging)) { 256 recordDerivations = Util.convertBooleanPredicateArg(parameter, value); 257 } else if (parameter.equals(ReasonerVocabulary.PROPtraceOn)) { 258 traceOn = Util.convertBooleanPredicateArg(parameter, value); 259 } else { 260 throw new IllegalParameterException("Don't recognize configuration parameter " + parameter + " for rule-based reasoner"); 261 } 262 } 263 264 268 public Capabilities getGraphCapabilities() { 269 if (capabilities == null) { 270 capabilities = new BaseInfGraph.InfCapabilities(); 271 } 272 return capabilities; 273 } 274 275 } 276 277 278 279 | Popular Tags |