Template-Axiom-Query (TAQ)

Operations

In the development of TAQ, built-in functions were created either out of necessity or opportunity. These are presented under the banner of "operations" as they are all implemented as template operands.

Criterion

A criterion is a test for a condition in relation to flow of execution. A criterion is easy to spot because it always] starts with a question mark ?*. There are three criterions that are special functions

  • regular expression
  • logical status query fact.
  • membership set (items enclosed in braces)

The expression "short circuit" is coined for when a logical decision is made before testing for all possibilities. A criterion always triggers a short circuit, It cannot make execution jump to some arbitrary location.

The logic of a criterion can be reversed by placing a colon ':' after the question mark. This can be used to test for something unusual or unexpected.

{} Set Selection

The set membership criterion is placed to the right of a variable to test if it matches one of a set of literal values. Braces {} are used to enclose a comma-delimited literal list with each item being of the same type as the variable on the left. Here is an example of matching a continent to either North or South America:

Continent ? {"North America","South America"}

american_megacities.taq demonstrates the above set membership operation.

Note that the criterion logic can be reversed to exclude items in the set by placing a colon : character immediately following the question mark.

Fact

A criterion consisting of the fact keyword placed in front of a variable is used to determine whether the variable is empty or otherwise invalid. This feature can be used, for example, to deal gracefully with incomplete or corrupt data.

The fact criterion establishes that a variable:

  1. is not empty
  2. is not a number with value NaN (not-a-number)
  3. in not of type "unknown"
  4. is not null (a value used to indicate an error has occurred)

For more details, see Fact / unknown.

Regular Expressions

A regular expressions matches text to a pattern. The hash '#' symbol is used as a regular expression operator.

Format

variable # pattern

The variable provides the text to be processed. The regular expression pattern is declared separately and referenced here by name. See Regular Expressions for more details.

TAQ regular expressions are implemented using the Java Pattern class.

As in Java, a backslash \ character, when used in a regular expression, needs to be escaped by using 2 backslashes \\.

Criterion

When a regular expression is applied to a template term it acts like a criterion. When a match fails, an execution short circuit is triggered.

Groups

A regular expression match can optionally collect embedded text fragments referred to as 'groups'. Parameters to receive the group items are appended to the # pattern as a comma-delimited list enclosed in parentheses. Grouping is not supported in templates and the first grouping example can be found here.

Example

query_in_words.taq selects words starting with "in" from a dictionary.

include "i-words.taq"

pattern in_words "^in[^ ]+"

template in_words
(
word # in_words,
definition
)

query<axiom> query_in_words(i_words : in_words)