[SPARQL][WIKIDATA] FILTER NOT EXISTS

FILTER NOT EXISTS

How did I encounter this?

It's found out that Wikidata keeps track of deprecated dates of videos games in case a game is delayed or with other reasons. The deprecated date is marked with p2241 code in publication date statement node. This is an unnecessary data for the project. I found a way to filter this out: FILTER NOT EXISTS.

Syntax

FILTER NOT EXISTS is used to exclude certain patterns from the results. It works by checking if the specified pattern exists in the graph. If the pattern exists for a given variable binding, the result is excluded. If the pattern does not exist, the result is included.

Example:

    OPTIONAL {
      ?item p:P577 ?publicationDateNode.
      FILTER NOT EXISTS {
        ?publicationDateNode pq:P2241 ?deprecationReason
      }
      ?publicationDateNode ps:P577 ?publicationDateLabel.
For each ?publicationDateNode:
  • If a P2241 qualifier exists, the node is excluded.
  • If no P2241 qualifier exists, the node is included.
Note: ?deprecationReason is a placeholder for the property of P2241. It's not necessary to use this variable. The variable can be replaced with a wild card of []
Note: that `FILTER NOT EXISTS` should be followed by patterns, not logical expressions. The following case doesn't work
FILTER NOT EXISTS {
  (?platformLabelFromDate != "PlayStation 4" || ?platformLabelFromDate != "PlayStation 5")
}
If the logical expression needs to be used, then it should have been `FILTER EXISTS`.

Comments