A namespace is collection of related keys (or entries) that may share common properties.
For example, ACME_CORPORATION_DEPARTMENTS can be a namespace that refers to a set of departments such as Human Resources, Engineering, IT, and Accounting.
In GLASS, namespaces are defined with the MAP operator and have the following properties:
The generic GLASS syntax for MAP is:
MAP [NOCASE|DECOMPOSE] '<source namespace>' [NOCASE|DECOMPOSE] '<key>[ = <literal>]'[, [NOCASE|DECOMPOSE] '<key>[ = <literal>]']*
GROUP '<namespace>'
RANGE '<range of characters>' [TIMES <integer>[-<integer>]] [EXCLUDE|REQUIRE '<namespace>']
CONTEXT '<context namespace>' [BEFORE|AFTER|AROUND] [REQUIRE|DENY] '<namespace>'
<search pattern> APPLY '<context namespace>'
See LIST Operator, RANGE Operator, REQUIRE Rule, EXCLUDE Rule and CONTEXT and APPLY for more information.
The MAP operator creates or appends to a namespace and associates a set of keys (or entries) with the given namespace.
Each namespace entry can be defined as a:
MAP NOCASE 'SWIFT_CODES' 'MACSUS33', 'WVIOUS6L'
MAP NOCASE 'SWIFT_CODES' \
'MACSUS33' = "Master Card International Inc.", \
'WVIOUS6L' = "World Vision International"
To find out more about using keys and associated literals in namespaces, see the META operator.
You can define (a combination of) literal values, integers, and integer ranges as keys in namespaces.
MAP 'NS0' 'AU'
''
) or double quotes (""
). MAP 'NS1' 123
MAP 'NS2' 2221-2720
By default, the GLASS expressions are case sensitive. The NOCASE (No Case) option determines if the GLASS pattern matching engine treats uppercase and lowercase characters as distinct (case sensitive) or equal (case-insensitive) characters.
Without the NOCASE option, uppercase and lowercase characters in namespace entries are distinct characters.
MAP '<namespace>' '<key 1>', '<key 2>', ..., '<key N>'
For example, lowercase usa
and uppercase USA
are treated as different
keys / entries by the GLASS pattern matching engine.
If the NOCASE (No Case) option specified or checked, uppercase and lowercase characters in namespace entries are equal.
MAP NOCASE '<namespace>' '<key 1>', '<key 2>', ..., '<key N>'
For example, lowercase usa
and uppercase USA
are treated as the same keys /
entries by the GLASS pattern matching engine.
You want to build a custom data type to search for Australia addresses. You start by defining a MAP namespace containing the abbreviations for all Australian States and Territories, and reference this namespace using the GROUP (LIST) component.
MAP NOCASE 'AU_STATES' 'ACT', 'NSW', 'NT', 'QLD', 'SA', 'TAS', 'VIC', 'WA'
GROUP 'AU_STATES'
Without specifying additional pattern rules, all the following lines will be returned as match locations by the GLASS pattern matching engine:
1 | Bennelong Point, Sydney NSW 2000, Australia |
2 | churchill ave, hobart tas 7005, australia |
3 | Queen Victoria |
The equivalent configuration in GLASS Studio Visual Builder mode is:
If the DECOMPOSE (Decompose) option is specified or checked, the GLASS pattern matching engine matches the namespace key / entry both in its original form and normalized (ASCII) form, where applicable.
This is useful when searching for data patterns that contain language-specific
accents or diacritics (e.g. s'il vous plaît
).
Without the DECOMPOSE option, the GLASS pattern matching engine matches a MAP namespace entry as is.
MAP '<namespace>' '<key 1>', '<key 2>', ..., '<key N>'
If the DECOMPOSE (Decompose) option is specified or checked, the GLASS pattern matching engine matches a MAP namespace entry both in its original form and normalized (ASCII) form, where applicable.
MAP DECOMPOSE '<namespace>' '<key 1>', '<key 2>', ..., '<key N>'
You define the following GLASS expression:
MAP NOCASE DECOMPOSE 'MENU_ITEMS' 'crème brûlée', 'gougères', 'paté de pâques'
GROUP 'MENU_ITEMS'
As the NOCASE and DECOMPOSE options are specified or checked, all the underlined terms will be returned as match locations by the GLASS engine:
1 | crème brûlée or creme brulee |
2 | CRÈME BRÛLÉE or CREME BRULEE |
3 | crème BRÛLÉE or creme BRULEE |
4 | gougères or gougeres |
5 | GOUGÈRES or GOUGERES |
6 | gougÈRES or gougERES |
7 | paté de pâques or pate de paques |
8 | PATÉ DE PÂQUES or PATE DE PAQUES |
9 | paté dE PÂQUES or pate dE PAQUES |
paté de paques
will
not match as the GLASS engine searches for terms
where all characters with accents or diacritics are either in their original
form (e.g. é and
â), or in their normalized form (e.g.
e and a).
The equivalent configuration in GLASS Studio Visual Builder mode is:
The COPY operator allows you to copy the contents / keys from a source namespace, to a target namespace.
If the target namespace does not exist at the time of the COPY operation, the namespace will be created. Otherwise, the contents of the source namespace will be appended to the target namespace.
The namespace COPY operation preserves all options defined in the source namespace.
The generic GLASS syntax for MAP and COPY is:
MAP [NOCASE|DECOMPOSE] '<source namespace>' [NOCASE|DECOMPOSE] '<key>[ = <literal>]'[, [NOCASE|DECOMPOSE] '<key>[ = <literal>]']*
MAP '<target namespace>' COPY '<source namespace>'[, COPY '<source namespace>']*
In GLASS Studio Visual Builder mode, when multiple namespaces are selected for base pattern components, (GROUP), pattern rules (RANGE with REQUIRE / EXCLUDE), or contextual keywords (CONTEXT), GLASS Studio automatically creates a new target namespace with a unique label and copies the selected source namespaces to the new namespace using the COPY operator.
Let's take a look at how the contents for each namespace changes with each new line of GLASS code.
Line 1
1 | MAP NOCASE 'HERBIVORE_INSECTS' 'butterfly', 'grasshopper' |
A new namespace 'HERBIVORE_INSECTS' is created with two case-insensitive keys.
Namespace | Keys |
---|---|
HERBIVORE_INSECTS | case insensitive keys: butterfly , grasshopper |
HERBIVORE_MAMMALS | - |
HERBIVORE_DINOSAURS | - |
HERBIVORES | - |
Line 2
1 | MAP NOCASE 'HERBIVORE_INSECTS' 'butterfly', 'grasshopper' |
2 | MAP 'HERBIVORE_MAMMALS' 'Deer', NOCASE 'giraffe' |
A new namespace 'HERBIVORE_MAMMALS' is created with one case-sensitive, and one case-insensitive key. The contents in namespace 'HERBIVORE_INSECTS' is unchanged.
Namespace | Keys |
---|---|
HERBIVORE_INSECTS | case insensitive key(s): butterfly , grasshopper |
HERBIVORE_MAMMALS | case sensitive key(s): Deer case insensitive key(s): giraffe |
HERBIVORE_DINOSAURS | - |
HERBIVORES | - |
Line 3
1 | MAP NOCASE 'HERBIVORE_INSECTS' 'butterfly', 'grasshopper' |
2 | MAP 'HERBIVORE_MAMMALS' 'Deer', NOCASE 'giraffe' |
3 | MAP 'HERBIVORES' COPY 'HERBIVORE_INSECTS', COPY 'HERBIVORE_MAMMALS' |
A new namespace 'HERBIVORES' is created and the contents from 'HERBIVORE_INSECTS' and 'HERBIVORE_MAMMALS' are copied to it.
The contents in namespaces 'HERBIVORE_INSECTS' and 'HERBIVORE_MAMMALS' are unchanged.
Namespace | Keys |
---|---|
HERBIVORE_INSECTS | case insensitive key(s): butterfly , grasshopper |
HERBIVORE_MAMMALS | case sensitive key(s): Deer case insensitive key(s): giraffe |
HERBIVORE_DINOSAURS | - |
HERBIVORES | case sensitive key(s): Deer case insensitive key(s): butterfly , grasshopper , giraffe |
Line 4
1 | MAP NOCASE 'HERBIVORE_INSECTS' 'butterfly', 'grasshopper' |
2 | MAP 'HERBIVORE_MAMMALS' 'Deer', NOCASE 'giraffe' |
3 | MAP 'HERBIVORES' COPY 'HERBIVORE_INSECTS', COPY 'HERBIVORE_MAMMALS' |
4 | MAP 'HERBIVORE_DINOSAURS' 'Diplodocus', 'Stegosaurus' |
A new namespace 'HERBIVORE_DINOSAURS' is created with two case-sensitive keys.
The contents in namespaces 'HERBIVORE_INSECTS', 'HERBIVORE_MAMMALS' and 'HERBIVORES' are unchanged.
Namespace | Keys |
---|---|
HERBIVORE_INSECTS | case insensitive key(s): butterfly , grasshopper |
HERBIVORE_MAMMALS | case sensitive key(s): Deer case insensitive key(s): giraffe |
HERBIVORE_DINOSAURS | case sensitive key(s): Diplodocus , Stegosaurus |
HERBIVORES | case sensitive key(s): Deer case insensitive key(s): butterfly , grasshopper , giraffe |
Line 5
1 | MAP NOCASE 'HERBIVORE_INSECTS' 'butterfly', 'grasshopper' |
2 | MAP 'HERBIVORE_MAMMALS' 'Deer', NOCASE 'giraffe' |
3 | MAP 'HERBIVORES' COPY 'HERBIVORE_INSECTS', COPY 'HERBIVORE_MAMMALS' |
4 | MAP 'HERBIVORE_DINOSAURS' 'Diplodocus', 'Stegosaurus' |
5 | MAP 'HERBIVORES' COPY 'HERBIVORE_DINOSAURS' |
The contents from 'HERBIVORE_DINOSAURS' are copied and appended to the target namespace 'HERBIVORES'.
The contents in namespaces 'HERBIVORE_INSECTS', 'HERBIVORE_MAMMALS' and 'HERBIVORE_DINOSAURS' are unchanged.
Namespace | Keys |
---|---|
HERBIVORE_INSECTS | case insensitive key(s): butterfly , grasshopper |
HERBIVORE_MAMMALS | case sensitive key(s): Deer case insensitive key(s): giraffe |
HERBIVORE_DINOSAURS | case sensitive key(s): Diplodocus , Stegosaurus |
HERBIVORES | case sensitive key(s): Deer , Diplodocus , Stegosaurus case insensitive key(s): butterfly , grasshopper , giraffe |
Suppose you are tasked to search for employee names across your organization's data storage locations:
Cara
, Grainne
, Shannon
Charlotte
, Evelyn
, Layla
, Sarah
Ava
, Gabrielle
, Ruby
, Sophie
You decide to take the approach to create separate namespaces for employee names by location (e.g. IE_NAMES, SG_NAMES, and US_NAMES), and select all three when defining a GROUP. This makes the namespaces easier to manage and also enables the namespaces to be reused in a more flexible manner.
MAP NOCASE 'IE_NAMES' 'Cara', 'Grainne', 'Shannon'
MAP NOCASE 'SG_NAMES' 'Charlotte', 'Evelyn', 'Layla', 'Sarah'
MAP NOCASE 'US_NAMES' 'Ava', 'Gabrielle', 'Ruby', 'Sophie'
MAP 'EMPLOYEE_NAMES' COPY 'IE_NAMES', COPY 'SG_NAMES', COPY 'US_NAMES'
GROUP 'EMPLOYEE_NAMES'
The equivalent configuration and generated GLASS Studio code in GLASS Studio Visual Builder mode is:
MAP NOCASE 'IE_NAMES' 'Cara', 'Grainne', 'Shannon'
MAP NOCASE 'SG_NAMES' 'Charlotte', 'Evelyn', 'Layla', 'Sarah'
MAP NOCASE 'US_NAMES' 'Ava', 'Gabrielle', 'Ruby', 'Sophie'
MAP 'NS_1673427388991' COPY 'IE_NAMES', COPY 'SG_NAMES', COPY 'US_NAMES'
GROUP 'NS_1673427388991'
To add a MAP namespace in GLASS Studio Visual Builder Mode:
Add a unique and descriptive label in the Map Name field to identify the MAP namespace.
Add keys to the MAP namespace.
Manual Entry
Key in a literal (enclosed in single ''
or double quotes ""
), integer,
or integer range into the MAP entries field below and press
the Enter key to add the key(s).
File Upload
Upload a set of keys by clicking on + Add from file and selecting a
text or CSV file. Each MAP entry must be
defined on a new line.
'AU'
'IE'
123
2221-2720
See Defining a MAP Namespace for more information.
To view a list of all MAP namespaces that have been added to the GLASS Studio data type project, click on the Map icon in the GLASS Studio playground to open the MAPS dialog.
All available MAP namespaces are displayed with the following details:
You can modify the label, add new keys, and/or remove existing keys when you edit a MAP namespace.
To edit a MAP namespace:
To remove a MAP namespace: