use of org.apache.clerezza.commons.rdf.Triple 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.clerezza.commons.rdf.Triple in project stanbol by apache.
the class GraphMultiplexer method listAliases.
/*
* XXX see if we can use reasoners, either live or by caching materialisations.
*/
protected Set<OWLOntologyID> listAliases(OWLOntologyID publicKey) {
if (publicKey == null || publicKey.isAnonymous())
throw new IllegalArgumentException("Cannot locate aliases for null or anonymous public keys.");
Set<OWLOntologyID> aliases = new HashSet<OWLOntologyID>();
IRI ont = buildResource(publicKey);
// Forwards
for (Iterator<Triple> it = meta.filter(ont, OWL.sameAs, null); it.hasNext(); ) {
RDFTerm r = it.next().getObject();
if (r instanceof IRI)
aliases.add(buildPublicKey((IRI) r));
}
// Backwards
for (Iterator<Triple> it = meta.filter(null, OWL.sameAs, ont); it.hasNext(); ) {
RDFTerm r = it.next().getSubject();
if (r instanceof IRI)
aliases.add(buildPublicKey((IRI) r));
}
return aliases;
}
use of org.apache.clerezza.commons.rdf.Triple 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.apache.clerezza.commons.rdf.Triple in project stanbol by apache.
the class GraphMultiplexer method updateSessionUnregistration.
private void updateSessionUnregistration(Session session) {
long before = System.currentTimeMillis();
boolean removable = false, conflict = false;
final IRI sessionur = getIRIforSession(session);
Set<Triple> removeUs = new HashSet<Triple>();
for (Iterator<Triple> it = meta.filter(sessionur, null, null); it.hasNext(); ) {
Triple t = it.next();
if (RDF.type.equals(t.getPredicate())) {
if (SESSION_URIREF.equals(t.getObject()))
removable = true;
else
conflict = true;
}
removeUs.add(t);
}
if (!removable) {
log.error("Cannot write session deregistration to persistence:");
log.error("-- resource {}", sessionur);
log.error("-- is not typed as a {} in the meta-graph.", SESSION_URIREF);
} else if (conflict) {
log.error("Conflict upon session deregistration:");
log.error("-- resource {}", sessionur);
log.error("-- has incompatible types in the meta-graph.");
} else {
log.debug("Removing all triples for session \"{}\".", session.getID());
Iterator<Triple> it;
for (it = meta.filter(null, null, sessionur); it.hasNext(); ) removeUs.add(it.next());
for (it = meta.filter(sessionur, null, null); it.hasNext(); ) removeUs.add(it.next());
meta.removeAll(removeUs);
log.debug("Done; removed {} triples in {} ms.", removeUs.size(), System.currentTimeMillis() - before);
}
}
use of org.apache.clerezza.commons.rdf.Triple 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.");
}
}
}
Aggregations