Search in sources :

Example 46 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 47 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 48 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)

Example 49 with OWLOntology

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

the class SessionResource method asOntologyOWL.

@GET
@Produces(value = { MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, TEXT_PLAIN })
public Response asOntologyOWL(@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();
    IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
    // Export to OWLOntology, the only to support OWL formats.
    ResponseBuilder 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 50 with OWLOntology

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

the class AbstractOWLApiReasoningService method isConsistent.

/**
     * Only check consistency.
     * 
     * Subclasses may want to change how.
     * 
     * @param ontology
     * @param rules
     * @return
     * @throws ReasoningServiceException
     */
@Override
public boolean isConsistent(OWLOntology ontology, List<SWRLRule> rules) throws ReasoningServiceException {
    log.debug("Create a input ontology to merge rules in.");
    OWLOntology input;
    try {
        OWLOntologyManager manager = createOWLOntologyManager();
        input = manager.createOntology();
        Set<SWRLRule> ruleSet = new HashSet<SWRLRule>();
        ruleSet.addAll(rules);
        manager.addAxioms(input, ruleSet);
        input = manager.getOntology(input.getOntologyID());
        log.debug("Created ontology: {}", input);
        return getReasoner(ontology).isConsistent();
    } catch (OWLOntologyCreationException e) {
        log.error("An error have been thrown while attempting to create ontology. Message was: {}", e.getLocalizedMessage());
        // TODO Add explanation of this exception
        throw new ReasoningServiceException();
    }
}
Also used : ReasoningServiceException(org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) HashSet(java.util.HashSet)

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