Search in sources :

Example 16 with OntologySpace

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

the class ScopeManagerImpl method bootstrapOntologyNetwork.

private void bootstrapOntologyNetwork(OWLOntology configOntology) {
    if (configOntology == null) {
        log.info("Ontology Network Manager starting with empty scope set.");
        return;
    }
    try {
        /**
             * We create and register the scopes before activating
             */
        for (String scopeId : OntologyNetworkConfigurationUtils.getScopes(configOntology)) {
            String[] cores = OntologyNetworkConfigurationUtils.getCoreOntologies(configOntology, scopeId);
            String[] customs = OntologyNetworkConfigurationUtils.getCustomOntologies(configOntology, scopeId);
            // "Be a man. Use printf"
            log.debug("Detected scope \"{}\"", scopeId);
            for (String s : cores) log.debug("\tDetected core ontology {}", s);
            for (String s : customs) log.debug("\tDetected custom ontology {}", s);
            // Create the scope
            log.debug("Rebuilding scope \"{}\"", scopeId);
            Scope sc = null;
            sc = /* factory. */
            createOntologyScope(scopeId, new BlankOntologySource());
            // Populate the core space
            if (cores.length > 0) {
                OntologySpace corespc = sc.getCoreSpace();
                corespc.tearDown();
                for (int i = 0; i < cores.length; i++) try {
                    corespc.addOntology(new RootOntologySource(IRI.create(cores[i])));
                } catch (Exception ex) {
                    log.warn("Failed to import ontology " + cores[i], ex);
                    continue;
                }
            }
            sc.setUp();
            registerScope(sc);
            sc.getCustomSpace().tearDown();
            for (String locationIri : customs) {
                try {
                    OntologyInputSource<?> src = new RootOntologySource(IRI.create(locationIri));
                    sc.getCustomSpace().addOntology(src);
                    log.debug("Added ontology from location {}", locationIri);
                } catch (UnmodifiableOntologyCollectorException e) {
                    log.error("An error occurred while trying to add the ontology from location: " + locationIri, e);
                    continue;
                }
            }
            sc.getCustomSpace().setUp();
        }
        /**
             * Try to get activation policies
             */
        toActivate = OntologyNetworkConfigurationUtils.getScopesToActivate(configOntology);
        for (String scopeID : toActivate) {
            try {
                scopeID = scopeID.trim();
                setScopeActive(scopeID, true);
                log.info("Ontology scope " + scopeID + " activated.");
            } catch (NoSuchScopeException ex) {
                log.warn("Tried to activate unavailable scope " + scopeID + ".");
            } catch (Exception ex) {
                log.error("Exception caught while activating scope " + scopeID + " . Skipping.", ex);
                continue;
            }
        }
    } catch (Throwable e) {
        log.warn("Invalid ONM configuration file found. " + "Starting with blank scope set.", e);
    }
}
Also used : Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) UnmodifiableOntologyCollectorException(org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException) OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace) RootOntologySource(org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource) BlankOntologySource(org.apache.stanbol.ontologymanager.sources.owlapi.BlankOntologySource) NoSuchScopeException(org.apache.stanbol.ontologymanager.servicesapi.scope.NoSuchScopeException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) NoSuchScopeException(org.apache.stanbol.ontologymanager.servicesapi.scope.NoSuchScopeException) MissingOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException) UnmodifiableOntologyCollectorException(org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException) DuplicateIDException(org.apache.stanbol.ontologymanager.servicesapi.collector.DuplicateIDException) IOException(java.io.IOException)

Example 17 with OntologySpace

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

the class ClerezzaCollectorFactory method createCoreOntologySpace.

@Override
public OntologySpace createCoreOntologySpace(String scopeId, OntologyInputSource<?>... coreSources) {
    OntologySpace s = new CoreSpaceImpl(scopeId, namespace, ontologyProvider);
    configureSpace(s, scopeId, coreSources);
    return s;
}
Also used : CoreSpaceImpl(org.apache.stanbol.ontologymanager.multiplexer.clerezza.impl.CoreSpaceImpl) OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace)

Example 18 with OntologySpace

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

the class ClerezzaCollectorFactory method createCustomOntologySpace.

@Override
public OntologySpace createCustomOntologySpace(String scopeId, OntologyInputSource<?>... customSources) {
    OntologySpace s = new CustomSpaceImpl(scopeId, namespace, ontologyProvider);
    configureSpace(s, scopeId, customSources);
    return s;
}
Also used : CustomSpaceImpl(org.apache.stanbol.ontologymanager.multiplexer.clerezza.impl.CustomSpaceImpl) OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace)

Example 19 with OntologySpace

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

the class GraphMultiplexer method onOntologyRemoved.

@Override
public void onOntologyRemoved(OntologyCollector collector, OWLOntologyID removedOntology) {
    log.info("Heard removal of ontology {} from collector {}", removedOntology, collector.getID());
    String colltype = "";
    if (// Cannot be
    collector instanceof Scope)
        // Cannot be
        colltype = Scope.shortName + "/";
    else if (collector instanceof OntologySpace)
        colltype = OntologySpace.shortName + "/";
    else if (collector instanceof Session)
        colltype = Session.shortName + "/";
    IRI c = new IRI(_NS_STANBOL_INTERNAL + colltype + collector.getID());
    Set<OWLOntologyID> aliases = listAliases(removedOntology);
    aliases.add(removedOntology);
    boolean badState = true;
    for (OWLOntologyID alias : aliases) {
        IRI u = buildResource(alias);
        // XXX condense the following code
        log.debug("Checking ({},{}) pattern", c, u);
        for (Iterator<Triple> it = meta.filter(c, null, u); it.hasNext(); ) {
            IRI property = it.next().getPredicate();
            if (collector instanceof OntologySpace || collector instanceof Session) {
                if (property.equals(MANAGES_URIREF))
                    badState = false;
            }
        }
        log.debug("Checking ({},{}) pattern", u, c);
        for (Iterator<Triple> it = meta.filter(u, null, c); it.hasNext(); ) {
            IRI property = it.next().getPredicate();
            if (collector instanceof OntologySpace || collector instanceof Session) {
                if (property.equals(IS_MANAGED_BY_URIREF))
                    badState = false;
            }
        }
        synchronized (meta) {
            if (collector instanceof OntologySpace || collector instanceof Session) {
                meta.remove(new TripleImpl(c, MANAGES_URIREF, u));
                meta.remove(new TripleImpl(u, IS_MANAGED_BY_URIREF, c));
            }
        }
    }
    if (badState)
        throw new InvalidMetaGraphStateException("No relationship found between ontology collector " + c + " and stored ontology " + removedOntology + " (or its aliases).");
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) Session(org.apache.stanbol.ontologymanager.servicesapi.session.Session)

Example 20 with OntologySpace

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

the class GraphMultiplexer method onOntologyAdded.

@Override
public void onOntologyAdded(OntologyCollector collector, OWLOntologyID addedOntology) {
    // When the ontology provider hears an ontology has been added to a collector, it has to register this
    // into the metadata graph.
    // log.info("Heard addition of ontology {} to collector {}", addedOntology, collector.getID());
    // log.info("This ontology is stored as {}", getKey(addedOntology));
    String colltype = "";
    if (// Cannot be
    collector instanceof Scope)
        // Cannot be
        colltype = Scope.shortName + "/";
    else if (collector instanceof OntologySpace)
        colltype = OntologySpace.shortName + "/";
    else if (collector instanceof Session)
        colltype = Session.shortName + "/";
    IRI c = new IRI(_NS_STANBOL_INTERNAL + colltype + collector.getID());
    IRI u = // keymap.getMapping(addedOntology);
    buildResource(addedOntology);
    // TODO OntologyProvider should not be aware of scopes, spaces or sessions. Move elsewhere.
    boolean hasValues = false;
    log.debug("Ontology {}", addedOntology);
    log.debug("-- is already managed by the following collectors :");
    for (Iterator<Triple> it = meta.filter(u, IS_MANAGED_BY_URIREF, null); it.hasNext(); ) {
        hasValues = true;
        log.debug("-- {}", it.next().getObject());
    }
    for (Iterator<Triple> it = meta.filter(null, MANAGES_URIREF, u); it.hasNext(); ) {
        hasValues = true;
        log.debug("-- {} (inverse)", it.next().getSubject());
    }
    if (!hasValues)
        log.debug("-- <none>");
    // Add both inverse triples. This graph has to be traversed efficiently, no need for reasoners.
    IRI predicate1 = null, predicate2 = null;
    if (collector instanceof OntologySpace) {
        predicate1 = MANAGES_URIREF;
        predicate2 = IS_MANAGED_BY_URIREF;
    } else if (collector instanceof Session) {
        // TODO implement model for sessions.
        predicate1 = MANAGES_URIREF;
        predicate2 = IS_MANAGED_BY_URIREF;
    } else {
        log.error("Unrecognized ontology collector type {} for \"{}\". Aborting.", collector.getClass(), collector.getID());
        return;
    }
    if (u != null)
        synchronized (meta) {
            Triple t;
            if (predicate1 != null) {
                t = new TripleImpl(c, predicate1, u);
                boolean b = meta.add(t);
                log.debug((b ? "Successful" : "Redundant") + " addition of meta triple");
                log.debug("-- {} ", t);
            }
            if (predicate2 != null) {
                t = new TripleImpl(u, predicate2, c);
                boolean b = meta.add(t);
                log.debug((b ? "Successful" : "Redundant") + " addition of meta triple");
                log.debug("-- {} ", t);
            }
        }
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) Session(org.apache.stanbol.ontologymanager.servicesapi.session.Session)

Aggregations

OntologySpace (org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace)29 Test (org.junit.Test)13 IRI (org.semanticweb.owlapi.model.IRI)9 UnmodifiableOntologyCollectorException (org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException)8 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)8 Path (javax.ws.rs.Path)7 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)7 GET (javax.ws.rs.GET)6 Produces (javax.ws.rs.Produces)6 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)6 Scope (org.apache.stanbol.ontologymanager.servicesapi.scope.Scope)4 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)4 IOException (java.io.IOException)3 IRI (org.apache.clerezza.commons.rdf.IRI)3 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)3 DuplicateIDException (org.apache.stanbol.ontologymanager.servicesapi.collector.DuplicateIDException)3 MissingOntologyException (org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException)3 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)3 InputStream (java.io.InputStream)2 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)2