Various examples with IN and NOT IN support

General

I'll show you what you can do since the support for IN. Let's first create some test data:

tracker-sparql -u -q "insert { <abc> a nie:InformationElement ; nie:title 'abc' }"
tracker-sparql -u -q "insert { <def> a nie:InformationElement ; nie:title 'def' }"
tracker-sparql -u -q "insert { <xyz> a nie:InformationElement ; nie:title 'xyz' }"

Ok, now let's see whether IN works in the first place:

tracker-sparql -q "select ?r { ?r nie:title ?t . FILTER (?t IN ('abc', 'def')) }"
Results: 2
  abc
  def

INSERT using IN

Now let's do an INSERT based on a WHERE that uses IN:

tracker-sparql -u -q "insert { ?r nie:subject 'set' } WHERE { ?r nie:title ?t . FILTER (?t IN ('def', 'xyz')) }"

tracker-sparql -q "select ?s { ?r nie:subject ?s ; nie:title ?t . FILTER (?t IN ('abc', 'def', 'xyz')) }"
Results: 2
  set
  set

Selecting resources

Just giving the resources as <resource> works fine:

tracker-sparql -q "select ?s { ?r nie:title ?s . FILTER (?r IN (<abc>, <def>, <xyz>)) }"
Results: 3
  abc
  def
  xyz

You can also do this, of course (but mind expanding your prefixes, if you use them):

tracker-sparql -q "select ?s { ?r nie:title ?s . FILTER (str(?r) IN ('abc', 'def', 'xyz')) }"
Results: 3
  abc
  def
  xyz

But it's either as strings or not as strings, of course (no mixing):

tracker-sparql -q "select ?s { ?r nie:title ?s . FILTER (str(?r) IN ('abc', <def>, <xyz>)) }"
Result: 1
  abc

DELETE and INSERT is UPDATE, with IN

This will also just work:

tracker-sparql -u -q "delete { ?r nie:title ?t } where { ?r nie:title ?t . FILTER (?r IN (<abc>, <def>, <xyz>)) } 
                      insert { ?r nie:title 'overwrite' }
                      where  { ?r a nie:InformationElement . FILTER (?r IN (<abc>, <def>, <xyz>)) }"

That'll give us this of course:

tracker-sparql -q "select ?s { ?r nie:title ?s . FILTER (?r IN (<abc>, <def>, <xyz>)) }"
Results: 3
 overwrite
 overwrite
 overwrite

Use tracker:id() with IN

This will be very useful with the class signals API:

tracker-sparql -q "select ?r { ?r a rdfs:Resource . FILTER (tracker:id(?r) IN (1, 2, 3)) }"
Results: 3
  http://www.w3.org/2001/XMLSchema#string
  http://www.w3.org/2001/XMLSchema#boolean
  http://www.w3.org/2001/XMLSchema#integer

So, that means:

tracker-sparql -q "select tracker:id (?r) { ?r a nie:InformationElement . FILTER (?r IN (<abc>, <def>, <xyz>)) }"
Results: 3
  955
  956
  957

tracker-sparql -q "select ?r { ?r a rdfs:Resource . FILTER (tracker:id(?r) IN (955, 956, 957)) }"
Results: 3
  abc
  def
  xyz

Projects/Tracker/Documentation/Examples/SPARQL/InSupport (last edited 2014-12-22 14:19:30 by PhilipVanHoof)