Search in sources :

Example 41 with OWLOntology

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

the class TestOntologyReconciliation method versionedOnlyFromStream.

/*
     * If an ontology has no ontology IRI but does have a version IRI, it should still be possible to load it,
     * but the version IRI must be erased.
     */
@Test
public void versionedOnlyFromStream() throws Exception {
    String location = "/ontologies/naming/versionedonly.owl";
    InputStream in = getClass().getResourceAsStream(location);
    in.mark(Integer.MAX_VALUE);
    OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
    OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(in);
    // Ensure that the OWL API erases the version IRI.
    assertTrue(o1.isAnonymous());
    assertNull(o1.getOntologyID().getVersionIRI());
    in.reset();
    // in = getClass().getResourceAsStream(location); // use if stream cannot be reset
    // The public key must be non-anonymous nonetheless.
    OWLOntologyID key = ontologyProvider.loadInStore(in, RDF_XML, false);
    assertNotNull(key);
    assertFalse(key.isAnonymous());
    assertNull(key.getVersionIRI());
    log.info("Wrongly versioned ontology loaded with public key {}", key);
    assertFalse(o1.equals(key));
    OWLOntology o1_1 = ontologyProvider.getStoredOntology(key, OWLOntology.class, false);
    assertNotNull(o1_1);
    assertTrue(o1_1.isAnonymous());
    assertNull(o1_1.getOntologyID().getVersionIRI());
    // Cannot equal two OWLOntology objects, especially if anonymous.
    // Check that they match axiom-wise.
    log.warn("Plain OWL API seems to be failing to preserve owl:versionInfo. Will test non-annotation axioms only.");
    assertEquals(o1.getTBoxAxioms(false), o1_1.getTBoxAxioms(false));
    log.info(" -- TBox axiom check successful.");
    assertEquals(o1.getABoxAxioms(false), o1_1.getABoxAxioms(false));
    log.info(" -- ABox axiom check successful.");
    // No aliases should have been created.
    assertSame(0, ontologyProvider.listAliases(key).size());
}
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)

Example 42 with OWLOntology

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

the class ScopeResource method getCoreSpaceOWL.

@GET
@Path("/core")
@Produces(value = { RDF_XML, TURTLE, X_TURTLE, MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, TEXT_PLAIN })
public Response getCoreSpaceOWL(@PathParam("scopeid") String scopeid, @DefaultValue("false") @QueryParam("merge") boolean merge, @Context UriInfo uriInfo, @Context HttpHeaders headers) {
    scope = onm.getScope(scopeid);
    OntologySpace space = scope.getCoreSpace();
    IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
    OWLOntology o = space.export(OWLOntology.class, merge, prefix);
    ResponseBuilder rb = Response.ok(o);
    // addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OntologySpace(org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 43 with OWLOntology

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

the class SessionManagerResource method listSessions.

@GET
@Produces(value = { RDF_XML, OWL_XML, TURTLE, X_TURTLE, FUNCTIONAL_OWL, MANCHESTER_OWL, RDF_JSON, N3, N_TRIPLE, TEXT_PLAIN })
public Response listSessions(@Context UriInfo uriInfo, @Context HttpHeaders headers) {
    OWLOntologyManager ontMgr = OWLManager.createOWLOntologyManager();
    OWLDataFactory df = ontMgr.getOWLDataFactory();
    OWLClass cSession = df.getOWLClass(IRI.create("http://stanbol.apache.org/ontologies/meta/Session"));
    OWLOntology o;
    try {
        o = ontMgr.createOntology(IRI.create(uriInfo.getRequestUri()));
        List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
        for (String id : sessionManager.getRegisteredSessionIDs()) {
            IRI sessionid = IRI.create(sessionManager.getDefaultNamespace() + sessionManager.getID() + "/" + id);
            OWLNamedIndividual ind = df.getOWLNamedIndividual(sessionid);
            changes.add(new AddAxiom(o, df.getOWLClassAssertionAxiom(cSession, ind)));
        }
        ontMgr.applyChanges(changes);
    } catch (OWLOntologyCreationException e) {
        throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
    }
    ResponseBuilder rb = Response.ok(o);
    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
    if (mediaType != null)
        rb.header(HttpHeaders.CONTENT_TYPE, mediaType);
    //        addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) AddAxiom(org.semanticweb.owlapi.model.AddAxiom) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntologyChange(org.semanticweb.owlapi.model.OWLOntologyChange) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) MediaType(javax.ws.rs.core.MediaType) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 44 with OWLOntology

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

the class TestOntologyRegistry method testLoopInLibrary.

@Test
public void testLoopInLibrary() throws Exception {
    // Create the model from the looping registry.
    OWLOntology oReg = virginOntologyManager.loadOntology(Locations._REGISTRY_TEST_LOOP);
    Set<Registry> rs = regman.createModel(Collections.singleton(oReg));
    // There has to be a single registry, with the expected number of children (one).
    assertEquals(1, rs.size());
    Registry r = rs.iterator().next();
    assertTrue(r.hasChildren());
    int count = 1;
    assertEquals(count, r.getChildren().length);
    // There are no libreries without ontologies in the test registry.
    for (RegistryItem child : r.getChildren()) {
        assertTrue(child instanceof Library);
        // Check both parent-child relations.
        assertTrue(child.hasChildren());
        for (RegistryItem grandchild : child.getChildren()) {
            assertTrue(grandchild instanceof RegistryOntology);
            assertTrue(grandchild.hasParents());
            assertTrue(Arrays.asList(grandchild.getParents()).contains(child));
        }
    }
}
Also used : RegistryOntology(org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) Library(org.apache.stanbol.ontologymanager.registry.api.model.Library) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) Test(org.junit.Test)

Example 45 with OWLOntology

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

the class TestOntologyRegistry method testRegistryUnion.

/**
     * Verifies that, when loading multiple registries that add library information to each other, the overall
     * model reflects the union of these registries.
     * 
     * @throws Exception
     */
@Test
public void testRegistryUnion() throws Exception {
    // Create the model from two overlapping registries.
    Set<OWLOntology> regs = new HashSet<OWLOntology>();
    regs.add(virginOntologyManager.loadOntology(Locations._REGISTRY_TEST));
    regs.add(virginOntologyManager.loadOntology(Locations._REGISTRY_TEST_ADDITIONS));
    Set<Registry> rs = regman.createModel(regs);
    for (Registry r : rs) {
        // The nonexistent library should also be included, if using the more powerful algorithm.
        // set to 2 if using the less powerful algorithm.
        int count = 3;
        if (Locations._REGISTRY_TEST.equals(r.getIRI()))
            assertEquals(count, r.getChildren().length);
        else if (Locations._REGISTRY_TEST_ADDITIONS.equals(r.getIRI()))
            assertEquals(1, r.getChildren().length);
        // Check that we find the expected ontology in the expected library.
        for (RegistryItem lib : r.getChildren()) {
            if (Locations.LIBRARY_TEST1.equals(lib.getIRI())) {
                boolean found = false;
                for (RegistryItem child : lib.getChildren()) {
                    if (child instanceof RegistryOntology && Locations.ONT_TEST1.equals(child.getIRI())) {
                        found = true;
                        break;
                    }
                }
                assertTrue(found);
                break;
            }
        }
    }
}
Also used : RegistryOntology(org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

OWLOntology (org.semanticweb.owlapi.model.OWLOntology)118 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)59 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)50 IRI (org.semanticweb.owlapi.model.IRI)31 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)31 Test (org.junit.Test)25 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)24 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)22 HashSet (java.util.HashSet)21 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)18 Produces (javax.ws.rs.Produces)17 AddImport (org.semanticweb.owlapi.model.AddImport)16 OntModel (com.hp.hpl.jena.ontology.OntModel)15 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)15 InputStream (java.io.InputStream)14 GET (javax.ws.rs.GET)14 OWLClass (org.semanticweb.owlapi.model.OWLClass)14 ArrayList (java.util.ArrayList)13 Graph (org.apache.clerezza.commons.rdf.Graph)12 ReasoningServiceException (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException)11