简体   繁体   English

SPARQL ASK查询中的多个条件

[英]multiple conditions in SPARQL ASK query

I need to include few conditions in SPARQL ASK query. 我需要在SPARQL ASK查询中包括一些条件。

I tried -- 我试过了 -

  • nesting a few ASK queries 嵌套一些ASK查询
  • nesting SELECT statement inside ASK query ASK查询中嵌套SELECT语句
  • just putting all the conditions in ASK query 只需将所有条件放在ASK查询中

-- but the answer is always wrong. -但是答案总是错误的。

I've checked all the conditions one by one and it's working, so the problem is just in query construction. 我已经一一检查了所有条件,它是否有效,所以问题就出在查询构造中。

Approximately this is what I want: 大概这就是我想要的:

PREFIX m: <http://data.linkedmdb.org/resource/movie/>
ASK
  {
    ?kraj  m:country        "United Kingdom".
    ?rez   m:director_name  ?rezyser .
    FILTER regex(?rezyser, "James", "i")
  }

How can I make it work? 我该如何运作?

If you simply put multiple clauses in the WHERE clause of any SPARQL query then you are asking that ALL those clauses must be satisfied in order for an answer to be returned. 如果仅将多个子句放在任何SPARQL查询的WHERE子句中,则您要求必须满足所有这些子句才能返回答案。

It sounds like what you actually want to know is if ANY of those clauses are satisfied in which case you need to use the UNION operator eg 听起来您实际上想知道的是,如果满足这些子句中的任何一个 ,在这种情况下,您需要使用UNION运算符,例如

PREFIX m: <http://data.linkedmdb.org/resource/movie/>
ASK
{
  {
    ?kraj m:country "United Kingdom".
  }
  UNION
  {
    ?rez m:director_name ?rezyser.
    FILTER regex(?rezyser, "James", "i")
  }
}

You can have as many branches in your UNION as you need, for example if you wanted to check if any of 4 clauses were satisfied: 您可以根据需要在UNION拥有任意多个分支,例如,如果要检查是否满足以下4个子句中的任何一个:

ASK
{
  {
    # Clause 1
  }
  UNION
  {
    # Clause 2
  }
  UNION
  {
    # Clause 3
  }
  UNION
  {
    # Clause 4
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM