The [predicate] command.


The predicate command lets you create and evaluate predicates which are logical operators that return a boolean value (true or false).
There are two types of predicates: Much like regular expressions, there is a syntax to specify predicates with a string expression. The predicate strings are parsed by a predicate engine which builds an internal representation. A set of attributes can then be evaluated against the predicate in order to check if they satisfy the conditions contained in the predicate.
The predicate string syntax is different from the regular expression syntax. To learn more about this syntax, see the following document:
Predicate Format String Syntax.
A predicate can also easily be constructed via a user interface using the PredicateEditor view.


The formal syntax of the [predicate] command is:
predicate subcommand ?options?
The possible subcommands are described below. Depending on the subcommand, some options may be specified.

Predicate subcommands

The [create] subcommand

This subcommand creates a new predicate. The complete syntax is:
    predicate create str
The str argument is the predicate string written using the predicate syntax (see
Predicate Format String Syntax). The command returns a unique token which can be used in other commands to refer to this predicate.

The [delete] subcommand

This subcommand deletes a predicate. The complete syntax is:
    predicate delete token
After deletion, the token associated with this predicate is not valid anymore.

The [eval] subcommand

This subcommand lets you evaluate a set of attributes against a predicate. The complete syntax is:
    predicate eval token dict
The token argument is typically obtained via the
[predicate create] command or via the -value option of a PredicateEditor view.
The command returns 1 if the attributes are validated by the predicate, and 0 otherwise.
The dict argument represents the set of attributes: it is a dictionary in which the keys typically correspond to left hand side expressions in some comparison predicates and the values are compared to the corresponding right hand side expressions.
The dictionary should contain simple key/value pairs where the key is a string and the value can be: An exception is raised if an integer value is passed for a predicate condition which expects a date. The date has to be explicitely cast.
    predicate eval $token [list Creator ALFA "Modification Date" date(506206024)]

The [format] subcommand

This subcommand returns a string representation of a predicate's format. The complete syntax is:
    predicate format token
Note that the string returned by this command is not guaranteed to be the same as the string used to create the predicate in the
[predicate create] command.

The [list] subcommand

This subcommand returns a list of the existing predicate tokens. The complete syntax is:
    predicate list


Here are a few examples demonstrating how the predicate command work:
    «» set tkn1 [predicate create "(firstName BEGINSWITH 'W') AND (lastName LIKE 'Shake*')"]
    «» predicate eval $tkn1 "firstName William lastName Shakespeare"
    «» set tkn2 [predicate create "(age BETWEEN {21,33}) AND (weight <= 170)"]
    «» predicate eval $tkn2 "weight 168.5 age 35"
See also the
PredicateEditor view for a user interface to build predicates.

Last updated 2017-01-18 08:51:49