The proposed hierarchy of built-ins for SWRL is motivated by a modular approach that will
allow further extensions in future releases of SWRL. At the same time, it will provide the
flexibility for various implementations to select the level of hierarchy to be support with
each version of SWRL.
SWRL's built-ins approach is also based on the reuse of existing built-ins in XQuery and XPath,
themselves derived from XML data types part 2 built-ins. Some other built-ins are specific
to SWRL, OWL, and RuleML, dealing with fact and rule prioritization.
This system of built-ins should also help in the interoperation of SWRL with
other Web formalisms by providing an extensible, modular built-ins infrastructure for
Semantic Web Languages, Web Services, and Web applications.
While we suggest to have a top level distinction between the following two categories:
Side-effect free built-ins
Side-effect full built-ins
the SWRL language will only provide support for side-effect free built-ins.
Even though the taxonomy may appear to be quite large, users only need to load the relevant ones.
The swrl presentation and XML/RDF syntax defines an abstraction layer on top of operators and functions. Comparison operators should be singled out as they return boolean values. They are defined as predicates in OWL.
Operators:
op:numeric-add Backs up the "+" operator and returns the arithmetic sum of its operands
op:numeric-subtract Backs up the "-" operator and returns the arithmetic difference of its operands
op:numeric-multiply Backs up the "*" operator and returns the arithmetic product of its operands
op:numeric-divide Backs up the "div" operator and returns the arithmetic quotient of its operands
op:numeric-integer-divide Backs up the "idiv" operator and returns the arithmetic quotient of its operands: ($arg1 idiv $arg2). If the numerator is not evenly divided by the divisor, then the quotient is the xs:integer value obtained, ignoring any remainder that results from the division (that is, no rounding is performed).
op:numeric-mod Backs up the "mod" operator. Informally, this function returns the remainder resulting from dividing $arg1, the dividend, by $arg2, the divisor. The operation a mod b for operands that are xs:integer or xs:decimal, or types derived from them, produces a result such that (a idiv b)*b+(a mod b) is equal to a and the magnitude of the result is always less than the magnitude of b. This identity holds even in the special case that the dividend is the negative integer of largest possible magnitude for its type and the divisor is -1 (the remainder is 0). It follows from this rule that the sign of the result is the sign of the dividend
op:numeric-unary-plus Backs up the unary "+" operator and returns its operand with the sign unchanged: (+ $arg). Semantically, this operation performs no operation
op:numeric-unary-minus Backs up the unary "-" operator and returns its operand with the sign reversed: (- $arg). If $arg is positive, its negative is returned; if it is negative, its positive is returned
Comparison predicates:
op:numeric-equal Satisified iff the value of $arg1 is equal to the value of $arg2.
op:numeric-less-than Satisfied iff $arg1 is less than $arg2
op:numeric-greater-than Satisfied iff $arg1 is greater than $arg2
Built-In Functions:
fn:abs Returns the absolute value of the argument
fn:ceiling Satisfied iff the output value is the smallest number with no fractional part that is greater than or equal to the argument
fn:floor Satisfied iff the output value is the largest number with no fractional part that is less than or equal to the argument.
fn:round Satisfied iff the output value is rounded to the nearest number with no fractional part.
fn:round-half-to-even Takes a number and a precision. It is satisfied iff the output value is a number rounded to the given precision. If the fractional part is exactly half, the result is the number whose least significant digit is even.
8.3. Built-In Functions and Operators over Boolean Values
"fn:not" is a function built-in where fn:not(true) returns false and fn:not(false) returns true.
One operator and one function are proposed:
op:boolean-equal
fn:boolean-not
8.4. Built-In Functions on Strings
The following built-in functions are proposed:
fn:compare Compares two input string arguments $string1 and $string2. Satisfied iff the output value is -1, 0, or 1, depending on whether the value of the $string1 is respectively less than, equal to, or greater than the value of $string2.
fn:string-less-than Satisfied iff the first string argument is less than the second string argument when ordered according to Unicode(tm) code order
fn:string-greater-than Satisfied iff the first string argument is greater than the second string argument when ordered according to Unicode(tm) code order
fn:string-equal Satisfied iff the first string argument is the same as the second string argument (case sensitive).
fn:string-equal-ignore-case Satisfied iff the first string argument is the same as the second string argument (upper/lower case ignored)
fn:string-concat Satisfied iff the output value is a string resulting in the concatenation of two or more strings.
fn:substring Satisfied iff the output value is the string located at a specified location in an input string
fn:string-length Satisfied iff the output value is the length of the string argument.
fn:normalize-space Satisfied iff the output value is the whitespace-normalized value of the argument.
fn:upper-case Satisfied iff the output value is the upper-cased value of the argument.
fn:lower-case Satisfied iff the output value is the lower-cased value of the argument.
fn:translate Satisfied iff the output value is the first string argument with occurrences of characters contained in the second argument replaced by the character at the corresponding position in the third argument.
fn:contains Satisfied iff the output value is the first string argument contains the second string argument (case sensitive)
fn:contains-ignore-case Satisfied iff the output value is the first string argument contains the second string argument (case ignored)
fn:starts-with Satisfied iff the output value is the first string argument starts with the second string argument.
fn:ends-with Satisfied iff the output value is the first string argument ends with the second string argument.
fn:substring-before Satisfied iff the output value is the collation units of the first string argument that precede in that string the collation units of the second string argument.
fn:substring-after Satisfied iff the output value is the collation units of the first string argument that follow in that string the collation units of the second string argument.
fn:matches Satisfied iff the output value is the value of the first argument is matched by the regular expression that is the value of the second argument.
fn:replace Satisfied iff the output value is the value of the first argument with every substring matched by the regular expression that is the value of the second argument replaced by the replacement string that is the value of the third argument.
fn:tokenize Satisfied iff the output value is a sequence of one or more strings whose values are substrings of the value of the first argument separated by substrings that match the regular expression that is the value of the second argument.
fn:string-diff Satisfied iff the output value is the string representing the diff between the two inpur string arguments (case sensitive)
fn:string-diff-ignore-case Satisfied iff the output value is the string representing the diff between the two inpur string arguments (case ignored)
8.5. Built-In Functions and Operators on Date, Time and Duration
The following set of built-ins is directly imported from XQuery. They are built-in operations on the date and time types as defined in XML Schema Part 2 Datatypes.
In the previous telecon, we decided to leave the QNames built-ins out.
Here is a list of proposed operators and functions:
fn:resolve-uri
op:anyURI-equal Satisfied iff $arg1 and $arg2 compare equal on a codepoint-by-codepoint basis. Otherwise, returns FALSE.
fn:uri-protocol Satisfied iff the output value is the URI protocol as a string
fn:uri-host Satisfied iff the output value is a string containing the fully qualified DNS host name or IP address of the server specified in the URI
fn:uri-port Satisfied iff the output value is the integer port number of the input URI argument
fn:uri-fragment Satisfied iff the output value is a URI fragment as a string
We are also adding a URI constructor from the individual components and a default base that, for example,
would allow us to express the following: http://www.w3.org/* owl:sameAs http://www.w3c.org/*.
8.7. Built-Ins for Lists
There are three basic operators:
op:list-concatenation Satisfied iff the output value is a list representing the concatenation of the two input list arguments.
op:list-intersection Satisfied iff the output value is a list representing the intersection of the two input list arguments.
op:list-subtraction Satisfied iff the output value is a list containing the elements of the first list argument that are not member of the second list argument.
Built-ins functions for lists:
fn:member Satisfied iff the output value is the first argument is a member of the second argument (a list)
fn:length Satisfied iff the output value is the length of the list (number of elements member of the of the list)
fn:head Satisfied iff the output value is the first member of the list argument
fn:tail Satisfied iff the output value is a list containing all members of the list argument except the first element (the head).
fn:sublist Satisfied iff the output value is the first list argument contains the second list argument.
fn:contains Satisfied iff the output value is the first list argument contains the second list argument.
8.8. Built-ins for module handling
The following functions may be introduced to manipulate modules in SWRL:
fn:declareModule This is a constructor allowing the creation of new modules. It is not fully side-effect free
fn:setModule This is a side-effectfull built-in function
fn:getModuleInfo Returns the detailed info given a declared module name. (We need to clarify what info is returned)
fn:listModules Returns the list of declared modules
8.9. Other Possible Built-Ins
This section focuses on built-ins extensions including, as listed below, various classes of built-ins, some of them outside the SWRL Kernel, and others are implementation and API level built-ins.
Control Built-ins: side-effectfull
Database Built-ins
Term Comparison Built-ins
Term Manipulation Built-ins
Stream I/O Built-ins
Character I/O Built-ins
Term I/O Built-ins
Event Handling Built-ins
Debugging Built-ins
Arrays and Global Variable Built-ins
Coroutining Built-ins
External Interface Built-ins (imports)
Prolog Environment Built-ins
Compiler Directives Built-Ins
Operating System Built-Ins
Sorting Library predicates Built-ins
It could also be allowed to extend the Taxonomy by defining further built-ins on the level of the implementation language of the SWRL built-ins.
NOTE: Built-ins for sequences and nodes are not currently supported in SWRL. They can be left as optional for the specification implementations.