felipe.zkn felipe.zkn - 9 months ago 32
Java Question

Jena API - How can I handle OWL files?

I have the below code to list individuals of an ontology:

public static void main(String[] args) {
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
String fileName = "C:/Users/Ikno/Desktop/workspace/Jena/ontrdf.rdf";

try {
InputStream inputStream = new FileInputStream(fileName);
model.read(inputStream, "RDF/XML");
//model.read(inputStream, "OWL/XML");
} catch (Exception e) {

ExtendedIterator<Individual> itI = model.listIndividuals();

while (itI.hasNext()) {
Individual i = itI.next();

The code is OK, and it returns all the individual local names. The problem is that I created the OWL ontology in Protégé and it is a wasteful step to convert it to RDF, just to be operated by Jena. If I uncomment
model.read(inputStream, "OWL/XML");
, it gives me the following error:

class org.apache.jena.riot.RiotException
[line: 266, col: 31] {E201} Multiple children of property element

Can't Jena support this kind of operation with OWL format?

Answer Source

According to Jena Documentation here If you look at the read method, it is clear that Jena does not support OWL/XML. Predefined values for lang (Second Arg to read method) are "RDF/XML", "N-TRIPLE", "TURTLE" (or "TTL") and "N3". null represents the default language, "RDF/XML". "RDF/XML-ABBREV" is a synonym for "RDF/XML". So in your case I would save the ontology as RDF/XML and then read it with Jena.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download