1 10 package com.hp.hpl.jena.reasoner.rulesys; 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.impl.OWLRuleTranslationHook; 18 import com.hp.hpl.jena.shared.impl.JenaParameters; 19 import com.hp.hpl.jena.graph.*; 20 21 27 public class OWLFBRuleReasoner extends FBRuleReasoner { 28 29 30 protected static final String RULE_FILE = "etc/owl-fb.rules"; 31 32 33 protected static List ruleSet; 34 35 36 protected static FBRuleInfGraph staticPreload; 37 38 protected static Log logger = LogFactory.getLog(OWLFBRuleReasoner.class); 39 40 43 public OWLFBRuleReasoner(ReasonerFactory factory) { 44 super(loadRules(), factory); 45 46 } 47 48 52 private OWLFBRuleReasoner(OWLFBRuleReasoner parent, InfGraph schemaGraph) { 53 super(parent.rules, schemaGraph, parent.factory); 54 } 55 56 59 public static List loadRules() { 60 if (ruleSet == null) ruleSet = loadRules( RULE_FILE ); 61 return ruleSet; 62 } 63 64 65 69 public Reasoner bindSchema(Graph tbox) throws ReasonerException { 70 checkArgGraph(tbox); 71 if (schemaGraph != null) { 72 throw new ReasonerException("Can only bind one schema at a time to an OWLRuleReasoner"); 73 } 74 FBRuleInfGraph graph = new FBRuleInfGraph(this, rules, getPreload(), tbox); 75 graph.addPreprocessingHook(new OWLRuleTranslationHook()); 76 graph.prepare(); 77 return new OWLFBRuleReasoner(this, graph); 78 } 79 80 91 public InfGraph bind(Graph data) throws ReasonerException { 92 checkArgGraph(data); 93 FBRuleInfGraph graph = null; 94 InfGraph schemaArg = schemaGraph == null ? getPreload() : (FBRuleInfGraph)schemaGraph; 95 List baseRules = ((FBRuleInfGraph)schemaArg).getRules(); 96 graph = new FBRuleInfGraph(this, baseRules, schemaArg); 97 graph.addPreprocessingHook(new OWLRuleTranslationHook()); 98 graph.setDerivationLogging(recordDerivations); 99 graph.setTraceOn(traceOn); 100 graph.rebind(data); 101 102 return graph; 103 } 104 105 108 public InfGraph getPreload() { 109 synchronized (OWLFBRuleReasoner.class) { 110 if (staticPreload == null) { 111 boolean prior = JenaParameters.enableFilteringOfHiddenInfNodes; 112 try { 113 JenaParameters.enableFilteringOfHiddenInfNodes = true; 114 staticPreload = new FBRuleInfGraph(this, rules, null); 115 staticPreload.prepare(); 116 } finally { 117 JenaParameters.enableFilteringOfHiddenInfNodes = prior; 118 } 119 } 120 return staticPreload; 121 } 122 } 123 124 128 private void checkArgGraph(Graph g) { 129 if (JenaParameters.enableOWLRuleOverOWLRuleWarnings) { 130 if (g instanceof InfGraph) { 131 if (((InfGraph)g).getReasoner() instanceof OWLFBRuleReasoner) { 132 logger.warn("Creating OWL rule reasoner working over another OWL rule reasoner"); 133 } 134 } 135 } 136 } 137 } 138 139 140 | Popular Tags |