use of org.semanticweb.owlapi.model.OWLDeclarationAxiom in project stanbol by apache.
the class ConversionTester method testAxiomOwlToJenaResource.
public void testAxiomOwlToJenaResource() {
JenaToOwlConvert j2o = new JenaToOwlConvert();
OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
OWLOntology ont = null;
try {
ont = mgr.createOntology();
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
fail("Can not create ontology");
}
OWLDataFactory factory = mgr.getOWLDataFactory();
StmtIterator resource = null;
OWLClass cls = factory.getOWLClass(IRI.create(CLAZZ));
OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
OWLObjectProperty op = factory.getOWLObjectProperty(IRI.create(OP));
OWLAnnotationProperty oa = factory.getOWLAnnotationProperty(IRI.create(label));
OWLAnnotation oav = factory.getOWLAnnotation(oa, factory.getOWLStringLiteral(clazzlabel, "en"));
OWLDatatype dt = factory.getOWLDatatype(IRI.create(DATATYPE));
OWLNamedIndividual sub = factory.getOWLNamedIndividual(IRI.create(SUBJECT));
OWLNamedIndividual obj = factory.getOWLNamedIndividual(IRI.create(OBJECT));
OWLLiteral literal1 = factory.getOWLTypedLiteral(VALUE, dt);
// Classe
OWLDeclarationAxiom daxiomcls = factory.getOWLDeclarationAxiom(cls);
// obj prop
OWLDeclarationAxiom daxiomop = factory.getOWLDeclarationAxiom(op);
// data prop
OWLDeclarationAxiom daxiomdp = factory.getOWLDeclarationAxiom(dp);
// subject
OWLDeclarationAxiom daxiomsub = factory.getOWLDeclarationAxiom(sub);
// object
OWLDeclarationAxiom daxiomobj = factory.getOWLDeclarationAxiom(obj);
// Istanza
OWLClassAssertionAxiom axiomsub = factory.getOWLClassAssertionAxiom(cls, sub);
// Istanza
OWLClassAssertionAxiom axiomobj = factory.getOWLClassAssertionAxiom(cls, obj);
// Obj
OWLObjectPropertyAssertionAxiom axiomop = factory.getOWLObjectPropertyAssertionAxiom(op, sub, obj);
// prop
// tra
// individui
OWLDataPropertyAssertionAxiom axiomvalue = factory.getOWLDataPropertyAssertionAxiom(dp, obj, // Dataprop all'istanza;
literal1);
// Annotazione
OWLAnnotationAssertionAxiom axioman = factory.getOWLAnnotationAssertionAxiom(cls.getIRI(), oav);
mgr.addAxiom(ont, daxiomcls);
mgr.addAxiom(ont, daxiomop);
mgr.addAxiom(ont, daxiomdp);
mgr.addAxiom(ont, daxiomsub);
mgr.addAxiom(ont, daxiomobj);
mgr.addAxiom(ont, axiomsub);
mgr.addAxiom(ont, axiomobj);
mgr.addAxiom(ont, axiomop);
mgr.addAxiom(ont, axiomvalue);
mgr.addAxiom(ont, axioman);
Set<OWLAxiom> setaxiom = ont.getAxioms();
try {
resource = j2o.AxiomOwlToJenaResource(setaxiom, RDFXML);
if (resource == null) {
fail("Some errors occur");
} else {
String statment = "[http://www.w3.org/2000/01/rdf-schema#label, http://www.w3.org/2000/01/rdf-schema#range, http://www.w3.org/2000/01/rdf-schema#Literal] " + "[http://example.org/dummy#hasAge, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#DatatypeProperty] " + "[http://example.org/dummy#Linus, http://example.org/dummy#hasAge, \"8\"^^http://www.w3.org/2001/XMLSchema#int] " + "[http://example.org/dummy#Linus, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://example.org/dummy#Peanut] " + "[http://example.org/dummy#hasSibling, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#ObjectProperty] " + "[http://example.org/dummy#Lucy, http://example.org/dummy#hasSibling, http://example.org/dummy#Linus] " + "[http://example.org/dummy#Lucy, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://example.org/dummy#Peanut] " + "[http://www.w3.org/2000/01/rdf-schema#label, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#AnnotationProperty] " + "[http://example.org/dummy#Peanut, http://www.w3.org/2000/01/rdf-schema#label, \"Peanut\"@en] " + "[http://example.org/dummy#Peanut, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#Class]";
int size = setaxiom.size();
int count = 0;
while (resource.hasNext()) {
Statement stm = resource.nextStatement();
Resource jsubj = stm.getSubject();
if (jsubj.getURI().equals(OP.toString()) || jsubj.getURI().equals(DP.toString()) || jsubj.getURI().equals(CLAZZ.toString()) || jsubj.getURI().equals(OBJECT.toString()) || jsubj.getURI().equals(SUBJECT.toString()) || jsubj.getURI().equals(label.toString()))
if (statment.contains(stm.toString()))
count++;
}
assertEquals(size, count);
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception caugth");
} finally {
assertNotNull(resource);
}
}
use of org.semanticweb.owlapi.model.OWLDeclarationAxiom 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.OWLDeclarationAxiom 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.OWLDeclarationAxiom in project stanbol by apache.
the class ConversionTester method testEntityOwlToJenaResource.
public void testEntityOwlToJenaResource() {
JenaToOwlConvert j2o = new JenaToOwlConvert();
OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
OWLOntology ont = null;
StmtIterator resource = null;
try {
ont = mgr.createOntology();
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
fail("Could not load ontology");
}
OWLDataFactory factory = mgr.getOWLDataFactory();
OWLClass cls = factory.getOWLClass(IRI.create(CLAZZ));
OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
OWLObjectProperty op = factory.getOWLObjectProperty(IRI.create(OP));
OWLAnnotationProperty oa = factory.getOWLAnnotationProperty(IRI.create(label));
OWLAnnotation oav = factory.getOWLAnnotation(oa, factory.getOWLStringLiteral(clazzlabel, "en"));
OWLDatatype dt = factory.getOWLDatatype(IRI.create(DATATYPE));
OWLNamedIndividual sub = factory.getOWLNamedIndividual(IRI.create(SUBJECT));
OWLNamedIndividual obj = factory.getOWLNamedIndividual(IRI.create(OBJECT));
OWLLiteral literal1 = factory.getOWLTypedLiteral(VALUE, dt);
// Classe
OWLDeclarationAxiom daxiomcls = factory.getOWLDeclarationAxiom(cls);
// obj prop
OWLDeclarationAxiom daxiomop = factory.getOWLDeclarationAxiom(op);
// data prop
OWLDeclarationAxiom daxiomdp = factory.getOWLDeclarationAxiom(dp);
// subject
OWLDeclarationAxiom daxiomsub = factory.getOWLDeclarationAxiom(sub);
// object
OWLDeclarationAxiom daxiomobj = factory.getOWLDeclarationAxiom(obj);
// Istanza
OWLClassAssertionAxiom axiomsub = factory.getOWLClassAssertionAxiom(cls, sub);
// Istanza
OWLClassAssertionAxiom axiomobj = factory.getOWLClassAssertionAxiom(cls, obj);
// Obj
OWLObjectPropertyAssertionAxiom axiomop = factory.getOWLObjectPropertyAssertionAxiom(op, sub, obj);
// prop
// tra
// individui
OWLDataPropertyAssertionAxiom axiomvalue = factory.getOWLDataPropertyAssertionAxiom(dp, sub, // Dataprop all'istanza;
literal1);
// Annotazione
OWLAnnotationAssertionAxiom axioman = factory.getOWLAnnotationAssertionAxiom(cls.getIRI(), oav);
mgr.addAxiom(ont, daxiomcls);
mgr.addAxiom(ont, daxiomop);
mgr.addAxiom(ont, daxiomdp);
mgr.addAxiom(ont, daxiomsub);
mgr.addAxiom(ont, daxiomobj);
mgr.addAxiom(ont, axiomsub);
mgr.addAxiom(ont, axiomobj);
mgr.addAxiom(ont, axiomop);
mgr.addAxiom(ont, axiomvalue);
mgr.addAxiom(ont, axioman);
Set<OWLIndividualAxiom> ind = ont.getAxioms(sub);
try {
resource = j2o.EntityOwlToJenaResource(daxiomsub.getEntity(), ont, RDFXML);
if (resource == null) {
fail("Some errors accour");
} else {
int cont = 0;
while (resource.hasNext()) {
Statement stm = resource.nextStatement();
IRI subres = IRI.create(stm.getSubject().getURI());
if (("<" + subres + ">").equals(daxiomsub.getEntity().toString()))
cont++;
}
assertEquals(ind.size(), (cont - 1));
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception caugth");
} finally {
assertNotNull(resource);
}
}
use of org.semanticweb.owlapi.model.OWLDeclarationAxiom 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;
}
}
Aggregations