MINUS

Created on Feb. 23, 2013, 12:30 p.m. by Hevok & updated by Hevok on May 2, 2013, 5:19 p.m.

The MINUS qualifier allows to exclude certain data.

Given a database with persons we have a given name and family name and one wants to nothing else than all triples, but not Triples that fulfill a specified condition, e.g. one do not want that the given name of any Resource or Subject has a certain Value. So the result will contain only Triples where the results has other names than that was specified.

  • Filtering of query solutions by removing possible solutions with MINUS

Data:

@prefix : <http://example.com>] .
@prefix foaf: <http:/xmlns.com/foaf/0.1>

:hevok foaf:givenName "Hevok" ;
       foaf:familyName "n/a" .

:eva foaf:givenName "EVA"
     foaf:familyName "unknown" .

:herbert foaf:givenName "Herbert" ;
         foaf:familyName "Kaebie" .

Query:

PREFIX : <http://example/>]
PREFIX foaf: <http://xmlns.com/foaf/0.1/>]
SELECT DISTINCT ?s
WHERE {
    ?s ?p ?o .
    MINUS {
        ?s foaf:givenName "Herbert" .
    }
 }

Result:

?s
:hevok
:eva
minus.png

Tags: query, coding, programing, exclusion
Categories: Tutorial
Parent: SPARQL 1.1

Update entry (Admin) | See changes

Comment on This Data Unit