THEN and OR

Overview of THEN and OR Connector

All base patterns (e.g. WORD, GROUP, RANGE) in a GLASS data type must be connected to another component (or group of components).

Two or more components can be joined in:

  • Series with a THEN connector so that the data patterns and the corresponding rules defined by the connector must be matched consecutively, or
  • Parallel with an OR connector so that the data patterns and the corresponding rules defined by either of the connectors may be matched.

Both THEN and OR operators can be used together in a GLASS expression.

THEN Connector

The THEN connector lets you join two or more search patterns or expressions such that they must be matched consecutively.

Join two components in series using THEN operator

A location will be returned as a match if the GLASS engine detects a data string that is a combination of the all the THEN operators.

The generic GLASS syntax for THEN is:

[(]<search pattern or expression> THEN <search pattern or expression>[)]

THEN Example 1

ACME Corporation's regional customer ID is a 12-digit string that starts with a supported 2-character ccTLD (<ccTLD>), followed by a 9-digit serial number (<9-digit serial number>), and a single check digit (<check digit>).

ACME Corporation Sample Regional Customer ID

One approach when building this GLASS data type would be to define separate base patterns to search for the ccTLD, serial number, and check digit, and combine the base patterns using the THEN connector.

Part 1 - ccTLD

GLASS expression to search for the accepted ccTLD values:

  • Data type component: LIST (GROUP)
  • Data pattern to search for (+ Create Map):
    • MAP Label: ACME_CUST_ID_CCTLD
    • MAP Entries: 'AU', 'IE', 'KR', 'SG', 'UK', 'US'
    • MAP No Case option: Checked
MAP NOCASE 'ACME_CUST_ID_CCTLD' 'AU', 'IE', 'KR', 'SG', 'UK', 'US'
GROUP 'ACME_CUST_ID_CCTLD'

Part 2 - Serial Number

GLASS expression to search for the 9-digit serial numbers:

  • Data type component: RANGE
  • Data pattern to search for (Select a keyword): DIGIT
  • Repeat Character/Octet (TIMES) option: Checked, 9 times
  • Exclude (EXCLUDE) rule:
    • MAP Label: INVALID_SERIAL_NUM
    • MAP Entries: 0
MAP 'INVALID_SERIAL_NUM' 0
RANGE DIGIT TIMES 9 EXCLUDE 'INVALID_SERIAL_NUM'

Part 3 - Check Digit

GLASS expression to search for the check digit:

  • Data type component: RANGE
  • Data pattern to search for (Select a keyword): DIGIT
RANGE DIGIT

Putting Everything Together with THEN Connector

The three GLASS expressions can be joined using the THEN connector to search for the regional customer ID number as a whole.

ACME Corporation Customer ID THEN Connector

The equivalent GLASS code for the combined GLASS expressions is:

MAP NOCASE 'ACME_CUST_ID_CCTLD' 'AU', 'IE', 'KR', 'SG', 'UK', 'US'
MAP 'INVALID_SERIAL_NUM' 0

GROUP 'ACME_CUST_ID_CCTLD' THEN \
RANGE DIGIT TIMES 9 EXCLUDE 'INVALID_SERIAL_NUM' THEN \
RANGE DIGIT

OR Connector

The OR connector lets you join two or more search patterns or expressions such that expressions on either side of the OR operator may be matched.

Join two components in parallel using OR operator

A location will result in a match if the GLASS engine detects a data string that is a result of the expression on either side of the OR operator.

The generic GLASS syntax for OR is:

(<search pattern or expression> OR <search pattern or expression>)

OR Example 1

ACME Corporation has received a Request for Information (RFI) on the following members of the Skywalker family:

  • Anakin Skywalker
  • Leia Skywalker
  • Luke Skywalker

You task is to develop a custom GLASS data type to search through ACME Corporation's databases for references to the Skywalker family, with the following assumptions:

  • Only records containing the full names of any member of the Skywalker family will need to be returned as matches.
  • Full names may be stored as first names followed by last names, or last names followed by first names.
  • First names and last names are expected to be separated by specific characters (e.g. whitespace  , pipe |, comma ,).
1 Leia Skywalker
2 Skywalker,Luke
3 Anakin|Skywalker

Part 1 - First Name Followed by Last Name

GLASS expression to search for first names followed by the last name:

  • Data type component: LIST (GROUP)
    • Data pattern to search for (+ Create Map):
      • MAP Label: FIRST_NAMES
      • MAP Entries: 'Anakin', 'Leia', 'Luke'
      • MAP No Case option: Checked
  • Data type component: RANGE
    • Data pattern to search for (Customized):  |,
  • Data type component: WORD
    • Data pattern to search for: Skywalker
    • No Case option: Checked
MAP NOCASE 'FIRST_NAMES' 'Anakin', 'Leia', 'Luke'
GROUP 'FIRST_NAMES' THEN RANGE ' |,' THEN WORD NOCASE 'Skywalker'

Part 2 - Last Name Followed by First Name

GLASS expression to search for the last name followed by the first names:

  • Data type component: WORD
    • Data pattern to search for: Skywalker
    • No Case option: Checked
  • Data type component: RANGE
    • Data pattern to search for (Customized):  |,
  • Data type component: LIST (GROUP)
    • Data pattern to search for (+ Create Map):
      • MAP Label: FIRST_NAMES
      • MAP Entries: 'Anakin', 'Leia', 'Luke'
      • MAP No Case option: Checked
MAP NOCASE 'FIRST_NAMES' 'Anakin', 'Leia', 'Luke'
WORD NOCASE 'Skywalker' THEN RANGE ' |,' THEN GROUP 'FIRST_NAMES'

Putting Everything Together with OR Connector

The two GLASS expressions can be joined using the OR connector to search for the names of the Skywalker family members, either as first names followed by last names, or last names followed by first names.

Skywalker Family RFI OR Connector

The equivalent GLASS code for the combined expressions is:

MAP NOCASE 'FIRST_NAMES' 'Anakin', 'Leia', 'Luke'
( \
  (GROUP 'FIRST_NAMES' THEN RANGE ' |,' THEN WORD NOCASE 'Skywalker') \
  OR \
  (WORD NOCASE 'Skywalker' THEN RANGE ' |,' THEN GROUP 'FIRST_NAMES') \
)

THEN and OR Example 1

The example in Part 1 - First Name Followed By Last Name can be written using the WORD in instead of GROUP base pattern component by using both THEN and OR in a single expression.

(WORD NOCASE 'Luke' OR WORD NOCASE 'Leia' OR WORD NOCASE 'Anakin') THEN \
RANGE ' |,' THEN \
WORD NOCASE 'Skywalker'
1 Leia Skywalker
2 Luke,Skywalker
3 Anakin|Skywalker