Search in sources :

Example 1 with ScopeManager

use of org.apache.stanbol.ontologymanager.servicesapi.scope.ScopeManager 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 2 with ScopeManager

use of org.apache.stanbol.ontologymanager.servicesapi.scope.ScopeManager in project stanbol by apache.

the class SessionImpl method exportToOWLOntology.

/**
     * TODO support merging for attached scopes as well?
     */
@Override
protected OWLOntology exportToOWLOntology(boolean merge, org.semanticweb.owlapi.model.IRI universalPrefix) {
    OWLOntology o = super.exportToOWLOntology(merge, universalPrefix);
    org.semanticweb.owlapi.model.IRI iri = o.getOntologyID().getOntologyIRI();
    if (merge) {
        // Re-merge
        // FIXME try to avoid this.
        ScopeManager onm = ScopeManagerImpl.get();
        final Set<OWLOntology> set = new HashSet<OWLOntology>();
        set.add(o);
        for (String scopeID : attachedScopes) {
            log.debug(" ... Merging with attached scope {}.", scopeID);
            Scope sc = onm.getScope(scopeID);
            if (sc != null)
                set.add(sc.export(OWLOntology.class, merge));
            for (OWLOntologyID ontologyId : managedOntologies) {
                set.add(getOntology(ontologyId, OWLOntology.class, true));
            }
            OWLOntologySetProvider provider = new OWLOntologySetProvider() {

                @Override
                public Set<OWLOntology> getOntologies() {
                    return set;
                }
            };
            OWLOntologyMerger merger = new OWLOntologyMerger(provider);
            try {
                o = merger.createMergedOntology(OWLManager.createOWLOntologyManager(), iri);
            } catch (OWLOntologyCreationException e) {
                log.error("Failed to merge imports for ontology " + iri, e);
                o = null;
            }
        }
    } else
        attachScopeImportsOwlApi(o, universalPrefix);
    return o;
}
Also used : OWLOntologyMerger(org.semanticweb.owlapi.util.OWLOntologyMerger) OWLOntologySetProvider(org.semanticweb.owlapi.model.OWLOntologySetProvider) ScopeManager(org.apache.stanbol.ontologymanager.servicesapi.scope.ScopeManager) Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) HashSet(java.util.HashSet)

Aggregations

Scope (org.apache.stanbol.ontologymanager.servicesapi.scope.Scope)2 ScopeManager (org.apache.stanbol.ontologymanager.servicesapi.scope.ScopeManager)2 HashSet (java.util.HashSet)1 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)1 IRI (org.apache.clerezza.commons.rdf.IRI)1 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)1 Triple (org.apache.clerezza.commons.rdf.Triple)1 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)1 SpaceType (org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace.SpaceType)1 SessionManager (org.apache.stanbol.ontologymanager.servicesapi.session.SessionManager)1 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)1 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)1 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)1 OWLOntologySetProvider (org.semanticweb.owlapi.model.OWLOntologySetProvider)1 OWLOntologyMerger (org.semanticweb.owlapi.util.OWLOntologyMerger)1