Search in sources :

Example 86 with OWLOntologyID

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());
}
Also used : OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) URL(java.net.URL) Test(org.junit.Test)

Aggregations

OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)86 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)31 Test (org.junit.Test)27 HashSet (java.util.HashSet)22 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)22 InputStream (java.io.InputStream)20 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)19 Triple (org.apache.clerezza.commons.rdf.Triple)19 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)19 IRI (org.apache.clerezza.commons.rdf.IRI)17 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)16 IRI (org.semanticweb.owlapi.model.IRI)14 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)13 IOException (java.io.IOException)12 UnmodifiableOntologyCollectorException (org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException)12 WebApplicationException (javax.ws.rs.WebApplicationException)11 Graph (org.apache.clerezza.commons.rdf.Graph)10 AddImport (org.semanticweb.owlapi.model.AddImport)10 Path (javax.ws.rs.Path)9 OntologySpace (org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace)8