Oh that's good! Thanks, I'll try this out. Especially "minus" seems more
convenient :)
Am 10.09.2012 13:53, schrieb Andy Seaborne:
On 10/09/12 12:16, Magnus Stuhr wrote:
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
Alternatives which are similar:
1/
SELECT ?r
{?r a ro:FR.
?r ?p ?a
FILTER ( ?p NOT IN (ro:hasSource, ro:isAuthoredBy) )
}
This has limited applicability -- it's using the fact you have only
one triple pattern in the NOT EXISTS clause.
2/
SELECT ?r
{ ?r a ro:FR.
MINUS { ?r ro:hasSource ?a }
MINUS { ?r ro:isAuthoredBy ?a }
}
Which style is best depends on how you think about the query and the
shape of the data.
Andy
-----Original Message-----
From: Katja Siegemund [mailto:katja.siegem...@tu-dresden.de]
Sent: 10. september 2012 13:03
To: users@jena.apache.org
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 <katja.siegem...@tu-dresden.de>
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 katja.siegem...@tu-dresden.de
WWW http://st.inf.tu-dresden.de/