This section defines a few datalog queries and rules for the standard example model
of Employees, Departments and Managers (see $CB_HOME/examples/QUERIES).
The first example defines a more efficient version of the recursive MetabossQuery.
DatalogQueryClass MetabossDatalogQuery isA Manager with
attribute,parameter
e : Employee
attribute,code
r1 : "In('~e',Employee),A('~e',boss,'~this')";
r2 : "vars([m]),
In('~e',Employee),
In(m,query('MetabossDatalogQuery[~e/e]')),
A(m,boss,'~this')"
end
Note that the disjunction of the original query is represented by two code-attributes. The example shows also the use of query expressions and existential variables.
The second example is the datalog version of the rule for the HighSalary class.
The infix-literal >= is represented by the literal LE.
Class HighSalary2 isA Integer
end
DatalogInRule HighSalaryRule2 with
concernedClass
cc: HighSalary2
code
c: "In('~this',Integer),LE('~this',60000)"
end
The last example shows the definition of a rule for an attribute. It also shows, how the performance of a rule can be improved by specifying different variants for different binding patterns. The example defines two rules, depending on the binding of the variable src.
DatalogAttrRule MetabossRule with
concernedClass
cc : Employee!boss
code
r1 : "ground('~src'),A('~src',boss,'~dst')";
r2 : "var('~src'),In('~dst',Manager),A('~src',boss,'~dst')"
end