Search in sources :

Example 56 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.

the class ClerezzaOntologyProvider method setLocatorMapping.

@Override
public void setLocatorMapping(org.semanticweb.owlapi.model.IRI locator, OWLOntologyID publicKey) {
    if (publicKey == null || publicKey.isAnonymous())
        throw new IllegalArgumentException("key must be non-null and non-anonymous.");
    log.info("Setting {} as the resource locator for ontology {}", locator, publicKey);
    new MetaGraphManager(tcManager, keymap.graph).updateAddAlias(new OWLOntologyID(locator), publicKey);
}
Also used : OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID)

Example 57 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.

the class AbstractOntologyCollectorImpl method getMergedTc.

private Graph getMergedTc() {
    // Takes less memory than the Indexed one
    Graph result = new SimpleGraph();
    for (OWLOntologyID key : listManagedOntologies()) {
        // TODO when implemented, switch to true.
        Graph managed = getOntology(key, Graph.class, false);
        Set<RDFTerm> exclusions = new HashSet<RDFTerm>();
        Iterator<Triple> it = managed.filter(null, RDF.type, OWL.Ontology);
        while (it.hasNext()) exclusions.add(it.next().getSubject());
        for (Triple t : managed) if (!exclusions.contains(t.getSubject()))
            result.add(t);
    }
    return result;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) HashSet(java.util.HashSet)

Example 58 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID 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)

Example 59 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.

the class TestStorage method storedOntologyOutlivesScope.

/**
     * If an ontology is removed from a scope, or the scope itself is torn down, this should not result in the
     * deletion of that ontology in general.
     */
@Test
public void storedOntologyOutlivesScope() throws Exception {
    String ephemeralScopeId = "CaducousScope";
    OntologyInputSource<OWLOntology> ois = new RootOntologySource(org.semanticweb.owlapi.model.IRI.create(getClass().getResource("/ontologies/nonexistentcharacters.owl")));
    OWLOntologyID ontologyId = ois.getRootOntology().getOntologyID();
    Scope scope = onManager.createOntologyScope(ephemeralScopeId);
    // Initially, the ontology is not there
    assertFalse(ontologyProvider.hasOntology(ontologyId));
    // Once added, the ontology is there
    scope.getCustomSpace().addOntology(ois);
    assertTrue(ontologyProvider.hasOntology(ontologyId));
    // Once removed from the scope, the ontology is still there
    scope.getCustomSpace().removeOntology(ontologyId);
    assertTrue(ontologyProvider.hasOntology(ontologyId));
    // Once the scope is killed, the ontology is still there
    // TODO find a more appropriate method to kill scopes?
    scope.tearDown();
    assertTrue(ontologyProvider.hasOntology(ontologyId));
}
Also used : Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) RootOntologySource(org.apache.stanbol.ontologymanager.sources.owlapi.RootOntologySource) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Test(org.junit.Test)

Example 60 with OWLOntologyID

use of org.semanticweb.owlapi.model.OWLOntologyID in project stanbol by apache.

the class TestOntologyReconciliation method anonymousFromStream.

/*
     * Anonymous ontologies loaded from a data stream must be stored with at least one non-null and
     * non-anonymous public key.
     */
@Test
public void anonymousFromStream() throws Exception {
    InputStream in = getClass().getResourceAsStream(location_nameless);
    in.mark(Integer.MAX_VALUE);
    OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
    OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(in);
    assertTrue(o1.isAnonymous());
    in.reset();
    // in = getClass().getResourceAsStream(location); // use if stream cannot be reset
    OWLOntologyID key = ontologyProvider.loadInStore(in, RDF_XML, false);
    assertNotNull(key);
    assertFalse(key.isAnonymous());
    log.info("Anonymous ontology loaded with non-anonymous public key {}", key);
    OWLOntology o2 = ontologyProvider.getStoredOntology(key, OWLOntology.class, false);
    assertTrue(o2.isAnonymous());
    // Cannot equal OWLOntology objects
    assertEquals(o1.getAxioms(), o2.getAxioms());
}
Also used : InputStream(java.io.InputStream) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) Test(org.junit.Test)

Aggregations

OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)86 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)31 Test (org.junit.Test)27 HashSet (java.util.HashSet)22 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)22 InputStream (java.io.InputStream)20 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)19 Triple (org.apache.clerezza.commons.rdf.Triple)19 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)19 IRI (org.apache.clerezza.commons.rdf.IRI)17 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)16 IRI (org.semanticweb.owlapi.model.IRI)14 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)13 IOException (java.io.IOException)12 UnmodifiableOntologyCollectorException (org.apache.stanbol.ontologymanager.servicesapi.collector.UnmodifiableOntologyCollectorException)12 WebApplicationException (javax.ws.rs.WebApplicationException)11 Graph (org.apache.clerezza.commons.rdf.Graph)10 AddImport (org.semanticweb.owlapi.model.AddImport)10 Path (javax.ws.rs.Path)9 OntologySpace (org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace)8