Exercise · beginner · 15 min
Map channels with an approved dictionary
Support tickets name the same channel a dozen ways. Map them with the approved dictionary only, and quarantine anything the dictionary doesn't cover instead of guessing.
The rules
These rules decide what a correct result is. Your answer is checked on this dataset and on hidden datasets that follow the same rules.
Input
tickets(id, channel) — text. id is unique. channel may be missing.
Rules
channel: remove ASCII whitespace (space, tab, CR, LF) at both ends, then lowercase; an empty result is missing.
Map channel with this approved dictionary (left → right) and nothing else:
email → email e-mail → email
phone → phone telephone → phone
chat → chat web chat → chat webchat → chat
Quarantine to exceptions with reason:
missing_channel channel is missing
unmapped_channel channel is present but not in the dictionary (never guess a mapping)
Outputs (row order does not matter)
clean(id text, channel text)
exceptions(id text, reason text)The data
tickets · 13 rows, first 12 shown
| id | channel |
|---|---|
| tx6ld | empty |
| t1bmf | Phone· |
| t6s3m | TELEPHONE |
| t7f5e | |
| tsvpj | Web Chat |
| ta4en | e mail |
| tacyt | WebChat· |
| t95p3 | ·· |
| t9ulv | chat |
| t9k3m | e-mail· |
| tzj97 | missing |
| t22bj | TELEPHONE |
What you practise
- mappings
- controlled vocabulary
- quarantine
- trimming
Your answer is also checked on hidden datasets generated from the same rules.
Sign in to bookmark this and keep private notes.