使用 SPARQL 和 Jena 查询 DBpedia
我不明白如何使用 Jena 查询 DBpedia。在此处等教程中(清单 4)模型是初始化如下:
// Open the bloggers RDF graph from the filesystem
InputStream in = new FileInputStream(new File("bloggers.rdf"));
// Create an empty in-memory model and populate it from the graph
Model model = ModelFactory.createMemModelMaker().createModel();
model.read(in,null); // null base URI, since model URIs are absolute
in.close();
假设我想编写一个查询来列出巴黎的教堂。在 SPARQL 中,它看起来像(取自 此邮件列表消息< /a>):
PREFIX p: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
PREFIX category: <http://dbpedia.org/resource/Category:>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX geo: <http://www.georss.org/georss/>
SELECT DISTINCT ?m ?n ?p ?d
WHERE {
?m rdfs:label ?n.
?m skos:subject ?c.
?c skos:broader category:Churches_in_Paris.
?m p:abstract ?d.
?m geo:point ?p
FILTER ( lang(?n) = "fr" )
FILTER ( lang(?d) = "fr" )
}
这个查询在 Java 中看起来如何?我特别感兴趣的是模型对象是如何初始化的。
I cannot understand how can I query DBpedia using Jena. In the tutorials like here(Listing 4) model is initialized as follows:
// Open the bloggers RDF graph from the filesystem
InputStream in = new FileInputStream(new File("bloggers.rdf"));
// Create an empty in-memory model and populate it from the graph
Model model = ModelFactory.createMemModelMaker().createModel();
model.read(in,null); // null base URI, since model URIs are absolute
in.close();
Let's say I want to write a query that will list churches in Paris. In SPARQL it will look like (taken from this mailing list message):
PREFIX p: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
PREFIX category: <http://dbpedia.org/resource/Category:>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX geo: <http://www.georss.org/georss/>
SELECT DISTINCT ?m ?n ?p ?d
WHERE {
?m rdfs:label ?n.
?m skos:subject ?c.
?c skos:broader category:Churches_in_Paris.
?m p:abstract ?d.
?m geo:point ?p
FILTER ( lang(?n) = "fr" )
FILTER ( lang(?d) = "fr" )
}
How will this query look in Java? Particularly, I'm interested in how the model object is initialized.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在浏览了大量的页面后,我找到了答案。也许我问的问题不够清楚,但无论如何,下面是对我有用的代码。
我在 dbpedia-discussion of www.mail- 上找到了这个答案archive.com 页面。
After browsing tons and tons of pages I found the answer. Perhaps I didn't ask the question clearly enough, but anyway below is the code that worked for me.
This answer I found on dbpedia-discussion of www.mail-archive.com page.