Search in sources :

Example 21 with RDFTerm

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));
    }
}
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 22 with RDFTerm

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;
}
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) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) HashSet(java.util.HashSet)

Example 23 with RDFTerm

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;
}
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) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) HashSet(java.util.HashSet)

Example 24 with RDFTerm

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;
}
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) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) HashSet(java.util.HashSet)

Example 25 with RDFTerm

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.");
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) OntologyCollector(org.apache.stanbol.ontologymanager.servicesapi.collector.OntologyCollector) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) HashSet(java.util.HashSet)

Aggregations

RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)126 IRI (org.apache.clerezza.commons.rdf.IRI)84 Triple (org.apache.clerezza.commons.rdf.Triple)70 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)48 Literal (org.apache.clerezza.commons.rdf.Literal)35 Test (org.junit.Test)35 HashSet (java.util.HashSet)30 HashMap (java.util.HashMap)28 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)26 Graph (org.apache.clerezza.commons.rdf.Graph)24 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)18 ArrayList (java.util.ArrayList)17 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)16 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)13 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)13 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)12 Collection (java.util.Collection)10 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)10 Lock (java.util.concurrent.locks.Lock)9 IOException (java.io.IOException)5