1 10 package com.hp.hpl.jena.reasoner; 11 12 import com.hp.hpl.jena.rdf.model.*; 13 import com.hp.hpl.jena.vocabulary.*; 14 import com.hp.hpl.jena.graph.*; 15 import com.hp.hpl.jena.reasoner.dig.DIGReasoner; 16 import com.hp.hpl.jena.reasoner.dig.DIGReasonerFactory; 17 import com.hp.hpl.jena.reasoner.rulesys.DAMLMicroReasonerFactory; 18 import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasonerFactory; 19 import com.hp.hpl.jena.reasoner.rulesys.OWLFBRuleReasonerFactory; 20 import com.hp.hpl.jena.reasoner.rulesys.OWLMicroReasonerFactory; 21 import com.hp.hpl.jena.reasoner.rulesys.OWLMiniReasonerFactory; 22 import com.hp.hpl.jena.reasoner.rulesys.RDFSRuleReasonerFactory; 23 import com.hp.hpl.jena.reasoner.transitiveReasoner.TransitiveReasonerFactory; 24 25 import java.util.*; 26 27 41 public class ReasonerRegistry { 42 43 44 protected static ReasonerRegistry theRegistry; 45 46 47 protected Map reasonerFactories = new HashMap(); 48 49 50 protected Model allDescriptions; 51 52 55 private ReasonerRegistry() { 56 allDescriptions = ModelFactory.createDefaultModel(); 57 register(TransitiveReasonerFactory.theInstance()); 59 register(RDFSRuleReasonerFactory.theInstance()); 60 register(OWLFBRuleReasonerFactory.theInstance()); 61 register(GenericRuleReasonerFactory.theInstance()); 62 register(DAMLMicroReasonerFactory.theInstance()); 63 register(DIGReasonerFactory.theInstance()); 64 register(OWLMicroReasonerFactory.theInstance()); 65 register(OWLMiniReasonerFactory.theInstance()); 66 } 67 68 71 public static ReasonerRegistry theRegistry() { 72 if (theRegistry == null) { 73 theRegistry = new ReasonerRegistry(); 74 } 75 return theRegistry; 76 } 77 78 82 public void register(ReasonerFactory factory) { 83 reasonerFactories.put(factory.getURI(), factory); 84 Model description = factory.getCapabilities(); 85 if (description != null) { 86 allDescriptions.add(description); 87 } 88 allDescriptions.createResource(factory.getURI()) 89 .addProperty(RDF.type, ReasonerVocabulary.ReasonerClass); 90 } 91 92 98 public void register(String reasonerUri, ReasonerFactory factory) { 99 reasonerFactories.put(reasonerUri, factory); 100 allDescriptions.createResource(reasonerUri) 101 .addProperty(RDF.type, ReasonerVocabulary.ReasonerClass); 102 } 103 104 109 public Model getAllDescriptions() { 110 return allDescriptions; 111 } 112 113 120 public Resource getDescription(String uri) { 121 Resource reasonerURI = allDescriptions.getResource(uri); 122 if (allDescriptions.contains(reasonerURI, RDF.type, ReasonerVocabulary.ReasonerClass)) { 123 return reasonerURI; 124 } else { 125 return null; 126 } 127 } 128 129 134 public ReasonerFactory getFactory(String uri) { 135 return (ReasonerFactory)reasonerFactories.get(uri); 136 } 137 138 148 public Reasoner create(String uri, Resource configuration) throws ReasonerException { 149 ReasonerFactory factory = getFactory(uri); 150 if (factory != null) { 151 return factory.create(configuration); 152 } else { 153 throw new ReasonerException("Attempted to instantiate an unknown reasoner: " + uri); 154 } 155 } 156 157 169 public static Node makeDirect(Node node) { 170 String directName = "urn:x-hp-direct-predicate:" + node.getURI().replace(':','_') ; 171 return Node.createURI(directName); 172 } 173 174 175 protected static Reasoner theRDFSReasoner = null; 176 177 180 public static Reasoner getRDFSReasoner() { 181 if (theRDFSReasoner == null) theRDFSReasoner = RDFSRuleReasonerFactory.theInstance().create(null); 182 return theRDFSReasoner; 183 } 184 185 186 187 protected static Reasoner theRDFSSimpleReasoner = null; 188 189 192 public static Reasoner getRDFSSimpleReasoner() { 193 if (theRDFSSimpleReasoner == null) { 194 theRDFSSimpleReasoner = RDFSRuleReasonerFactory.theInstance().create(null); 195 theRDFSSimpleReasoner.setParameter(ReasonerVocabulary.PROPsetRDFSLevel, ReasonerVocabulary.RDFS_SIMPLE); 196 } 197 return theRDFSSimpleReasoner; 198 } 199 200 201 protected static Reasoner theTRANSITIVEReasoner; 202 203 206 public static Reasoner getTransitiveReasoner() { 207 if (theTRANSITIVEReasoner == null) theTRANSITIVEReasoner = TransitiveReasonerFactory.theInstance().create(null); 208 return theTRANSITIVEReasoner; 209 } 210 211 212 protected static Reasoner theOWLReasoner; 213 214 218 public static Reasoner getOWLReasoner() { 219 if (theOWLReasoner == null) theOWLReasoner = OWLFBRuleReasonerFactory.theInstance().create(null); 220 return theOWLReasoner; 221 } 222 223 224 protected static Reasoner theOWLMicroReasoner; 225 226 230 public static Reasoner getOWLMicroReasoner() { 231 if (theOWLMicroReasoner == null) theOWLMicroReasoner = OWLMicroReasonerFactory.theInstance().create(null); 232 return theOWLMicroReasoner; 233 } 234 235 236 protected static Reasoner theOWLMiniReasoner; 237 238 243 public static Reasoner getOWLMiniReasoner() { 244 if (theOWLMiniReasoner == null) theOWLMiniReasoner = OWLMiniReasonerFactory.theInstance().create(null); 245 return theOWLMiniReasoner; 246 } 247 248 254 public static DIGReasoner getDIGReasoner() { 255 return getDIGReasoner( OWL.NAMESPACE, null ); 256 } 257 258 266 public static DIGReasoner getDIGReasoner( Resource lang, Resource config ) { 267 return getDIGReasoner( lang, false, config ); 268 } 269 270 280 public static DIGReasoner getDIGReasoner( Resource lang, boolean withAxioms, Resource config ) { 281 if (!lang.equals( DAML_OIL.NAMESPACE_DAML ) && !lang.equals( OWL.NAMESPACE )) { 282 throw new ReasonerException( "Cannot create DIG reasoner for unknown language: " + lang ); 283 } 284 285 boolean owl = lang.equals( OWL.NAMESPACE ); 286 String axioms = withAxioms ? 287 (owl ? DIGReasonerFactory.DEFAULT_OWL_AXIOMS : DIGReasonerFactory.DEFAULT_DAML_AXIOMS) : 288 null; 289 290 return DIGReasonerFactory.theInstance().create( lang, axioms, config ); 291 } 292 } 293 294 323 324 | Popular Tags |