2

これは Sparql と Wikidata に関する質問です。インスタンス型のリレーションを返すクエリを作成したいのですが、利用できない場合はそのサブクラスを返します。私は試した:

SELECT DISTINCT  ?ent_type  WHERE { 

 { wd:Q7696957 wdt:P31 ?instanceof . } UNION 
 { wd:Q7696957 wdt:P31/wdt:P279? ?subclass .  } UNION 
 { wd:Q7696957 wdt:P279* ?subclass  . } 

 BIND ( IF (BOUND (?instanceof), ?instanceof, ?subclass ) as ?ent_type  ) 

残念ながら、これはすべてのソリューションを返しますが、私は1つのソリューションしか必要としません

ent_type
----------
wd:Q811979
wd:Q386724
wd:Q811430
wd:Q7696957
4

2 に答える 2

5

合体を使用してこれを実現できます。

select distinct ?ent_type where { 
  optional { wd:Q7696957 wdt:P31 ?direct }
  optional { wd:Q7696957 wdt:P31/wdt:P279? ?indirect }
  optional { wd:Q7696957 wdt:P279* ?ancestor }
  bind(coalesce(?direct, ?indirect, ?ancestor) as ?ent_type)
}
于 2016-04-25T23:12:25.813 に答える