Search in sources :

Example 6 with OWLOntologyStorageException

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

the class OWLOntologyWriter method writeTo.

@Override
public void writeTo(OWLOntology ontology, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType mediaType, MultivaluedMap<String, Object> arg5, OutputStream out) throws IOException, WebApplicationException {
    Logger log = LoggerFactory.getLogger(getClass());
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    log.debug("Rendering ontology " + ontology.getOntologyID() + " to knowledge representation format " + mediaType);
    // Native formats first
    if (RDF_XML_TYPE.equals(mediaType) || OWL_XML_TYPE.equals(mediaType) || MANCHESTER_OWL_TYPE.equals(mediaType) || FUNCTIONAL_OWL_TYPE.equals(mediaType) || TURTLE_TYPE.equals(mediaType) || X_TURTLE_TYPE.equals(mediaType)) {
        OWLOntologyFormat format = null;
        if (RDF_XML_TYPE.equals(mediaType))
            format = new RDFXMLOntologyFormat();
        else if (OWL_XML_TYPE.equals(mediaType))
            format = new OWLXMLOntologyFormat();
        else if (MANCHESTER_OWL_TYPE.equals(mediaType))
            format = new ManchesterOWLSyntaxOntologyFormat();
        else if (FUNCTIONAL_OWL_TYPE.equals(mediaType))
            format = new OWLFunctionalSyntaxOntologyFormat();
        else if (TURTLE_TYPE.equals(mediaType) || X_TURTLE_TYPE.equals(mediaType))
            format = new TurtleOntologyFormat();
        if (format != null)
            try {
                manager.saveOntology(ontology, format, out);
            } catch (OWLOntologyStorageException e) {
                log.error("Failed to store ontology for rendering.", e);
                throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
            }
        else
            throw new IOException();
    } else {
        // Non-native formats that require a conversion to Clerezza
        if (RDF_JSON_TYPE.equals(mediaType) || N3_TYPE.equals(mediaType) || TEXT_PLAIN.equals(mediaType.toString()) || N_TRIPLE_TYPE.equals(mediaType)) {
            Graph mGraph = OWLAPIToClerezzaConverter.owlOntologyToClerezzaGraph(ontology);
            SerializingProvider serializer = null;
            if (RDF_JSON_TYPE.equals(mediaType))
                serializer = new RdfJsonSerializingProvider();
            else if (N3_TYPE.equals(mediaType) || N_TRIPLE_TYPE.equals(mediaType) || TEXT_PLAIN.equals(mediaType.toString()))
                serializer = new JenaSerializerProvider();
            // text/plain is interpreted as N3.
            if (serializer != null)
                serializer.serialize(out, mGraph, TEXT_PLAIN.equals(mediaType.toString()) ? N3 : mediaType.toString());
        }
    }
    // JSON_LD not supported until both parser and serializer are stable.
    out.flush();
}
Also used : ManchesterOWLSyntaxOntologyFormat(org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat) TurtleOntologyFormat(org.coode.owlapi.turtle.TurtleOntologyFormat) WebApplicationException(javax.ws.rs.WebApplicationException) OWLFunctionalSyntaxOntologyFormat(org.semanticweb.owlapi.io.OWLFunctionalSyntaxOntologyFormat) JenaSerializerProvider(org.apache.clerezza.rdf.jena.serializer.JenaSerializerProvider) RDFXMLOntologyFormat(org.semanticweb.owlapi.io.RDFXMLOntologyFormat) IOException(java.io.IOException) Logger(org.slf4j.Logger) RdfJsonSerializingProvider(org.apache.clerezza.rdf.rdfjson.serializer.RdfJsonSerializingProvider) SerializingProvider(org.apache.clerezza.rdf.core.serializedform.SerializingProvider) Graph(org.apache.clerezza.commons.rdf.Graph) RdfJsonSerializingProvider(org.apache.clerezza.rdf.rdfjson.serializer.RdfJsonSerializingProvider) OWLXMLOntologyFormat(org.semanticweb.owlapi.io.OWLXMLOntologyFormat) OWLOntologyFormat(org.semanticweb.owlapi.model.OWLOntologyFormat) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 7 with OWLOntologyStorageException

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

the class OWLAPIToClerezzaConverter method owlOntologyToClerezzaGraph.

/**
     * 
     * Converts a OWL API {@link OWLOntology} to Clerezza {@link Graph}.
     * 
     * @param ontology
     *            {@link OWLOntology}
     * @return the equivalent Clerezza {@link Graph}.
     */
public static org.apache.clerezza.commons.rdf.Graph owlOntologyToClerezzaGraph(OWLOntology ontology) {
    org.apache.clerezza.commons.rdf.Graph mGraph = null;
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    OWLOntologyManager manager = ontology.getOWLOntologyManager();
    try {
        manager.saveOntology(ontology, new RDFXMLOntologyFormat(), out);
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        ParsingProvider parser = new JenaParserProvider();
        mGraph = new SimpleGraph();
        parser.parse(mGraph, in, SupportedFormat.RDF_XML, null);
    } catch (OWLOntologyStorageException e) {
        log.error("Failed to serialize OWL Ontology " + ontology + "for conversion", e);
    }
    return mGraph;
}
Also used : JenaParserProvider(org.apache.clerezza.rdf.jena.parser.JenaParserProvider) ParsingProvider(org.apache.clerezza.rdf.core.serializedform.ParsingProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) RDFXMLOntologyFormat(org.semanticweb.owlapi.io.RDFXMLOntologyFormat) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 8 with OWLOntologyStorageException

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

the class OntologyImportUtils method printOntology.

@Deprecated
public static void printOntology(OWLOntology o, PrintStream printer) {
    OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
    StringDocumentTarget tgt = new StringDocumentTarget();
    try {
        mgr.saveOntology(o, new RDFXMLOntologyFormat(), tgt);
    } catch (OWLOntologyStorageException e) {
        e.printStackTrace(printer);
    }
    printer.println(tgt.toString());
}
Also used : OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) RDFXMLOntologyFormat(org.semanticweb.owlapi.io.RDFXMLOntologyFormat) StringDocumentTarget(org.semanticweb.owlapi.io.StringDocumentTarget) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 9 with OWLOntologyStorageException

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

the class ScopeResource method managedOntologyShow.

@GET
@Path("/{ontologyId:.+}")
@Produces(TEXT_HTML)
public Response managedOntologyShow(@PathParam("scopeid") String scopeid, @PathParam("ontologyId") String ontologyId, @Context HttpHeaders headers) {
    ResponseBuilder rb;
    scope = onm.getScope(scopeid);
    if (scope == null)
        rb = Response.status(NOT_FOUND);
    else if (ontologyId == null || ontologyId.isEmpty())
        rb = Response.status(BAD_REQUEST);
    else if (!ontologyProvider.hasOntology(OntologyUtils.decode(ontologyId)))
        rb = Response.status(NOT_FOUND);
    else {
        IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
        OWLOntology o = scope.getCustomSpace().getOntology(OntologyUtils.decode(ontologyId), OWLOntology.class, false, prefix);
        if (o == null)
            o = scope.getCoreSpace().getOntology(OntologyUtils.decode(ontologyId), OWLOntology.class, false, prefix);
        if (o == null)
            rb = Response.status(NOT_FOUND);
        else
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                o.getOWLOntologyManager().saveOntology(o, new ManchesterOWLSyntaxOntologyFormat(), out);
                rb = Response.ok(new Viewable("ontology", new OntologyPrettyPrintResource(uriInfo, out, scope)));
            } catch (OWLOntologyStorageException e) {
                throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
            }
    }
    rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
    // addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) ManchesterOWLSyntaxOntologyFormat(org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat) WebApplicationException(javax.ws.rs.WebApplicationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Viewable(org.apache.stanbol.commons.web.viewable.Viewable) OntologyPrettyPrintResource(org.apache.stanbol.ontologymanager.web.util.OntologyPrettyPrintResource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with OWLOntologyStorageException

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

the class SessionResource method managedOntologyShow.

@GET
@Path("/{ontologyId:.+}")
@Produces(TEXT_HTML)
public Response managedOntologyShow(@PathParam("ontologyId") String ontologyId, @Context HttpHeaders headers) {
    ResponseBuilder rb;
    if (session == null)
        rb = Response.status(NOT_FOUND);
    else if (ontologyId == null || ontologyId.isEmpty())
        rb = Response.status(BAD_REQUEST);
    else if (!ontologyProvider.hasOntology(OntologyUtils.decode(ontologyId)))
        rb = Response.status(NOT_FOUND);
    else {
        IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
        OWLOntology o = session.getOntology(OntologyUtils.decode(ontologyId), OWLOntology.class, false, prefix);
        if (o == null)
            rb = Response.status(NOT_FOUND);
        else
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                o.getOWLOntologyManager().saveOntology(o, new ManchesterOWLSyntaxOntologyFormat(), out);
                rb = Response.ok(new Viewable("ontology", new OntologyPrettyPrintResource(uriInfo, out, session)));
            } catch (OWLOntologyStorageException e) {
                throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
            }
    }
    rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
    //        addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) ManchesterOWLSyntaxOntologyFormat(org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat) WebApplicationException(javax.ws.rs.WebApplicationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Viewable(org.apache.stanbol.commons.web.viewable.Viewable) OntologyPrettyPrintResource(org.apache.stanbol.ontologymanager.web.util.OntologyPrettyPrintResource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)14 RDFXMLOntologyFormat (org.semanticweb.owlapi.io.RDFXMLOntologyFormat)8 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)8 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)8 ManchesterOWLSyntaxOntologyFormat (org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 TurtleOntologyFormat (org.coode.owlapi.turtle.TurtleOntologyFormat)5 Graph (org.apache.clerezza.commons.rdf.Graph)4 RdfJsonSerializingProvider (org.apache.clerezza.rdf.rdfjson.serializer.RdfJsonSerializingProvider)4 OWLFunctionalSyntaxOntologyFormat (org.semanticweb.owlapi.io.OWLFunctionalSyntaxOntologyFormat)4 OWLXMLOntologyFormat (org.semanticweb.owlapi.io.OWLXMLOntologyFormat)4 IRI (org.semanticweb.owlapi.model.IRI)4 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)4 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)4 Logger (org.slf4j.Logger)4 WebApplicationException (javax.ws.rs.WebApplicationException)3 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)3 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)3 OWLOntologyFormat (org.semanticweb.owlapi.model.OWLOntologyFormat)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2