如何使用维基数据 SPARQL 查询服务访问子属性?
How to access child properties using Wikidata SPARQL Query Service?
我想访问维基数据实体的子属性。例如 属性 P1033, which is a child of P4952, for an entity such as Q49546。如何在 SPARQL 查询中动态执行此操作?
使用在线提供的查询构建器Wikidata Query Service, I can construct a simple query, which works for normal properties (in the linked example: mass), but not for the desired sub-properties (in the linked example: NPFA-code for health hazard), which end up empty, even though they are clearly set in the web-result。旁注:它与第一段中的示例不同。
想要的objective动态查询如下:
SELECT ?p ?item ?itemDescription ?prop ?value ?valueLabel ?itemLabel ?itemAltLabel ?propLabel WHERE {
BIND(wd:Q138809 AS ?item)
?prop wikibase:directClaim ?p.
#?item ?p ?value.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
?value rdfs:label ?valueLabel.
?prop rdfs:label ?propLabel.
?item rdfs:label ?itemLabel;
skos:altLabel ?itemAltLabel;
schema:description ?itemDescription.
}
}
ORDER BY DESC(?prop)
LIMIT 10
将第4行作为注释,我可以根据需要获得我的propLabel,但没有价值;反过来用 not as comment 行,我只得到在第一层设置的属性,而不是子属性。
感谢 ,我特此 post 解决我的问题的最终查询:
SELECT ?item ?itemLabel ?itemDescription ?itemAltLabel ?prop ?propertyLabel ?propertyValue ?propertyValueLabel ?qualifier ?qualifierLabel ?qualifierValue
{
VALUES (?item) {(wd:Q138809)}
?item ?prop ?statement .
?statement ?ps ?propertyValue .
?property wikibase:claim ?prop .
?property wikibase:statementProperty ?ps .
OPTIONAL { ?statement ?pq ?qualifierValue . ?qualifier wikibase:qualifier ?pq . }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
对我来说关键的一步是理解子属性实际上被称为 qualifiers。
我想访问维基数据实体的子属性。例如 属性 P1033, which is a child of P4952, for an entity such as Q49546。如何在 SPARQL 查询中动态执行此操作?
使用在线提供的查询构建器Wikidata Query Service, I can construct a simple query, which works for normal properties (in the linked example: mass), but not for the desired sub-properties (in the linked example: NPFA-code for health hazard), which end up empty, even though they are clearly set in the web-result。旁注:它与第一段中的示例不同。
想要的objective动态查询如下:
SELECT ?p ?item ?itemDescription ?prop ?value ?valueLabel ?itemLabel ?itemAltLabel ?propLabel WHERE {
BIND(wd:Q138809 AS ?item)
?prop wikibase:directClaim ?p.
#?item ?p ?value.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
?value rdfs:label ?valueLabel.
?prop rdfs:label ?propLabel.
?item rdfs:label ?itemLabel;
skos:altLabel ?itemAltLabel;
schema:description ?itemDescription.
}
}
ORDER BY DESC(?prop)
LIMIT 10
将第4行作为注释,我可以根据需要获得我的propLabel,但没有价值;反过来用 not as comment 行,我只得到在第一层设置的属性,而不是子属性。
感谢
SELECT ?item ?itemLabel ?itemDescription ?itemAltLabel ?prop ?propertyLabel ?propertyValue ?propertyValueLabel ?qualifier ?qualifierLabel ?qualifierValue
{
VALUES (?item) {(wd:Q138809)}
?item ?prop ?statement .
?statement ?ps ?propertyValue .
?property wikibase:claim ?prop .
?property wikibase:statementProperty ?ps .
OPTIONAL { ?statement ?pq ?qualifierValue . ?qualifier wikibase:qualifier ?pq . }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
对我来说关键的一步是理解子属性实际上被称为 qualifiers。