1 10 package com.hp.hpl.jena.reasoner.rulesys.impl.oldCode; 11 12 import java.util.*; 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 16 import com.hp.hpl.jena.reasoner.*; 17 import com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph; 18 import com.hp.hpl.jena.reasoner.rulesys.FBRuleReasoner; 19 import com.hp.hpl.jena.reasoner.rulesys.Rule; 20 import com.hp.hpl.jena.reasoner.rulesys.Util; 21 import com.hp.hpl.jena.reasoner.rulesys.impl.OWLRuleTranslationHook; 22 import com.hp.hpl.jena.shared.WrappedIOException; 23 import com.hp.hpl.jena.graph.*; 24 25 31 public class OWLExptRuleReasoner extends FBRuleReasoner { 32 33 34 protected static final String RULE_FILE = "etc/owl-fb.rules"; 35 36 37 protected static List ruleSet; 38 39 40 protected static FBRuleInfGraph preload; 41 42 43 private static final boolean USE_LP = true; 44 45 protected static Log logger = LogFactory.getLog(OWLExptRuleReasoner.class); 46 47 50 public OWLExptRuleReasoner(ReasonerFactory factory) { 51 super(loadRules(), factory); 52 53 } 54 55 59 private OWLExptRuleReasoner(OWLExptRuleReasoner parent, InfGraph schemaGraph) { 60 super(parent.rules, schemaGraph, parent.factory); 61 } 62 63 66 public static List loadRules() { 67 if (ruleSet == null) { 68 try { 69 ruleSet = Rule.parseRules(Util.loadRuleParserFromResourceFile(RULE_FILE)); 70 } catch (WrappedIOException e) { 71 throw new ReasonerException("Can't load rules file: " + RULE_FILE, e); 72 } 73 } 74 return ruleSet; 75 } 76 77 78 82 public Reasoner bindSchema(Graph tbox) throws ReasonerException { 83 if (schemaGraph != null) { 84 throw new ReasonerException("Can only bind one schema at a time to an OWLRuleReasoner"); 85 } 86 FBRuleInfGraph graph = makeInfGraph(rules, tbox, true); 87 graph.addPreprocessingHook(new OWLRuleTranslationHook()); 88 graph.prepare(); 89 return new OWLExptRuleReasoner(this, graph); 90 } 91 92 103 public InfGraph bind(Graph data) throws ReasonerException { 104 FBRuleInfGraph graph = null; 105 InfGraph schemaArg = schemaGraph == null ? getPreload() : (FBRuleInfGraph)schemaGraph; 106 List baseRules = ((FBRuleInfGraph)schemaArg).getRules(); 107 graph = makeInfGraph(baseRules, schemaArg, false); 108 graph.addPreprocessingHook(new OWLRuleTranslationHook()); 109 graph.setDerivationLogging(recordDerivations); 110 graph.setTraceOn(isTraceOn()); 111 graph.rebind(data); 112 113 return graph; 114 } 115 116 119 public InfGraph getPreload() { 120 synchronized (OWLExptRuleReasoner.class) { 121 if (preload == null) { 122 preload = makeInfGraph(rules, null, false); 123 preload.prepare(); 124 } 125 return preload; 126 } 127 } 128 129 133 private FBRuleInfGraph makeInfGraph(List rules, Graph schema, boolean doPreload) { 134 if (USE_LP) { 135 if (doPreload) { 136 return new FBRuleInfGraph(this, rules, getPreload(), schema); 137 } else { 138 return new FBRuleInfGraph(this, rules, schema); 139 } 140 } else { 141 if (doPreload) { 142 return new FBRuleInfGraph(this, rules, getPreload(), schema); 143 } else { 144 return new FBRuleInfGraph(this, rules, schema); 145 } 146 } 147 } 148 } 149 150 151 | Popular Tags |