组连接不起作用

Group concat not working

我在不使用 group_concat 的情况下编写了一个查询并返回了 9 行,一行对应爱因斯坦持有的每个职业。

当我在职业栏中添加 group_concat 时,该栏为空。我不明白我在这里做错了什么。我希望看到的是职业列中包含所有 9 个职业的 1 行。

这是简单的查询。

SELECT ?item ?itemLabel ?genderLabel (GROUP_CONCAT(?occupationLabel) AS ?occupations)
WHERE {
  ?item wdt:P31 wd:Q5.
  ?item ?label "Albert Einstein"@en.
  ?item wdt:P21 ?gender .
  ?item wdt:P106 ?occupation .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?item ?itemLabel ?genderLabel

编辑:

这是生成重复值的代码。

SELECT ?item ?itemLabel ?genderLabel (GROUP_CONCAT(?occupationLabel) AS ?occupations)
WHERE {
  ?item wdt:P31 wd:Q5.
  ?item ?label "Albert Einstein"@en.
  ?item wdt:P21 ?gender .
  OPTIONAL {
    ?item wdt:P106 ?occupation .
    ?occupation rdfs:label ?occupationLabel
    FILTER(LANGMATCHES(LANG(?occupationLabel), 'en'))
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?item ?itemLabel ?genderLabel

运行 这个查询给了我以下信息:

professor professor physicist physicist inventor educationalist educationist university teacher academic science writer non-fiction writer philosopher of science theoretical physicist

教授和物理学家重复


第二次编辑

另外值得注意的是,当我将查询修改为不使用 rdfs:label 时,我在职业列中得到了正确的连接结果(我已经将括号和标签添加到 URL):

http://www.wikidata.org/entity/Q121594 (professor) 
http://www.wikidata.org/entity/Q169470 (physicist) 
http://www.wikidata.org/entity/Q205375 (inventor) 
http://www.wikidata.org/entity/Q1231865 (educationalist)
http://www.wikidata.org/entity/Q1622272 (university teacher)
http://www.wikidata.org/entity/Q3745071 (science writer)
http://www.wikidata.org/entity/Q15980158 (non-fiction writer)
http://www.wikidata.org/entity/Q16389557 (philosopher of science)
http://www.wikidata.org/entity/Q19350898(theoretical physicist)

那么,我想我现在的问题是,是否可以为每个 ID 获取一个标签?

粗略的想法是使用专用的 SPARQL 三重模式来获取标签,而不是 "label service":

SELECT ?item ?itemLabel ?genderLabel (GROUP_CONCAT(?occupationLabel) AS ?occupations)
WHERE {
  ?item wdt:P31 wd:Q5.
  ?item ?label "Albert Einstein"@en.
  ?item wdt:P21 ?gender .
  OPTIONAL {
    ?item wdt:P106 ?occupation .
  }
  SERVICE wikibase:label { 
    bd:serviceParam wikibase:language "en". 
    ?item rdfs:label ?itemLabel . 
    ?gender rdfs:label ?genderLabel . 
    ?occupation rdfs:label ?occupationLabel 
  }
}
GROUP BY ?item ?itemLabel ?genderLabel