use of com.hp.hpl.jena.ontology.OntModel in project stanbol by apache.
the class JenaToOwlConvert method ClassJenaToOwl.
// //////////////////////////////////////////////////////////////////////////////
/**
* This function converts a single OntClass of Jena to an OWLClass of OWLAPI
*
* @param jenadata
* {Jena class object}
* @param format
* {RDF/XML}
* @return {An OWLclass}
*/
public synchronized OWLClass ClassJenaToOwl(OntClass jenadata, String format) {
while (available == false) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("ClassJenaToOwl::: " + e);
}
}
available = false;
try {
OntModel model = ModelFactory.createOntologyModel();
model.createClass(jenadata.getURI());
OWLOntology owlmodel = ModelJenaToOwlConvert(model, format);
available = true;
notifyAll();
return owlmodel.getClassesInSignature().iterator().next();
} catch (Exception e) {
System.err.print("ClassJenaToOwl::: ");
e.printStackTrace();
return null;
}
}
use of com.hp.hpl.jena.ontology.OntModel in project stanbol by apache.
the class JenaToOwlConvert method ResourceJenaToOwlAxiom.
// //////////////////////////////////////////////////////////////////////////////
/**
* This function converts every statments relative to a resource in an a set of OWLAxiom objects
*
* @param jenadata
* {A resource in the form (S,P,O), it could be any kind of resource (a class, a data property,
* an object property and an instance) except a litteral}
* @param format
* {The format of the ontology, i.e. "RDF/XML"}
* @return {A set of axiom in the form of Set<OWLAxiom>}
*/
public synchronized Set<OWLAxiom> ResourceJenaToOwlAxiom(Resource jenadata, String format) {
while (available == false) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("ResourceJenaToOwlAxiom::: " + e);
}
}
available = false;
try {
OntModel model = ModelFactory.createOntologyModel();
StmtIterator prop = jenadata.listProperties();
while (prop.hasNext()) {
Statement stat = prop.nextStatement();
model.add(stat);
RDFNode obj = stat.getObject();
if (obj.isResource()) {
if (!obj.isURIResource()) {
StmtIterator aux = ((Resource) obj).listProperties();
while (aux.hasNext()) {
Statement stataux = aux.nextStatement();
model.add(stataux);
}
}
}
}
OWLOntology owlmodel = ModelJenaToOwlConvert(model, format);
available = true;
notifyAll();
return owlmodel.getAxioms();
} catch (Exception e) {
System.err.print("ResourceJenaToOwlAxiom::: ");
e.printStackTrace();
return null;
}
}
use of com.hp.hpl.jena.ontology.OntModel 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 com.hp.hpl.jena.ontology.OntModel 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 com.hp.hpl.jena.ontology.OntModel 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;
}
}
Aggregations