Reputation: 2060
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");
inputStream.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
ExtendedIterator<Individual> itI = model.listIndividuals();
while (itI.hasNext()) {
Individual i = itI.next();
System.out.println(i.getLocalName());
}
}
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?
Upvotes: 2
Views: 2941
Reputation: 835
As an option you can use ONT-API, which is a kind of bridge between OWL-API and Apache Jena. Thus, it supports all jena and owl-api formats together (OWL/XML is the original format of OWL-API&protege only), but (note) without its own implementation.
Upvotes: 3
Reputation: 1304
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.
Upvotes: 2