Search in sources :

Example 16 with Scope

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

the class TestOntologyNetworkPersistence method scopePreservesManagedOntologies.

@Test
public void scopePreservesManagedOntologies() throws Exception {
    String id = "preserve";
    Scope scope = onManager.createOntologyScope(id, new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/mockfoaf.rdf")));
    scope.getCustomSpace().addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/nonexistentcharacters.owl")));
    Collection<OWLOntologyID> cores = scope.getCoreSpace().listManagedOntologies();
    Collection<OWLOntologyID> customs = scope.getCustomSpace().listManagedOntologies();
    // Simulate Stanbol going down.
    log.info("Stanbol going down...");
    // but keep the TcProvider
    resetOntologyProvider();
    resetManagers();
    Scope sc = onManager.getScope(id);
    assertNotNull(sc);
    assertEquals(cores, sc.getCoreSpace().listManagedOntologies());
    assertEquals(customs, sc.getCustomSpace().listManagedOntologies());
    // XXX Remember that only weak equality is implemented.
    assertEquals(scope, sc);
}
Also used : Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) GraphContentInputSource(org.apache.stanbol.ontologymanager.sources.clerezza.GraphContentInputSource) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Test(org.junit.Test)

Example 17 with Scope

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

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

the class ClerezzaCollectorFactory method createOntologyScope.

@Override
public Scope createOntologyScope(String scopeID, OntologyInputSource<?>... coreOntologies) throws DuplicateIDException {
    // Scope constructor also creates core and custom spaces
    Scope scope = new ScopeImpl(scopeID, getDefaultNamespace(), this, coreOntologies);
    fireScopeCreated(scope);
    return scope;
}
Also used : Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) ScopeImpl(org.apache.stanbol.ontologymanager.multiplexer.clerezza.impl.ScopeImpl)

Example 19 with Scope

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

the class ScopeSetRenderer method getScopes.

public static OWLOntology getScopes(Set<Scope> scopes) {
    OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
    OWLOntology ont = null;
    try {
        ont = mgr.createOntology();
    } catch (OWLOntologyCreationException e) {
        LoggerFactory.getLogger(ScopeSetRenderer.class).error("KReS :: could not create empty ontology for rendering scopes.", e);
        return null;
    }
    List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
    // The ODP metadata vocabulary is always imported.
    // TODO : also import the ONM meta when it goes online.
    additions.add(new AddImport(ont, __factory.getOWLImportsDeclaration(IRI.create("http://www.ontologydesignpatterns.org/schemas/meta.owl"))));
    for (Scope scope : scopes) {
        OWLNamedIndividual iScope = __factory.getOWLNamedIndividual(IRI.create(scope.getDefaultNamespace() + scope.getID()));
        OWLAxiom ax = __factory.getOWLClassAssertionAxiom(cScope, iScope);
        additions.add(new AddAxiom(ont, ax));
    }
    mgr.applyChanges(additions);
    return ont;
}
Also used : AddAxiom(org.semanticweb.owlapi.model.AddAxiom) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) OWLOntologyChange(org.semanticweb.owlapi.model.OWLOntologyChange) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) AddImport(org.semanticweb.owlapi.model.AddImport) LinkedList(java.util.LinkedList)

Example 20 with Scope

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

the class ScopeRegistryImpl method setScopeActive.

@Override
public void setScopeActive(String scopeID, boolean active) {
    if (!containsScope(scopeID))
        throw new NoSuchScopeException(scopeID);
    // Prevent no-changes from firing events.
    boolean previousStatus = isScopeActive(scopeID);
    Scope scope = getScope(scopeID);
    if (active == previousStatus)
        return;
    if (active) {
        scope.setUp();
        activeScopeIRIs.add(scopeID);
    } else {
        scope.tearDown();
        activeScopeIRIs.remove(scopeID);
    }
    fireScopeActivationChange(scopeID, active);
}
Also used : Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) NoSuchScopeException(org.apache.stanbol.ontologymanager.servicesapi.scope.NoSuchScopeException)

Aggregations

Scope (org.apache.stanbol.ontologymanager.servicesapi.scope.Scope)22 Test (org.junit.Test)7 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)7 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)6 HashSet (java.util.HashSet)5 IRI (org.apache.clerezza.commons.rdf.IRI)5 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)5 IOException (java.io.IOException)4 Triple (org.apache.clerezza.commons.rdf.Triple)4 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)4 OntologySpace (org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace)4 GraphContentInputSource (org.apache.stanbol.ontologymanager.sources.clerezza.GraphContentInputSource)4 Produces (javax.ws.rs.Produces)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)3 UnmodifiableOntologyCollectorException (org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException)3 NoSuchScopeException (org.apache.stanbol.ontologymanager.servicesapi.scope.NoSuchScopeException)3 Session (org.apache.stanbol.ontologymanager.servicesapi.session.Session)3 InputStream (java.io.InputStream)2 POST (javax.ws.rs.POST)2