Search in sources :

Example 16 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 17 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)

Example 18 with OWLOntology

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

the class TestOntologyRegistry method testPopulateRegistry.

/**
     * Verifies that a call to {@link RegistryManager#createModel(Set)} with a registry location creates the
     * object model accordingly.
     * 
     * @throws Exception
     */
@Test
public void testPopulateRegistry() throws Exception {
    // Create the model from a single registry.
    OWLOntology oReg = virginOntologyManager.loadOntology(Locations._REGISTRY_TEST);
    Set<Registry> rs = regman.createModel(Collections.singleton(oReg));
    // There has to be a single registry, with the expected number of children.
    assertEquals(1, rs.size());
    Registry r = rs.iterator().next();
    assertTrue(r.hasChildren());
    // 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;
    assertEquals(count, r.getChildren().length);
    // There are no libraries without ontologies in the test registry.
    for (RegistryItem ri : r.getChildren()) assertTrue(ri.hasChildren());
}
Also used : OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) Test(org.junit.Test)

Example 19 with OWLOntology

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

the class ScopeResource method getCustomSpaceOWL.

@GET
@Path("/custom")
@Produces(value = { RDF_XML, TURTLE, X_TURTLE, MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, TEXT_PLAIN })
public Response getCustomSpaceOWL(@PathParam("scopeid") String scopeid, @DefaultValue("false") @QueryParam("merge") boolean merge, @Context UriInfo uriInfo, @Context HttpHeaders headers) {
    scope = onm.getScope(scopeid);
    OntologySpace space = scope.getCustomSpace();
    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 20 with OWLOntology

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

the class SessionResource method asOntologyMixed.

@GET
@Produces(value = { RDF_XML, TURTLE, X_TURTLE })
public Response asOntologyMixed(@PathParam(value = "id") String sessionId, @PathParam("scopeid") String scopeid, @DefaultValue("false") @QueryParam("merge") boolean merge, @Context HttpHeaders headers) {
    session = sesMgr.getSession(sessionId);
    if (session == null)
        return Response.status(NOT_FOUND).build();
    ResponseBuilder rb;
    IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
    // Export smaller graphs to OWLOntology due to the more human-readable rendering.
    if (merge)
        rb = Response.ok(session.export(ImmutableGraph.class, merge, prefix));
    else
        rb = Response.ok(session.export(OWLOntology.class, merge, prefix));
    //        addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

OWLOntology (org.semanticweb.owlapi.model.OWLOntology)116 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)58 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)49 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)31 IRI (org.semanticweb.owlapi.model.IRI)30 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