use of org.semanticweb.owlapi.model.OWLOntologyManager in project stanbol by apache.
the class AbstractOWLApiReasoningService method createOWLOntologyManager.
/**
* An OWLOntologyManager to be used to place a target ontology. We don't want to use the manager bound to
* the input ontologies for that, we don't want to interfere with it.
*
* Other {@see OWLApiReasoningService}s may want to change this.
*
* @return
*/
protected OWLOntologyManager createOWLOntologyManager() {
log.info("createOWLOntologyManager()");
// We want a single instance here
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
log.info("manager: {}", manager);
// FIXME Which is the other way of doing this?
// Maybe -> OWLOntologyManagerProperties();
manager.setSilentMissingImportsHandling(true);
// Listening for missing imports
manager.addMissingImportListener(new MissingImportListener() {
@Override
public void importMissing(MissingImportEvent arg0) {
log.warn("Missing import {} ", arg0.getImportedOntologyURI());
}
});
manager.addOntologyLoaderListener(new OWLOntologyLoaderListener() {
@Override
public void finishedLoadingOntology(LoadingFinishedEvent arg0) {
log.info("Finished loading {} (imported: {})", arg0.getOntologyID(), arg0.isImported());
}
@Override
public void startedLoadingOntology(LoadingStartedEvent arg0) {
log.info("Started loading {} (imported: {}) ...", arg0.getOntologyID(), arg0.isImported());
log.info(" ... from {}", arg0.getDocumentIRI().toString());
}
});
return manager;
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project stanbol by apache.
the class AbstractOWLApiReasoningService method run.
/**
* Generic method for running the reasoner
*
* @param input
* @param generators
* @return
*/
@Override
public Set<OWLAxiom> run(OWLOntology input, List<InferredAxiomGenerator<? extends OWLAxiom>> generators) throws ReasoningServiceException, InconsistentInputException {
log.debug("run(OWLOntology input, List<InferredAxiomGenerator<? extends OWLAxiom>> generators)");
try {
// Get the manager
OWLOntologyManager manager = createOWLOntologyManager();
// Get the reasoner
OWLReasoner reasoner = getReasoner(input);
log.info("Running {} reasoner on {} ", reasoner.getClass(), input.getOntologyID());
// To generate inferred axioms
InferredOntologyGenerator inferred = new InferredOntologyGenerator(reasoner, generators);
// We fill an anonymous ontology with the result, the return the
// axiom set
Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
try {
OWLOntology output = manager.createOntology();
log.debug("Created output ontology: {}", output);
try {
inferred.fillOntology(manager, output);
} catch (InconsistentOntologyException i) {
throw i;
} catch (Throwable t) {
log.error("Some problem occurred:\n {}", t.getStackTrace());
throw new ReasoningServiceException();
}
log.debug("Filled ontology: {}", output);
log.debug("Temporary ID is {}", output.getOntologyID());
axioms = manager.getOntology(output.getOntologyID()).getAxioms();
// IMPORTANT We remove the ontology from the manager
manager.removeOntology(output);
} catch (OWLOntologyCreationException e) {
log.error("An exception have been thrown when instantiating the ontology");
throw new ReasoningServiceException();
}
return axioms;
} catch (InconsistentOntologyException inconsistent) {
/**
* TODO Add report. Why it is inconsistent?
*/
throw new InconsistentInputException();
} catch (Exception exception) {
log.error("An exception have been thrown while executing method run()", exception);
throw new ReasoningServiceException();
}
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project goci by EBISPOT.
the class IRITreeBuilder method buildIRITree.
// OntologyLoader ontologyLoader;
//
// @Autowired
// public IRITreeBuilder(OntologyLoader ontologyLoader){
// this.ontologyLoader = ontologyLoader;
// }
public IRITree buildIRITree(URL efoLocation) throws URISyntaxException, OWLOntologyCreationException {
// load efo
getLog().info("Loading efo...");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology efo = manager.loadOntology(IRI.create(efoLocation));
owlNothingIRI = manager.getOWLDataFactory().getOWLNothing().getIRI().toString();
// create a reasoner over efo
getLog().info("Reasoning over efo...");
OWLReasonerFactory factory = new Reasoner.ReasonerFactory();
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
OWLReasoner reasoner = factory.createReasoner(efo, config);
getLog().info("Precomputing inferences...");
reasoner.precomputeInferences();
getLog().info("Checking ontology consistency...");
reasoner.isConsistent();
// get 'top' class
OWLClass topClass = reasoner.getTopClassNode().getRepresentativeElement();
getLog().info("Reasoner 'top class' element is " + topClass.getIRI());
IRITree tree = new IRITree();
// do one level deep manually - should only be experimental factor
IRINode rootNode = null;
OWLClass efClass = null;
NodeSet<OWLClass> subclasses = reasoner.getSubClasses(topClass, true);
for (Node<OWLClass> node : subclasses) {
OWLClass cls = node.getRepresentativeElement();
getLog().debug("Next child of " + topClass + " is " + cls);
if (cls.getIRI().toString().equals(OntologyConstants.EXPERIMENTAL_FACTOR_CLASS_IRI)) {
efClass = cls;
rootNode = new IRINode(cls.getIRI(), getClassLabel(efo, cls));
}
}
if (rootNode != null) {
getLog().info("Building tree... walking ontology from " + rootNode.getLabel() + " down...");
tree.setRootNode(rootNode);
recurse(reasoner, efo, efClass, rootNode);
getLog().info("...Tree build complete!");
} else {
throw new RuntimeException("Could not find Experimental Factor as a child of OWL:Thing");
}
return tree;
}
Aggregations