use of org.semanticweb.owlapi.model.OWLOntology in project goci by EBISPOT.
the class AbstractOntologyLoader method getStringLiteralAnnotationValues.
protected Set<String> getStringLiteralAnnotationValues(OWLOntology ontology, OWLClass ontologyClass, OWLAnnotationProperty annotationProperty) {
Set<String> vals = new HashSet<>();
Collection<OWLAnnotation> annotations = ontologyClass.getAnnotations(ontology, annotationProperty);
annotations.stream().filter(annotation -> annotation.getValue() instanceof OWLLiteral).forEach(annotation -> {
OWLLiteral val = (OWLLiteral) annotation.getValue();
vals.add(val.getLiteral());
});
return vals;
}
use of org.semanticweb.owlapi.model.OWLOntology 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.OWLOntology in project stanbol by apache.
the class HermitReasoningServiceTest method testInstantiation.
@Test
public void testInstantiation() {
log.info("Testing the innstantiation of an HermitReasoningService");
OWLOntology foaf = TestData.manager.getOntology(IRI.create(TestData.FOAF_NS));
// Here we want to be sure that the getReasoner() method creates an
// instance correctly
HermitReasoningService akindofhermit = new HermitReasoningService() {
protected OWLReasoner getReasoner(OWLOntology ontology) {
try {
OWLReasoner reasoner = super.getReasoner(ontology);
assertTrue(reasoner != null);
return reasoner;
} catch (Throwable t) {
log.error("Some prolem occurred while instantiating the HermitReasoningService. Message was: {}", t.getLocalizedMessage());
// We force tests to stop here
assertTrue(false);
return null;
}
}
};
long startHere = System.currentTimeMillis();
// This is possible only because the subclass is in this scope...
akindofhermit.getReasoner(foaf);
long endHere = System.currentTimeMillis();
log.info("Instantiating an Hermit reasoner lasts {} milliseconds", (endHere - startHere));
}
use of org.semanticweb.owlapi.model.OWLOntology 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.OWLOntology 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