I need to include few conditions in SPARQL ASK query.
I tried --
ASK
queries SELECT
statement inside ASK
query ASK
query -- 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.
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
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:
ASK
{
{
# Clause 1
}
UNION
{
# Clause 2
}
UNION
{
# Clause 3
}
UNION
{
# Clause 4
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.