Cocomi - ION Orchard
services
General Services
Location: To parse the mall location/address, we'll use regular expressions to identify patterns for level, unit, and tower information. The logic prioritizes explicit mentions and then infers information where appropriate, strictly adhering to the specified output format rules.
Here's the breakdown of the extraction and formatting logic:
1. **Initialize variables**: `level_val`, `unit_val`, `tower_val` to `None`.
2. **Extract Tower**: Look for "Tower" followed by a number or letter (e.g., "Tower 3", "Tower A").
3. **Extract Explicit Level**: Look for "Level" followed by a level number (e.g., "Level 2", "Level B1").
4. **Extract Unit Number**:
* First, try to find unit numbers prefixed with "#" or "Unit #" (e.g., "#02-42", "Unit #B1-47A").
* If no unit is found yet, and no explicit level was found, then look for standalone patterns like "B3-06/07" which imply both a level and a unit. If such a pattern is found, extract it as the unit and also infer the level from its prefix (e.g., "B3" from "B3-06/07").
5. **Construct Output**: Based on the presence of `level_val`, `unit_val`, and `tower_val`, build the output string following the user's specific formatting rules.
Let's apply this to the given address: "2 Orchard Turn, B3-06/07, Singapore 238801"
- **Tower**: No "Tower" information is found. (`tower_val = None`)
- **Explicit Level**: No "Level X" is explicitly mentioned. (`level_val = None`)
- **Unit Number**:
* Searching for `(?:Unit\s*)?#([BL]?\d+-\d+[A-Z]?(?:/\d+[A-Z]?)?)` (e.g., "#02-42"): No match.
* Since `unit_val` is `None` and `level_val` is `None`, we look for a standalone unit-like pattern `\b([BL]?\d+-\d+[A-Z]?(?:/\d+[A-Z]?)?)\b`. This matches "B3-06/07".
* `unit_val` is set to "B3-06/07".
* From "B3-06/07", we infer the level part "B3". So, `level_val` is set to "B3".
- **Constructing the output**:
* `level_val` ("B3") is present.
* `unit_val` ("B3-06/07") is present.
* `tower_val` is `None`.
* Following the rule "If you have level and unit: 'Level X, Unit Number #XX-XX'", the output will be "Level B3, Unit Number #B3-06/07".
Level B3, Unit Number #B3-06/07