Search in sources :

Example 36 with OWLOntologyID

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

the class GraphMultiplexer method getPublicKeys.

@Override
public Set<OWLOntologyID> getPublicKeys() {
    Set<OWLOntologyID> result = new HashSet<OWLOntologyID>();
    Iterator<Triple> it = meta.filter(null, RDF.type, ENTRY_URIREF);
    while (it.hasNext()) {
        RDFTerm obj = it.next().getSubject();
        if (obj instanceof IRI)
            result.add(buildPublicKey((IRI) obj));
    }
    return result;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) HashSet(java.util.HashSet)

Example 37 with OWLOntologyID

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

the class TestOntologyNetworkPersistence method sessionPreservesManagedOntologies.

@Test
public void sessionPreservesManagedOntologies() throws Exception {
    // The kind of thing an idiot would have on his luggage.
    String id = "12345";
    Session session = sessionManager.createSession(id);
    // Anonymous ontologies must preserve their public keys!
    session.addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/nameless_ontology.owl")));
    // Same for named ontologies...
    session.addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/nonexistentcharacters.owl")));
    // ... and versioned ontologies too.
    session.addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/versiontest_v1.owl")));
    session.addOntology(new GraphContentInputSource(getClass().getResourceAsStream("/ontologies/versiontest_v2.owl")));
    Collection<OWLOntologyID> managed = session.listManagedOntologies();
    assertEquals(4, managed.size());
    // Simulate Stanbol going down.
    log.info("Stanbol going down...");
    // but keep the TcProvider
    resetOntologyProvider();
    resetManagers();
    Session ses = sessionManager.getSession(id);
    assertNotNull(ses);
    assertEquals(managed, ses.listManagedOntologies());
    // XXX Remember that only weak equality is implemented.
    assertEquals(session, ses);
}
Also used : GraphContentInputSource(org.apache.stanbol.ontologymanager.sources.clerezza.GraphContentInputSource) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Session(org.apache.stanbol.ontologymanager.servicesapi.session.Session) Test(org.junit.Test)

Example 38 with OWLOntologyID

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

the class TestAliasing method cannotReplaceExistingDataStream.

@Test
public void cannotReplaceExistingDataStream() throws Exception {
    // Create a new full entry.
    String location = "/ontologies/test1.owl";
    InputStream in = getClass().getResourceAsStream(location);
    OWLOntologyID key = ontologyProvider.loadInStore(in, RDF_XML, false);
    log.info("Created and filled entry {}", key);
    assertNotNull(key);
    assertEquals(MATCH, ontologyProvider.getStatus(key));
    assertEquals(1, ontologyProvider.listAllRegisteredEntries().size());
    // Try to replace the data stream of a full entry (should fail).
    location = "/ontologies/mockfoaf.rdf";
    in = getClass().getResourceAsStream(location);
    try {
        OWLOntologyID wrongKey = ontologyProvider.loadInStore(in, RDF_XML, false, Origin.create(key));
        log.error("Replaced existing data stream. This should not happen.");
        log.error(" ... key: ", wrongKey);
        fail("Replaced existing data stream without warning.");
    } catch (Exception ex) {
        log.info("Caught exception of type {}", ex.getClass().getCanonicalName());
        assertEquals(MATCH, ontologyProvider.getStatus(key));
        assertEquals(1, ontologyProvider.listAllRegisteredEntries().size());
        assertEquals(1, ontologyProvider.listPrimaryKeys().size());
    }
    // Create a new uncharted entry and fill its data stream with the failed one.
    OWLOntologyID uncharted = new OWLOntologyID(IRI.create(prefix), IRI.create(getClass().getCanonicalName() + "#cannotReplaceExistingDataStream()"));
    ontologyProvider.createBlankOntologyEntry(uncharted);
    assertEquals(UNCHARTED, ontologyProvider.getStatus(uncharted));
    in = getClass().getResourceAsStream(location);
    ontologyProvider.loadInStore(in, RDF_XML, false, Origin.create(uncharted));
    assertEquals(MATCH, ontologyProvider.getStatus(uncharted));
    assertEquals(2, ontologyProvider.listPrimaryKeys().size());
}
Also used : InputStream(java.io.InputStream) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Test(org.junit.Test)

Example 39 with OWLOntologyID

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

the class TestAliasing method canCreateUnchartedOnce.

@Test
public void canCreateUnchartedOnce() throws Exception {
    OWLOntologyID uncharted = new OWLOntologyID(IRI.create(prefix), IRI.create(getClass().getCanonicalName() + "#canCreateUnchartedOnce()"));
    OWLOntologyID uncharted_copy = ontologyProvider.createBlankOntologyEntry(uncharted);
    log.info("Created uncharted ontology entry.");
    log.info(" ... key: {}", uncharted);
    assertEquals(uncharted, uncharted_copy);
    assertEquals(UNCHARTED, ontologyProvider.getStatus(uncharted));
    int entries = ontologyProvider.listAllRegisteredEntries().size();
    log.info("{} entries registered.", entries);
    try {
        log.info("Re-creating uncharted ontology entry...");
        OWLOntologyID recreated = ontologyProvider.createBlankOntologyEntry(uncharted);
        log.error(" ... Created same entry twice. This should not happen.");
        log.error(" ... key: {}", recreated);
        fail("Created same entry twice. This should not happen.");
    } catch (Exception ex) {
        log.info(" ... Creation failed. This is expected.");
        assertEquals(UNCHARTED, ontologyProvider.getStatus(uncharted));
        int newsize = ontologyProvider.listAllRegisteredEntries().size();
        assertEquals(entries, newsize);
        log.info("{} entries registered.", newsize);
        assertTrue(ontologyProvider.listOrphans().contains(uncharted));
        assertFalse(ontologyProvider.listPrimaryKeys().contains(uncharted));
    }
}
Also used : OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) Test(org.junit.Test)

Example 40 with OWLOntologyID

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

the class TestOntologyReconciliation method anonymousFromURLWithCustomKeys.

/*
     * If an anonymous ontology is loaded from a URL and at least one override is provided, the first override
     * should be the primary key, while everything else, including the URL, should be an alias for that key.
     */
@Test
public void anonymousFromURLWithCustomKeys() throws Exception {
    OWLOntologyID myKey = new OWLOntologyID(IRI.create("nameless"), IRI.create(getClass().getCanonicalName() + "#anonymousFromURLWithCustomKeys()"));
    OWLOntologyID alias = new OWLOntologyID(IRI.create("nameless"), IRI.create(getClass().getCanonicalName() + "#anonymousFromURLWithCustomKeys().alias"));
    URL url = getClass().getResource(location_nameless);
    OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
    OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(IRI.create(url));
    assertTrue(o1.isAnonymous());
    OWLOntologyID key = ontologyProvider.loadInStore(IRI.create(url), RDF_XML, false, Origin.create(myKey), Origin.create(alias));
    assertNotNull(key);
    assertFalse(key.isAnonymous());
    assertEquals(myKey, key);
    log.info("Anonymous ontology loaded with non-anonymous public key {} (submitted)", key);
    // should have 2 aliases: the physical location and the submitted alias.
    assertEquals(2, ontologyProvider.listAliases(key).size());
    for (OWLOntologyID al : ontologyProvider.listAliases(key)) {
        assertFalse(al.isAnonymous());
        log.info("Named alias detected {}", al);
    }
    // Now retrieve using the alias...
    OWLOntology o2 = ontologyProvider.getStoredOntology(alias, OWLOntology.class, false);
    assertTrue(o2.isAnonymous());
    // Cannot equal OWLOntology objects
    assertEquals(o1.getAxioms(), o2.getAxioms());
    // ... and using the physical IRI
    o2 = ontologyProvider.getStoredOntology(new OWLOntologyID(IRI.create(url)), OWLOntology.class, false);
    assertTrue(o2.isAnonymous());
    // Cannot equal OWLOntology objects
    assertEquals(o1.getAxioms(), o2.getAxioms());
}
Also used : OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) URL(java.net.URL) Test(org.junit.Test)

Aggregations

OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)101 Test (org.junit.Test)32 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)32 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)23 HashSet (java.util.HashSet)22 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)21 InputStream (java.io.InputStream)20 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)19 Triple (org.apache.clerezza.commons.rdf.Triple)19 IRI (org.semanticweb.owlapi.model.IRI)18 IRI (org.apache.clerezza.commons.rdf.IRI)17 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)16 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