Axiom choice is one of two selection artifacts, the second being term choice. A term choice selects a single term value, while an axiom choice selects one axiom from a collection. An axiom choice is a hybrid template and axiom collection combination which is used to select a data set for use in generating a solution based on query criteria.
Format
The axiom choice format is similar to that of a literal axiom collection, except keyword axiom is replaced with choice, anonymous terms are not allowed and each row contains a hybrid combination of a match term followed by one or more literals:
choice name( term-names ) { match-term, literals } ...
The match term is unique to axiom choice and it provides the logic on which a selection is made. A match term can be one of two types, both of which involve a match variable indicated by the first name in the term names header:
- Literal value which is compared to the match variable
- Boolean expression containing the match variable which is evaluated at the time the selection is made
Usage
Axiom choice is versatile in that it can be placed in a query chain or used in a calculator like a conditional branch. There are subtle differences in behaviour to be pointed out later. The format for using an axiom choice in a calculator is simple. The axiom choice is referenced by name and an optional comma-delimited parameter list can follow:
choice name [( parameters )]
An axiom choice declaration may be several lines long, so is not allowed to be attached to a template as this would be confusing. However, when referenced by a calculator, the axiom choice is automatically incorporated in the calculator and a set of variables is provided to hold the selection when it is made. As the axiom choice is in a term position, it must return a value, which in this case is a selection index. Values range from zero upwards, and if no match is found, the returned value is -1.
Axiom choice allows selection based on value ranges. The following example shows an axiom choice named "bracket" used to find the stamp duty applicable to a real estate transaction:
{amount < 12000, 0, 0.00, 1.00}
{amount < 30000, 12000, 120.00, 2.00}
{amount < 50000, 30000, 480.00, 3.00}
{amount < 100000, 50000, 1080.00, 3.50}
{amount < 200000, 100000, 2830.00, 4.00}
{amount < 250000, 200000, 6830.00, 4.25}
{amount < 300000, 250000, 8955.00, 4.75}
{amount < 500000, 300000, 11330.00, 5.00}
{amount > 500000, 500000, 21330.00, 5.50};
There are several important details about how the bracket axiom choice is applied:
- All the choice terms are named. The first, "amount", identifies the match variable.
- Each match term contains a boolean expression which compares the match variable to a literal value
- There is no default selection as the last option is open ended.
If a default selection is needed as a "catch-all" last option, then the keyword unknown is used as the last match term.
Choice as a Query Chain
The selection term is set by unifying with the incoming axiom. The result of the axiom choice is placed in the solution. If no match occurs, then the query step is short circuited. This allows cases to be filtered from the query results based on certain criteria. Note that when a match occurs, the selection index is also placed int the solution as a term with the same name as the choice.
