use of org.apache.stanbol.ontologymanager.servicesapi.scope.Scope in project stanbol by apache.
the class TestAxiomInterpretation method testCustomAboxCoreTbox.
@Test
public void testCustomAboxCoreTbox() throws Exception {
String path = "/ontologies/imports-disconnected";
InputStream content = getClass().getResourceAsStream(path + "/abox.owl");
OntologyInputSource<?> coreSrc = new GraphContentInputSource(content, SupportedFormat.TURTLE);
Scope scope = onManager.createOntologyScope("imports-disconnected", coreSrc);
assertNotNull(scope);
content = getClass().getResourceAsStream(path + "/tbox.owl");
OntologyInputSource<?> custSrc = new GraphContentInputSource(content, SupportedFormat.TURTLE);
scope.getCustomSpace().addOntology(custSrc);
ImmutableGraph g = scope.export(ImmutableGraph.class, true);
// for (Triple t : g)
// System.out.println(t);
//
// OWLOntology o = scope.export(OWLOntology.class, true);
// for (OWLAxiom ax : o.getAxioms())
// System.out.println(ax);
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.Scope in project stanbol by apache.
the class TestOntologyNetworkPersistence method updatesGraphOnSpaceModification.
@Test
public void updatesGraphOnSpaceModification() throws Exception {
// Ensure the metadata graph is there.
Graph meta = ontologyProvider.getMetaGraph(Graph.class);
assertNotNull(meta);
String scopeId = "updateTest";
Scope scope = onm.createOntologyScope(scopeId, new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/test1.owl")));
IRI collector = new IRI(_NS_STANBOL_INTERNAL + OntologySpace.shortName + "/" + scope.getCoreSpace().getID());
// Has no versionIRI
IRI test1id = new IRI("http://stanbol.apache.org/ontologies/test1.owl");
// Be strict: the whole property pair must be there.
IRI predicate = MANAGES_URIREF;
assertTrue(meta.contains(new TripleImpl(collector, predicate, test1id)));
predicate = IS_MANAGED_BY_URIREF;
assertTrue(meta.contains(new TripleImpl(test1id, predicate, collector)));
// To modify the core space.
scope.tearDown();
scope.getCoreSpace().addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/minorcharacters.owl")));
IRI minorId = new IRI("http://stanbol.apache.org/ontologies/pcomics/minorcharacters.owl");
predicate = MANAGES_URIREF;
assertTrue(meta.contains(new TripleImpl(collector, predicate, minorId)));
predicate = IS_MANAGED_BY_URIREF;
assertTrue(meta.contains(new TripleImpl(minorId, predicate, collector)));
scope.getCustomSpace().addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/test1.owl")));
scope.getCustomSpace().addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/minorcharacters.owl")));
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.Scope in project stanbol by apache.
the class GraphMultiplexer method checkHandle.
private void checkHandle(IRI candidate, Set<OntologyCollector> handles) {
/*
* We have to do it like this because we cannot make this class a Component and reference ONManager
* and SessionManager, otherwise an activation cycle will occur.
*/
// FIXME get rid of this.
ScopeManager scopeManager = ScopeManagerImpl.get();
SessionManager sessionManager = SessionManagerImpl.get();
String prefix_scope = _NS_STANBOL_INTERNAL + Scope.shortName + "/", prefix_session = _NS_STANBOL_INTERNAL + Session.shortName + "/";
// TODO check when not explicitly typed.
SpaceType spaceType;
if (meta.contains(new TripleImpl(candidate, RDF.type, SPACE_URIREF))) {
RDFTerm rScope;
Iterator<Triple> parentSeeker = meta.filter(candidate, IS_SPACE_CORE_OF_URIREF, null);
if (parentSeeker.hasNext()) {
rScope = parentSeeker.next().getObject();
spaceType = SpaceType.CORE;
} else {
parentSeeker = meta.filter(candidate, IS_SPACE_CUSTOM_OF_URIREF, null);
if (parentSeeker.hasNext()) {
rScope = parentSeeker.next().getObject();
spaceType = SpaceType.CUSTOM;
} else {
parentSeeker = meta.filter(null, HAS_SPACE_CORE_URIREF, candidate);
if (parentSeeker.hasNext()) {
rScope = parentSeeker.next().getSubject();
spaceType = SpaceType.CORE;
} else {
parentSeeker = meta.filter(null, HAS_SPACE_CUSTOM_URIREF, candidate);
if (parentSeeker.hasNext()) {
rScope = parentSeeker.next().getSubject();
spaceType = SpaceType.CUSTOM;
} else
throw new InvalidMetaGraphStateException("Ontology space " + candidate + " does not declare a parent scope.");
}
}
}
if (!(rScope instanceof IRI))
throw new InvalidMetaGraphStateException(rScope + " is not a legal scope identifier.");
String scopeId = ((IRI) rScope).getUnicodeString().substring(prefix_scope.length());
Scope scope = scopeManager.getScope(scopeId);
switch(spaceType) {
case CORE:
handles.add(scope.getCoreSpace());
break;
case CUSTOM:
handles.add(scope.getCustomSpace());
break;
}
} else if (meta.contains(new TripleImpl(candidate, RDF.type, SESSION_URIREF))) {
String sessionId = candidate.getUnicodeString().substring(prefix_session.length());
handles.add(sessionManager.getSession(sessionId));
}
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.Scope in project stanbol by apache.
the class ScopeManagerImpl method createOntologyScope.
@Override
public Scope createOntologyScope(String scopeID, OntologyInputSource<?>... coreOntologies) throws DuplicateIDException {
Scope sc = scopeFactory.createOntologyScope(scopeID, coreOntologies);
configureScope(sc);
return sc;
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.Scope 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