Search in sources :

Example 46 with OWLOntologyManager

use of org.semanticweb.owlapi.model.OWLOntologyManager 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 47 with OWLOntologyManager

use of org.semanticweb.owlapi.model.OWLOntologyManager 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 48 with OWLOntologyManager

use of org.semanticweb.owlapi.model.OWLOntologyManager 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 49 with OWLOntologyManager

use of org.semanticweb.owlapi.model.OWLOntologyManager 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)

Example 50 with OWLOntologyManager

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

the class TestOntologyReconciliation method versionedOnlyFromURL.

/*
     * If an ontology has no ontology IRI but does have a version IRI, it should still be possible to load it,
     * but the version IRI must be erased. Plus, the public key should be created after the resource URL.
     */
@Test
public void versionedOnlyFromURL() throws Exception {
    String location = "/ontologies/naming/versionedonly.owl";
    IRI url = IRI.create(getClass().getResource(location));
    OWLOntologyID expected = new OWLOntologyID(url);
    OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
    OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(url);
    // Ensure that the OWL API erases the version IRI.
    assertTrue(o1.isAnonymous());
    assertNull(o1.getOntologyID().getVersionIRI());
    // The public key must be non-anonymous nonetheless.
    OWLOntologyID key = ontologyProvider.loadInStore(url, RDF_XML, false);
    assertNotNull(key);
    assertFalse(key.isAnonymous());
    log.info("Wrongly versioned ontology loaded with public key {}", key);
    assertFalse(o1.equals(key));
    assertEquals(expected, key);
    log.info(" -- (matches resource URL).");
    OWLOntology o1_1 = ontologyProvider.getStoredOntology(key, OWLOntology.class, false);
    assertNotNull(o1_1);
    assertTrue(o1_1.isAnonymous());
    assertNull(o1_1.getOntologyID().getVersionIRI());
    // Cannot equal two OWLOntology objects, especially if anonymous.
    // Check that they match axiom-wise.
    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.");
    // No aliases should have been created.
    assertSame(0, ontologyProvider.listAliases(key).size());
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) Test(org.junit.Test)

Aggregations

OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)83 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)52 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)42 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)23 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)21 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)17 IRI (org.semanticweb.owlapi.model.IRI)14 HashSet (java.util.HashSet)13 AddImport (org.semanticweb.owlapi.model.AddImport)12 OWLClass (org.semanticweb.owlapi.model.OWLClass)12 Test (org.junit.Test)11 ReasoningServiceException (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException)10 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)10 OntModel (com.hp.hpl.jena.ontology.OntModel)9 InputStream (java.io.InputStream)9 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)9 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)9 ArrayList (java.util.ArrayList)8 InconsistentInputException (org.apache.stanbol.reasoners.servicesapi.InconsistentInputException)8 OWLOntologyChange (org.semanticweb.owlapi.model.OWLOntologyChange)8