组连动不起作用

NaN*_*NaN 1 sparql

我编写了一个不使用group_concat的查询,并返回了9行,爱因斯坦持有的每个职业都包含一行。

当我在占领列上添加group_concat时,该列为null。我不明白我在做什么错。我希望看到的是“职业”列中所有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
Run Code Online (Sandbox Code Playgroud)

编辑:

这是产生重复值的代码。

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
Run Code Online (Sandbox Code Playgroud)

运行此查询将为我提供以下内容:

教授教授物理学家物理学家发明家教育家教育家大学老师学术科学作家非小说类作家科学哲学家理论物理学家

教授和物理学家重复


第二次编辑

另外值得注意的是,当我将查询修改为not use时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)
Run Code Online (Sandbox Code Playgroud)

因此,我想我现在的问题是,是否可以为每个ID获得一个标签?

AKS*_*KSW 5

粗略的想法是使用专用的SPARQL三元模式来获取标签,而不是使用“标签服务”:

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
Run Code Online (Sandbox Code Playgroud)