use of org.semanticweb.owlapi.model.OWLAxiom in project stanbol by apache.
the class HermitReasoningServiceTest method testClassify.
/**
* We may want to test this method with more then 1 ontology. This is why the implementation is in
* aprivate method. This method tests if all the logical axioms in testExpectedID ontology are inferences
* of the testID ontology.
*
* @param testID
* // The ID of the ontology to be the input (loaded in the TestData.manager)
* @param testExpectedID
* // The ID of the ontology which contains logical axioms expected in the result
*/
private void testClassify(String testID, String testExpectedID) {
log.info("Testing the CLASSIFY task");
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);
manager.applyChange(new AddImport(testOntology, TestData.factory.getOWLImportsDeclaration(IRI.create(testID))));
// 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.runTask(ReasoningService.Tasks.CLASSIFY, manager.getOntology(testOntologyID));
// Maybe we want to see the inferred axiom list
if (log.isDebugEnabled()) {
TestUtils.debug(inferred, log);
}
Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(IRI.create(testExpectedID)).getLogicalAxioms();
Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
for (OWLAxiom expected : expectedAxioms) {
if (!inferred.contains(expected)) {
log.error("missing expected axiom: {}", expected);
missing.add(expected);
}
}
assertTrue(missing.isEmpty());
// We want only Class related axioms in the result set
for (OWLAxiom a : inferred) {
assertTrue(a instanceof OWLClassAssertionAxiom || a instanceof OWLSubClassOfAxiom || a instanceof OWLEquivalentClassesAxiom || a instanceof OWLDisjointClassesAxiom);
}
// 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 (ReasoningServiceException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (InconsistentInputException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (UnsupportedTaskException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
}
}
use of org.semanticweb.owlapi.model.OWLAxiom in project stanbol by apache.
the class HermitReasoningServiceTest method testEnrich.
/**
* We may want to test this method with more then 1 ontology. This is why the implementation is in
* aprivate method. This method tests if all the logical axioms in testExpectedID ontology are inferences
* of the testID ontology.
*
* TODO: This method is the same as testClassify(String,String), with the only difference - the task
* called. We may want to have this procedure isolated.
*
* @param testID
* // The ID of the ontology to be the input (loaded in the TestData.manager)
* @param testExpectedID
* // The ID of the ontology which contains logical axioms expected in the result
*/
private void testEnrich(String testID, String testExpectedID) {
log.info("Testing the ENRICH task");
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);
OWLImportsDeclaration importTest = TestData.factory.getOWLImportsDeclaration(IRI.create(testID));
manager.applyChange(new AddImport(testOntology, importTest));
// 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.runTask(ReasoningService.Tasks.ENRICH, manager.getOntology(testOntologyID));
// Maybe we want to see the inferred axiom list
if (log.isDebugEnabled()) {
TestUtils.debug(inferred, log);
}
Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(IRI.create(testExpectedID)).getLogicalAxioms();
Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
for (OWLAxiom expected : expectedAxioms) {
if (!inferred.contains(expected)) {
log.error("missing expected axiom: {}", expected);
missing.add(expected);
}
}
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 (ReasoningServiceException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (InconsistentInputException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (UnsupportedTaskException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
}
}
use of org.semanticweb.owlapi.model.OWLAxiom in project stanbol by apache.
the class HermitReasoningServiceTest method testEnrichResultTypes.
/**
*
* @param testID
* // The ontology to run
* @param types
* // The type of axioms we expect in the result
*/
private void testEnrichResultTypes(String testID, AxiomType<?>[] types) {
List<AxiomType<?>> typelist = new ArrayList<AxiomType<?>>();
typelist.addAll(Arrays.asList(types));
log.info("Testing the enrich() method (result axioms types)");
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);
OWLImportsDeclaration importTest = TestData.factory.getOWLImportsDeclaration(IRI.create(testID));
manager.applyChange(new AddImport(testOntology, importTest));
// 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.runTask(ReasoningService.Tasks.ENRICH, manager.getOntology(testOntologyID));
// Maybe we want to see the inferred axiom list
if (log.isDebugEnabled()) {
TestUtils.debug(inferred, log);
}
for (OWLAxiom a : inferred) {
typelist.remove(a.getAxiomType());
}
if (!typelist.isEmpty()) {
for (AxiomType<?> t : typelist) log.error("Missing axiom type: {}", t);
}
assertTrue(typelist.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 (ReasoningServiceException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (InconsistentInputException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (UnsupportedTaskException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
}
}
use of org.semanticweb.owlapi.model.OWLAxiom in project stanbol by apache.
the class TestUtils method debug.
public static void debug(OWLOntology ont, Logger log) {
// For debug only
if (log.isDebugEnabled()) {
// We show all axioms in this ontology
log.debug("OntologyID: {}", ont.getOntologyID());
log.debug("Imports:");
// Imports
for (OWLOntology o : ont.getOWLOntologyManager().getImports(ont)) {
log.debug(" - {}", o);
}
log.debug("Axioms:");
for (OWLAxiom a : ont.getAxioms()) log.debug(" - {}", a);
}
}
use of org.semanticweb.owlapi.model.OWLAxiom in project stanbol by apache.
the class UrlInputProvider method getInput.
@Override
public <T> Iterator<T> getInput(Class<T> type) throws IOException {
if (type.isAssignableFrom(OWLAxiom.class)) {
// We add additional axioms
OWLOntology fromUrl;
try {
fromUrl = createOWLOntologyManager().loadOntologyFromOntologyDocument(IRI.create(url));
} catch (OWLOntologyCreationException e) {
throw new IOException(e);
}
Set<OWLOntology> all = fromUrl.getImportsClosure();
List<OWLAxiom> axiomList = new ArrayList<OWLAxiom>();
for (OWLOntology o : all) {
axiomList.addAll(o.getAxioms());
}
final Iterator<OWLAxiom> iterator = axiomList.iterator();
return new Iterator<T>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@SuppressWarnings("unchecked")
@Override
public T next() {
return (T) iterator.next();
}
@Override
public void remove() {
// This iterator is read-only
throw new UnsupportedOperationException("Cannot remove statements from the iterator");
}
};
} else if (type.isAssignableFrom(Statement.class)) {
final OntModel input = ModelFactory.createOntologyModel();
synchronized (url) {
// FIXME: use instead:
// FileManager.get().loadModel
input.read(url);
}
final StmtIterator iterator = input.listStatements();
return new Iterator<T>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@SuppressWarnings("unchecked")
@Override
public T next() {
return (T) iterator.next();
}
@Override
public void remove() {
// This iterator is read-only
throw new UnsupportedOperationException("Cannot remove statements from the iterator");
}
};
} else {
throw new UnsupportedOperationException("This provider does not adapt to the given type");
}
}
Aggregations