Ash*_*ngh 0 java semantic-web sparql dbpedia
我有许多 DBpedia 页面的链接,例如:
http://dbpedia.org/resource/Harry_Potter
http://dbpedia.org/resource/Twilight_(series)
http://dbpedia.org/resource/Bible
http:// /dbpedia.org/resource/Manga
我想获取其中每一个的 Abstract 和 Thumbnail 实体。
我可以使用以下方法单独获取它们:
对于摘要:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX res: <http://dbpedia.org/resource/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?label
WHERE { <http://dbpedia.org/resource/Harry_Potter>
dbo:abstract ?label . FILTER (lang(?label) = \'en\')}
Run Code Online (Sandbox Code Playgroud)对于缩略图:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX res: <http://dbpedia.org/resource/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?thumbnail
WHERE { <http://dbpedia.org/resource/Harry_Potter>
dbo:thumbnail ?thumbnail}
Run Code Online (Sandbox Code Playgroud)是否可以将上述两个查询合并为一个查询。我对 SPARQL 很陌生,无法让它工作。
另外,有没有比我目前的方法更好的查询方法?
当然可以将它们组合起来,简单的方法就是将两个WHEREs的主体连接起来并相应地调整SELECT:
SELECT ?label ?thumbnail
WHERE {
<http://dbpedia.org/resource/Harry_Potter> dbo:abstract ?label .
FILTER (lang(?label) = 'en')
<http://dbpedia.org/resource/Harry_Potter> dbo:thumbnail ?thumbnail .
}
Run Code Online (Sandbox Code Playgroud)
如果您想更简洁,可以使用以下命令将具有相同主题的两个三元组组合起来;:
SELECT ?label ?thumbnail
WHERE {
<http://dbpedia.org/resource/Harry_Potter>
dbo:abstract ?label ;
dbo:thumbnail ?thumbnail .
FILTER (lang(?label) = 'en')
}
Run Code Online (Sandbox Code Playgroud)
由于您定义了res:前缀,您可以使用它来缩短 URI:
SELECT ?label ?thumbnail
WHERE {
res:Harry_Potter
dbo:abstract ?label ;
dbo:thumbnail ?thumbnail .
FILTER (lang(?label) = 'en')
}
Run Code Online (Sandbox Code Playgroud)