What kind of rules can I write in RDFox?

RDFox allows the user to control semantic reasoning by adding Datalog rules to a data store.

Rules are essentially if-then statements that add data to the graph when certain conditions are met.

These rules can specify a pattern that is matched to triples, like this:

[?person, :hasNickname, “Bob”] :-
   [?person, :hasFirstName, “Robert”] .

(This rule assigns the nickname “Bob” to all people named “Robert”)

They can also use expressions borrowed from SPARQL (like BIND or FILTER) as well as SPARQL functions:

[?person, :hasFullName, ?fullName] :-
   [?person, :hasFirstName, ?firstName],
   [?person, :hasLastName, ?lastName],
   BIND(CONCAT(?firstName, “ “, ?lastName) AS ?fullName) .

(This rule concatenates a person’s first and last names to create their full name)

[?person, :hasPosition, :manager] :-
   [?person, :hasPositionDescription, ?description],
   FILTER(CONTAINS(LCASE(?description), “manager”)) .

(This rule assigns the position of manager to anyone who has “manager” in their job description)

The functions allow the user to manipulate strings, numbers, dates, and IRIs. Some of the examples include:

  • REGEX – regular expression matching function
  • REPLACE – function for replacing part of a string
  • STR – function for converting other data types to strings
  • Constructor functions that let users convert strings to various data types
  • Hashing functions
  • MAXFN, MINFN – these functions choose the maximum or minimum argument
  • Mathematical functions like exponentials and logarithms
  • Trigonometric functions

RDFox also extends Datalog to include negation:

[?person, a, :Unemployed] :-
   [?person, a, :Person],
   NOT EXISTS ?job IN [?person, :hasJob, ?job] .

(This rule assigns the class “unemployed” to all people without jobs)

And aggregation:

[?person, :hasChildNumber, ?count] :-
       [?child, :hasParent, ?parent]
   ON ?parent BIND COUNT(?child) AS ?count
   ) .

(This rule adds a property assigning the number of children to each person who has any)

Down arrow icon.