Search in sources :

Example 16 with OWLOntologyCreationException

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

the class JenaToOwlConvert method ModelJenaToOwlConvert.

// //////////////////////////////////////////////////////////////////////////////
// ////////////////////////////FUNCTIONS/////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts an ontology object from Jena to OWLapi
     * 
     * @param jenamodel
     *            {An OntModel object}
     * @param format
     *            {only in "RDF/XML"}
     * @return {An OWLOntology that is an owl object}
     */
public synchronized OWLOntology ModelJenaToOwlConvert(Model jenamodel, String format) {
    while (availablemain == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("ModelJenaToOwlConvert::: " + e);
        }
    }
    availablemain = false;
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        if (!format.equals("RDF/XML")) {
            System.err.println("The only format supported is RDF/XML. Please check the format!");
            availablemain = true;
            notifyAll();
            return null;
        } else {
            jenamodel.write(out, format);
            OWLOntologyManager owlmanager = OWLManager.createOWLOntologyManager();
            OWLOntology owlmodel = owlmanager.loadOntologyFromOntologyDocument(new ByteArrayInputStream(out.toByteArray()));
            availablemain = true;
            notifyAll();
            return owlmodel;
        }
    } catch (OWLOntologyCreationException eoc) {
        System.err.print("ModelJenaToOwlConvert::: ");
        eoc.printStackTrace();
        return null;
    }
}
Also used : OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) ByteArrayInputStream(java.io.ByteArrayInputStream) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager)

Example 17 with OWLOntologyCreationException

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

the class JenaToOwlConvert method AxiomOwlToJenaResource.

// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts a set of OWLAxiom in an iterator over jena statements
     * 
     * @param axioms
     *            {A set of aximos}
     * @param format
     *            {RDF/XML or TURTLE}
     * @return {An iterator over statments}
     */
public synchronized StmtIterator AxiomOwlToJenaResource(Set<OWLAxiom> axioms, String format) {
    while (available == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("AxiomOwlToJenaResource::: " + e);
        }
    }
    available = false;
    try {
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        OWLOntology ontology = manager.createOntology(IRI.create("http://www.semanticweb.org/owlapi/ontologies/ontology"));
        Iterator<OWLAxiom> axiom = axioms.iterator();
        while (axiom.hasNext()) manager.addAxiom(ontology, axiom.next());
        OntModel jenamodel = ModelOwlToJenaConvert(ontology, format);
        available = true;
        notifyAll();
        return jenamodel.listStatements();
    } catch (OWLOntologyCreationException eoc) {
        System.err.print("AxiomOwlToJenaResource::: ");
        eoc.printStackTrace();
        return null;
    }
}
Also used : OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom)

Example 18 with OWLOntologyCreationException

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

the class JenaToOwlConvert method AnnotationPropOwlToJena.

// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts a single OWLAnnotationProperty of OWL to an AnnotationProperty of Jena
     * 
     * @param data
     *            {An OWLAnnotationProperty object}
     * @param format
     *            {RDF/XML or TURTLE}
     * @return {An AnnotationProperty object}
     */
public synchronized AnnotationProperty AnnotationPropOwlToJena(OWLAnnotationProperty data, String format) {
    while (available == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("AnnotationPropOwlToJena::: " + e);
        }
    }
    available = false;
    try {
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        OWLOntology ontology = manager.createOntology(IRI.create("http://www.semanticweb.org/owlapi/ontologies/ontology"));
        OWLDataFactory factory = manager.getOWLDataFactory();
        OWLDeclarationAxiom declarationAxiom = factory.getOWLDeclarationAxiom(data);
        manager.addAxiom(ontology, declarationAxiom);
        OntModel jenamodel = ModelOwlToJenaConvert(ontology, format);
        available = true;
        notifyAll();
        return jenamodel.getAnnotationProperty(data.getIRI().toString());
    } catch (OWLOntologyCreationException eoc) {
        System.err.print("AnnotationPropOwlToJena::: ");
        eoc.printStackTrace();
        return null;
    }
}
Also used : OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLDeclarationAxiom(org.semanticweb.owlapi.model.OWLDeclarationAxiom) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 19 with OWLOntologyCreationException

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

the class JenaToOwlConvert method ObjPropOwlToJena.

// //////////////////////////////////////////////////////////////////////////////
/**
     * This function converts a single OWLObjectProperty of owl to an ObjectProperty of Jena
     * 
     * @param data
     *            {An OWLObjectProperty object}
     * @param format
     *            {RDF/XML or TURTLE}
     * @return {An ObjectProperty}
     */
public synchronized ObjectProperty ObjPropOwlToJena(OWLObjectProperty data, String format) {
    while (available == false) {
        try {
            wait();
        } catch (InterruptedException e) {
            System.err.println("ObjPropOwlToJena::: " + e);
        }
    }
    available = false;
    try {
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        OWLOntology ontology = manager.createOntology(IRI.create("http://www.semanticweb.org/owlapi/ontologies/ontology"));
        OWLDataFactory factory = manager.getOWLDataFactory();
        OWLDeclarationAxiom declarationAxiom = factory.getOWLDeclarationAxiom(data);
        manager.addAxiom(ontology, declarationAxiom);
        OntModel jenamodel = ModelOwlToJenaConvert(ontology, format);
        available = true;
        notifyAll();
        return jenamodel.getObjectProperty(data.getIRI().toString());
    } catch (OWLOntologyCreationException eoc) {
        System.err.print("ObjPropOwlToJena::: ");
        eoc.printStackTrace();
        return null;
    }
}
Also used : OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLDeclarationAxiom(org.semanticweb.owlapi.model.OWLDeclarationAxiom) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OntModel(com.hp.hpl.jena.ontology.OntModel) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 20 with OWLOntologyCreationException

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

the class OWLAPIToClerezzaConverter method clerezzaGraphToOWLOntology.

public static OWLOntology clerezzaGraphToOWLOntology(org.apache.clerezza.commons.rdf.Graph graph, OWLOntologyManager ontologyManager) {
    /*
         * The root graph can be serialized and de-serialized, but before that we should decide what to do
         * with imports. We can proceed as follows:
         * 
         * for each import statement, - check if the ontology manager has (1) an ontology or (2) a mapping. -
         * if (1), just get it and add it to the merge pool - if (2), do nothing. the ontology manager should
         * handle it when loading the root, - if neither, fetch the graph and call the procideure on it
         * 
         * Alternatively, construct the whole reverse imports stack, then traverse it again, get the
         * OWLOntology version for each (with the phony mapper set) and add it to the merge pool
         * 
         * If it works, just add all the triples to a Graph, but no, we don't want to store that
         * change.
         */
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SerializingProvider serializingProvider = new JenaSerializerProvider();
    serializingProvider.serialize(out, graph, SupportedFormat.RDF_XML);
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    OWLOntology ontology = null;
    try {
        ontology = ontologyManager.loadOntologyFromOntologyDocument(in);
    } catch (OWLOntologyAlreadyExistsException e) {
        ontology = ontologyManager.getOntology(e.getOntologyID());
    } catch (OWLOntologyCreationException e) {
        log.error("Failed to serialize OWL Ontology " + ontology + "for conversion", e);
    }
    return ontology;
}
Also used : OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) ByteArrayInputStream(java.io.ByteArrayInputStream) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) JenaSerializerProvider(org.apache.clerezza.rdf.jena.serializer.JenaSerializerProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SerializingProvider(org.apache.clerezza.rdf.core.serializedform.SerializingProvider) OWLOntologyAlreadyExistsException(org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException)

Aggregations

OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)57 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)46 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)33 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)18 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)15 HashSet (java.util.HashSet)13 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)13 AddImport (org.semanticweb.owlapi.model.AddImport)12 ReasoningServiceException (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 OntModel (com.hp.hpl.jena.ontology.OntModel)9 WebApplicationException (javax.ws.rs.WebApplicationException)9 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)9 IRI (org.semanticweb.owlapi.model.IRI)9 OWLClass (org.semanticweb.owlapi.model.OWLClass)9 Consumes (javax.ws.rs.Consumes)8 InconsistentInputException (org.apache.stanbol.reasoners.servicesapi.InconsistentInputException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 POST (javax.ws.rs.POST)7