This document describes the built-in functions for use in Jena rules that are included as a part of the SADL Open Source release, along with information on how to use them in the SADL language.
When using Jena-provided built-ins, it is important to understand the difference between the Jena syntax (see "Builtin Primitives" at http://jena.apache.org/documentation/inference/#RULEbuiltins ) and the SADL syntax. In the actual Jena rule created from the SADL rule, which is what is shown in the Jena documentation at the link above, if an assignment of the result is made to a variable, that variable will be the last argument to the actual built-in. In SADL syntax, the assignment is shown explicitly to be the variable on the left of the "=" or "is" assignment or implicitly as a nesting of terms. This is illustrated below for the sum built-in:
Note that if built-ins combine operations they can hide important dependencies from the Jena Rule Engine. For example, if one built-in creates a structure (a set of triples) and another uses the structure, the Rule Engine may not detect that the structure must be built by one rule or set of rules before it can be used by another. The solution to this problem is to always work with the individual elements, not with larger structures. To this end, getDataValue, getInstance, and update can be used together to do interesting things--see ShapesComplex example.
A table of Jena Built-Ins Available in the Open Source Version of SADL is shown below. The package name for all of these is "com.ge.research.sadl.jena.reasoner.builtin". To make the table more readable, only the class name is shown. However, in registration references the entire fully-qualified class name must be specified.
Built-in, SADL Rule Syntax | Java Implementation Class | Purpose |
y is abs(x) | Abs | Return the absolute value of the numerical value x |
y is acos(x) | Acos | Return the inverse cosine of the numerical value x (return value in radians) |
y is asin(x) | Asin | Return the inverse sine of the numerical value x (return value in radians) |
y is atan(x) | Atan | Return the inverse tangent of the numerical value x (return value in radians) |
z is average(x,y, ...) | Average | Return the average of any number of numerical values |
y is ceiling(x) | Ceiling | Return the smallest integer larger than x |
y is cos(x) | Cos | Return the cosine of the numerical value x representing an angle in radians |
y is floor(x) | Floor | Return the largest integer smaller than x |
greaterThan(x,y) or x > y |
GreaterThan | This extends the Jena GreaterThan built-in by a) adding string comparison so that ordering of URI's can be acheived, and b) allowing a returned boolean value to be bound to a variable ("bval is greaterThan(x,y)"). Note that the latter only works with the explicit form of the built-in, not with the "x > y" representation. |
lessThan(x,y) or x < y |
LessThan | This extends the Jena LessThan built-in by a) adding string comparison so that ordering of URI's can be acheived, and b) allowing a returned boolean value to be bound to a variable ("bval is lessThan(x,y)"). Note that the latter only works with the explicit form of the built-in, not with the "x < y" representation. |
y is max(x1, x2, ...) y is max(lst) |
Max | Return the minimum of any number of arguments, each of which must be a numerical value. Can take a single argument of type rdf:List. |
y is min(x1, x2, ...) y is min(lst) |
Min | Return the minimum of any number of arguments, each of which must be a numerical value. Can take a single argument of type rdf:List. |
z is mod(x,y) | Mod | Return the value of x mod y |
noSubjectsOtherThan(s, p, o) | NoSubjectsOtherThan | Given three arguments, s, p, and o, which identify a triple pattern, return true (premise matches) if and only if the model contains the specified triple but does not contain any other triples with the same predicate and object |
notOnlyValue(s, p, o) | NotOnlyValue | Returns true if there is at least one triple with subject s, property p, and value o but there is also at least one triple with subject s, property p, and a value other than o. |
noUnknownValues(s, op, p2) | NoUnknownValues | For the given subject s, if all values of the object property op have at least one value of the property p2, return true. Otherwise return false. |
noValuesOtherThan(s, p, o) | NoValuesOtherThan | Given three arguments, s, p, and o, which identify a triple pattern, return true (premise matches) if and only if the model contains the specified triple but does not contain any other triples with the same subject and predicate |
y is pow(x1, x2) | Pow | Return the result of raising the first argument, which must be a numerical value to the second, which must also be a numerical value |
print("hi there ", x) | Like the Jena print builtin, but overrides it to output to stdout. For the IDE, this will be the console window. | |
y is product(x1, x2, ...)
y is product(lst) |
Product | For 2 or more arguments, return the product of the arguments, all of which must be numerical values. Alternatively, a single argument is an rdf:List of numerical values which are multiplied together to determine the return value. |
y is sin(x) | Sin | Return the sine of the numerical value x representing an angle in radians |
y is sqrt(x) | Sqrt | Return the square root of a number x |
y is subtractDates(x1, x2, x3) | SubtractDates | The first argument must be an xsd DateTime. The second argument may be (a) an xsd DateTime, in which case the difference between the first and second arguments is computed, or it may be (b) a number, in which case its value is subtracted from the first argument. The third argument is a string which must begin with one of "y" (year), "mo" (month), "d" (day), "mi" (minute), "h" (hour), or "s (second). If the second argument is an xsd DateTime (a), the difference is converted to a number with the units specified by the third argument. If the second argument is a number (b), then the third argument is taken to be the units of this number. The calculated value, which will be (a) a number, or (b) an xsd DateTime, is returned. |
y is sum(x1, x2, ...)
y is sum(lst) |
Sum | For 2 or more arguments, return the sum of the arguments, all of which must be numerical values. Alternatively, a single argument is an rdf:List of numerical values which are summed to determine the return value. |
y is tan(x) | Tan | Return the tangent of the numerical value x representing an angle in radians |
x < y, x > y | lessThan, greaterThan | These two comparison built-ins are extensions of the Jena-provided built-ins of the same name (different package). They may be used for strings and URIs. |
Several of these built-ins have special syntax in SADL. These include the following.