use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.
the class ConversionTester method testModelOwlToJenaConvert.
public void testModelOwlToJenaConvert() {
JenaToOwlConvert j2o = new JenaToOwlConvert();
OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
OWLOntologyManager mgrf = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = mgrf.getOWLDataFactory();
String dul = "http://www.loa-cnr.it/ontologies/DUL.owl";
OWLOntology owl = null;
OntModel jena = null;
try {
owl = mgr.loadOntologyFromOntologyDocument(IRI.create(dul));
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
fail("Could not load ontology");
}
try {
jena = j2o.ModelOwlToJenaConvert(owl, "RDF/XML");
if (jena == null) {
fail("Some errors occur");
} else {
ExtendedIterator<OntClass> jenaclass = jena.listNamedClasses();
int jenaclassset = jenaclass.toSet().size();
jenaclass = jena.listNamedClasses();
Set<OWLClass> owlclass = owl.getClassesInSignature();
int countclass = 0;
while (jenaclass.hasNext()) if (owlclass.contains(factory.getOWLClass(IRI.create(jenaclass.next().getURI()))))
countclass++;
if (countclass == jenaclassset)
assertEquals(countclass, jenaclassset);
else
fail("Error in number of classes");
ExtendedIterator<ObjectProperty> jenaprop = jena.listObjectProperties();
int jenapropset = jenaprop.toSet().size();
jenaprop = jena.listObjectProperties();
Set<OWLObjectProperty> owlprop = owl.getObjectPropertiesInSignature();
int countprop = 0;
while (jenaprop.hasNext()) if (owlprop.contains(factory.getOWLObjectProperty(IRI.create(jenaprop.next().getURI()))))
countprop++;
if (countprop == jenapropset)
assertEquals(countprop, jenapropset);
else
fail("Error in number of object properties");
ExtendedIterator<DatatypeProperty> jenadata = jena.listDatatypeProperties();
int jenadataset = jenadata.toSet().size();
jenadata = jena.listDatatypeProperties();
Set<OWLDataProperty> owldata = owl.getDataPropertiesInSignature();
int countdata = 0;
while (jenadata.hasNext()) if (owldata.contains(factory.getOWLDataProperty(IRI.create(jenadata.next().getURI()))))
countdata++;
if (countdata == jenadataset)
assertEquals(countdata, jenadataset);
else
fail("Error in number of data properties");
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception caugth");
} finally {
assertNotNull(jena);
}
}
use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.
the class JenaToOwlConvert method DataPropOwlToJena.
// //////////////////////////////////////////////////////////////////////////////
/**
* This function converts a single OWLDataProperty of OWL to DatatypeProperty of Jena
*
* @param data
* {An OWLDataProperty object}
* @param format
* {RDF/XML or TURTLE}
* @return {A DatatypeProperty object}
*/
public synchronized DatatypeProperty DataPropOwlToJena(OWLDataProperty data, String format) {
while (available == false) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("DataPropOwlToJena::: " + 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.getDatatypeProperty(data.getIRI().toString());
} catch (OWLOntologyCreationException eoc) {
System.err.print("DataPropOwlToJena::: ");
eoc.printStackTrace();
return null;
}
}
use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.
the class JenaToOwlConvert method ModelJenaToOwlConvert.
/**
* 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(IRI ontologyIRI, 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();
owlmanager.loadOntologyFromOntologyDocument(new ByteArrayInputStream(out.toByteArray()));
OWLOntologyMerger merger = new OWLOntologyMerger(owlmanager);
OWLOntology ontology = merger.createMergedOntology(owlmanager, ontologyIRI);
availablemain = true;
notifyAll();
return ontology;
}
} catch (OWLOntologyCreationException eoc) {
System.err.print("ModelJenaToOwlConvert::: ");
eoc.printStackTrace();
return null;
}
}
use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.
the class JenaToOwlConvert method AnnotationPropJenaToOwl.
// //////////////////////////////////////////////////////////////////////////////
/**
* This function converts a single AnnotationProperty of Jena to an OWLAnnotationProperty of OWL
*
* @param jenadata
* {Jena DatatypeProperty object}
* @param format
* {RDF/XML}
* @return {An OWLAnnotationProperty object}
*/
public synchronized OWLAnnotationProperty AnnotationPropJenaToOwl(AnnotationProperty jenadata, String format) {
while (available == false) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("AnnotationPropJenaToOwl::: " + e);
}
}
available = false;
try {
OntModel model = ModelFactory.createOntologyModel();
model.createAnnotationProperty(jenadata.getURI());
OWLOntology owlmodel = ModelJenaToOwlConvert(model, format);
available = true;
notifyAll();
return owlmodel.getAnnotationPropertiesInSignature().iterator().next();
} catch (Exception e) {
System.err.print("AnnotationPropJenaToOwl::: ");
e.printStackTrace();
return null;
}
}
use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.
the class JenaToOwlConvert method ClassOwlToJena.
// //////////////////////////////////////////////////////////////////////////////
/**
* This function converts a single OWLClass of OWLAPI to an OntClass of Jena
*
* @param data
* {An OWLClass}
* @param format
* {RDF/XML or TURTLE}
* @return {An OntClass}
*/
public synchronized OntClass ClassOwlToJena(OWLClass data, String format) {
while (available == false) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("ClassOwlToJena::: " + 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.getOntClass(data.getIRI().toString());
} catch (OWLOntologyCreationException eoc) {
System.err.print("ClassOwlToJena::: ");
eoc.printStackTrace();
return null;
}
}
Aggregations