use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project goci by EBISPOT.
the class DefaultGWASOWLConverter method createConversionOntology.
public OWLOntology createConversionOntology() throws OWLConversionException {
try {
// create a new graph to represent our data dump
OWLOntology conversion = getManager().createOntology(IRI.create(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI + "/" + new SimpleDateFormat("yyyy/MM/dd").format(new Date())));
// import the gwas ontology schema and efo
OWLImportsDeclaration gwasImportDecl = getDataFactory().getOWLImportsDeclaration(IRI.create(OntologyConstants.GWAS_ONTOLOGY_SCHEMA_IRI));
ImportChange gwasImport = new AddImport(conversion, gwasImportDecl);
getManager().applyChange(gwasImport);
OWLImportsDeclaration efoImportDecl = getDataFactory().getOWLImportsDeclaration(IRI.create(OntologyConstants.EFO_ONTOLOGY_SCHEMA_IRI));
ImportChange efoImport = new AddImport(conversion, efoImportDecl);
getManager().applyChange(efoImport);
return conversion;
} catch (OWLOntologyCreationException e) {
throw new OWLConversionException("Failed to create new ontology", e);
}
}
use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project goci by EBISPOT.
the class KBMetricsDriver method generateMetricsReport.
/**
* Generate a report on the data metrics of the knowledgebase and write them this report to the supplied output
* stream
*
* @param out the output stream to write the report to
*/
public void generateMetricsReport(OutputStream out) throws MetricsCalculationException, IOException {
try {
// first, calculate data spread in KB
Map<IRI, Integer> metrics = loader.quantifyKnowledgeBase(_efoLocation, _gwasSchemaLocation, _kbLocation);
// build the efo tree
IRITree tree = treeBuilder.buildIRITree(_efoLocation);
// now tree is constructed, overlay counts onto it
walkTreeAndAddCounts(tree.getRootNode(), metrics);
// process the tree and write the "ideal legend" report
treeProcessor.processTree(tree, out);
// write the tree into a report
tree.prettyPrint(out);
} catch (OWLOntologyCreationException e) {
throw new MetricsCalculationException("Failed to calculate metrics because one or more ontologies failed to load " + "(" + e.getMessage() + ")", e);
} catch (URISyntaxException e) {
throw new MetricsCalculationException("Failed to calculate metrics - a reference to a supplied location was not valid " + "(" + e.getMessage() + ")", e);
}
}
use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project goci by EBISPOT.
the class AbstractOntologyLoader method loadOntology.
/**
* Extracts and loads into memory all the class labels and corresponding IRIs. This class makes the assumption that
* one primary label per class exists. If any classes contain multiple rdfs:labels, these classes are ignored.
* <p>
* Once loaded, this method must set the IRI of the ontology, and should add class labels, class types (however you
* chose to implement the concept of a "type") and synonyms, where they exist.
* <p>
* Implementations do not need to concern themselves with resolving imports or physical/logical mappings as this is
* done in initialisation at the abstract level. Subclasses can simply do <code>OWLOntology ontology =
* getManager().loadOntology(IRI.create(getOntologyURI()));</code> as a basic implementation before populating the
* various required caches
*/
protected OWLOntology loadOntology() throws OWLOntologyCreationException {
try {
getLog().debug("Loading ontology...");
OWLOntology ontology = getManager().loadOntology(IRI.create(getOntologyURI()));
IRI ontologyIRI = ontology.getOntologyID().getOntologyIRI();
if (ontologyIRI == null) {
throw new OWLOntologyCreationException("Failed to load ontology from " + getOntologyURI() + ": " + "no IRI present for this ontology");
} else {
setOntologyIRI(ontologyIRI);
if (getOntologyName() == null) {
URI ontologyURI = ontologyIRI.toURI();
String name = ontologyURI.getFragment() != null ? ontologyURI.getFragment() : ontologyURI.getPath();
if (name == null) {
getLog().warn("Can't shorten the name for " + ontologyIRI.toString());
name = ontologyURI.toString();
}
setOntologyName(name);
}
getLog().debug("Successfully loaded ontology " + ontologyIRI);
getLog().debug("Computing indexes...");
return indexOntology(ontology);
}
} finally {
getLog().debug("Done loading/indexing");
}
}
use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.
the class HermitReasoningServiceTest method testRun.
private void testRun(String testID, String expectedID) {
log.info("Testing the run() method");
OWLOntologyManager manager = TestData.manager;
// We prepare the input ontology
try {
OWLOntology testOntology = manager.createOntology();
OWLOntologyID testOntologyID = testOntology.getOntologyID();
log.debug("Created test ontology with ID: {}", testOntologyID);
AddImport addImport = new AddImport(testOntology, TestData.factory.getOWLImportsDeclaration(IRI.create(testID)));
manager.applyChange(addImport);
// We just test class assertions
List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
gens.add(new InferredClassAssertionAxiomGenerator());
// Maybe we want to see what is in before
if (log.isDebugEnabled())
TestUtils.debug(manager.getOntology(testOntologyID), log);
// Now we test the method
log.debug("Running HermiT");
Set<OWLAxiom> inferred = this.theinstance.run(manager.getOntology(testOntologyID), gens);
// Maybe we want to see the inferred axiom list
if (log.isDebugEnabled()) {
TestUtils.debug(inferred, log);
}
// These are the set of expected axioms
Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(IRI.create(expectedID)).getLogicalAxioms();
Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
for (OWLAxiom expected : expectedAxioms) {
if (!inferred.contains(expected)) {
log.error("missing expected axiom: {}", expected);
missing.add(expected);
}
}
log.info("Are all expected axioms in the result (true)? {}", missing.isEmpty());
assertTrue(missing.isEmpty());
// We want to remove the ontology from the manager
manager.removeOntology(testOntology);
} catch (OWLOntologyCreationException e) {
log.error("An {} have been thrown while creating the input ontology for test", e.getClass());
assertTrue(false);
} catch (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (org.apache.stanbol.reasoners.servicesapi.InconsistentInputException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
}
}
use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.
the class OntologyManagerInputProvider method getFromOntoMgr.
private OWLOntology getFromOntoMgr() throws IOException {
try {
Scope scope = null;
synchronized (onManager) {
scope = onManager.getScope(this.scopeId);
}
if (scope == null) {
log.error("Scope {} cannot be retrieved", this.scopeId);
throw new IOException("Scope " + this.scopeId + " cannot be retrieved");
}
Session session = null;
if (sessionManager != null)
synchronized (sessionManager) {
session = sessionManager.getSession(sessionId);
}
if (session == null)
log.warn("Session {} cannot be retrieved. Ignoring.", this.sessionId);
final Set<OWLOntology> set = new HashSet<OWLOntology>();
set.add(scope.export(OWLOntology.class, true));
if (session != null)
set.add(session.export(OWLOntology.class, true));
if (set.size() == 1)
return set.iterator().next();
OWLOntologyMerger merger = new OWLOntologyMerger(new OWLOntologySetProvider() {
@Override
public Set<OWLOntology> getOntologies() {
return set;
}
});
return merger.createMergedOntology(createOWLOntologyManager(), IRI.create("reasoners:input-" + System.currentTimeMillis()));
} catch (OWLOntologyCreationException e) {
String message = "The network for scope/session cannot be retrieved";
log.error(message + ":", e);
throw new IllegalArgumentException(message);
}
}
Aggregations