【问题标题】:How to query a particular DBpedia Resource/Page for multiple entities?如何为多个实体查询特定的 DBpedia 资源/页面?
【发布时间】:2016-03-03 15:04:32
【问题描述】:

我有许多 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\')}
    
  • 对于缩略图:

    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}
    

是否可以将上述两个查询合并为一个查询。我对 SPARQL 非常陌生,无法让 it 工作。

另外,有没有比我目前的方法更好的查询方式?

【问题讨论】:

  • 当然,您可以将三种模式组合成一个查询。更好是什么意思?
  • 如何组合它们?更好的意思是更优化的方式
  • 在最简单的情况下,只需将两个三元组模式放在同一个查询中,每个模式都以一个点 . 结尾。在您的示例中,没有太多优化空间,因为它太简单了。如果您想编写更紧凑的 SPARQL 查询,可以查看 TURTLE 语法,它基本上是您在 SPARQL 中编写三元组模式的方法。
  • 谢谢@AKSW 我已经搞定了。
  • 这似乎表明缺乏研究工作:即使浏览 Stack Overflow 上最近的任何 sparql 问题都会显示大量示例,说明您所要求的内容。几乎任何 sparql 教程都是如此,w3c'so sparql 规范也是如此,它充满了示例。

标签: java sparql semantic-web dbpedia


【解决方案1】:

当然可以将它们组合起来,简单的方法就是连接两个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 .
}

如果你想更简洁,你可以使用;将两个三元组与同一主题组合起来:

SELECT ?label ?thumbnail
WHERE {
    <http://dbpedia.org/resource/Harry_Potter>
        dbo:abstract ?label ; 
        dbo:thumbnail ?thumbnail .
    FILTER (lang(?label) = 'en')
}

并且由于您定义了 res: 前缀,您可以使用它来缩短 URI:

SELECT ?label ?thumbnail
WHERE {
    res:Harry_Potter
        dbo:abstract ?label ; 
        dbo:thumbnail ?thumbnail .
    FILTER (lang(?label) = 'en')
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-06
  • 2016-07-11
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 1970-01-01
相关资源
最近更新 更多