use of org.semanticweb.owlapi.model.OWLImportsDeclaration 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.OWLImportsDeclaration in project stanbol by apache.
the class AbstractOntologyCollectorImpl method getOntologyAsOWLOntology.
protected OWLOntology getOntologyAsOWLOntology(OWLOntologyID ontologyId, boolean merge, org.semanticweb.owlapi.model.IRI universalPrefix) {
// if (merge) throw new UnsupportedOperationException("Merge not implemented yet for OWLOntology.");
// Remove the check below. It might be an unmanaged dependency (TODO remove from collector and
// reintroduce check?).
// if (!hasOntology(ontologyIri)) return null;
OWLOntology o;
o = ontologyProvider.getStoredOntology(ontologyId, OWLOntology.class, merge);
if (merge) {
final Set<OWLOntology> set = new HashSet<OWLOntology>();
log.debug("Merging {} with its imports, if any.", o);
set.add(o);
// Actually, if the provider already performed the merge, this won't happen
for (OWLOntology impo : o.getImportsClosure()) {
log.debug("Imported ontology {} will be merged with {}.", impo, o);
set.add(impo);
}
OWLOntologySetProvider provider = new OWLOntologySetProvider() {
@Override
public Set<OWLOntology> getOntologies() {
return set;
}
};
OWLOntologyMerger merger = new OWLOntologyMerger(provider);
try {
o = merger.createMergedOntology(OWLManager.createOWLOntologyManager(), ontologyId.getOntologyIRI());
} catch (OWLOntologyCreationException e) {
log.error("Failed to merge imports for ontology " + ontologyId, e);
// do not reassign the root ontology
}
} else {
// Rewrite import statements
List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
OWLDataFactory df = OWLManager.getOWLDataFactory();
/*
* TODO manage import rewrites better once the container ID is fully configurable (i.e. instead of
* going upOne() add "session" or "ontology" if needed). But only do this if we keep considering
* imported ontologies as *not* managed.
*/
for (OWLImportsDeclaration oldImp : o.getImportsDeclarations()) {
changes.add(new RemoveImport(o, oldImp));
String s = oldImp.getIRI().toString();
// FIXME Ugly way to check, but we'll get through with it
if (s.contains("::"))
s = s.substring(s.indexOf("::") + 2, s.length());
boolean managed = managedOntologies.contains(oldImp.getIRI());
// For space, always go up at least one
String tid = getID();
if (backwardPathLength > 0)
tid = tid.split("/")[0];
org.semanticweb.owlapi.model.IRI target = org.semanticweb.owlapi.model.IRI.create((managed ? universalPrefix + "/" + tid + "/" : URIUtils.upOne(universalPrefix) + "/") + s);
changes.add(new AddImport(o, df.getOWLImportsDeclaration(target)));
}
o.getOWLOntologyManager().applyChanges(changes);
}
return o;
}
use of org.semanticweb.owlapi.model.OWLImportsDeclaration 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.OWLImportsDeclaration in project stanbol by apache.
the class HermitReasoningServiceTest method testIsConsistent.
/**
* Check whether the ontology is consistent
*
* @param testID
* // The ID of the ontology to test
* @param expected
* // If it is expected to be consistent or not
*/
private void testIsConsistent(String testID, boolean expected) {
log.info("Testing the isConsistent 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);
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");
try {
assertTrue(this.theinstance.isConsistent(testOntology) == expected);
} catch (ReasoningServiceException e) {
log.error("Error while testing the isConsistent method. Message was: {}", e.getLocalizedMessage());
assertTrue(false);
}
// 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);
}
}
use of org.semanticweb.owlapi.model.OWLImportsDeclaration in project stanbol by apache.
the class HermitReasoningServiceTest method testClassifyWithRules.
private void testClassifyWithRules(String testID, String rulesID, String testExpectedID) {
log.info("Testing the task CLASSIFY with rules");
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));
Set<SWRLRule> rules = manager.getOntology(IRI.create(rulesID)).getAxioms(AxiomType.SWRL_RULE);
// Maybe we want to see the list of rules
if (log.isDebugEnabled()) {
log.debug("List of {} rules: ", rules.size());
TestUtils.debug(rules, log);
}
log.debug("We add the rules to the ontology");
manager.addAxioms(manager.getOntology(testOntologyID), rules);
// Maybe we want to see what is in before
if (log.isDebugEnabled())
log.debug("Content of the input is:");
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()) {
log.debug("{} inferred axioms:", inferred.size());
TestUtils.debug(inferred, log);
}
Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(IRI.create(testExpectedID)).getLogicalAxioms();
Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
for (OWLAxiom expected : expectedAxioms) {
// We consider here only two kind of axioms
if (expected instanceof OWLSubClassOfAxiom || expected instanceof OWLClassAssertionAxiom) {
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);
}
}
Aggregations