SPARQL新手求教:如何查询Wikibase中语句的限定符信息?
解决SPARQL查询Wikibase限定符的问题
要获取公共资金(P92)附带的限定符(资金子部分P62),你需要调整查询结构——直接属性(epfowdt:*)会跳过statement层级,而限定符是绑定在statement节点上的元数据,必须通过statement节点才能访问。
修改后的完整查询
PREFIX epfowd: <https://wikibase.epfo.eu/entity/> PREFIX epfowdt: <https://wikibase.epfo.eu/prop/direct/> PREFIX epfop: <https://wikibase.epfo.eu/prop/> PREFIX epfops: <https://wikibase.epfo.eu/prop/statement/> PREFIX epfopq: <https://wikibase.epfo.eu/prop/qualifier/> SELECT ?itemLabel ?publicfunding ?mepfunding ?mepfundingLabel WHERE { # 筛选政党实体 ?item epfowdt:P9 epfowd:Q2 ; # 关联到P92对应的statement节点 epfop:P92 ?statement . # 从statement节点提取公共资金金额 ?statement epfops:P92 ?publicfunding ; # 从同一个statement节点提取P62限定符的值 epfopq:P62 ?mepfunding . # 获取多语言可读标签 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". } } ORDER BY ?itemLabel
关键修改说明
- 引入statement节点:用
epfop:P92 ?statement替代原查询的epfowdt:P92 ?publicfunding,先获取属性对应的statement节点,这是访问限定符的前提 - 拆分主值与限定符:通过
epfops:P92获取公共资金的实际数值,通过epfopq:P62获取绑定在该statement上的限定符内容 - 可选优化:如果需要
?mepfunding的可读标签,只需在SELECT子句和标签服务中添加?mepfundingLabel即可
内容的提问来源于stack exchange,提问作者KenMatsuo
相关产品推荐
相关产品推荐

