Search in sources :

Example 46 with OWLOntologyID

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

the class TestOntologyNetworkPersistence method canRetrieveOntologySingleton.

@Test
public void canRetrieveOntologySingleton() throws Exception {
    OWLOntologyID foaf = new OWLOntologyID(org.semanticweb.owlapi.model.IRI.create("http://xmlns.com/foaf/0.1/"));
    OWLOntology o1;
    // Get the fake FOAF and load it into the ontology provider
    InputStream data = getClass().getResourceAsStream("/ontologies/mockfoaf.rdf");
    // Keep track of its storage key
    OWLOntologyID key = ontologyProvider.loadInStore(data, SupportedFormat.RDF_XML, false);
    assertNotNull(key);
    assertFalse(key.isAnonymous());
    // Retrieve the stored fake FOAF
    assertEquals(1, ontologyProvider.listPrimaryKeys().size());
    o1 = ontologyProvider.getStoredOntology(key, OWLOntology.class, false);
    OWLOntologyID id = o1.getOntologyID();
    assertNotNull(id);
    assertEquals(foaf, id);
    // Check there is a storage key for the (real) ID of the FOAF ontology
    // key = ontologyProvider.getKey(foaf);
    // assertNotNull(key);
    // assertFalse(key.isAnonymous());
    assertTrue(ontologyProvider.hasOntology(foaf));
    log.info("Stanbol going down...");
    // but keep the TcProvider
    resetOntologyProvider();
    assertEquals(1, ontologyProvider.listPrimaryKeys().size());
    // Check again for the FOAF key
    // key = ontologyProvider.getKey(foaf);
    // assertNotNull(key);
    // assertFalse(key.isAnonymous());
    assertTrue(ontologyProvider.hasOntology(foaf));
    // The OWL API implements OWLOntology#equals()
    assertEquals(o1, ontologyProvider.getStoredOntology(key, OWLOntology.class, false));
}
Also used : InputStream(java.io.InputStream) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Test(org.junit.Test)

Example 47 with OWLOntologyID

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

the class TestOntologyNetworkPersistence method scopePreservesManagedOntologies.

@Test
public void scopePreservesManagedOntologies() throws Exception {
    String id = "preserve";
    Scope scope = onManager.createOntologyScope(id, new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/mockfoaf.rdf")));
    scope.getCustomSpace().addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/nonexistentcharacters.owl")));
    Collection<OWLOntologyID> cores = scope.getCoreSpace().listManagedOntologies();
    Collection<OWLOntologyID> customs = scope.getCustomSpace().listManagedOntologies();
    // Simulate Stanbol going down.
    log.info("Stanbol going down...");
    // but keep the TcProvider
    resetOntologyProvider();
    resetManagers();
    Scope sc = onManager.getScope(id);
    assertNotNull(sc);
    assertEquals(cores, sc.getCoreSpace().listManagedOntologies());
    assertEquals(customs, sc.getCustomSpace().listManagedOntologies());
    // XXX Remember that only weak equality is implemented.
    assertEquals(scope, sc);
}
Also used : Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) GraphContentInputSource(org.apache.stanbol.ontologymanager.sources.clerezza.GraphContentInputSource) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Test(org.junit.Test)

Example 48 with OWLOntologyID

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

the class TestOntologyNetworkPersistence method canRetrieveOntologyImported.

@Test
public void canRetrieveOntologyImported() throws Exception {
    String pcomics = "http://stanbol.apache.org/ontologies/pcomics/";
    OWLOntologyID foaf = new OWLOntologyID(org.semanticweb.owlapi.model.IRI.create("http://xmlns.com/foaf/0.1/")), all = new OWLOntologyID(org.semanticweb.owlapi.model.IRI.create(pcomics + "characters_all.owl")), main = new OWLOntologyID(org.semanticweb.owlapi.model.IRI.create(pcomics + "maincharacters.owl")), minor = new OWLOntologyID(org.semanticweb.owlapi.model.IRI.create(pcomics + "minorcharacters.owl"));
    OWLOntology oAll, oMain, oMinor, oFoaf;
    final int total = 4;
    // Load the Peanuts characters_all ontology (has 2 import levels)
    InputStream data = getClass().getResourceAsStream("/ontologies/characters_all.owl");
    OWLOntologyID key = ontologyProvider.loadInStore(data, SupportedFormat.RDF_XML, false);
    assertNotNull(key);
    assertFalse(key.isAnonymous());
    /*
         * characters_all, main, minor + mockfoaf (note: imports are available only because the xml:base is
         * set to be the same as the import target)
         */
    assertEquals(total, ontologyProvider.listPrimaryKeys().size());
    // Check that each imported ontology is stored
    oAll = ontologyProvider.getStoredOntology(all, OWLOntology.class, false);
    OWLOntologyID id = oAll.getOntologyID();
    assertNotNull(id);
    assertEquals(all, id);
    oMain = ontologyProvider.getStoredOntology(main, OWLOntology.class, false);
    id = oMain.getOntologyID();
    assertNotNull(id);
    assertEquals(main, id);
    oMinor = ontologyProvider.getStoredOntology(minor, OWLOntology.class, false);
    id = oMinor.getOntologyID();
    assertNotNull(id);
    assertEquals(minor, id);
    oFoaf = ontologyProvider.getStoredOntology(foaf, OWLOntology.class, false);
    id = oFoaf.getOntologyID();
    assertNotNull(id);
    assertEquals(foaf, id);
    log.info("Stanbol going down...");
    // but keep the TcProvider
    resetOntologyProvider();
    assertEquals(total, ontologyProvider.listPrimaryKeys().size());
    // The OWL API implements OWLOntology#equals()
    assertEquals(oAll, ontologyProvider.getStoredOntology(all, OWLOntology.class, false));
    assertEquals(oMain, ontologyProvider.getStoredOntology(main, OWLOntology.class, false));
    assertEquals(oMinor, ontologyProvider.getStoredOntology(minor, OWLOntology.class, false));
    assertEquals(oFoaf, ontologyProvider.getStoredOntology(foaf, OWLOntology.class, false));
}
Also used : InputStream(java.io.InputStream) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Test(org.junit.Test)

Example 49 with OWLOntologyID

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

the class TestAliasing method canFillDeferred.

@Test
public void canFillDeferred() throws Exception {
    log.info("Creating uncharted ontology entry.");
    OWLOntologyID key = new OWLOntologyID(IRI.create(prefix), IRI.create(getClass().getCanonicalName() + "#canFillDeferred()"));
    log.info(" ... key: {}", key);
    OWLOntologyID key2 = ontologyProvider.createBlankOntologyEntry(key);
    assertEquals(key, key2);
    assertEquals(UNCHARTED, ontologyProvider.getStatus(key));
    String location = "/ontologies/test1.owl";
    log.info("Filling from data stream.");
    log.info(" ... source: {}", getClass().getResource(location));
    log.info(" ... target: {}", key);
    InputStream in = getClass().getResourceAsStream(location);
    key2 = ontologyProvider.loadInStore(in, RDF_XML, false, Origin.create(key));
    assertEquals(key, key2);
    log.info(" ... DONE. Primary keys match.");
    assertEquals(MATCH, ontologyProvider.getStatus(key));
}
Also used : InputStream(java.io.InputStream) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Test(org.junit.Test)

Example 50 with OWLOntologyID

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

the class TestSessions method zombieSessionClearsContents.

// @Test
public void zombieSessionClearsContents() throws Exception {
    Session ses = sessionManager.createSession();
    ses.addOntology(new RootOntologySource((IRI.create(getClass().getResource("/ontologies/mockfoaf.rdf")))));
    OWLOntologyID expectedKey = new OWLOntologyID(IRI.create("http://xmlns.com/foaf/0.1/"));
    assertTrue(ontologyProvider.hasOntology(expectedKey));
    sessionManager.destroySession(ses.getID());
}
Also used : RootOntologySource(org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Session(org.apache.stanbol.ontologymanager.servicesapi.session.Session)

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