Search in sources :

Example 6 with OWLOntologyMerger

use of org.semanticweb.owlapi.util.OWLOntologyMerger 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

OWLOntology (org.semanticweb.owlapi.model.OWLOntology)6 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)6 OWLOntologyMerger (org.semanticweb.owlapi.util.OWLOntologyMerger)6 HashSet (java.util.HashSet)5 OWLOntologySetProvider (org.semanticweb.owlapi.model.OWLOntologySetProvider)5 AddImport (org.semanticweb.owlapi.model.AddImport)3 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)3 OWLOntologyChange (org.semanticweb.owlapi.model.OWLOntologyChange)3 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)3 LinkedList (java.util.LinkedList)2 Scope (org.apache.stanbol.ontologymanager.servicesapi.scope.Scope)2 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 OntologySpace (org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace)1 ScopeManager (org.apache.stanbol.ontologymanager.servicesapi.scope.ScopeManager)1 Session (org.apache.stanbol.ontologymanager.servicesapi.session.Session)1