use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl 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.clerezza.commons.rdf.impl.utils.TripleImpl 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.");
}
}
}
use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl 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.impl.utils.TripleImpl in project stanbol by apache.
the class CustomSpaceImpl method getOntologyAsGraph.
@Override
protected Graph getOntologyAsGraph(OWLOntologyID ontologyId, boolean merge, org.semanticweb.owlapi.model.IRI universalPrefix) {
Graph o = super.getOntologyAsGraph(ontologyId, merge, universalPrefix);
switch(getConnectivityPolicy()) {
case LOOSE:
break;
case TIGHT:
// Expected to be a singleton
Set<BlankNodeOrIRI> onts = new HashSet<BlankNodeOrIRI>();
synchronized (o) {
Iterator<Triple> it = o.filter(null, RDF.type, OWL.Ontology);
while (it.hasNext()) onts.add(it.next().getSubject());
}
String s = getID();
// strip "custom"
s = s.substring(0, s.indexOf(SUFFIX));
// concatenate "core"
s += SpaceType.CORE.getIRISuffix();
IRI target = new IRI(universalPrefix + s);
for (BlankNodeOrIRI subject : onts) o.add(new TripleImpl(subject, OWL.imports, target));
break;
default:
break;
}
return o;
}
use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.
the class IndexedGraph method performFilter.
@Override
protected Iterator<Triple> performFilter(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
if (subject == null && predicate == null && object == null) {
// [n,n,n]
return createIterator(spo, spo.iterator());
}
final Triple low = new TripleImpl(subject == null ? MIN : subject, predicate == null ? MIN : predicate, object == null ? MIN : object);
final Triple high = new TripleImpl(subject == null ? MAX : subject, predicate == null ? MAX : predicate, object == null ? MAX : object);
if (subject != null && predicate != null && object != null) {
// NOTE: low.equals(high) in that case!
return createIterator(spo, spo.subSet(low, true, low, true).iterator());
} else if (subject != null && object == null) {
// [S,n,n], [S,P,n]
return createIterator(spo, spo.subSet(low, high).iterator());
} else if (predicate != null) {
// [n,P,n], [n,P,O]
return createIterator(pos, pos.subSet(low, high).iterator());
} else {
// [n,n,O] , [S,n,O]
return createIterator(osp, osp.subSet(low, high).iterator());
}
}
Aggregations