- From: Thomas FRANCART <thomas.francart@mondeca.com>
- Date: Mon, 23 Mar 2009 14:20:33 +0100
- To: Lee Feigenbaum <lee@thefigtrees.net>
- Cc: public-sparql-dev@w3.org
- Message-ID: <2d799a410903230620o2be3f6aaude8e582d07d18ed6@mail.gmail.com>
Hi - the solution with the sameTerm operator works fine. Thanks Thomas Thomas Francart CTO Mondeca 3, cité Nollez 75018 Paris France Tel. +33 (0)1 44 92 35 04 - fax +33 (0)1 44 92 02 59 Mail: thomas.francart@mondeca.com Website: www.mondeca.com Blog: Leçons de choses <http://mondeca.wordpress.com> On Mon, Mar 9, 2009 at 4:14 PM, Lee Feigenbaum <lee@thefigtrees.net> wrote: > Thomas FRANCART wrote: > >> Hi SPARQL gurus >> >> I have a set of statements separated in 2 named graphs : >> >> - some statements appear in named-graph A >> - some statements appear in named-graph A and named-graph B >> >> I would like to make a query on statements that are in named-graph A but >> _not_ in named-graph B. Is it possible, and how can I do that ? >> >> Thanks >> Thomas >> > > Hi Thomas, > > It's possible, but it's not pretty. :-) > > Something like this, maybe? (untested) > > PREFIX ex: <http://example.org/> > CONSTRUCT { ?s ?p ?o } > FROM NAMED ex:A > FROM NAMED ex:B > WHERE { > GRAPH ex:A { > ?s ?p ?o . # match any triple in A > } > OPTIONAL { > GRAPH ex:B { > ?s2 ?p ?o . # match the same triple in B, introduce a new var > FILTER(sameTerm(?s, ?s2)) . # constrain the new var > } > } > FILTER(!bound(?s2)) . # test that the new var (?s2) was not found > } > > You may also be able to get away with just FILTER(?s = ?s2), but I think > using sameTerm is slightly more correct in the case that you happen to have > extended datatypes and an engine that knows about them. > > You could also make the graph pattern inside the GRAPH ex:B { ... } clause: > > ?s ?p ?o, ?o2 . > > ...and then change the !bound(?s2) to !bound(?o2). Again, untested. > > Lee >
Received on Monday, 23 March 2009 13:21:09 UTC