A back arrow icon.
RDFox Blog
A back arrow icon.
RDFox Videos

How to use negation in semantic reasoning for a Knowledge Graph (and how incremental retraction works)

How to use negation in semantic reasoning for a Knowledge Graph (and how incremental retraction works)
Thomas Vout

Next episode: click here

Hello and welcome to another episode of the RDFox introductory series.  

In this episode will be looking at using negation within reasoning and rules, so if you haven't already, please do check out our other videos where we cover the foundations of reasoning and of course Datalog.  

Negation is an incredibly powerful feature within reasoning as it allows us to look for the absence of data, inferring new data based on it not existing. This is particularly powerful when combined with incremental reasoning where reasoning updates automatically as knew data or rules are added because it enables things like IOT or on device use cases to make use of negation where otherwise they would be unable to because data is continually streaming in and out of the system.  

Here, though, let's have a look at an example where we're inferring our drivers who have never finished on the podium. This has become quite simple because in a previous rule we have defined our relationship: driver ‘hasPodiumInRace’ race.  

So really what we're just looking for here is the absence of this pattern ‘hasPodiumInRace’ and where they do not have any podiums in any races, we can infer that they are a ‘driverWithoutPodiums'.

How do we actually do this? Well, in the body of the rule, first and foremost, we have to describe a triple pattern that we know will exist. In this case it is simply saying that we have some variable ‘?driver’ is a ‘driver’ to find an anchor for our negation.

Then we use the NOT EXISTS function to look for values of the variable ‘race’ in the pattern, ‘driver hasPodiumInRace race’ and where there exists no value for race, where RDFox can find no bindings for this given driver as defined above, then we can use this information to infer ‘driver a DriverWithoutPodiums’. Again, if there is a value found for race for a given driver, this ‘driverWithoutPodiums' class will not be inferred for them. All we're doing is looking for the absence of data, something that is missing—not there—and from that, inferring and creating a new fact.  

Let's have a look at how this works in RDFox by importing our rule and running a query. Then we'll have a look at what happens when we actually add some new data that invalidates this class.  

So heading back to the terminal, we can see that we have imported our previous 4 rules and the data set upTo2020.ttl so from here what we can do is import our fifth rule, the rule we've just been through, a you can see here. We can do this with the input command and then we can use a query to validate our new rule. You can see here we're looking for the pattern that includes our ‘DriversWithoutPodiums’ class. Again, we can evaluate this query with the ‘evaluate’ command and by running it we can see a limited list with 10 drivers who have never finished on a podium.

But, this is where things get really interesting. Because allowing negation with incremental reasoning leads to a problem called non-monotonic reasoning where we could find ourselves in a situation where we've added new data and based on the new data an old, previously inferred result is now invalid.  

For example, if we have a driver who, after our initial data update, achieves a podium in a race and then we add that data to our data store, this will need to be updated because previously a fact would have been added saying they were a ‘driverWithoutPodiums'. But now, that's no longer true, based on your data. So, we need to retract the fact based on the addition of data.

Now, this is exactly what happened in 2021 with a driver called George Russell. So, here we have a query that looks for all of the information we have about George. Let's evaluate that query as things stand. You can see that George is a ‘driverWithoutPodiums'. We can see all of the other information we have about George, so we're not hiding anything but we can also see as part of that all of the races that he's raced in. There are quite a few, 38 in fact, but we can see that that he has no podiums in any race. This is why he's been tagged as a ‘driverWithoutPodiums'.

But let's import our more recent data from 2021 to 23. Again, I want to make it very clear here that I have not restarted the system, everything we’re doing here is live. We have just added additional data to our existing, running system.

Now we can run the very same query again, without having to trigger an update or manually tell RDFox that it needs to be careful about its ‘driverWithoutPodiums’, we simply re-run our query about George, and we can see that the fact that he is a ‘driverWithoutPodiums’ has disappeared.

It has been retracted by RDFox’s reasoning because the new data includes an example of where George has finished on a podium. And again, if we scroll up, we can see the evidence for that. Now he has finished in many many more races, in fact 104, and he has even had several podiums in races, including a single win! Because of this information, George is no longer a ‘driverWithoutPodiums’ and RDFox recognises this fact and remains self-consistent with the data and with the rule set and has retracted the fact that George was a ‘driverWithoutPodiums’.

If you’d like to learn more about what RDFox can do with reasoning, please do check out our other videos in this series.

Take your first steps towards a solution.

Start with a free RDFox demo!

Take your first steps towards a solution.

Get started with RDFox for free!

Team and Resources

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).