use of org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace 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.servicesapi.scope.OntologySpace in project stanbol by apache.
the class ClerezzaCollectorFactory method createCoreOntologySpace.
@Override
public OntologySpace createCoreOntologySpace(String scopeId, OntologyInputSource<?>... coreSources) {
OntologySpace s = new CoreSpaceImpl(scopeId, namespace, ontologyProvider);
configureSpace(s, scopeId, coreSources);
return s;
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace in project stanbol by apache.
the class ClerezzaCollectorFactory method createCustomOntologySpace.
@Override
public OntologySpace createCustomOntologySpace(String scopeId, OntologyInputSource<?>... customSources) {
OntologySpace s = new CustomSpaceImpl(scopeId, namespace, ontologyProvider);
configureSpace(s, scopeId, customSources);
return s;
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace in project stanbol by apache.
the class GraphMultiplexer method onOntologyRemoved.
@Override
public void onOntologyRemoved(OntologyCollector collector, OWLOntologyID removedOntology) {
log.info("Heard removal of ontology {} from collector {}", removedOntology, collector.getID());
String colltype = "";
if (// Cannot be
collector instanceof Scope)
// Cannot be
colltype = Scope.shortName + "/";
else if (collector instanceof OntologySpace)
colltype = OntologySpace.shortName + "/";
else if (collector instanceof Session)
colltype = Session.shortName + "/";
IRI c = new IRI(_NS_STANBOL_INTERNAL + colltype + collector.getID());
Set<OWLOntologyID> aliases = listAliases(removedOntology);
aliases.add(removedOntology);
boolean badState = true;
for (OWLOntologyID alias : aliases) {
IRI u = buildResource(alias);
// XXX condense the following code
log.debug("Checking ({},{}) pattern", c, u);
for (Iterator<Triple> it = meta.filter(c, null, u); it.hasNext(); ) {
IRI property = it.next().getPredicate();
if (collector instanceof OntologySpace || collector instanceof Session) {
if (property.equals(MANAGES_URIREF))
badState = false;
}
}
log.debug("Checking ({},{}) pattern", u, c);
for (Iterator<Triple> it = meta.filter(u, null, c); it.hasNext(); ) {
IRI property = it.next().getPredicate();
if (collector instanceof OntologySpace || collector instanceof Session) {
if (property.equals(IS_MANAGED_BY_URIREF))
badState = false;
}
}
synchronized (meta) {
if (collector instanceof OntologySpace || collector instanceof Session) {
meta.remove(new TripleImpl(c, MANAGES_URIREF, u));
meta.remove(new TripleImpl(u, IS_MANAGED_BY_URIREF, c));
}
}
}
if (badState)
throw new InvalidMetaGraphStateException("No relationship found between ontology collector " + c + " and stored ontology " + removedOntology + " (or its aliases).");
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace in project stanbol by apache.
the class GraphMultiplexer method onOntologyAdded.
@Override
public void onOntologyAdded(OntologyCollector collector, OWLOntologyID addedOntology) {
// When the ontology provider hears an ontology has been added to a collector, it has to register this
// into the metadata graph.
// log.info("Heard addition of ontology {} to collector {}", addedOntology, collector.getID());
// log.info("This ontology is stored as {}", getKey(addedOntology));
String colltype = "";
if (// Cannot be
collector instanceof Scope)
// Cannot be
colltype = Scope.shortName + "/";
else if (collector instanceof OntologySpace)
colltype = OntologySpace.shortName + "/";
else if (collector instanceof Session)
colltype = Session.shortName + "/";
IRI c = new IRI(_NS_STANBOL_INTERNAL + colltype + collector.getID());
IRI u = // keymap.getMapping(addedOntology);
buildResource(addedOntology);
// TODO OntologyProvider should not be aware of scopes, spaces or sessions. Move elsewhere.
boolean hasValues = false;
log.debug("Ontology {}", addedOntology);
log.debug("-- is already managed by the following collectors :");
for (Iterator<Triple> it = meta.filter(u, IS_MANAGED_BY_URIREF, null); it.hasNext(); ) {
hasValues = true;
log.debug("-- {}", it.next().getObject());
}
for (Iterator<Triple> it = meta.filter(null, MANAGES_URIREF, u); it.hasNext(); ) {
hasValues = true;
log.debug("-- {} (inverse)", it.next().getSubject());
}
if (!hasValues)
log.debug("-- <none>");
// Add both inverse triples. This graph has to be traversed efficiently, no need for reasoners.
IRI predicate1 = null, predicate2 = null;
if (collector instanceof OntologySpace) {
predicate1 = MANAGES_URIREF;
predicate2 = IS_MANAGED_BY_URIREF;
} else if (collector instanceof Session) {
// TODO implement model for sessions.
predicate1 = MANAGES_URIREF;
predicate2 = IS_MANAGED_BY_URIREF;
} else {
log.error("Unrecognized ontology collector type {} for \"{}\". Aborting.", collector.getClass(), collector.getID());
return;
}
if (u != null)
synchronized (meta) {
Triple t;
if (predicate1 != null) {
t = new TripleImpl(c, predicate1, u);
boolean b = meta.add(t);
log.debug((b ? "Successful" : "Redundant") + " addition of meta triple");
log.debug("-- {} ", t);
}
if (predicate2 != null) {
t = new TripleImpl(u, predicate2, c);
boolean b = meta.add(t);
log.debug((b ? "Successful" : "Redundant") + " addition of meta triple");
log.debug("-- {} ", t);
}
}
}
Aggregations