Bookshelf Home | Contents | Index | PDF

## Attribute Operators

Rule Assembly Language includes special operators for doing comparisons and particular math operations on attribute values. These operators extract information about the attributes of all the products that have been selected in a relationship. For example, you can determine the number of relationship items that have been selected that have an attribute value greater than a specified amount.

#### Attribute Comparison Operators

These operators return the number of relationship items that have been selected for which the comparison is true. For example, you can use `numAttr>` to find out how many items with Length greater than 5 feet in a relationship have been selected.

The operators count all the items selected from the relationship, not the number of different items. In the preceding example, if the user selects two of the same item and enters a length greater than 5 feet, the `numAttr>` operator will return 2.

The operators take two arguments, A and B. Argument A is the full path from the root of the product to the attribute. Argument B is the comparison value. This value can be of type Integer, Number, Date, or Time. Type DateTime is not supported. Argument B can also be a sub-expression that resolves to one of these data types.

In addition, for the `numAttr==` and `numAttr!=` operators, argument B can be a text string.

Use attribute comparison operators to create subexpressions that form conditions. Attribute comparison operators are shown in Table 42.

Table 42.  Attribute Comparison Operators
Operator
Syntax
Properties

Greater than

`numAttr>(``A, B``)`

Returns the number of items in the relationship for which the value of attribute A is greater than B.

Not less than

`numAttr>=(``A, B``)`

Returns the number of items in the relationship for which the value of attribute A is greater than or equal to B.

Equals

`numAttr==(``A, B``)`

Returns the number of items in the relationship for which the value of attribute A is equal to B.

Not equal to

`numAttr!=(``A, B``)`

Returns the number of items in the relationship for which the value of attribute A is not equal to B.

Not greater than

`numAttr<=(``A, B``)`

Returns the number of items in the relationship for which the value of attribute A is less than or equal to B.

Less than

`numAttr<(``A, B``)`

Returns the number of items in the relationship for which the value of attribute A is less than or equal to B.

You can use the numAttr operators to create "any/all" conditions in rules involving attributes:

• You create the condition "any instance of products in R has attribute A=X" as follows:

>=(numAttr==(@.[R].[A], X), 1)

• You create the condition "all instances of products in R have attribute A=X" as follows:

==(numAttr==(@.[R].[A], X), @.[R])

For example, you want to write the rule, when all the instances of products in P have attribute A=X then exclude any instance of products in Q that have attribute B =Y. You would write this rule as follows:

excl(==(numAttr==(@.[P].[A], X), @[P]),

>=(numAttr(==(@.[Q].[B], Y), 1)))

#### Attribute Arithmetic Operators

The arithmetic operators allow you to determine the maximum and minimum value of an attribute for items that have been selected in a relationship. You can also sum the values of the attributes.

The operators take one argument, which is the path to the attribute. Attributes can be of type Number, Integer, Date, or Time. DateTime and Text are not supported. If the type is Date or Time, `minAttr` returns the time or date closest to the present. The `maxAttr` operator, returns the time or date furthest from the present.

Use attribute arithmetic operators to create subexpressions that form conditions. Attribute arithmetic operators are shown in Table 43.

Table 43.  Attribute Arithmetic Operators
Operator
Syntax
Properties

Minimum

`minAttr(``A``)`

For items selected from a relationship, returns the smallest value for attribute A.

Maximum

`maxAttr(``A``)`

For items selected from a relationship, returns the largest value for attribute A.

Sum

`sumAttr(A)`

Returns the sum of attribute A for all items selected from a relationship.