我正在尝试获取拥有超过 3 件作品的所有作者的列表 - DBpedia Sparql

I am trying to get list of all the authors who have had more than 3 piece of work - DBpedia Sparql

我正在尝试获取已完成 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

使用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)

HAVING (?tw > 3) 是正确的 SPARQL。由于 SELECTHAVING 在赋值之后进行过滤,因此 ?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 的赋值。