jenan-triples

How to load N-TRIPLE file in apache jena?


I am quite new to RDF and Jena. I want load a .nt (N- TRIPLE) file to a model. I have tried read(inputStream, "N-TRIPLE") but did not help.

It throws

org.apache.jena.riot.RiotException: Element or attribute do not match QName production: QName::=(NCName':')?NCName.

Can anyone point me out what is wrong?

Here is the link for the N-TRiple file which I tried to load : http://dbpedia.org/data/Berlin.ntriples


Solution

  • read(inputStream, string) uses the string argument as the base URI, not the syntax language. It's trying the default, which is RDF/XML. Check the javadoc for Model#read(InputStream in, String base) and Model#read(InputStream in, String base, String lang) for more information.

    model.read(inputStream, null, "N-TRIPLES") ;
    

    or

    RDFDataMgr.read(model, inputStream, LANG.NTRIPLES) ;
    

    If you are just opening the stream from a file (or URL) then Apache Jena will sort out the details. E.g.,

    RDFDataMgr.read(model, "file:///myfile.nt") ;
    

    There are various related operations. See the javadoc for Model and RDFDataMgr.