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:
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)
[?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)