1 10 package com.hp.hpl.jena.reasoner.rulesys; 11 import com.hp.hpl.jena.rdf.model.*; 12 import com.hp.hpl.jena.reasoner.*; 13 import com.hp.hpl.jena.vocabulary.ReasonerVocabulary; 14 import com.hp.hpl.jena.graph.*; 15 16 import java.util.*; 17 18 23 public class BasicForwardRuleReasoner implements Reasoner { 24 25 26 protected ReasonerFactory factory; 27 28 29 protected List rules; 30 31 32 protected InfGraph schemaGraph; 33 34 35 protected boolean recordDerivations = false; 36 37 38 protected boolean traceOn = false; 39 40 41 protected Capabilities capabilities; 42 43 48 public BasicForwardRuleReasoner(List rules) { 49 this.rules = rules; 50 } 51 52 57 public BasicForwardRuleReasoner(List rules, ReasonerFactory factory) { 58 this.rules = rules; 59 this.factory = factory; 60 } 61 62 66 private BasicForwardRuleReasoner(List rules, InfGraph schemaGraph, ReasonerFactory factory) { 67 this.rules = rules; 68 this.schemaGraph = schemaGraph; 69 this.factory = factory; 70 } 71 72 78 public Model getReasonerCapabilities() { 79 if (factory != null) { 80 return factory.getCapabilities(); 81 } else { 82 return null; 83 } 84 } 85 86 92 public void addDescription(Model configSpec, Resource base) { 93 } 95 96 103 public boolean supportsProperty(Property property) { 104 if (factory == null) return false; 105 Model caps = factory.getCapabilities(); 106 Resource root = caps.getResource(factory.getURI()); 107 return caps.contains(root, ReasonerVocabulary.supportsP, property); 108 } 109 110 114 public Reasoner bindSchema(Graph tbox) throws ReasonerException { 115 InfGraph graph = new BasicForwardRuleInfGraph(this, rules, null, tbox); 116 return new BasicForwardRuleReasoner(rules, graph, factory); 117 } 118 119 123 public Reasoner bindSchema(Model tbox) throws ReasonerException { 124 InfGraph graph = new BasicForwardRuleInfGraph(this, rules, null, tbox.getGraph()); 125 return new BasicForwardRuleReasoner(rules, graph, factory); 126 } 127 128 139 public InfGraph bind(Graph data) throws ReasonerException { 140 BasicForwardRuleInfGraph graph = new BasicForwardRuleInfGraph(this, rules, schemaGraph); 141 graph.setDerivationLogging(recordDerivations); 142 graph.setTraceOn(traceOn); 143 graph.rebind(data); 144 return graph; 145 } 146 147 151 public List getRules() { 152 return rules; 153 } 154 155 163 public void setDerivationLogging(boolean logOn) { 164 recordDerivations = logOn; 165 } 166 167 171 public void setTraceOn(boolean state) { 172 traceOn = state; 173 } 174 175 187 public void setParameter(Property parameter, Object value) { 188 if (parameter.equals(ReasonerVocabulary.PROPderivationLogging)) { 189 recordDerivations = Util.convertBooleanPredicateArg(parameter, value); 190 } else if (parameter.equals(ReasonerVocabulary.PROPtraceOn)) { 191 traceOn = Util.convertBooleanPredicateArg(parameter, value); 192 } else { 193 throw new IllegalParameterException("Don't recognize configuration parameter " + parameter + " for rule-based reasoner"); 194 } 195 } 196 197 198 202 public Capabilities getGraphCapabilities() { 203 if (capabilities == null) { 204 capabilities = new BaseInfGraph.InfCapabilities(); 205 } 206 return capabilities; 207 } 208 209 } 210 211 240 | Popular Tags |