use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class TestOntologyReconciliation method versioned.
/*
* Two versioned ontologies that share their ontology IRI are stored with separate public keys that manage
* their full ontology IDs.
*/
@Test
public void versioned() throws Exception {
OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
// Load the first ontology
String location = "/ontologies/versiontest_v1.owl";
InputStream in = getClass().getResourceAsStream(location);
in.mark(Integer.MAX_VALUE);
// Keep tack of the original in a separate ontology.
OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(in);
assertFalse(o1.isAnonymous());
OWLOntologyID id1 = o1.getOntologyID();
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("Named ontology loaded with public key {}", key);
assertEquals(id1, key);
log.info(" -- (matches actual ontology ID).");
// The unversioned ID should return no match...
OWLOntologyID unversioned = new OWLOntologyID(key.getOntologyIRI());
assertSame(Status.NO_MATCH, ontologyProvider.getStatus(unversioned));
// ...but a query on the available versions should return only the public key.
Set<OWLOntologyID> versions = ontologyProvider.listVersions(key.getOntologyIRI());
assertFalse(versions.isEmpty());
assertSame(1, versions.size());
assertTrue(versions.contains(id1));
// Now load the second version.
location = "/ontologies/versiontest_v2.owl";
in = getClass().getResourceAsStream(location);
in.mark(Integer.MAX_VALUE);
// Keep tack of the original in a separate ontology.
OWLOntology o2 = onMgr.loadOntologyFromOntologyDocument(in);
assertFalse(o2.isAnonymous());
OWLOntologyID id2 = o2.getOntologyID();
in.reset();
// in = getClass().getResourceAsStream(location); // use if stream cannot be reset
key = ontologyProvider.loadInStore(in, RDF_XML, false);
assertNotNull(key);
assertFalse(key.isAnonymous());
log.info("Named ontology loaded with public key {}", key);
assertEquals(id2, key);
log.info(" -- (matches actual ontology ID).");
// The unversioned ID should still return no match...
assertSame(Status.NO_MATCH, ontologyProvider.getStatus(unversioned));
// ...but a query on the available versions should return both public keys now.
versions = ontologyProvider.listVersions(key.getOntologyIRI());
assertFalse(versions.isEmpty());
assertSame(2, versions.size());
assertTrue(versions.contains(id1));
assertTrue(versions.contains(id2));
// Check that axioms match for version 1
log.info("Version 1:");
OWLOntology o1_1 = ontologyProvider.getStoredOntology(id1, OWLOntology.class, false);
assertFalse(o1_1.isAnonymous());
// Cannot equal OWLOntology objects
assertEquals(o1.getOntologyID(), o1_1.getOntologyID());
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.");
// Check that axioms match for version 2 (therefore differ from each other)
log.info("Version 2:");
OWLOntology o2_1 = ontologyProvider.getStoredOntology(id2, OWLOntology.class, false);
assertFalse(o2_1.isAnonymous());
// Cannot equal OWLOntology objects
assertEquals(o2.getOntologyID(), o2_1.getOntologyID());
log.warn("Plain OWL API seems to be failing to preserve owl:versionInfo. Will test non-annotation axioms only.");
assertEquals(o2.getTBoxAxioms(false), o2_1.getTBoxAxioms(false));
log.info(" -- TBox axiom check successful.");
assertEquals(o2.getABoxAxioms(false), o2_1.getABoxAxioms(false));
log.info(" -- ABox axiom check successful.");
// There should be no aliases.
assertSame(0, ontologyProvider.listAliases(unversioned).size());
assertSame(0, ontologyProvider.listAliases(id1).size());
assertSame(0, ontologyProvider.listAliases(id2).size());
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class TestOntologyReconciliation method versionedOnlyFromStream.
/*
* 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.
*/
@Test
public void versionedOnlyFromStream() throws Exception {
String location = "/ontologies/naming/versionedonly.owl";
InputStream in = getClass().getResourceAsStream(location);
in.mark(Integer.MAX_VALUE);
OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(in);
// Ensure that the OWL API erases the version IRI.
assertTrue(o1.isAnonymous());
assertNull(o1.getOntologyID().getVersionIRI());
in.reset();
// in = getClass().getResourceAsStream(location); // use if stream cannot be reset
// The public key must be non-anonymous nonetheless.
OWLOntologyID key = ontologyProvider.loadInStore(in, RDF_XML, false);
assertNotNull(key);
assertFalse(key.isAnonymous());
assertNull(key.getVersionIRI());
log.info("Wrongly versioned ontology loaded with public key {}", key);
assertFalse(o1.equals(key));
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());
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class GraphMultiplexer method removeDependency.
@Override
public void removeDependency(OWLOntologyID dependent, OWLOntologyID dependency) {
if (dependent == null)
throw new IllegalArgumentException("dependent cannot be null");
if (dependency == null)
throw new IllegalArgumentException("dependency cannot be null");
log.debug("Removing dependency.");
log.debug(" ... dependent : {}", dependent);
log.debug(" ... dependency : {}", dependency);
IRI depy = buildResource(dependency);
synchronized (meta) {
Set<OWLOntologyID> aliases = listAliases(dependent);
aliases.add(dependent);
for (OWLOntologyID depalias : aliases) {
IRI dep = buildResource(depalias);
Triple t = new TripleImpl(dep, DEPENDS_ON_URIREF, depy);
boolean found = false;
if (meta.contains(t)) {
found = true;
meta.remove(t);
}
t = new TripleImpl(depy, HAS_DEPENDENT_URIREF, dep);
if (meta.contains(t)) {
found = true;
meta.remove(t);
}
if (!found)
log.warn("No such dependency found.");
else
log.debug("DONE removing dependency.");
}
}
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class GraphMultiplexer method getDependencies.
@Override
public Set<OWLOntologyID> getDependencies(OWLOntologyID dependent) {
Set<OWLOntologyID> dependencies = new HashSet<OWLOntologyID>();
log.debug("Getting dependencies for {}", dependent);
synchronized (meta) {
Set<OWLOntologyID> aliases = listAliases(dependent);
aliases.add(dependent);
for (OWLOntologyID depalias : aliases) {
IRI dep = buildResource(depalias);
Iterator<Triple> it = meta.filter(dep, DEPENDS_ON_URIREF, null);
while (it.hasNext()) {
RDFTerm obj = it.next().getObject();
log.debug(" ... found {} (inverse).", obj);
if (obj instanceof IRI)
dependencies.add(buildPublicKey((IRI) obj));
else
log.warn(" ... Unexpected literal value!");
}
it = meta.filter(null, HAS_DEPENDENT_URIREF, dep);
while (it.hasNext()) {
RDFTerm sub = it.next().getSubject();
log.debug(" ... found {} (inverse).", sub);
if (sub instanceof IRI)
dependencies.add(buildPublicKey((IRI) sub));
else
log.warn(" ... Unexpected literal value!");
}
}
}
return dependencies;
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class ScopeManagerImpl method rebuildScopes.
private void rebuildScopes() {
OntologyNetworkConfiguration struct = ontologyProvider.getOntologyNetworkConfiguration();
for (String scopeId : struct.getScopeIDs()) {
long before = System.currentTimeMillis();
log.debug("Rebuilding scope with ID \"{}\".", scopeId);
Collection<OWLOntologyID> coreOnts = struct.getCoreOntologyKeysForScope(scopeId);
OntologyInputSource<?>[] srcs = new OntologyInputSource<?>[coreOnts.size()];
int i = 0;
for (OWLOntologyID coreOnt : coreOnts) {
log.debug("Core ontology key : {}", coreOnts);
srcs[i++] = new StoredOntologySource(coreOnt);
}
Scope scope;
try {
scope = createOntologyScope(scopeId, srcs);
} catch (DuplicateIDException e) {
String dupe = e.getDuplicateID();
log.warn("Scope \"{}\" already exists and will be reused.", dupe);
scope = getScope(dupe);
}
OntologySpace custom = scope.getCustomSpace();
// Register even if some ontologies were to fail to be restored afterwards.
scopeMap.put(scopeId, scope);
for (OWLOntologyID key : struct.getCustomOntologyKeysForScope(scopeId)) try {
log.debug("Custom ontology key : {}", key);
custom.addOntology(new StoredOntologySource(key));
} catch (MissingOntologyException ex) {
log.error("Could not find an ontology with public key {} to be managed by scope \"{}\". Proceeding to next ontology.", key, scopeId);
continue;
} catch (Exception ex) {
log.error("Exception caught while trying to add ontology with public key " + key + " to rebuilt scope \"" + scopeId + "\". proceeding to next ontology", ex);
continue;
}
log.info("Scope \"{}\" rebuilt in {} ms.", scopeId, System.currentTimeMillis() - before);
}
}
Aggregations