MaatDeamon
MaatDeamon

Reputation: 9771

Filter not Exists yielding confusing results

I tried the following query in sparql:

Select distinct (count(?jel) AS ?jelCount )

Where {

  ?jel a skos:Concept .
  ?jel skos:prefLabel ?label .


  Filter not Exists {
    ?jel skos:narrower ?narrower .
    ?jel skos:notation ?notation .
  }             
}

However it does not give me the answer i want, it actually filter nothing.

However if i write:

Select distinct (count(?jel) AS ?jelCount )

Where {

  ?jel a skos:Concept .
  ?jel skos:prefLabel ?label .


Filter not Exists {
    ?jel skos:narrower ?narrower .
  }

  Filter not Exists {
    ?jel skos:notation ?notation .
  }

}

Then i get the answer that i want.

I am not able to explain why ? Can someone enlighten me on this please?

Upvotes: 1

Views: 84

Answers (1)

RobV
RobV

Reputation: 28655

In SPARQL the entirety of each pattern (denoted by { }) must match to have an effect.

So your first query asks for items where both of the skos:narrower and skos:notation triples do not exist for an item because they are in the same FILTER NOT EXISTS pattern. Presumably there are no items where both of those triples exist for an item in your data and thus nothing is filtered out.

However in your second query you ask for items where either of the skos:narrower or skos:notation do not exist (because each is in a separate FILTER NOT EXISTS pattern). As there are some of these triples for some items in your data then some things are filtered out.

Upvotes: 1

Related Questions