User's Reference - Lookup

### Lookup

Category

Transformation

Function

Syntax

    output = Lookup(input, table, data, lookup, value, destination, ignore, notFound);

Inputs

Name | Type | Default | Description
--- | --- | --- | ---
`input` | field, string list, value, value list | (none) | object to lookup
`table` | field, string, value list | (dataname lookup) | lookup table
`data` | string | "data" | component of `input` to lookup
`lookup` | string | "positions" | component of `table` in which to look
`value` | string | "data" | component in `table` containing lookup results
`destination` | string | "lookedup" | component of `input` in which to put result
`ignore` | string list | (no default) | Properties to ignore in string lookup
`notFound` | value or string | (zero or empty string) | What to return for data values that were not found.

Outputs

Name | Type | Description
--- | --- | ---
`output` | field or array | field or array with looked-up values

Functional Details

`input` | field containing the component to use as lookup
`table` | field containing the lookup table components
`data` | component in input to use for looking up
`lookup` | component in table that the data component is to match
`value` | component in table to use as the looked up result
`destination` | component of input in which to put the looked up results
`ignore` | properties to ignore in string lookup. Can be one of "case", "space", "lspace", "rspace", "lrspace", "punctuation". "case" means to ignore the case of the characters, "space" means to ignore all white space (spaces, tabs, ...), "lspace" means to ignore white space on the left side of the string, "rspace" means to ignore white space on the right side of the string, "lrspace" means to ignore white space on both the left and right sides (but not internal white space), and "punctuation" means to ignore all punctuation characters (anything other than alphabetic and numeric characters and white space). `ignore` can be a list of strings; for example, a commonly used combination is {"space", "case", "punctuation"}.
`notFound` | value to return when a given lookup value is not found. By default, Lookup returns 0 or "" for any item that is not found in the lookup table. This can be confounding, e.g., when returning "positions" to obtain indices: one cannot distinguish between not found and found in the 0-th position. Specifying notFound provides a means to disambiguate in these cases.

Lookup uses one component to find another by "looking up" the corresponding value in a lookup table. Lookup serves to convert a categorized component back to its original form, or more generally to provide arbitrary associations of unrelated object types. The lookup can occur entirely within the input field when it contains all components necessary to do the lookup, or alternatively the lookup table can be provided as a separate field in `table`.

If `table` is an array, Lookup treats it as if it has an implicit "positions" component with values from 0 to n-1, where n is the number of items in the array. Thus if the `data` component is integer, and `lookup` is an array of strings, `data` can be used to lookup a matching value in the implicit positions component and return the string. Alternatively, if `data` were also a string array, Lookup could lookup a matching value in the `table` array and return the corresponding implicit position.

Note: The lookup is done using a binary search of the lookup component. If this component is not already sorted, it will be internally sorted in order to perform the lookup. Connections are not used by this module. Since Data Explorer does not support string positions, if lookup is done using a string data type the table input must have a separate float positions component. If the lookup component has duplicate values, the value corresponding to the first one found will be used.

Components

Adds a new component as specified by the `destination` parameter containing the looked-up values.

Example Visual Programs

    Duplicates.net

See Also

Categorize, Map, CategoryStatistics

[ OpenDX Home at IBM | OpenDX.org ]