Denigma
hevok @hevok February 23, 2013
Tutorial #coding #existance #programming #query

Negation

Negation allows to refer to conditions where an answer exists or does not exists.

For instance making a small select statement on a database with three individuals in it for which not all the name is given but the type Person is defined.

If one wants to select all person from a database where one specific attribute is not available then one can do this with the filter expression NOT EXISTS, where one can say FILTER NOT EXIST the name, or a Triple that has a foaf name in it. With such a simple filter NOT EXISTS one can filter out results and therefore give specific things that should not be provides in the results.

  • Filter of Query solutions is done within a [FILTER](/blog/657/) expression using NOT EXISTS and EXISTS

Data:

@prefix : ](http://example/>)] .
@prefix rdf: ](http://www.w3.org/1999/02/22-rdf-syntax-ns#>)]
@prefix foaf: ](http://xmlns.com/foaf/0.1/>)] .

:hevok rdf:type foaf:Person .
:hevok foaf:name "Hevok" .
:eva   rdf:type foaf:Person .

Query:

PREFIX rdf: ](http://www.w3.org/1999/02/22-rdf-syntax-nx#>)]
PREFIX foaf: ](http://xmlns/foaf/0.1/>)]
[SELECT](/blog/651/) ?person
WHERE 
{
    ?person rdf:type foaf:Person .
    [FILTER](/blog/657/) NOT EXISTS { ?person foaf:name ?name }
}

Result

?person
eva