use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class ClerezzaOntologyProvider method setLocatorMapping.
@Override
public void setLocatorMapping(org.semanticweb.owlapi.model.IRI locator, OWLOntologyID publicKey) {
if (publicKey == null || publicKey.isAnonymous())
throw new IllegalArgumentException("key must be non-null and non-anonymous.");
log.info("Setting {} as the resource locator for ontology {}", locator, publicKey);
new MetaGraphManager(tcManager, keymap.graph).updateAddAlias(new OWLOntologyID(locator), publicKey);
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class AbstractOntologyCollectorImpl method getMergedTc.
private Graph getMergedTc() {
// Takes less memory than the Indexed one
Graph result = new SimpleGraph();
for (OWLOntologyID key : listManagedOntologies()) {
// TODO when implemented, switch to true.
Graph managed = getOntology(key, Graph.class, false);
Set<RDFTerm> exclusions = new HashSet<RDFTerm>();
Iterator<Triple> it = managed.filter(null, RDF.type, OWL.Ontology);
while (it.hasNext()) exclusions.add(it.next().getSubject());
for (Triple t : managed) if (!exclusions.contains(t.getSubject()))
result.add(t);
}
return result;
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class AbstractOntologyCollectorImpl method addOntology.
@Override
public synchronized OWLOntologyID addOntology(OntologyInputSource<?> ontologySource) throws UnmodifiableOntologyCollectorException {
// Check for error conditions.
if (locked)
throw new UnmodifiableOntologyCollectorException(this);
if (ontologySource == null)
throw new IllegalArgumentException("Ontology source cannot be null.");
log.debug("Adding ontology to collector {}", getID());
OWLOntologyID key = null;
if (ontologySource.hasRootOntology()) {
long before = System.currentTimeMillis();
Object o = ontologySource.getRootOntology();
// Check the origin anyhow, as it may be useful for setting aliases with physical locations etc.
if (ontologySource.hasOrigin())
key = ontologyProvider.loadInStore(o, false, ontologySource.getOrigin());
else
key = ontologyProvider.loadInStore(o, false);
if (key != null) {
managedOntologies.add(key);
// Note that imported ontologies are not considered as managed! TODO should we change this?
log.info("Add ontology completed in {} ms.", (System.currentTimeMillis() - before));
// Fire the event
fireOntologyAdded(key);
}
} else if (ontologySource.hasOrigin()) {
// Just the origin : see if it is satisfiable
log.debug("Checking origin satisfiability...");
Origin<?> origin = ontologySource.getOrigin();
Object ref = origin.getReference();
log.debug("Origin wraps a {}", ref.getClass().getCanonicalName());
if (ref instanceof org.semanticweb.owlapi.model.IRI)
try {
log.debug("Deferring addition to physical IRI {} (if available).", ref);
key = addOntology(new RootOntologySource((org.semanticweb.owlapi.model.IRI) ref));
} catch (OWLOntologyCreationException e) {
throw new RuntimeException(e);
}
else if (ref instanceof IRI) {
log.debug("Deferring addition to stored Clerezza graph {} (if available).", ref);
key = addOntology(new GraphSource((IRI) ref));
} else if (ref instanceof OWLOntologyID) {
OWLOntologyID idref = (OWLOntologyID) ref;
log.debug("Deferring addition to stored ontology with public key {} (if available).", ref);
if (!ontologyProvider.hasOntology(idref))
throw new MissingOntologyException(this, idref);
key = idref;
if (managedOntologies.add(idref))
fireOntologyAdded(idref);
} else
throw new IllegalArgumentException("Invalid origin " + origin);
} else
throw new IllegalArgumentException("Ontology source must provide either an ontology object, or a way to reference one (i.e. an origin).");
log.info("Public key : {}", key);
return key;
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class TestStorage method storedOntologyOutlivesScope.
/**
* If an ontology is removed from a scope, or the scope itself is torn down, this should not result in the
* deletion of that ontology in general.
*/
@Test
public void storedOntologyOutlivesScope() throws Exception {
String ephemeralScopeId = "CaducousScope";
OntologyInputSource<OWLOntology> ois = new RootOntologySource(org.semanticweb.owlapi.model.IRI.create(getClass().getResource("/ontologies/nonexistentcharacters.owl")));
OWLOntologyID ontologyId = ois.getRootOntology().getOntologyID();
Scope scope = onManager.createOntologyScope(ephemeralScopeId);
// Initially, the ontology is not there
assertFalse(ontologyProvider.hasOntology(ontologyId));
// Once added, the ontology is there
scope.getCustomSpace().addOntology(ois);
assertTrue(ontologyProvider.hasOntology(ontologyId));
// Once removed from the scope, the ontology is still there
scope.getCustomSpace().removeOntology(ontologyId);
assertTrue(ontologyProvider.hasOntology(ontologyId));
// Once the scope is killed, the ontology is still there
// TODO find a more appropriate method to kill scopes?
scope.tearDown();
assertTrue(ontologyProvider.hasOntology(ontologyId));
}
use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.
the class TestOntologyReconciliation method anonymousFromStream.
/*
* Anonymous ontologies loaded from a data stream must be stored with at least one non-null and
* non-anonymous public key.
*/
@Test
public void anonymousFromStream() throws Exception {
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);
assertNotNull(key);
assertFalse(key.isAnonymous());
log.info("Anonymous ontology loaded with non-anonymous public key {}", key);
OWLOntology o2 = ontologyProvider.getStoredOntology(key, OWLOntology.class, false);
assertTrue(o2.isAnonymous());
// Cannot equal OWLOntology objects
assertEquals(o1.getAxioms(), o2.getAxioms());
}
Aggregations