Hi,
I just mocked up a template really quick, but something like this should work:
SELECT ?s WHERE {
{
{ ?s ?p ?o. FILTER NOT EXISTS {?s ?p ?o}}
UNION
{?s ?p ?o. FILTER NOT EXISTS {?s ?p ?o}}
UNION
{?s ?p ?o. FILTER NOT EXISTS {?s ?p ?o}}
}
UNION
{?s ?p ?o. FILTER NOT EXISTS {?s ?p ?o}}
}
On top of this you can add even more UNION clauses. Obviously, you have to
replace the triple-patterns and solution variables with whatever you want to
find in your query.
Regards,
Magnus Stuhr
-----Original Message-----
From: Katja Siegemund [mailto:[email protected]]
Sent: 10. september 2012 13:03
To: [email protected]
Subject: Re: using "or" in sparql
Hm, well, but how can I use UNION for multiple times? I have a lot of "or's" in
my query :(
Am 10.09.2012 12:29, schrieb Francesco Panico:
> Hi
>
> Your query selects all triples without "source", at first. If the two
> elements without an "author" have a "source", they will be discarded,
> because the values added by "optional" clause have to respect "where
> clauses" anyway.
> You can check it.
>
> You can try to use UNION construct, because you want to retrieve a list
> with
> -item without a source
> -item without author
>
> SELECT ?r
> WHERE {?r a ro:FR.
> FILTER NOT EXISTS {?r ro:hasSource ?a}
>
> UNION{ ?r a ro:FR.
> FILTER NOT EXISTS {?r ro:isAuthoredBy ?a}
> }
> }
>
>
> I hope it is useful.
> Regards
> Francesco.
>
>
>
>
>
>
> 2012/9/10 Katja Siegemund <[email protected]>
>
>> Hi,
>>
>> I'm having trouble with constructing a query that uses "or". I already
>> tried optional, but it does not lead to the expected result. I'd be glad if
>> someone could help me. I'd like to query for:
>>
>> all var bindings that have no author or no source.
>>
>> I tried:
>>
>> SELECT ?r WHERE {?r a ro:FR. FILTER NOT EXISTS {?r ro:hasSource ?a}
>> OPTIONAL {FILTER NOT EXISTS {?r ro:isAuthoredBy ?a}}}";
>>
>> But it only computes the first part (source).
>>
>> If I have 3 items without a source and 2 others with no author, then I
>> should get 5 results instead only the first 3. What am I doing wrong?
>>
>> Thanks in advance,
>> Katja
>>
>>
>
--
Dipl.-Medieninf. Katja Siegemund
Research Assistant
Technische Universität Dresden
Department of Computer Science
Phone +49 (0)40 572 44 55 1
Email [email protected]
WWW http://st.inf.tu-dresden.de/