Search in sources :

Example 51 with OWLOntologyID

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

Example 52 with OWLOntologyID

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

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

the class TestClerezzaSpaces method testAddOntology.

@Test
public void testAddOntology() throws Exception {
    OntologySpace space = null;
    OWLOntologyID logicalId = OWLUtils.extractOntologyID(nonexSrc.getRootOntology());
    assertNotNull(logicalId);
    space = factory.createCustomOntologySpace(scopeId, dropSrc, minorSrc);
    space.addOntology(minorSrc);
    space.addOntology(nonexSrc);
    assertTrue(space.hasOntology(logicalId));
    logicalId = OWLUtils.extractOntologyID(dropSrc.getRootOntology());
    assertNotNull(logicalId);
    assertTrue(space.hasOntology(logicalId));
}
Also used : OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Test(org.junit.Test)

Example 54 with OWLOntologyID

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

the class TestClerezzaSpaces method testRemoveCustomOntology.

@Test
public void testRemoveCustomOntology() throws Exception {
    OntologySpace space = null;
    space = factory.createCustomOntologySpace(scopeId, dropSrc);
    OWLOntologyID dropId = OWLUtils.extractOntologyID(dropSrc.getRootOntology());
    OWLOntologyID nonexId = OWLUtils.extractOntologyID(nonexSrc.getRootOntology());
    space.addOntology(inMemorySrc);
    space.addOntology(nonexSrc);
    // The other remote ontologies may change base IRI...
    // baseIri is maincharacters
    assertTrue(space.hasOntology(baseIri));
    assertTrue(space.hasOntology(dropId));
    assertTrue(space.hasOntology(nonexId));
    space.removeOntology(dropId);
    assertFalse(space.hasOntology(dropId));
    space.removeOntology(nonexId);
    assertFalse(space.hasOntology(nonexId));
// OntologyUtils.printOntology(space.getTopOntology(), System.err);
}
Also used : OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Test(org.junit.Test)

Example 55 with OWLOntologyID

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

the class ClerezzaOntologyProvider method addAlias.

@Override
public boolean addAlias(OWLOntologyID primaryKey, OWLOntologyID alias) {
    log.info("Adding alias for ontology entry.");
    log.info(" ... Primary key : {}", primaryKey);
    log.info(" ... Alias : {}", alias);
    // Check that they do not map to two different ontologies.
    OWLOntologyID already = checkAlias(primaryKey, alias);
    /* if (already != null) throw new IllegalArgumentException */
    log.warn(alias + " is already an alias for primary key " + already);
    // XXX a SPARQL query could come in handy.
    // Nothing to do but defer to the meta graph,
    new MetaGraphManager(tcManager, keymap.graph).updateAddAlias(primaryKey, alias);
    log.info(" ... DONE.");
    return true;
}
Also used : OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID)

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