use of org.semanticweb.owlapi.model.OWLDataFactory 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.OWLDataFactory 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.OWLDataFactory 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;
}
}
use of org.semanticweb.owlapi.model.OWLDataFactory in project stanbol by apache.
the class ConversionTester method testObjPropOwlToJena.
public void testObjPropOwlToJena() {
JenaToOwlConvert j2o = new JenaToOwlConvert();
OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = mgr.getOWLDataFactory();
OWLObjectProperty op = factory.getOWLObjectProperty(IRI.create(OP));
ObjectProperty jop = null;
try {
jop = j2o.ObjPropOwlToJena(op, RDFXML);
if (jop == null) {
fail("Some errore occurs");
} else {
assertEquals(jop.getURI(), op.getIRI().toString());
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception caught");
} finally {
assertNotNull(jop);
}
}
use of org.semanticweb.owlapi.model.OWLDataFactory in project stanbol by apache.
the class ConversionTester method testAnnotationPropOwlToJena.
public void testAnnotationPropOwlToJena() {
JenaToOwlConvert j2o = new JenaToOwlConvert();
OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = mgr.getOWLDataFactory();
OWLAnnotationProperty wp = factory.getOWLAnnotationProperty(IRI.create(label));
AnnotationProperty jp = null;
try {
jp = j2o.AnnotationPropOwlToJena(wp, RDFXML);
if (jp == null) {
fail("Some errors occur");
} else {
assertEquals(wp.getIRI().toURI().toString(), jp.getURI());
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception caugth");
} finally {
assertNotNull(jp);
}
}
Aggregations