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