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

What is a Datalog rule? How to write a Datalog rule and how Datalog performs reasoning

What is a Datalog rule? How to write a Datalog rule and how Datalog performs reasoning
Thomas Vout

Next episode: click here

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

In this episode, we're going to be looking at the anatomy of a Datalog rule, including some syntax and terminology that are important to be aware of. If you haven't already, please do check out our previous videos on the foundations of reasoning, including materialisation and incremental reasoning, which are key components to understanding Datalog.  

As we've seen in previous videos, reasoning can be used to encode, scale and automate domain expertise. We've seen how this can be done with OWL and ontological reasoning, but Datalog takes things one step further with a more expressive syntax. The way that does this is by following a pattern similar to SPARQL where you can describe triple patterns and bind variables, and in this episode, will be exploring how we do that.

You can see here the anatomy of a rule. Generally speaking, we have two sets of facts separated by an inference symbol. Everything before the inference symbol is called the ‘head’ and everything after is called the ‘body’. The body could be thought of in a similar way to the WHERE clause of a SPARQL query, where you're describing some triple patterns that need to be matched. With reasoning, wherever this pattern is matched, the head will be inferred, and actually added to the graph, and because of this, this rule can be read as ‘A is true whenever B is true’.

This makes RDFox particularly useful for things like data analysis or automated decision making, particularly when combined with incremental materialisation, as I mentioned at the beginning.

So let's actually have a look at an example. Here we have a real rule that simply captures a very simple pattern of 2 triples and infers a single triple in the head. The pattern that we're describing and looking to match is that of a result that has an associated race and an associated driver. With all of this information, and with the variable bound in the same way that we use them in a SPARQL query, we can then take them and use them in the head to create a new fact. In this case, a direct link between our drivers and their races, creating this new relationship has raced in between the pair.  

If you'd like to learn more about Datalog will be covering further examples in episodes to come so please do look out for those.

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