A back arrow icon.
RDFox Blog

RDFox’s improved OWL implementation

RDFox’s improved OWL implementation
Valerio Cocchi

In RDFox v5.0.0, we have changed the way the implementation of OWL works, as well as a bunch of other things (see here).

In this article, we will outline the difference between the two approaches, and why the new one is better. If you’d like to follow along, you can find the data and ontologies in this GitHub repository.

OWL in Turtle vs Functional Style

In both RDFox v4 and v5, OWL is supported in 2 syntaxes:
Axioms can be imported in functional-style syntax (fss):

#ontology.fss#
Prefix(:=<http://www.example.com/ontology1#>)
Ontology( <http://www.example.com/ontology1>
    SubClassOf( :Cat :Mammal )
    SubClassOf( :Mammal :Animal))

And in Turtle (ttl):

#ontology.ttl#
@prefix : <http://www.example.com/ontology1#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<http://www.example.com/ontology1> a owl:Ontology .
:Cat rdfs:subClassOf :Mammal .
:Mammal rdfs:subClassOf :Animal .

Now, Turtle has the advantage that one is able to ‘query the ontology’ directly. However, it also means that the ontology and data are mixed, which we may wish to avoid.

Importing fss ontologies

When working with fss ontologies, there is no change between version 4 and 5. These are imported with:

import ontology.fss

An ontology can also be applied to a particular named graph with:

import > :data ontology.fss

Furthermore, in v5 we can specify what named graph an ontology should be applied to directly in the ontology file:

#ontology_all_graphs.fss#
Prefix(:=<http://www.example.com/ontology1#>)
Ontology( <http://www.example.com/ontology1>
    Annotation(rdfox:NamedGraph :data)
    SubClassOf( :Child :Person )
    SubClassOf( :Person ObjectUnionOf(:Child :Adult) )
)

This means that we can have a single file with multiple ontologies, each of which is applied to a particular named graph, and we can import it with just one command:

import ontology_all_graphs.fss

Note that in this case we only have one ontology with one named graph.

Importing Turtle ontologies

However, when it comes to ontologies in Turtle, there is a difference between v4 and v5. In v4, Turtle ontologies can be enabled at datastore creation with the following flag:

owl-in-rdf-support off | relaxed | strict

However, ontologies cannot be parsed if they are in a named graph, nor can they be applied to data that is in a named graph. In v5 however, we address this issue.

Example

Let us go through an example of the new OWL implementation in the shell:

dstore create default
prefix : <http://www.example.com/ontology1#>
set output out
import > :data data.ttl
import > :ontology ontology.ttl

Now, this has not parsed the triples of the ontology as actual axioms yet, as evidenced by the fact that no triples were inferred, as you can see by running:

select ?type from :data where { ?cat a :Cat , ?type . FILTER(?type != :Cat)}

Note above that our cats are not inferred to also be member of other classes, i.e. mammals and animals.

You can see what axioms apply to the data graph with this command:

info axioms :data

which returns an empty list, meaning that no axioms apply (yet).

We will instead parse the axioms asynchronously with:

importaxioms :ontology > :data

See the docs here for the specifics of the command.

Now we can see that inferences have happened:

select ?type from :data where {?cat a :Cat , ?type FILTER(?type != :Cat)}
info axioms :data

We can also export the axioms to a file:

export myAxioms.fss text/owl-functional
#or in the datalog conversion
export myAxioms.dlog application/x.datalog rule-domain axioms

Now, it is generally advisable to have the ontology and data kept in separate named graphs, but there is nothing stopping us from putting both into the default graph and parsing axioms like this:

dstore create default
import data.ttl #import into default graph
import ontology.ttl
importaxioms rdfox:DefaultTriples > rdfox:DefaultTriples

Note that rdfox:DefaultTriples is the name of the default graph in RDFox.

Semantic Reasoning

What we have described so far was ‘data reasoning’, i.e. given a dataset and an ontology, we apply the ontology’s axioms to the dataset to draw inferences.
This is what OWL 2 RL (the fragment supported by RDFox) was designed to achieve.

However, some ‘schema’ reasoning can also be achieved with RDFox. To do this, RDFox can load a predefined set of 15 rules into a named graph containing OWL axioms in Turtle format and derive new such axioms (see more here).

The following command:

answer ! LOAD <rdfox:TBoxReasoning> INTO GRAPH :ontology

will then materialise the fact that :Cat is a direct subclass of :Animal in the :ontology graph.

The rule that derives this fact is:

[?X, rdfs:subClassOf,?Z] :-
    rdfs:subClassOf[?X,?Y],
    rdfs:subClassOf[?Y,?Z],
    FILTER(isIRI(?Z)) .

Here, ?X is bound to :Cat, ?Y to :Mammal, ?Z to :Animal.
There are 14 other rules that derive similar results.

This contrasts with the data reasoning approach. In data reasoning a specific cat, say :sylvester, is inferred to be a mammal with the first axiom.
Then, given that :sylvester is now also a mammal he is further inferred to be an animal, this time with the second axiom.

What about migration from v4 to v5?

For devs using RDFox persistence:
Between versions 4 and 5 the persistence format has changed, to improve usability and add SHACL support. However, because OWL support is now more straightforward than before, this is not an issue. We can migrate from v4’s persistence by using the usual transcribe command in the v4 shell (see instructions here).

In short, this command will produce a script (stable across versions) that we can use to recreate the persisted data in v5 because the old database would have had both axioms and triples in it.

If you wish for the axioms to be parsed, you then need to run:

importaxioms rdfox:DefaultTriples > rdfox:DefaultTriples

If you further wish to add schema reasoning (as was automatically added in v4), then just run:

answer ! LOAD <rdfox:TBoxReasoning>

Conclusion

We hope this short tutorial has guided you through the latest updates to our OWL implementation. If you haven’t given this a go for yourself yet, you can find the repository here. You can try through this example both in the shell and in REST (with cURL).

If you’d like to try out Version 5, you can request a 30 day free trial or a demonstration. For more information on RDFox check out the RDFox info page and blog.

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