开发者

Problem of reading OWL/XML

I have a problem reading OWL/XML files from Java using Jena.

I have no problem reading RDF/XML files, but whenever I create a OWL/XML file from Protege and try to read it, Java gives this error below : WARN [main] (RDFDefaultErrorHandler.java:36) Exception in thread "main" java.lang.NullPointerException at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.endElement(XMLHandler.java:143)

The code that I use to retrieve RDF/XML is below :

OntModel ontModel = ModelFactory.createOntologyModel();
Input开发者_如何学PythonStream in = FileManager.get().open(inputFileName);
    if (in == null) {
        throw new IllegalArgumentException( "File: " + inputFileName + " not found");
    }
    ontModel.read(in, "");

This code works with RDF/XML perfectly. However, I cannot read an OWL/XML. I looked at Internet and I couldn't find anything. I would really appreciate, if someone shows me a way. Many thanks


For OWL/XML use the OWL-API.


Jena does not support OWL/XML. It ships with readers for RDF/XML, Turtle (a.k.a. N3) and N-Triples. See for example here for the list of supported formats.


You can find a good answer here.

  • http://answers.semanticweb.com/questions/15004/using-jena-to-access-an-owlxml-file-made-from-protege

I tested the code that is provided in the 4th answer and it works for me 100%. I copied the answer here for you.

String inputFileName = "D:\Ontologia\OntoSME_V7.owl";

OntModel onto = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, null);

try {
    InputStream in = FileManager.get().open(inputFileName);
    onto.read(in, "RDF/XML");
} catch (JenaException je) {
    System.out.println("ERROR" + je.getMessage());
    je.printStackTrace();
    System.exit(0);
}

you can use protege to save the file in RDF/XML format and read the file with above technique.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜