W3C home > Mailing lists > Public > public-sparql-dev@w3.org > January to March 2007

Re: SPARQL Query Puzzler

From: Simon Schenk <sschenk@uni-koblenz.de>
Date: Fri, 26 Jan 2007 09:34:45 +0100
To: public-sparql-dev@w3.org
Message-Id: <1169800485.5254.27.camel@lapace01>

Hello Torben

I think this should work:
1) Select all elements in some set, which are NOT contained in SetA.
   If such elements exist, this set is one we do not want to select.
2) Select all sets, which are not such 'bad' sets.

SELECT ?set 
    ?badSet a :Set;
            :contains ?x.
      :setA :contains ?y.
      FILTER (?x = ?y).
    FILTER ((!BOUND(?y)) && (?badSet = ?set)).

  ?set a :Set.
  FILTER (!BOUND(?badSet)).

Looks a bit weird, because what we do here is model "all sets, where all
elements are in SetA" as "all sets which are not sets with elements not
in SetA". As there is nothing like FORALL X in SPARQL, we need to
express this as NOT EXISTS NOT X. The negations are expressed using
OPTIONAL ... !BOUND and make the query a bit ugly. Some syntactic sugar
would make SPARQL easier to use for such cases.

Hope that helps.

Best regards,

Am Donnerstag, den 25.01.2007, 23:45 +0100 schrieb Torben Knerr:
> Dear List Members,
> I am stuck with formulating a SPARQL query which checks wheter one
> graph structure is contained in another.
> Consider the following example of an imaginery "theory-of-sets"
> ontology:
> setA a Set
> setB a Set
> setC a Set
> setD a Set
> el_1 a Element
> el_2 a Element
> el_3 a Element
> el_4 a Element
> setA contains el_1, el_2, el_3
> setB contains el_1, el_3
> setC contains el_2, el_4
> setD contains el_3
> Now here is the question: Is it possible (with a SPARQL query) to
> retrieve all sets, which are sub-sets of setA? 
> To be more precise: Is there a SPARQL query, which returns all Sets
> containing only Elements, which are also contained in setA? 
> Premise: you know the Elements of setA explicitly, but you know
> nothing about the other Sets and their Elements.
> Here's my try (Problem: it doesn't filter out setC):
> SELECT ?set
> WHERE { 
>         ?set a :Set .
>         ?set :contains ?x .
>         FILTER (?x = :Element_1 || ?x = :Element_2 || ?x
> = :Element_3 ) 
> }
> The obvious solution would be setB and setD (and maybe setA itself,
> too), but not setC. 
> I have tried to solve this puzzle for days now, without success. I
> wonder if such a query is possible with SPARQL.
> Any suggestions are welcome!
> Best regards,
> Torben
Received on Friday, 26 January 2007 08:35:08 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:26:58 UTC