查找在SPARQL查询中应用的直接属性 [英] Find which direct property applied in a SPARQL query
问题描述
我有一个要应用于特定实体mathematics: wd:Q395
的属性列表.在这种情况下:
I have a list of properties I want to apply to a specific entity mathematics: wd:Q395
. In this case:
instanceOf: 'wdt:P31'
subclassOf: 'wdt:P279'
结果是:
数学是学科的实例, 数学是精确科学和形式科学的子类
Mathematics is instance of academic discipline and Mathematics is subclass of exact science and formal science
我不想一次进行两个不同的查询,而是希望一次全部完成:
Instead of making two different queries I would like to make them all at once:
SELECT ?field ?fieldLabel ?propertyApplied
WHERE {
wd:Q395 wdt:P31 | wdt:P279 ?field.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
BIND("" AS ?propertyApplied)
}
我如何知道哪个属性应用于填充右列?(例如,我希望在学科旁边显示它的实例)
How can I know which property applied to fill the right column? ( for example next to academic discipline I would like that it appears instance of)
我尝试过,但是看起来很奇怪,结果重复出现.
I tried this but it looks weird and the results repeat themselves.
SELECT ?instanceOf ?subclassOf ?instanceOfLabel ?subclassOfLabel
WHERE {
OPTIONAL { wd:Q395 wdt:P31 ?instanceOf. }
OPTIONAL { wd:Q395 wdt:P279 ?subclassOf. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
推荐答案
SELECT ?field ?fieldLabel ?propertyLabel WHERE {
VALUES (?predicate) {(wdt:P31) (wdt:P279)}
wd:Q395 ?predicate ?field .
?property wikibase:directClaim ?predicate .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
这篇关于查找在SPARQL查询中应用的直接属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!