This article will show you how to very quickly set up your very own knowledge graph database and semantic reasoning engine. By the end you'll be able to setup RDFox locally, import triples and rules, and run queries. To follow along, request an RDFox license and download the latest release. Once you’ve received your license key, place it in a directory with your RDFox download.
Please note, this article has been updated since the release of RDFox v6.0.
The article consists of the following:
If you would like a visual aid, watch our getting started series on youtube.
You can also watch our Getting Started Webinar. The webinar was created for Version 3.0.0, but remains applicable today.
Open the directory with RDFox and your license key, in the IDE of your choice. Open a new terminal and then launch RDFox by typing one of the following.
Linux or Mac:
Windows:
This should result in a command prompt, where you can run any of the commands described in Section 15.2 of the documentation.
Data stores hold all facts and rules in RDFox. At present, there is no data store in the directory, so we must create one before we can load any triples. To create a data store we use the dstore command as follows:
N.B. This example uses a family dataset, hence the data store name ‘family’.
Next, to ensure that subsequent shell commands address our new data store, we use the active command to set the family data store active within the shell:
We are going to load a small RDF graph in Turtle format into the active data store. This can be downloaded from here and saved in the same directory as the RDFox executable and license key.
To import the data into the active datastore we use the following command:
TIP: remember to use the command set output out if you would like the terminal to print results. This command should report the time taken by the import and that 21 data items have been loaded from the file.
The primary query language recognized by RDFox is SPARQL. SPARQL queries can be typed or pasted directly into the shell. For more information, read our article SPARQL Basic and RDFox.
Copy and paste the following SPARQL into the shell and hit enter to print all of the triples in the store:
You should see a few lines beginning @prefix followed by a blank line and then the original 21 triples (facts) from data.ttl. After the triples, a summary of the number of answers returned and the time taken for the query is printed.
To demonstrate a simple conjunction, print each person’s forename:
Note that :brian is not returned as this entity is not of type :Person as required by the first part of the where clause.
It is also possible to modify the contents of the data store via queries. For example, make the :marriedTo relationship symmetric:
This adds one new triple to the data store reflecting the fact that Lois is married to Peter, which was derived from the fact that Peter is married to Lois. Running the query from step 3 again should now return 22 triples (use the up arrow key to step back through your command history).
Reasoning is the ability to calculate the logical consequences of applying a set of rules to a set of facts. RDFox uses the Datalog language for expressing rules. For a more detailed explanation, read Datalog Basics and RDFox.
Reasoning is useful because it allows us to enrich a data store. For example, we can add a rule to state that if ?c has a parent ?p then ?p has a child ?c. With this rule, RDFox can then determine all of the :hasChild relationships — including for any new families that we add to the data store later on.
The above rule can be added with the following command:
To check that we now have some triples with :hasChild as the predicate, evaluate the following query:
Four results are returned, all of which have all been added by RDFox by evaluating the rule defined above.
To prove that the rule really is ‘live’, delete the triple that says :stewie has :lois as a parent and check that the corresponding :hasChild relationship goes away too. Do this with the following SPARQL:
Now re-run the query from step 2 and note that the answer :lois :hasParent :stewie . no longer appears.
Shut down RDFox by typing the quit command. Since RDFox is an in-memory database, and because we started the process using the sandbox command, which disables any form of persistence, the contents of the data store will be dropped when the process exits. While experimenting with RDFox, it may therefore be useful to write the commands to initialize the data store and load data into a script which can be passed to RDFox at startup.
The following script repeats the whole of this tutorial, including starting an endpoint.
For ease, you can save this script to a new file e.g. <working_directory>/start.txt and then run it when you restart RDFox with the following command.
Linux and Mac:
Windows:
To find out more about how scripts can help, read the article on script writing here.
RDFox also offers a UI console which provides a user friendly approach to writing and visualising SPARQL queries. To launch the console, RDFox needs to expose a REST API which includes a SPARQL over HTTP endpoint. We can do this from the terminal with the following command:
The terminal will print the port number. In a web browser, navigate to http://localhost:<port>/console, and substitute <port> with the port number printed in the terminal.
For further instructions on how to use the console for querying see the documentation here.
The data explorer provides users with a user friendly method for representing and exploring their data.
To explore the results as a graph, simply click the 'Explore results' button alongside 'run'. This will take the user to the Explore tab, populating the screen with their results. Users can now switch between the SPARQL editor and Explore view by clicking on their respective tabs at the top of the page. The Explore view will be held until 'Explore results' is clicked once again.
For example, the graph representation of the family data store would be the following:
For a more detailed walkthrough, please visit our documentation.
Looking for next steps? You can learn more about RDFox, request a demo, or start a free trial!
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).