This site has been retired. For up to date information, see handbook.gnome.org or gitlab.gnome.org.


[Home] [TitleIndex] [WordIndex

1. Various examples with IN and NOT IN support

1.1. 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

1.2. 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

1.3. 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

1.4. 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

1.5. 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

2024-10-23 10:59