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));
}
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);
}
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));
}
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));
}
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());
}
Aggregations