Search in sources :

Example 91 with OWLOntology

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

the class JenaToOwlConvert method DataPropJenaToOwl.

// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts a DatatypeProperty of Jena to and OWLDataProperty of owl
     * 
     * @param jenadata
     *            {Jena DatatypeProperty object}
     * @param format
     *            {RDF/XML}
     * @return {An OWLDataProperty}
     */
public synchronized OWLDataProperty DataPropJenaToOwl(DatatypeProperty jenadata, String format) {
    while (available == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("DataPropJenaToOwl::: " + e);
        }
    }
    available = false;
    try {
        OntModel model = ModelFactory.createOntologyModel();
        model.createDatatypeProperty(jenadata.getURI());
        OWLOntology owlmodel = ModelJenaToOwlConvert(model, format);
        available = true;
        notifyAll();
        return owlmodel.getDataPropertiesInSignature().iterator().next();
    } catch (Exception e) {
        System.err.print("DataPropJenaToOwl::: ");
        e.printStackTrace();
        return null;
    }
}
Also used : OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 92 with OWLOntology

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

the class JenaToOwlConvert method ObjPropJenaToOwl.

// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts a single ObjectProperty of Jena to an OWLObjectProperty of OWLAPI
     * 
     * @param jenadata
     *            {Jena ObjectProperty object}
     * @param format
     *            {RDF/XML}
     * @return {An OWLObjectProperty}
     */
public synchronized OWLObjectProperty ObjPropJenaToOwl(ObjectProperty jenadata, String format) {
    while (available == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("ClassOwlToJena::: " + e);
        }
    }
    available = false;
    try {
        OntModel model = ModelFactory.createOntologyModel();
        model.createObjectProperty(jenadata.getURI());
        OWLOntology owlmodel = ModelJenaToOwlConvert(model, format);
        available = true;
        notifyAll();
        return owlmodel.getObjectPropertiesInSignature().iterator().next();
    } catch (Exception e) {
        System.err.print("ClassOwlToJena::: ");
        e.printStackTrace();
        return null;
    }
}
Also used : OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 93 with OWLOntology

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

the class OWLAPIToClerezzaConverterTest method testGraphToOWLOntology.

@Test
public void testGraphToOWLOntology() {
    /*
         * Transform the Clerezza Graph to an OWLOntology.
         */
    OWLOntology ontology = OWLAPIToClerezzaConverter.clerezzaGraphToOWLOntology(mGraph);
    /*
         * Print the number of axioms contained in the OWLOntology.
         */
    int axiomCount = ontology.getAxiomCount();
    log.info("The ontology contatins " + axiomCount + " axioms: ");
    /*
         * Print the axioms contained in the OWLOntology.
         */
    Set<OWLAxiom> axioms = ontology.getAxioms();
    for (OWLAxiom axiom : axioms) {
        log.info("    " + axiom.toString());
    }
}
Also used : OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) Test(org.junit.Test)

Example 94 with OWLOntology

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

the class RootResource method getOWLOntology.

private OWLOntology getOWLOntology(String ontologyId, boolean merge, URI requestUri) {
    long before = System.currentTimeMillis();
    IRI iri = URIUtils.sanitize(IRI.create(ontologyId));
    log.debug("Will try to retrieve ontology {} from provider.", iri);
    // TODO be selective: if the ontology is small enough, use OWLOntology otherwise export to ImmutableGraph.
    OWLOntology o = null;
    try {
        // XXX Guarantee that there MUST always be an entry for any decoded ontology ID submitted.
        OWLOntologyID id = OntologyUtils.decode(ontologyId);
        o = ontologyProvider.getStoredOntology(id, OWLOntology.class, merge);
    } catch (Exception ex) {
        log.warn("Retrieval of ontology with ID " + iri + " failed.", ex);
    }
    if (o == null) {
        log.debug("Ontology {} missing from provider. Trying libraries...", iri);
        // See if we can touch a library. TODO: replace with event model on the ontology provider.
        int minSize = -1;
        IRI smallest = null;
        for (Library lib : registryManager.getLibraries(iri)) {
            int size = lib.getChildren().length;
            if (minSize < 1 || size < minSize) {
                smallest = lib.getIRI();
                minSize = size;
            }
        }
        if (smallest != null) {
            log.debug("Selected library for ontology {} is {} .", iri, smallest);
            try {
                o = registryManager.getLibrary(smallest).getOntology(iri, OWLOntology.class);
            } catch (RegistryContentException e) {
                log.warn("The content of library " + smallest + " could not be accessed.", e);
            }
        }
    }
    if (o == null) {
        log.debug("Ontology {} not found in any ontology provider or library.", iri);
        return null;
    }
    log.debug("Retrieved ontology {} .", iri);
    // Rewrite import statements - no ontology collector to do it for us here.
    URI base = URI.create(getPublicBaseUri() + "ontonet/");
    List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
    OWLDataFactory df = o.getOWLOntologyManager().getOWLDataFactory();
    // TODO manage import rewrites better once the container ID is fully configurable.
    for (OWLImportsDeclaration oldImp : o.getImportsDeclarations()) {
        changes.add(new RemoveImport(o, oldImp));
        String s = oldImp.getIRI().toString();
        if (s.contains("::")) {
            s = s.substring(s.indexOf("::") + 2, s.length());
        }
        IRI target = IRI.create(base + s);
        changes.add(new AddImport(o, df.getOWLImportsDeclaration(target)));
    }
    // Versioning.
    OWLOntologyID id = o.getOntologyID();
    if (!id.isAnonymous() && id.getVersionIRI() == null) {
        IRI viri = IRI.create(requestUri);
        log.debug("Setting version IRI for export : {}", viri);
        changes.add(new SetOntologyID(o, new OWLOntologyID(id.getOntologyIRI(), viri)));
    }
    o.getOWLOntologyManager().applyChanges(changes);
    log.debug("Exported as Clerezza ImmutableGraph in {} ms. Handing over to writer.", System.currentTimeMillis() - before);
    return o;
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) ArrayList(java.util.ArrayList) OWLImportsDeclaration(org.semanticweb.owlapi.model.OWLImportsDeclaration) URI(java.net.URI) AddImport(org.semanticweb.owlapi.model.AddImport) UnsupportedFormatException(org.apache.clerezza.rdf.core.serializedform.UnsupportedFormatException) WebApplicationException(javax.ws.rs.WebApplicationException) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) OntologyLoadingException(org.apache.stanbol.ontologymanager.servicesapi.ontology.OntologyLoadingException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OntologyHandleException(org.apache.stanbol.ontologymanager.servicesapi.ontology.OntologyHandleException) RegistryContentException(org.apache.stanbol.ontologymanager.registry.api.RegistryContentException) OrphanOntologyKeyException(org.apache.stanbol.ontologymanager.servicesapi.ontology.OrphanOntologyKeyException) RemoveImport(org.semanticweb.owlapi.model.RemoveImport) SetOntologyID(org.semanticweb.owlapi.model.SetOntologyID) OWLOntologyChange(org.semanticweb.owlapi.model.OWLOntologyChange) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) RegistryContentException(org.apache.stanbol.ontologymanager.registry.api.RegistryContentException) Library(org.apache.stanbol.ontologymanager.registry.api.model.Library) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 95 with OWLOntology

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

the class RootResource method getStandaloneOntology.

/**
     * Gets the ontology with the given identifier in its version managed by the session.
     * 
     * @param sessionId
     *            the session identifier.
     * @param ontologyId
     *            the ontology identifier.
     * @param uriInfo
     * @param headers
     * @return the requested managed ontology, or {@link Status#NOT_FOUND} if either the sessionn does not
     *         exist, or the if the ontology either does not exist or is not managed.
     */
@GET
@Path("/{ontologyId:.+}")
@Produces(value = { RDF_XML, TURTLE, X_TURTLE, MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, TEXT_PLAIN })
public Response getStandaloneOntology(@PathParam("ontologyId") String ontologyId, @DefaultValue("false") @QueryParam("merge") boolean merged, @Context UriInfo uriInfo, @Context HttpHeaders headers) {
    ResponseBuilder rb;
    if (ontologyId == null || ontologyId.isEmpty()) {
        rb = Response.status(BAD_REQUEST);
    }
    OWLOntologyID key = OntologyUtils.decode(ontologyId);
    if (ontologyProvider.listOrphans().contains(key)) {
        rb = Response.status(NO_CONTENT);
    } else {
        OWLOntology o = getOWLOntology(ontologyId, merged, uriInfo.getRequestUri());
        rb = o == null ? Response.status(NOT_FOUND) : Response.ok(o);
    }
    // addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) 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)

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