use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class GraphMultiplexer method getPublicKeys.
@Override
public Set<OWLOntologyID> getPublicKeys() {
Set<OWLOntologyID> result = new HashSet<OWLOntologyID>();
Iterator<Triple> it = meta.filter(null, RDF.type, ENTRY_URIREF);
while (it.hasNext()) {
RDFTerm obj = it.next().getSubject();
if (obj instanceof IRI)
result.add(buildPublicKey((IRI) obj));
}
return result;
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class TestOntologyNetworkPersistence method sessionPreservesManagedOntologies.
@Test
public void sessionPreservesManagedOntologies() throws Exception {
// The kind of thing an idiot would have on his luggage.
String id = "12345";
Session session = sessionManager.createSession(id);
// Anonymous ontologies must preserve their public keys!
session.addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/nameless_ontology.owl")));
// Same for named ontologies...
session.addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/nonexistentcharacters.owl")));
// ... and versioned ontologies too.
session.addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/versiontest_v1.owl")));
session.addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/versiontest_v2.owl")));
Collection<OWLOntologyID> managed = session.listManagedOntologies();
assertEquals(4, managed.size());
// Simulate Stanbol going down.
log.info("Stanbol going down...");
// but keep the TcProvider
resetOntologyProvider();
resetManagers();
Session ses = sessionManager.getSession(id);
assertNotNull(ses);
assertEquals(managed, ses.listManagedOntologies());
// XXX Remember that only weak equality is implemented.
assertEquals(session, ses);
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class TestAliasing method cannotReplaceExistingDataStream.
@Test
public void cannotReplaceExistingDataStream() throws Exception {
// Create a new full entry.
String location = "/ontologies/test1.owl";
InputStream in = getClass().getResourceAsStream(location);
OWLOntologyID key = ontologyProvider.loadInStore(in, RDF_XML, false);
log.info("Created and filled entry {}", key);
assertNotNull(key);
assertEquals(MATCH, ontologyProvider.getStatus(key));
assertEquals(1, ontologyProvider.listAllRegisteredEntries().size());
// Try to replace the data stream of a full entry (should fail).
location = "/ontologies/mockfoaf.rdf";
in = getClass().getResourceAsStream(location);
try {
OWLOntologyID wrongKey = ontologyProvider.loadInStore(in, RDF_XML, false, Origin.create(key));
log.error("Replaced existing data stream. This should not happen.");
log.error(" ... key: ", wrongKey);
fail("Replaced existing data stream without warning.");
} catch (Exception ex) {
log.info("Caught exception of type {}", ex.getClass().getCanonicalName());
assertEquals(MATCH, ontologyProvider.getStatus(key));
assertEquals(1, ontologyProvider.listAllRegisteredEntries().size());
assertEquals(1, ontologyProvider.listPrimaryKeys().size());
}
// Create a new uncharted entry and fill its data stream with the failed one.
OWLOntologyID uncharted = new OWLOntologyID(IRI.create(prefix), IRI.create(getClass().getCanonicalName() + "#cannotReplaceExistingDataStream()"));
ontologyProvider.createBlankOntologyEntry(uncharted);
assertEquals(UNCHARTED, ontologyProvider.getStatus(uncharted));
in = getClass().getResourceAsStream(location);
ontologyProvider.loadInStore(in, RDF_XML, false, Origin.create(uncharted));
assertEquals(MATCH, ontologyProvider.getStatus(uncharted));
assertEquals(2, ontologyProvider.listPrimaryKeys().size());
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class TestAliasing method canCreateUnchartedOnce.
@Test
public void canCreateUnchartedOnce() throws Exception {
OWLOntologyID uncharted = new OWLOntologyID(IRI.create(prefix), IRI.create(getClass().getCanonicalName() + "#canCreateUnchartedOnce()"));
OWLOntologyID uncharted_copy = ontologyProvider.createBlankOntologyEntry(uncharted);
log.info("Created uncharted ontology entry.");
log.info(" ... key: {}", uncharted);
assertEquals(uncharted, uncharted_copy);
assertEquals(UNCHARTED, ontologyProvider.getStatus(uncharted));
int entries = ontologyProvider.listAllRegisteredEntries().size();
log.info("{} entries registered.", entries);
try {
log.info("Re-creating uncharted ontology entry...");
OWLOntologyID recreated = ontologyProvider.createBlankOntologyEntry(uncharted);
log.error(" ... Created same entry twice. This should not happen.");
log.error(" ... key: {}", recreated);
fail("Created same entry twice. This should not happen.");
} catch (Exception ex) {
log.info(" ... Creation failed. This is expected.");
assertEquals(UNCHARTED, ontologyProvider.getStatus(uncharted));
int newsize = ontologyProvider.listAllRegisteredEntries().size();
assertEquals(entries, newsize);
log.info("{} entries registered.", newsize);
assertTrue(ontologyProvider.listOrphans().contains(uncharted));
assertFalse(ontologyProvider.listPrimaryKeys().contains(uncharted));
}
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class TestOntologyReconciliation method anonymousFromURLWithCustomKeys.
/*
* If an anonymous ontology is loaded from a URL and at least one override is provided, the first override
* should be the primary key, while everything else, including the URL, should be an alias for that key.
*/
@Test
public void anonymousFromURLWithCustomKeys() throws Exception {
OWLOntologyID myKey = new OWLOntologyID(IRI.create("nameless"), IRI.create(getClass().getCanonicalName() + "#anonymousFromURLWithCustomKeys()"));
OWLOntologyID alias = new OWLOntologyID(IRI.create("nameless"), IRI.create(getClass().getCanonicalName() + "#anonymousFromURLWithCustomKeys().alias"));
URL url = getClass().getResource(location_nameless);
OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(IRI.create(url));
assertTrue(o1.isAnonymous());
OWLOntologyID key = ontologyProvider.loadInStore(IRI.create(url), 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);
// should have 2 aliases: the physical location and the submitted alias.
assertEquals(2, 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());
// ... and using the physical IRI
o2 = ontologyProvider.getStoredOntology(new OWLOntologyID(IRI.create(url)), OWLOntology.class, false);
assertTrue(o2.isAnonymous());
// Cannot equal OWLOntology objects
assertEquals(o1.getAxioms(), o2.getAxioms());
}
Aggregations