use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class TestOntologyReconciliation method namedFromURL.
/*
* Named ontologies loaded from an URL must reconcile with both their logical ID and their resource URL
* (through aliasing).
*/
@Test
public void namedFromURL() throws Exception {
String location = "/ontologies/naming/named-1.owl";
OWLOntologyID expectedId = new OWLOntologyID(IRI.create("http://stanbol.apache.org/ontologies/test/naming/named-1"));
URL url = getClass().getResource(location);
OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(IRI.create(url));
assertFalse(o1.isAnonymous());
assertEquals(expectedId, o1.getOntologyID());
// in = getClass().getResourceAsStream(location); // use if stream cannot be reset
OWLOntologyID key = ontologyProvider.loadInStore(IRI.create(url), RDF_XML, false);
assertNotNull(key);
assertFalse(key.isAnonymous());
log.info("Named ontology loaded with public key {}", key);
assertEquals(expectedId, key);
log.info(" -- (matches actual ontology ID).");
OWLOntology o1_1 = ontologyProvider.getStoredOntology(key, OWLOntology.class, false);
assertFalse(o1_1.isAnonymous());
// Cannot equal OWLOntology objects
assertEquals(expectedId, o1_1.getOntologyID());
// Check that axioms match
log.warn("Plain OWL API seems to be failing to preserve owl:versionInfo. Will test non-annotation axioms only.");
assertEquals(o1.getTBoxAxioms(false), o1_1.getTBoxAxioms(false));
log.info(" -- TBox axiom check successful.");
assertEquals(o1.getABoxAxioms(false), o1_1.getABoxAxioms(false));
log.info(" -- ABox axiom check successful.");
// Now check the alias from the physical URL
OWLOntologyID aliasId = new OWLOntologyID(IRI.create(url));
Set<OWLOntologyID> aliases = ontologyProvider.listAliases(expectedId);
assertSame(1, aliases.size());
assertTrue(aliases.contains(aliasId));
// Check that it actually *is* an alias
OWLOntology alias = ontologyProvider.getStoredOntology(aliasId, OWLOntology.class);
assertNotNull(alias);
assertEquals(expectedId, alias.getOntologyID());
// Both ontologies come from the ontology provider and should have preserved ontology annotations.
// Therefore ass axioms should match safely.
assertEquals(o1_1.getAxioms(), alias.getAxioms());
}
Aggregations