查找在SPARQL查询中应用的直接属性 [英] Find which direct property applied in a SPARQL query

查看:100
本文介绍了查找在SPARQL查询中应用的直接属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要应用于特定实体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". }
}

推荐答案

使用 VALUES UNION :

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆