SPARQL 未使用图像网格视图显示部分结果

问题描述 投票:0回答:1

我根据某些条件创建了一个查找女性艺术家的查询,并希望在查询结果中包含图片,以便 #defaultView: ImageGrid 视图不仅显示所需的数据,还显示相应的艺术家图像(P18) 。我知道有时图像可能不存在,所以我使用了一个可选子句,以免丢失有关没有图像的艺术家的数据。

但是,当默认视图设置为 ImageGrid 时,我看不到所有结果。要检查所有这些,我必须切换到表格视图。

查询是:

#defaultView:ImageGrid

SELECT distinct
  (year(?birthDate) as ?year)
  ?person
  ?personLabel
  (count(distinct ?notablework) as ?workCount)
  (GROUP_CONCAT(DISTINCT ?notableworkLabel; separator="; ") AS ?works )
  (sample(?image) as ?imageSample)
  ?placeOfBirth
  ?cood

WHERE {
  ?person wdt:P106 wd:Q483501 .
  ?person rdfs:label ?personLabel .
  FILTER (LANG ( ?personLabel ) = "en" )
  
  ?person wdt:P21 wd:Q6581072 .
  ?person wdt:P569 ?birthDate .
  
  ?person wdt:P800 ?notablework .
  ?notablework rdfs:label ?notableworkLabel .
  FILTER (LANG ( ?notableworkLabel ) = "en" )
  
  FILTER(year(?birthDate) > 1899 && year(?birthDate) < 2000)
  
  ?person wdt:P27 wd:Q30 .
  ?person wdt:P6379 wd:Q160236.
  
  OPTIONAL {?person wdt:P18 ?image} .
  OPTIONAL {?person wdt:P19 ?country .
    ?country rdfs:label ?placeOfBirth .
    ?country wdt:P625 ?cood .
    FILTER (LANG ( ?placeOfBirth ) = "en")
  }
}

GROUP BY ?person ?personLabel ?placeOfBirth ?cood ?birthDate
HAVING (?workCount >= 3)
ORDER BY ?personLabel

我所说的可选子句是第 30 行:

OPTIONAL {?person wdt:P18 ?image} .

Query actually retrieves 7 results, But only 3 are shown in an image grid.

使用 OPTIONAL 子句,我希望在 ImageGrid 视图中看到所有 7 个结果,认为会出现某种“图像不可用”消息而不是图片,但这并没有发生。

我也认为这与我的浏览器有关,但从 Firefox 切换到 Chrome 没有成功。

实际上是否有一种方法可以在 SPARQL 中执行类似的操作,或者我描述的预期布局通常不会在服务中实现?

sparql rdf wikidata wikidata-query-service
1个回答
0
投票

正如 UninformedUser 在评论中所说,您可以使用以下 SPARQL 片段:

OPTIONAL {?person wdt:P18 ?image_} .
BIND(
    COALESCE(?image_, <http://commons.wikimedia.org/wiki/Special:FilePath/File:Profile_avatar_placeholder_large.png>)
    AS ?image)

根据SPARQL 1.1规范

COALESCE 函数形式返回第一个计算无误的表达式的 RDF 项值。

因此,如果

?image_
变量在 OPTIONAL 子句中定义,它将绑定到
?image
变量。否则,默认图像将绑定到
?image
变量。

© www.soinside.com 2019 - 2024. All rights reserved.