Search in sources :

Example 71 with OWLOntology

use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.

the class TestOntologyReconciliation method anonymousFromStreamWithCustomKeys.

/*
     * If an anonymous ontology is loaded from a stream and at least one override is provided, the first
     * override should be the primary key, while every other override should be an alias for that key.
     */
@Test
public void anonymousFromStreamWithCustomKeys() throws Exception {
    OWLOntologyID myKey = new OWLOntologyID(IRI.create("nameless"), IRI.create(getClass().getCanonicalName() + "#anonymousFromStreamWithCustomKeys()"));
    OWLOntologyID alias = new OWLOntologyID(IRI.create("nameless"), IRI.create(getClass().getCanonicalName() + "#anonymousFromStreamWithCustomKeys().alias"));
    InputStream in = getClass().getResourceAsStream(location_nameless);
    in.mark(Integer.MAX_VALUE);
    OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
    OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(in);
    assertTrue(o1.isAnonymous());
    in.reset();
    // in = getClass().getResourceAsStream(location); // use if stream cannot be reset
    OWLOntologyID key = ontologyProvider.loadInStore(in, RDF_XML, false, Origin.create(myKey), Origin.create(alias));
    assertNotNull(key);
    assertFalse(key.isAnonymous());
    assertEquals(myKey, key);
    log.info("Anonymous ontology loaded with non-anonymous public key {} (submitted)", key);
    assertEquals(1, ontologyProvider.listAliases(key).size());
    for (OWLOntologyID al : ontologyProvider.listAliases(key)) {
        assertFalse(al.isAnonymous());
        log.info("Named alias detected {}", al);
    }
    // Now retrieve using the alias
    OWLOntology o2 = ontologyProvider.getStoredOntology(alias, OWLOntology.class, false);
    assertTrue(o2.isAnonymous());
    // Cannot equal OWLOntology objects
    assertEquals(o1.getAxioms(), o2.getAxioms());
}
Also used : InputStream(java.io.InputStream) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) Test(org.junit.Test)

Example 72 with OWLOntology

use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.

the class TestStorage method storedOntologyOutlivesScope.

/**
     * If an ontology is removed from a scope, or the scope itself is torn down, this should not result in the
     * deletion of that ontology in general.
     */
@Test
public void storedOntologyOutlivesScope() throws Exception {
    String ephemeralScopeId = "CaducousScope";
    OntologyInputSource<OWLOntology> ois = new RootOntologySource(org.semanticweb.owlapi.model.IRI.create(getClass().getResource("/ontologies/nonexistentcharacters.owl")));
    OWLOntologyID ontologyId = ois.getRootOntology().getOntologyID();
    Scope scope = onManager.createOntologyScope(ephemeralScopeId);
    // Initially, the ontology is not there
    assertFalse(ontologyProvider.hasOntology(ontologyId));
    // Once added, the ontology is there
    scope.getCustomSpace().addOntology(ois);
    assertTrue(ontologyProvider.hasOntology(ontologyId));
    // Once removed from the scope, the ontology is still there
    scope.getCustomSpace().removeOntology(ontologyId);
    assertTrue(ontologyProvider.hasOntology(ontologyId));
    // Once the scope is killed, the ontology is still there
    // TODO find a more appropriate method to kill scopes?
    scope.tearDown();
    assertTrue(ontologyProvider.hasOntology(ontologyId));
}
Also used : Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) RootOntologySource(org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Test(org.junit.Test)

Example 73 with OWLOntology

use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.

the class TestOntologyReconciliation method anonymousFromStream.

/*
     * Anonymous ontologies loaded from a data stream must be stored with at least one non-null and
     * non-anonymous public key.
     */
@Test
public void anonymousFromStream() throws Exception {
    InputStream in = getClass().getResourceAsStream(location_nameless);
    in.mark(Integer.MAX_VALUE);
    OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
    OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(in);
    assertTrue(o1.isAnonymous());
    in.reset();
    // in = getClass().getResourceAsStream(location); // use if stream cannot be reset
    OWLOntologyID key = ontologyProvider.loadInStore(in, RDF_XML, false);
    assertNotNull(key);
    assertFalse(key.isAnonymous());
    log.info("Anonymous ontology loaded with non-anonymous public key {}", key);
    OWLOntology o2 = ontologyProvider.getStoredOntology(key, OWLOntology.class, false);
    assertTrue(o2.isAnonymous());
    // Cannot equal OWLOntology objects
    assertEquals(o1.getAxioms(), o2.getAxioms());
}
Also used : InputStream(java.io.InputStream) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) Test(org.junit.Test)

Example 74 with OWLOntology

use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.

the class TestOntologyReconciliation method namedFromStream.

/*
     * Named ontologies loaded from a data stream should have no aliases and directly reconcile with the
     * ontology IRI.
     */
@Test
public void namedFromStream() throws Exception {
    String location = "/ontologies/naming/named-2.owl";
    OWLOntologyID expectedId = new OWLOntologyID(IRI.create("http://stanbol.apache.org/ontologies/test/naming/named-2"));
    InputStream in = getClass().getResourceAsStream(location);
    in.mark(Integer.MAX_VALUE);
    OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
    OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(in);
    assertFalse(o1.isAnonymous());
    in.reset();
    assertEquals(expectedId, o1.getOntologyID());
    // in = getClass().getResourceAsStream(location); // use if stream cannot be reset
    OWLOntologyID key = ontologyProvider.loadInStore(in, 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 there are no aliases.
    assertSame(0, ontologyProvider.listAliases(expectedId).size());
}
Also used : InputStream(java.io.InputStream) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) Test(org.junit.Test)

Example 75 with OWLOntology

use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.

the class TestOntologyReconciliation method anonymousFromURL.

/*
     * Anonymous ontologies loaded from a URL must reconcile with a public key that matches the resource URL
     * in its ontology IRI.
     */
@Test
public void anonymousFromURL() throws Exception {
    URL in = getClass().getResource(location_nameless);
    OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
    OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(IRI.create(in));
    assertTrue(o1.isAnonymous());
    // in = getClass().getResourceAsStream(location); // use if stream cannot be reset
    OWLOntologyID key = ontologyProvider.loadInStore(IRI.create(in), RDF_XML, false);
    assertNotNull(key);
    assertFalse(key.isAnonymous());
    log.info("Anonymous ontology loaded with non-anonymous public key {}", key);
    OWLOntology o2 = ontologyProvider.getStoredOntology(key, OWLOntology.class, false);
    assertTrue(o2.isAnonymous());
    // Cannot equal OWLOntology objects
    assertEquals(o1.getAxioms(), o2.getAxioms());
}
Also used : OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) URL(java.net.URL) Test(org.junit.Test)

Aggregations

OWLOntology (org.semanticweb.owlapi.model.OWLOntology)118 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)59 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)50 IRI (org.semanticweb.owlapi.model.IRI)31 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)31 Test (org.junit.Test)25 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)24 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)22 HashSet (java.util.HashSet)21 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)18 Produces (javax.ws.rs.Produces)17 AddImport (org.semanticweb.owlapi.model.AddImport)16 OntModel (com.hp.hpl.jena.ontology.OntModel)15 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)15 InputStream (java.io.InputStream)14 GET (javax.ws.rs.GET)14 OWLClass (org.semanticweb.owlapi.model.OWLClass)14 ArrayList (java.util.ArrayList)13 Graph (org.apache.clerezza.commons.rdf.Graph)12 ReasoningServiceException (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException)11