Search in sources :

Example 6 with RootOntologySource

use of org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource 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 7 with RootOntologySource

use of org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource in project stanbol by apache.

the class TestSessions method zombieSessionClearsContents.

// @Test
public void zombieSessionClearsContents() throws Exception {
    Session ses = sessionManager.createSession();
    ses.addOntology(new RootOntologySource((IRI.create(getClass().getResource("/ontologies/mockfoaf.rdf")))));
    OWLOntologyID expectedKey = new OWLOntologyID(IRI.create("http://xmlns.com/foaf/0.1/"));
    assertTrue(ontologyProvider.hasOntology(expectedKey));
    sessionManager.destroySession(ses.getID());
}
Also used : RootOntologySource(org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Session(org.apache.stanbol.ontologymanager.servicesapi.session.Session)

Example 8 with RootOntologySource

use of org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource in project stanbol by apache.

the class TestSessions method setup.

@BeforeClass
public static void setup() throws Exception {
    OWLOntologyManager mgr = OWLOntologyManagerFactory.createOWLOntologyManager(null);
    src1 = new RootOntologySource(mgr.createOntology(baseIri));
    src2 = new RootOntologySource(mgr.createOntology(baseIri2));
    reset();
}
Also used : RootOntologySource(org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) BeforeClass(org.junit.BeforeClass)

Example 9 with RootOntologySource

use of org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource in project stanbol by apache.

the class TestOntologySpaces method setup.

@BeforeClass
public static void setup() throws Exception {
    factory = onManager.getOntologySpaceFactory();
    if (factory == null)
        fail("Could not instantiate ontology space factory");
    OWLOntologyManager mgr = OWLOntologyManagerFactory.createOWLOntologyManager(onManager.getOfflineConfiguration().getOntologySourceLocations().toArray(new IRI[0]));
    OWLDataFactory df = mgr.getOWLDataFactory();
    ont = mgr.createOntology(baseIri);
    inMemorySrc = new RootOntologySource(ont);
    // Let's state that Linus is a human being
    OWLClass cHuman = df.getOWLClass(IRI.create(baseIri + "/" + Constants.humanBeing));
    OWLIndividual iLinus = df.getOWLNamedIndividual(IRI.create(baseIri + "/" + Constants.linus));
    linusIsHuman = df.getOWLClassAssertionAxiom(cHuman, iLinus);
    mgr.applyChange(new AddAxiom(ont, linusIsHuman));
    ont2 = mgr.createOntology(baseIri2);
    minorSrc = new RootOntologySource(ont2);
    dropSrc = getLocalSource("/ontologies/droppedcharacters.owl", mgr);
    nonexSrc = getLocalSource("/ontologies/nonexistentcharacters.owl", mgr);
    minorSrc = new RootOntologySource(ont2);
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) AddAxiom(org.semanticweb.owlapi.model.AddAxiom) RootOntologySource(org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) BeforeClass(org.junit.BeforeClass)

Example 10 with RootOntologySource

use of org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource in project stanbol by apache.

the class AbstractOntologyCollectorImpl method addOntology.

@Override
public synchronized OWLOntologyID addOntology(OntologyInputSource<?> ontologySource) throws UnmodifiableOntologyCollectorException {
    // Check for error conditions.
    if (locked)
        throw new UnmodifiableOntologyCollectorException(this);
    if (ontologySource == null)
        throw new IllegalArgumentException("Ontology source cannot be null.");
    log.debug("Adding ontology to collector {}", getID());
    OWLOntologyID key = null;
    if (ontologySource.hasRootOntology()) {
        long before = System.currentTimeMillis();
        Object o = ontologySource.getRootOntology();
        // Check the origin anyhow, as it may be useful for setting aliases with physical locations etc.
        if (ontologySource.hasOrigin())
            key = ontologyProvider.loadInStore(o, false, ontologySource.getOrigin());
        else
            key = ontologyProvider.loadInStore(o, false);
        if (key != null) {
            managedOntologies.add(key);
            // Note that imported ontologies are not considered as managed! TODO should we change this?
            log.info("Add ontology completed in {} ms.", (System.currentTimeMillis() - before));
            // Fire the event
            fireOntologyAdded(key);
        }
    } else if (ontologySource.hasOrigin()) {
        // Just the origin : see if it is satisfiable
        log.debug("Checking origin satisfiability...");
        Origin<?> origin = ontologySource.getOrigin();
        Object ref = origin.getReference();
        log.debug("Origin wraps a {}", ref.getClass().getCanonicalName());
        if (ref instanceof org.semanticweb.owlapi.model.IRI)
            try {
                log.debug("Deferring addition to physical IRI {} (if available).", ref);
                key = addOntology(new RootOntologySource((org.semanticweb.owlapi.model.IRI) ref));
            } catch (OWLOntologyCreationException e) {
                throw new RuntimeException(e);
            }
        else if (ref instanceof IRI) {
            log.debug("Deferring addition to stored Clerezza graph {} (if available).", ref);
            key = addOntology(new GraphSource((IRI) ref));
        } else if (ref instanceof OWLOntologyID) {
            OWLOntologyID idref = (OWLOntologyID) ref;
            log.debug("Deferring addition to stored ontology with public key {} (if available).", ref);
            if (!ontologyProvider.hasOntology(idref))
                throw new MissingOntologyException(this, idref);
            key = idref;
            if (managedOntologies.add(idref))
                fireOntologyAdded(idref);
        } else
            throw new IllegalArgumentException("Invalid origin " + origin);
    } else
        throw new IllegalArgumentException("Ontology source must provide either an ontology object, or a way to reference one (i.e. an origin).");
    log.info("Public key : {}", key);
    return key;
}
Also used : Origin(org.apache.stanbol.ontologymanager.servicesapi.io.Origin) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) MissingOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) UnmodifiableOntologyCollectorException(org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) RootOntologySource(org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource) GraphSource(org.apache.stanbol.ontologymanager.sources.clerezza.GraphSource)

Aggregations

RootOntologySource (org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource)11 UnmodifiableOntologyCollectorException (org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException)7 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)7 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)5 IOException (java.io.IOException)4 Consumes (javax.ws.rs.Consumes)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)4 POST (javax.ws.rs.POST)3 DuplicateIDException (org.apache.stanbol.ontologymanager.servicesapi.collector.DuplicateIDException)3 Scope (org.apache.stanbol.ontologymanager.servicesapi.scope.Scope)3 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 IRI (org.apache.clerezza.commons.rdf.IRI)2 LibrarySource (org.apache.stanbol.ontologymanager.registry.io.LibrarySource)2 IrremovableOntologyException (org.apache.stanbol.ontologymanager.servicesapi.collector.IrremovableOntologyException)2 MissingOntologyException (org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException)2 OntologyCollectorModificationException (org.apache.stanbol.ontologymanager.servicesapi.collector.OntologyCollectorModificationException)2 OntologyLoadingException (org.apache.stanbol.ontologymanager.servicesapi.ontology.OntologyLoadingException)2