use of com.hp.hpl.jena.ontology.OntModel in project stanbol by apache.
the class JenaToOwlConvert method ObjPropJenaToOwl.
// //////////////////////////////////////////////////////////////////////////////
/**
* This function converts a single ObjectProperty of Jena to an OWLObjectProperty of OWLAPI
*
* @param jenadata
* {Jena ObjectProperty object}
* @param format
* {RDF/XML}
* @return {An OWLObjectProperty}
*/
public synchronized OWLObjectProperty ObjPropJenaToOwl(ObjectProperty jenadata, String format) {
while (available == false) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("ClassOwlToJena::: " + e);
}
}
available = false;
try {
OntModel model = ModelFactory.createOntologyModel();
model.createObjectProperty(jenadata.getURI());
OWLOntology owlmodel = ModelJenaToOwlConvert(model, format);
available = true;
notifyAll();
return owlmodel.getObjectPropertiesInSignature().iterator().next();
} catch (Exception e) {
System.err.print("ClassOwlToJena::: ");
e.printStackTrace();
return null;
}
}
use of com.hp.hpl.jena.ontology.OntModel in project stanbol by apache.
the class ConversionTester method testDataPropJenaToOwl.
public void testDataPropJenaToOwl() {
JenaToOwlConvert j2o = new JenaToOwlConvert();
OntModel model = ModelFactory.createOntologyModel();
DatatypeProperty jp = model.createDatatypeProperty(DP.toString());
OWLDataProperty wp = null;
try {
wp = j2o.DataPropJenaToOwl(jp, RDFXML);
if (wp == null) {
fail("Some problem accours");
} else {
assertEquals(wp.getIRI().toURI().toString(), jp.getURI());
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception caugth");
} finally {
assertNotNull(wp);
}
}
use of com.hp.hpl.jena.ontology.OntModel in project stanbol by apache.
the class UrlInputProvider method getInput.
@Override
public <T> Iterator<T> getInput(Class<T> type) throws IOException {
if (type.isAssignableFrom(OWLAxiom.class)) {
// We add additional axioms
OWLOntology fromUrl;
try {
fromUrl = createOWLOntologyManager().loadOntologyFromOntologyDocument(IRI.create(url));
} catch (OWLOntologyCreationException e) {
throw new IOException(e);
}
Set<OWLOntology> all = fromUrl.getImportsClosure();
List<OWLAxiom> axiomList = new ArrayList<OWLAxiom>();
for (OWLOntology o : all) {
axiomList.addAll(o.getAxioms());
}
final Iterator<OWLAxiom> iterator = axiomList.iterator();
return new Iterator<T>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@SuppressWarnings("unchecked")
@Override
public T next() {
return (T) iterator.next();
}
@Override
public void remove() {
// This iterator is read-only
throw new UnsupportedOperationException("Cannot remove statements from the iterator");
}
};
} else if (type.isAssignableFrom(Statement.class)) {
final OntModel input = ModelFactory.createOntologyModel();
synchronized (url) {
// FIXME: use instead:
// FileManager.get().loadModel
input.read(url);
}
final StmtIterator iterator = input.listStatements();
return new Iterator<T>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@SuppressWarnings("unchecked")
@Override
public T next() {
return (T) iterator.next();
}
@Override
public void remove() {
// This iterator is read-only
throw new UnsupportedOperationException("Cannot remove statements from the iterator");
}
};
} else {
throw new UnsupportedOperationException("This provider does not adapt to the given type");
}
}
use of com.hp.hpl.jena.ontology.OntModel in project stanbol by apache.
the class ByteArrayInputProvider method getInput.
@Override
public <T> Iterator<T> getInput(Class<T> type) throws IOException {
if (type.isAssignableFrom(OWLAxiom.class)) {
// We add additional axioms
OWLOntology fromUrl;
try {
fromUrl = createOWLOntologyManager().loadOntologyFromOntologyDocument(new ByteArrayInputStream(bytes));
} catch (OWLOntologyCreationException e) {
throw new IOException(e);
}
Set<OWLOntology> all = fromUrl.getImportsClosure();
List<OWLAxiom> axiomList = new ArrayList<OWLAxiom>();
for (OWLOntology o : all) {
axiomList.addAll(o.getAxioms());
}
final Iterator<OWLAxiom> iterator = axiomList.iterator();
return new Iterator<T>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@SuppressWarnings("unchecked")
@Override
public T next() {
return (T) iterator.next();
}
@Override
public void remove() {
// This iterator is read-only
throw new UnsupportedOperationException("Cannot remove statements from the iterator");
}
};
} else if (type.isAssignableFrom(Statement.class)) {
final OntModel input = ModelFactory.createOntologyModel();
synchronized (bytes) {
// XXX
// Not sure this would always work. What if we have an RDF/XML relying on an implicit base?
input.read(new ByteArrayInputStream(bytes), "");
}
final StmtIterator iterator = input.listStatements();
return new Iterator<T>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@SuppressWarnings("unchecked")
@Override
public T next() {
return (T) iterator.next();
}
@Override
public void remove() {
// This iterator is read-only
throw new UnsupportedOperationException("Cannot remove statements from the iterator");
}
};
} else {
throw new UnsupportedOperationException("This provider does not adapt to the given type");
}
}
use of com.hp.hpl.jena.ontology.OntModel in project stanbol by apache.
the class JenaToOwlConvert method ModelOwlToJenaConvert.
// //////////////////////////////////////////////////////////////////////////////
/**
* This function converts an ontology object from OWLapi to Jena
*
* @param owlmodel
* {An OWLOntology object}
* @param format
* {RDF/XML or TURTLE}
* @return {An OntModel that is a Jena object}
*/
public synchronized OntModel ModelOwlToJenaConvert(OWLOntology owlmodel, String format) {
while (availablemain == false) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("ModelOwlToJenaConvert::: " + e);
}
}
availablemain = false;
OWLOntologyID id;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
OWLOntologyManager owlmanager = owlmodel.getOWLOntologyManager();
format = format.trim();
if (format.equals("TURTLE") || format.equals("RDF/XML")) {
if (format.equals("TURTLE"))
owlmanager.setOntologyFormat(owlmodel, new TurtleOntologyFormat());
if (format.equals("RDF/XML"))
owlmanager.setOntologyFormat(owlmodel, new RDFXMLOntologyFormat());
OWLOntologyFormat owlformat = owlmanager.getOntologyFormat(owlmodel);
owlmanager.saveOntology(owlmodel, owlformat, out);
OntModel jenamodel = ModelFactory.createOntologyModel();
id = owlmodel.getOntologyID();
jenamodel.read(new ByteArrayInputStream(out.toByteArray()), id.toString().replace("<", "").replace(">", ""), format);
availablemain = true;
notifyAll();
return jenamodel;
} else {
System.err.println("The only format supported is RDF/XML or TURTLE. Please check the format!");
availablemain = true;
notifyAll();
return null;
}
} catch (OWLOntologyStorageException eos) {
System.err.print("ModelOwlToJenaConvert::: ");
eos.printStackTrace();
return null;
}
}
Aggregations