从lastfm.rdfize.com 添加RDF 模型
我正在用 Java 编程,尝试使用 Jena 库和 lastfm.rdfize.com 网站创建一个简单的 RDF 存储。
我遇到了以下问题: lastfm.rdfize.com 生成一个 rdf,例如在 Turtle 中,请求如下: “http://lastfm.rdfize.com/?username=&eventID=&artistName="+artistName+"&venueID=&output=turtle”
我发出请求并获取结果网页的内容。 如果我打印它们 - 对我来说它们似乎是一个不错的 RDF。
但是,我无法将它们添加到模型中。
我尝试创建一个文件,将字符串(即 HTML 内容)写入该文件(看起来也不错)并将其读取到模型中:
InputStream lastf = FileManager.get().open("lastfm.txt");
Model temp=null;
temp=ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
temp.read(lastf,null,"Turtle");
但是,此时我收到以下错误消息:
(ErrorHandlerLib.java :49) - [行: 22, 列: 2 ] 未知字符:
I am programming in Java, trying to make a simple RDF Store using Jena library and lastfm.rdfize.com website.
I'm getting into the following problem:
the lastfm.rdfize.com produces an rdf, for example in Turtle on the request like:
"http://lastfm.rdfize.com/?username=&eventID=&artistName="+artistName+"&venueID=&output=turtle"
I make a request and take the contents of the resulting web page.
If I print them - they seem like a decent RDF to me.
However, I can't add them to the model.
I tried creating a file, writing the String(which is the HTML content) to this file(which also seems okay) and reading it to the model like that:
InputStream lastf = FileManager.get().open("lastfm.txt");
Model temp=null;
temp=ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RDFS_INF);
temp.read(lastf,null,"Turtle");
However, at this point I get the following error message:
(ErrorHandlerLib.java:49) - [line: 22, col: 2 ] Unknown char:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码确实适合我使用像这样的简单的 RDF/Turtle ...
因此,您的数据文件
lastfm.txt
中似乎存在某种格式或字符集错误。我建议使用 RDF 验证器验证您的文件,尝试使用 http://www.rdfabout.com/demo /验证器/
使用此验证器,您可以测试 RDF/XML 和 RDF/Turtle,确保您为正在使用的 RDF 序列化类型选择正确的格式。
验证数据的另一个选项可能是来自 http://librdf.org 的 raptor 工具
但这有点复杂,您需要在本地安装它。
如果验证器提示字符集错误,那么您可以更改用于读取数据的字符集。像这样的东西应该可以工作..
所有这些都应该为您提供发现错误的指南(我希望),但如果您没有发现它,则发布数据以便我们可以查看它。
Your code does work for me with a trivial RDF/Turtle like ...
It seems therefore that you have some format or charset error in your data file
lastfm.txt
.I suggest to validate your file with an RDF validator, try with http://www.rdfabout.com/demo/validator/
With this validator you can test both RDF/XML and RDF/Turtle make sure you select the correct format for the type of RDF serialization you are working with.
Another option to validate your data could be the raptor tool from http://librdf.org
but this one is a bit more sophisticated and you need to install it locally.
If the validators shouts with a charset error then you could change the charset you are using to read your data. Something like this should work ..
All this should give you a guideline to spot the error (I hope) but If you don't spot it then post the data so that we can have a look at it.
听起来像是字符集问题。该文件是 utf-8 还是其他格式?
Sounds like charset trouble. Is the file in uTF-8 or something else?