按人数统计子职业并对其进行排名
Counting and rank subprofessions by number of people
我目前正在尝试为 Wikidata 编写一个 SPARQL 查询,其中我根据拥有相应职业的人数对子职业进行排名,并根据他们的父职业按字母顺序对其进行分组。
我的最终结果应该类似于
Profession | Subprofession | Count
Artist | Painter | 34
Artist | Actor | 12
Politician | President | 67
Politician | Minister | 13
现在,我只能显示父职业,但我觉得我还有很长的路要走,在查询中引入子职业并尝试将其与父职业领导一起显示一直到Timeout。我应该在这里使用嵌套 SELECTS 吗?我对他们不是很熟悉
SELECT ?occupation ?suboccupation (count(*) as ?count)
WHERE
{
?people wdt:P106 ?occupation . #occupation
?suboccupation wdt:P279 ?occupation . #subclassof
}
GROUP BY ?occupation ?suboccupation
ORDER BY DESC(?count)
先谢谢大家了!
好吧,似乎有些职业和子职业没有英文语言标签,所以有些列表不是很有用。此外,这个列表很长!您可能希望聚合更多或以某种方式限制结果。
这是您可能想要的开始:
SELECT ?profLabel ?subprofLabel ?count
WITH {
SELECT ?prof ?subprof (COUNT(?person) AS ?count) WHERE {
?prof wdt:P31 wd:Q28640.
?subprof wdt:P279+ ?prof.
?person wdt:P106 ?subprof.
}
GROUP BY ?prof ?subprof
} AS %main {
INCLUDE %main .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?profLabel DESC(?count)
我目前正在尝试为 Wikidata 编写一个 SPARQL 查询,其中我根据拥有相应职业的人数对子职业进行排名,并根据他们的父职业按字母顺序对其进行分组。 我的最终结果应该类似于
Profession | Subprofession | Count
Artist | Painter | 34
Artist | Actor | 12
Politician | President | 67
Politician | Minister | 13
现在,我只能显示父职业,但我觉得我还有很长的路要走,在查询中引入子职业并尝试将其与父职业领导一起显示一直到Timeout。我应该在这里使用嵌套 SELECTS 吗?我对他们不是很熟悉
SELECT ?occupation ?suboccupation (count(*) as ?count)
WHERE
{
?people wdt:P106 ?occupation . #occupation
?suboccupation wdt:P279 ?occupation . #subclassof
}
GROUP BY ?occupation ?suboccupation
ORDER BY DESC(?count)
先谢谢大家了!
好吧,似乎有些职业和子职业没有英文语言标签,所以有些列表不是很有用。此外,这个列表很长!您可能希望聚合更多或以某种方式限制结果。
这是您可能想要的开始:
SELECT ?profLabel ?subprofLabel ?count
WITH {
SELECT ?prof ?subprof (COUNT(?person) AS ?count) WHERE {
?prof wdt:P31 wd:Q28640.
?subprof wdt:P279+ ?prof.
?person wdt:P106 ?subprof.
}
GROUP BY ?prof ?subprof
} AS %main {
INCLUDE %main .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?profLabel DESC(?count)