Conditional expressions
The conditional expression is enclosed in brackets immediately following the pattern operand.
If simple values or tables of values are not sufficient to qualify pattern matching, you can use conditional expressions. These expressions have the following format:
operand [conditional expression]
A simple conditional expression consists of an operand, a relational operator, and a second operand. The following are the relational operators:
Relational Operator | Value |
---|---|
< | Original token is less than |
> | Original token is greater than |
= | Abbreviation or original token is equal to |
=A= | Abbreviation is equal to |
<= | Original token is equal to |
>= | Original token is less than or equal to |
!= | Abbreviation or original token is not equal to |
!=A= | Abbreviation is not equal to |
!=T= | Original token is not equal to |
The left operand can be any of the following elements:
- A variable name
- The field contents for the current operand
- The contents for any dictionary field
The right operand can be any of the following elements:
- A variable name
- A literal
- A constant
The complete format of a conditional expression is:
left-operand relational-operator right-operand
The following table explains the expression:
Operation | Valid values |
---|---|
left-operand | |
relational-operator | |
right-operand | |
Current operand contents
The contents of the current operand are in left and right braces ({ }).
An example that uses calendar dates best illustrates this concept. When verifying dates, you want to verify the length of numbers. One example is as follows:
^ [{}LEN=4] | - | ^ [{}LEN=2] | - | ^ [{}LEN=2]
; format for ccyy-mm-dd
This pattern matches on 2009-07-08 but not on 07-08-09.
The pattern operands in the preceding example have the following meaning:
Operand | Symbol | Description |
---|---|---|
Operand [1] | ^ | A 4-digit number |
Operand [2] | - | A hyphen |
Operand [3] | ^ | A 2-digit number |
Operand [4] | - | A hyphen |
Operand [5] | ^ | A 2-digit number |
When character literals are in an equality test, the standard abbreviation is tested if one is available. If this fails, the original input is tested. The following examples show pattern operands when you have ROAD RD T in your classifications:
Pattern | Description |
---|---|
|
Compares the abbreviation of the current operand (RD) to the literal RD |
|
Compares the entire input operand to the literal (because it fails to compare to the abbreviation) |
|
Compares only the abbreviation of the current operand to RD |
|
Compares the original value of the token to ROAD and not to the abbreviation |
|
When comparisons (other than the equality operators)
are specified, the original input is used rather than the abbreviation. This is true for any comparison to a literal value. If the original value is RD, the result is true, but, if the original value is ROAD, the result is false. |
Dictionary field contents
The dictionary field is identified by the field name that is listed in the first column of the table in the dictionary definition file (.DCT).
Sometimes you need to test a value placed in a dictionary field from an earlier process or from a pattern-action set that was previously executed. This can be accomplished by specifying the field name enclosed in braces.
For example, you have two streets named EAST WEST HIGHWAY. In postal codes 20100 - 20300, the name of the street is EAST WEST, and in postal codes 80000 - 90000, WEST is the name of the street and EAST is the direction. If the postal code field is populated by an earlier process and named {ZipCode}, you can use the following pattern-action sets:
^ | D = "E" | D = "W" | T = "HWY" | [ {ZipCode} >= 20100 & {ZipCode} <= 20300 ]
COPY [1] {HouseNumber} ; move house number to {HouseNumber} field
COPY [2] temp ; concat EAST WEST and move
CONCAT [3] temp ; to street name field
COPY temp {StreetName}
COPY_A [4] {StreetSuffixType} ; move HWY to street type field
^ | D = "E" | D = "W" | T = "HWY" | [ {ZipCode} >= 80000 & {ZipCode} <= 90000 ]
COPY [1] {HouseNumber} ; move house number to {HouseNumber} field
COPY_A [2] {StreetPrefixDirectional} ; move EAST to direction
COPY [3] {StreetName} ; move WEST to street name
COPY_A [4] {StreetSuffixType} ; move HWY to street type field
In this pattern, the operand [{ZipCode} >= 20100 & {ZipCode} <= 20300] states:
Operand Element | Description |
---|---|
{ZipCode} |
The value in the postal code field |
>= |
is greater than or equal to |
20100 |
the number 20100 |
& |
and |
{ZipCode} |
the value in the postal code field |
<= |
is less than or equal to |
20300 |
the number 20300 |
The logical operator & is used to connect
two conditional expressions. The condition is placed in a separate
operand. It can also be placed in the operand for HWY
;
for example:
^ | D = "E" | D = "W" | T = "HWY" [ {ZipCode} >= 80000 & {ZipCode} <= 90000 ]
These two forms are identical in function. However, the first form is easier to read because the conditions are placed in separate pattern operands.
When conditions only reference
dictionary field contents (and not any pattern operand), as in the
preceding example with {ZipCode}
, the condition must
follow all pattern operands. The following example is not valid since
the second operand does not reference an input field and a third operand
(T) follows the condition:
^ | [{ZipCode} = 80000] | T
The correct form is:
^ | T | [{ZipCode} = 80000]
If you use in a condition a dictionary field name that is not defined in the dictionary definition file, any test on its value always returns FALSE. If you are testing for NULL contents, the test returns TRUE; for example:
{ZZ} = ""
This facility allows use of the same general Pattern-Action files on projects which dispense with certain fields (as opposed to ending the program with an invalid field error).
Literals: character constants and user variables
Literals are character constants. They are represented by enclosing a string in quotes.
Numeric constants are referenced to by coding a number. Negative numbers and decimal points are not permitted in numeric constants. The following pattern operand matches on a number equal to 10000:
^ [{} = 10000]
The following example matches to the text MAIN:
? [ {} = "MAIN" ]
If an unknown operand (?) is specified, multiple words are concatenated to a single word. To match to CHERRY HILL, use the following pattern:
? [ {} = "CHERRYHILL" ]
A NULL or empty value is indicated by two consecutive quote marks.
[ user_variable = ""]
You can use any of the relational operators for character
strings. The following example matches on all strings starting with MA
or
greater, including MA, MAIN, NAN, PAT,
but not ADAMS,
M
, or LZ
:
? [ {} > "MA" ]
The equality (=) is tested on the abbreviation for the operand first if one exists, and then on the full operand. The other relational operators test on the full operand and not the abbreviation.
You can define variables to which you assign specific values by using the actions. You can test variables for specific values within conditions. Variables must be named according to the following conventions:
- The first character must be alphabetic.
- The name cannot exceed 32 characters.
After the first alphabetic character, you can use any combination of alphanumeric characters or the underline (_).
For example, if you set the variable postcode to the postal code, you can test to see if the post code is 12345 as follows:
[postcode = 12345]
This type of condition can be a separate pattern operand or combined with a standard class. For example, the following two patterns produce identical results:
^ | [postcode = 12345]
^ [postcode = 12345]
If a user variable is set to a numeric value, its type is numeric. If it is set to a literal value, its type is character.
If a condition only references variables or dictionary fields, and not current input operands, the condition must follow all operands. The following example is not valid since the second operand does not reference an input field and a third operand follows:
^ | [postcode = 12345] | T
You must replace it with:
^ | T | [postcode = 12345]
Referencing lengths of operands (LEN)
LEN represents the length of an operand.
A special LEN function is available. You can use the expression in one of the following three ways:
Expression | Description |
---|---|
{} LEN | Length of the current operand |
variable LEN | Length of the contents of a variable |
{field-name} LEN | Length of the contents of a dictionary field |
If you want to search for a nine-digit postal code of 12345-6789, check for a five-digit number followed by a hyphen and a four-digit number, for example:
^ [ {} LEN = 5] | - | ^ [{} LEN = 4]
If the numerics do not match the length, the pattern does not match.
Similarly to test the length of a variable, the following pattern matches if the variable contains five characters:
? [ temp LEN = 5]
Finally, to test the length of a dictionary field, use the field name within braces:
[ {StreetName} LEN = 20 ]
Any trailing blanks are ignored in the calculation of the length. Leading blanks are counted. For example, if a user variable or a dictionary field is set to " XY" (two leading spaces), the length of either is 4.
Referencing formats of operands (PICT)
The picture defines how the numeric and alphabetic characters are formatted.
In some cases, you must test for special formats. You
can use the PICT (picture) function. For example, Canadian postal
codes have the form character-number-character (space) number-character-number;
for example, K1A 3H4
. You can use the PICT function
to represent these sequences:
@ [{} PICT = "cnc"] | @ [{} PICT = "ncn"]
The @ (at sign) matches to a complex type (mixed numeric and alphabetic characters).
String | Description |
---|---|
cnc | For character-number-character |
ncn | For number-character-number |
Some British postal codes use the form character-character-number
(space) number-character-character; for example, AB3 5NW
.
< [{} PICT = "ccn"] | > [{} PICT = "ncc"]
The PICT clause works for dictionary field values:
[ {ZipCode} PICT = "ccn" ]
The PICT operand works for user variables:
[ temp PICT = "ncncn" ]
Only the equality (=) and inequality (!=) operators can be used with PICT comparisons.
Referencing substrings of operands
A special form is provided in the patterns to test a portion of an operand.
These portions are called substrings. The following forms are valid:
Form | Description |
---|---|
{} (beg:end) | Substring of the current operand |
variable (beg:end) | Substring of the content of the user variable |
field-name (beg:end) | Substring of the content of the dictionary field |
The (beg:end) specifies the beginning and ending character to extract. The first character in the string is 1, the last character is –1, and so on.
For example, German style addresses have the street type appended to the end of the street name. Thus, HESSESTRASSE means HESSE STREET. The substring form can be used to test for these suffixes. Consider an input address of HESSESTRASSE 15. The following pattern matches to all words ending in STRASSE that are followed by a numeric:
+ [{} (-7:-1) = "STRASSE"] | ^
Similarly, variables and fields can be tested:
[temp(2:4) = "BCD"]
[{StreetName}(1:4) = "FORT"]
? [{} (1:12) = "MARTINLUTHERKING"]