Search in sources :

Example 6 with Scope

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

the class TestAxiomInterpretation method testCustomAboxCoreTbox.

@Test
public void testCustomAboxCoreTbox() throws Exception {
    String path = "/ontologies/imports-disconnected";
    InputStream content = getClass().getResourceAsStream(path + "/abox.owl");
    OntologyInputSource<?> coreSrc = new GraphContentInputSource(content, SupportedFormat.TURTLE);
    Scope scope = onManager.createOntologyScope("imports-disconnected", coreSrc);
    assertNotNull(scope);
    content = getClass().getResourceAsStream(path + "/tbox.owl");
    OntologyInputSource<?> custSrc = new GraphContentInputSource(content, SupportedFormat.TURTLE);
    scope.getCustomSpace().addOntology(custSrc);
    ImmutableGraph g = scope.export(ImmutableGraph.class, true);
// for (Triple t : g)
// System.out.println(t);
// 
// OWLOntology o = scope.export(OWLOntology.class, true);
// for (OWLAxiom ax : o.getAxioms())
// System.out.println(ax);
}
Also used : Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) InputStream(java.io.InputStream) GraphContentInputSource(org.apache.stanbol.ontologymanager.sources.clerezza.GraphContentInputSource) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) Test(org.junit.Test)

Example 7 with Scope

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

the class TestOntologyNetworkPersistence method updatesGraphOnSpaceModification.

@Test
public void updatesGraphOnSpaceModification() throws Exception {
    // Ensure the metadata graph is there.
    Graph meta = ontologyProvider.getMetaGraph(Graph.class);
    assertNotNull(meta);
    String scopeId = "updateTest";
    Scope scope = onm.createOntologyScope(scopeId, new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/test1.owl")));
    IRI collector = new IRI(_NS_STANBOL_INTERNAL + OntologySpace.shortName + "/" + scope.getCoreSpace().getID());
    // Has no versionIRI
    IRI test1id = new IRI("http://stanbol.apache.org/ontologies/test1.owl");
    // Be strict: the whole property pair must be there.
    IRI predicate = MANAGES_URIREF;
    assertTrue(meta.contains(new TripleImpl(collector, predicate, test1id)));
    predicate = IS_MANAGED_BY_URIREF;
    assertTrue(meta.contains(new TripleImpl(test1id, predicate, collector)));
    // To modify the core space.
    scope.tearDown();
    scope.getCoreSpace().addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/minorcharacters.owl")));
    IRI minorId = new IRI("http://stanbol.apache.org/ontologies/pcomics/minorcharacters.owl");
    predicate = MANAGES_URIREF;
    assertTrue(meta.contains(new TripleImpl(collector, predicate, minorId)));
    predicate = IS_MANAGED_BY_URIREF;
    assertTrue(meta.contains(new TripleImpl(minorId, predicate, collector)));
    scope.getCustomSpace().addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/test1.owl")));
    scope.getCustomSpace().addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/minorcharacters.owl")));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Graph(org.apache.clerezza.commons.rdf.Graph) Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) GraphContentInputSource(org.apache.stanbol.ontologymanager.sources.clerezza.GraphContentInputSource) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) Test(org.junit.Test)

Example 8 with Scope

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

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

the class ScopeManagerImpl method createOntologyScope.

@Override
public Scope createOntologyScope(String scopeID, OntologyInputSource<?>... coreOntologies) throws DuplicateIDException {
    Scope sc = scopeFactory.createOntologyScope(scopeID, coreOntologies);
    configureScope(sc);
    return sc;
}
Also used : Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope)

Example 10 with Scope

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

the class ScopeManagerImpl method rebuildScopes.

private void rebuildScopes() {
    OntologyNetworkConfiguration struct = ontologyProvider.getOntologyNetworkConfiguration();
    for (String scopeId : struct.getScopeIDs()) {
        long before = System.currentTimeMillis();
        log.debug("Rebuilding scope with ID \"{}\".", scopeId);
        Collection<OWLOntologyID> coreOnts = struct.getCoreOntologyKeysForScope(scopeId);
        OntologyInputSource<?>[] srcs = new OntologyInputSource<?>[coreOnts.size()];
        int i = 0;
        for (OWLOntologyID coreOnt : coreOnts) {
            log.debug("Core ontology key : {}", coreOnts);
            srcs[i++] = new StoredOntologySource(coreOnt);
        }
        Scope scope;
        try {
            scope = createOntologyScope(scopeId, srcs);
        } catch (DuplicateIDException e) {
            String dupe = e.getDuplicateID();
            log.warn("Scope \"{}\" already exists and will be reused.", dupe);
            scope = getScope(dupe);
        }
        OntologySpace custom = scope.getCustomSpace();
        // Register even if some ontologies were to fail to be restored afterwards.
        scopeMap.put(scopeId, scope);
        for (OWLOntologyID key : struct.getCustomOntologyKeysForScope(scopeId)) try {
            log.debug("Custom ontology key : {}", key);
            custom.addOntology(new StoredOntologySource(key));
        } catch (MissingOntologyException ex) {
            log.error("Could not find an ontology with public key {} to be managed by scope \"{}\". Proceeding to next ontology.", key, scopeId);
            continue;
        } catch (Exception ex) {
            log.error("Exception caught while trying to add ontology with public key " + key + " to rebuilt scope \"" + scopeId + "\". proceeding to next ontology", ex);
            continue;
        }
        log.info("Scope \"{}\" rebuilt in {} ms.", scopeId, System.currentTimeMillis() - before);
    }
}
Also used : MissingOntologyException(org.apache.stanbol.ontologymanager.servicesapi.collector.MissingOntologyException) StoredOntologySource(org.apache.stanbol.ontologymanager.servicesapi.io.StoredOntologySource) 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) OntologyNetworkConfiguration(org.apache.stanbol.ontologymanager.ontonet.api.OntologyNetworkConfiguration) Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) DuplicateIDException(org.apache.stanbol.ontologymanager.servicesapi.collector.DuplicateIDException) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace) OntologyInputSource(org.apache.stanbol.ontologymanager.servicesapi.io.OntologyInputSource)

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