我想获得所有作者超过3件作品的列表 - DBpedia Sparql

时间:2017-04-25 17:33:16

标签: bigdata sparql dbpedia virtuoso triplestore

我正在尝试获取所有已完成3项或更多工作的作者的列表(在DBpedia中)。

我的示例可以在http://dbpedia.org/sparql

上运行

基本代码

select (count(?work) as ?totalWork), ?author
Where
{
  ?work dbo:author ?author.
}
GROUP BY ?author

我得到每个作者完成的工作总量。但是当我尝试过滤以仅显示具有超过3件作品的作者列表时。我收到错误:

我尝试了HAVING关键字或使用FILTER关键字。

使用过滤器

select (count(?work) as ?tw), ?author
Where
{
  ?work dbo:author ?author.
  FILTER (?work > 3).
}
GROUP BY ?author

error: Virtuoso 22023 Error VECDT: SR066: Unsupported case in CONVERT (INTEGER -> IRI_ID)

使用HAVING关键字

select (count(?work) as ?tw), ?author
Where
{
  ?work dbo:author ?author.
}
GROUP BY ?author
HAVING (?tw > 3)

Virtuoso 37000 Error SP031: SPARQL compiler: Variable ?tw is used in the result set outside aggregate and not mentioned in GROUP BY clause

2 个答案:

答案 0 :(得分:3)

使用HAVING是正确的,但有一个limitation in SPARQL with indirectly referring to aggregates

这个有效:

SELECT (count(?work) as ?tw) ?author
WHERE
{
  ?work dbo:author ?author.
}
GROUP BY ?author
HAVING (count(?work) > 3)

答案 1 :(得分:1)

HAVING (?tw > 3)是正确的SPARQL。由于HAVING而导致分配后SELECT过滤,因此?tw可见,并且在投影之前。

(prefix ((dbo: <http://purl.org/dc/elements/1.1/>))
    (project (?tw ?author)
      (filter (> ?tw 3)
        (extend ((?tw ?.0))
          (group (?author) ((?.0 (count ?work)))
            (bgp (triple ?work dbo:author ?author)))))))

其中?.0count的分配。