sparql - SPARQL:排除 COUNT 中的双重资源
问题描述
我正在尝试编写一个 SPARQL 查询,它只计算每所大学的荷兰政治家人数。然而,对于每个 dbo:almaMater,对于一些政治家来说,有一个额外的资源(例如他们的专业,dbr:Sociology)。这也反映在 COUNT 中。例如。我得到莱顿大学的计数 49,这应该只有 42。知道如何解决这个问题吗?我已经尝试过 FILTER NOT EXISTS 和 MINUS 但两者都对计数没有任何作用。谢谢你。
我的查询:
SELECT distinct ?education (COUNT(?education) AS ?edu_count)
WHERE { ?name <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Person>.
?name <http://dbpedia.org/ontology/birthPlace> <http://dbpedia.org/resource/Netherlands>.
?name <http://dbpedia.org/ontology/party> ?party.
?name <http://dbpedia.org/ontology/almaMater> ?education.
?education <http://dbpedia.org/ontology/type> <http://dbpedia.org/resource/Public_university>.
} GROUP BY ?education
ORDER BY DESC(?edu_count)
解决方案
修改后的查询,基于评论,为了清楚起见,有额外的空格。查询形式,结果——
SELECT ?education
( COUNT ( DISTINCT ?name ) AS ?cnt )
WHERE { ?name <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Person> .
?name <http://dbpedia.org/ontology/birthPlace> <http://dbpedia.org/resource/Netherlands> .
?name <http://dbpedia.org/ontology/party> ?party .
?name <http://dbpedia.org/ontology/almaMater> ?education .
?education <http://dbpedia.org/ontology/type> <http://dbpedia.org/resource/Public_university> .
}
GROUP BY ?education
ORDER BY DESC ( ?cnt )
ASC ( ?education )
推荐阅读
- javascript - 解决小图中简单的 D3.js 交叉边
- python - 找到 3 个 Numpy 数组 Python 的交点
- facebook - 如何获取分享我的 Facebook 帖子的人员列表?
- ios - 在 IOS 中用自定义 SFSafariViewController 替换 AppAuth
- laravel - 调用未定义的方法 Illuminate\Container\Container::getLocale() | 拉拉维尔 8
- grpc-web - gRPC-js + Angular ngx-grpc - Stream 在收到 4 条消息后停止接收消息
- r - 将宽数据帧重塑为长格式
- php - 比较数组值并选择特定的值
- linux - X11 窗口失去 Qt 窗口的活动状态
- keycloak - 我可以将“主题提示”传递给 Keycloak,例如 kc_idp_hint