Search in sources :

Example 21 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 22 with OWLOntologyCreationException

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

the class ClerezzaOntologyProvider method getStoredOntology.

/**
     * In this implementation the identifier is the ImmutableGraph Name (e.g. ontonet::blabla)
     */
@SuppressWarnings("unchecked")
@Override
@Deprecated
public <O> O getStoredOntology(String identifier, Class<O> returnType, boolean forceMerge) {
    if (identifier == null || identifier.isEmpty())
        throw new IllegalArgumentException("Identifier cannot be null or empty.");
    if (returnType == null) {
        // Defaults to OWLOntology
        returnType = (Class<O>) OWLOntology.class;
        log.warn("No return type given for the ontology. Will return a {}", returnType.getCanonicalName());
    }
    boolean canDo = false;
    for (Class<?> clazz : getSupportedReturnTypes()) if (clazz.isAssignableFrom(returnType)) {
        canDo = true;
        break;
    }
    if (!canDo)
        throw new UnsupportedOperationException("Return type " + returnType.getCanonicalName() + " is not allowed in this implementation. Only allowed return types are " + supported);
    Graph tc = store.getGraph(new IRI(identifier));
    if (tc == null)
        return null;
    if (Graph.class.equals(returnType) || Graph.class.isAssignableFrom(returnType)) {
        return returnType.cast(tc);
    } else if (OWLOntology.class.isAssignableFrom(returnType)) {
        try {
            return (O) toOWLOntology(new IRI(identifier), forceMerge);
        } catch (OWLOntologyCreationException e) {
            log.error("Failed to return stored ontology " + identifier + " as type " + returnType.getCanonicalName(), e);
        }
    }
    return null;
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) Graph(org.apache.clerezza.commons.rdf.Graph) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology)

Example 23 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 24 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 25 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)54 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)45 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 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 IOException (java.io.IOException)8 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