Next episode: click here
Hello and welcome to another episode of the introductory series into RDFox.
In this episode, we're going to be running through more SPARQL queries, this time focusing on negation. If you're not sure how we got to this stage, check out our earlier videos that cover the foundations of SPARQL, querying and RDFox.
So let's have a look at our query over here. What we're looking for here is drivers who have never finished on a podium. That is, drivers who have never finished first, second, or third in any race they have ever raced.
Now, this is a bit of a complicated concept because we're looking for something that does not exist, something where the data is missing.
So let's get started with something simple. First and foremost we need to find all of our drivers and some nice information about them for us to read, such as their forename and surname so ultimately we can just create a very nice human readable list.
But, then comes the interesting part where we filter this list down to remove any driver who has finished on a podium. However, this is where things get a little bit more interesting because if we just asked for somebody for a driver who had not finished on a podium, well, one week they might have finished on a podium and then the next they might not. And so we could find that example where they finished, say 5th and say, well, they're a driver who's not finished on a podium even though the week before maybe they finished first, and so what we have to do here instead is look for drivers where it has never existed that they've finished on a podium.
So to do this, we have to use this complicated filter block and the best way to explain this is from the inside out. First and foremost, we find our result associated to a driver using the same driver variable as we'd find earlier on and for this result, we find the result position order. So this, the value at the end of this relationship is going to be the position in which they finished each race. So whether that's first, second, 10th, last, whatever it happened to be, this is where that value is stored.
We're then using a simple filter to ensure that position order is in the list 1, 2 or 3. What the function 'IN’ does is it checks the variable that precedes it and compares its value to the values in its list. Here we've given it the values 1, 2, and 3 so it checks that position order is in 1, 2, or 3. If it does, it returns true and the filter passes, but if the position order is not 1, 2, or 3, then this returns false and the filter fails.
However, what we've described here is the pattern of a driver who has finished first, second or third in a race at least one time and so we wrap all of that around an additional filter, but this time we use ‘FILTER NOT EXISTS’ which checks this pattern, and if it finds no result, if it searches for this and it comes back undefined, then that filter passes, meaning the wider pattern will only include drivers where it does not exist that they have had a podium; they have not got any position 1, 2, or 3. Therefore we are left with just a list of drivers who have never finished on a podium.
So if we click Run this SPARQL, we will see a long list of names of drivers who have never finished on a podium.
If you'd like to find out more about the SPARQL and additional functions that we can use, check out our other videos on the topic.
The team behind Oxford Semantic Technologies started working on RDFox in 2011 at the Computer Science Department of the University of Oxford with the conviction that flexible and high-performance reasoning was a possibility for data-intensive applications without jeopardising the correctness of the results. RDFox is the first market-ready knowledge graph designed from the ground up with reasoning in mind. Oxford Semantic Technologies is a spin-out of the University of Oxford and is backed by leading investors including Samsung Venture Investment Corporation (SVIC), Oxford Sciences Enterprises (OSE) and Oxford University Innovation (OUI).