How to load N-TRIPLE file in apache jena?

岁酱吖の 提交于 2019-12-11 00:54:33

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/23978172/how-to-load-n-triple-file-in-apache-jena

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!