use of org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource in project stanbol by apache.
the class ScopeManagerImpl method bootstrapOntologyNetwork.
private void bootstrapOntologyNetwork(OWLOntology configOntology) {
if (configOntology == null) {
log.info("Ontology Network Manager starting with empty scope set.");
return;
}
try {
/**
* We create and register the scopes before activating
*/
for (String scopeId : OntologyNetworkConfigurationUtils.getScopes(configOntology)) {
String[] cores = OntologyNetworkConfigurationUtils.getCoreOntologies(configOntology, scopeId);
String[] customs = OntologyNetworkConfigurationUtils.getCustomOntologies(configOntology, scopeId);
// "Be a man. Use printf"
log.debug("Detected scope \"{}\"", scopeId);
for (String s : cores) log.debug("\tDetected core ontology {}", s);
for (String s : customs) log.debug("\tDetected custom ontology {}", s);
// Create the scope
log.debug("Rebuilding scope \"{}\"", scopeId);
Scope sc = null;
sc = /* factory. */
createOntologyScope(scopeId, new BlankOntologySource());
// Populate the core space
if (cores.length > 0) {
OntologySpace corespc = sc.getCoreSpace();
corespc.tearDown();
for (int i = 0; i < cores.length; i++) try {
corespc.addOntology(new RootOntologySource(IRI.create(cores[i])));
} catch (Exception ex) {
log.warn("Failed to import ontology " + cores[i], ex);
continue;
}
}
sc.setUp();
registerScope(sc);
sc.getCustomSpace().tearDown();
for (String locationIri : customs) {
try {
OntologyInputSource<?> src = new RootOntologySource(IRI.create(locationIri));
sc.getCustomSpace().addOntology(src);
log.debug("Added ontology from location {}", locationIri);
} catch (UnmodifiableOntologyCollectorException e) {
log.error("An error occurred while trying to add the ontology from location: " + locationIri, e);
continue;
}
}
sc.getCustomSpace().setUp();
}
/**
* Try to get activation policies
*/
toActivate = OntologyNetworkConfigurationUtils.getScopesToActivate(configOntology);
for (String scopeID : toActivate) {
try {
scopeID = scopeID.trim();
setScopeActive(scopeID, true);
log.info("Ontology scope " + scopeID + " activated.");
} catch (NoSuchScopeException ex) {
log.warn("Tried to activate unavailable scope " + scopeID + ".");
} catch (Exception ex) {
log.error("Exception caught while activating scope " + scopeID + " . Skipping.", ex);
continue;
}
}
} catch (Throwable e) {
log.warn("Invalid ONM configuration file found. " + "Starting with blank scope set.", e);
}
}
use of org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource 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());
}
use of org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource in project stanbol by apache.
the class TestSessions method setup.
@BeforeClass
public static void setup() throws Exception {
OWLOntologyManager mgr = OWLOntologyManagerFactory.createOWLOntologyManager(null);
src1 = new RootOntologySource(mgr.createOntology(baseIri));
src2 = new RootOntologySource(mgr.createOntology(baseIri2));
reset();
}
use of org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource in project stanbol by apache.
the class TestOntologySpaces method setup.
@BeforeClass
public static void setup() throws Exception {
factory = onManager.getOntologySpaceFactory();
if (factory == null)
fail("Could not instantiate ontology space factory");
OWLOntologyManager mgr = OWLOntologyManagerFactory.createOWLOntologyManager(onManager.getOfflineConfiguration().getOntologySourceLocations().toArray(new IRI[0]));
OWLDataFactory df = mgr.getOWLDataFactory();
ont = mgr.createOntology(baseIri);
inMemorySrc = new RootOntologySource(ont);
// Let's state that Linus is a human being
OWLClass cHuman = df.getOWLClass(IRI.create(baseIri + "/" + Constants.humanBeing));
OWLIndividual iLinus = df.getOWLNamedIndividual(IRI.create(baseIri + "/" + Constants.linus));
linusIsHuman = df.getOWLClassAssertionAxiom(cHuman, iLinus);
mgr.applyChange(new AddAxiom(ont, linusIsHuman));
ont2 = mgr.createOntology(baseIri2);
minorSrc = new RootOntologySource(ont2);
dropSrc = getLocalSource("/ontologies/droppedcharacters.owl", mgr);
nonexSrc = getLocalSource("/ontologies/nonexistentcharacters.owl", mgr);
minorSrc = new RootOntologySource(ont2);
}
use of org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource 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;
}
Aggregations