Search in sources :

Example 31 with TripleImpl

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")));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Graph(org.apache.clerezza.commons.rdf.Graph) Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) GraphContentInputSource(org.apache.stanbol.ontologymanager.sources.clerezza.GraphContentInputSource) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) Test(org.junit.Test)

Example 32 with TripleImpl

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.");
        }
    }
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)

Example 33 with TripleImpl

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));
    }
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) ScopeManager(org.apache.stanbol.ontologymanager.servicesapi.scope.ScopeManager) Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) SessionManager(org.apache.stanbol.ontologymanager.servicesapi.session.SessionManager) SpaceType(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace.SpaceType) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)

Example 34 with TripleImpl

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;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) Graph(org.apache.clerezza.commons.rdf.Graph) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) HashSet(java.util.HashSet)

Example 35 with TripleImpl

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());
    }
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)

Aggregations

TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)143 IRI (org.apache.clerezza.commons.rdf.IRI)104 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)69 Graph (org.apache.clerezza.commons.rdf.Graph)66 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)49 Triple (org.apache.clerezza.commons.rdf.Triple)41 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)26 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)23 HashMap (java.util.HashMap)20 Language (org.apache.clerezza.commons.rdf.Language)20 Literal (org.apache.clerezza.commons.rdf.Literal)20 LiteralFactory (org.apache.clerezza.rdf.core.LiteralFactory)20 IOException (java.io.IOException)18 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)17 Test (org.junit.Test)16 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)15 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)14 HashSet (java.util.HashSet)13 StringSource (org.apache.stanbol.enhancer.servicesapi.impl.StringSource)13 BlankNode (org.apache.clerezza.commons.rdf.BlankNode)11