use of org.apache.clerezza.commons.rdf.RDFTerm 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.RDFTerm 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.RDFTerm 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.RDFTerm in project stanbol by apache.
the class GraphMultiplexer method getPublicKeys.
@Override
public Set<OWLOntologyID> getPublicKeys() {
Set<OWLOntologyID> result = new HashSet<OWLOntologyID>();
Iterator<Triple> it = meta.filter(null, RDF.type, ENTRY_URIREF);
while (it.hasNext()) {
RDFTerm obj = it.next().getSubject();
if (obj instanceof IRI)
result.add(buildPublicKey((IRI) obj));
}
return result;
}
use of org.apache.clerezza.commons.rdf.RDFTerm in project stanbol by apache.
the class GraphMultiplexer method getHandles.
@Override
public Set<OntologyCollector> getHandles(OWLOntologyID publicKey) {
Set<OntologyCollector> handles = new HashSet<OntologyCollector>();
Set<OWLOntologyID> aliases = listAliases(publicKey);
aliases.add(publicKey);
for (OWLOntologyID alias : aliases) {
IRI ontologyId = buildResource(alias);
for (Iterator<Triple> it = meta.filter(null, MANAGES_URIREF, ontologyId); it.hasNext(); ) {
BlankNodeOrIRI sub = it.next().getSubject();
if (sub instanceof IRI)
checkHandle((IRI) sub, handles);
else
throw new InvalidMetaGraphStateException(sub + " is not a valid ontology collector identifer.");
}
for (Iterator<Triple> it = meta.filter(ontologyId, IS_MANAGED_BY_URIREF, null); it.hasNext(); ) {
RDFTerm obj = it.next().getObject();
if (obj instanceof IRI)
checkHandle((IRI) obj, handles);
else
throw new InvalidMetaGraphStateException(obj + " is not a valid ontology collector identifer.");
}
}
return handles;
// throw new UnsupportedOperationException("Not implemented yet.");
}
Aggregations