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;
}
}
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;
}
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;
}
}
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;
}
}
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;
}
Aggregations