Route intersection descriptions for review
Use this guide when a location-intake workflow receives a possible streetstreetThe named linear feature along which house numbers are ordered. Decomposes into a name plus street affixes; one of the Tier 2 fine labels. intersectionintersectionAn address that names a location by two crossing streets ('5th & Main') rather than a number and street. Mailwoman tags the two streets as intersection_a and intersection_b — a negative-space format that starved the early model. and needs the two streetstreetThe named linear feature along which house numbers are ordered. Decomposes into a name plus street affixes; one of the Tier 2 fine labels. descriptions before a person checks the location. The parser identifies text spansspanA contiguous range of characters or tokens in the input string, tagged with an address component type (street, locality, postcode, etc.). Parsed addresses are represented as collections of spans, possibly nested in a tree.. This example routes the description for review and leaves the crossing coordinate unknown.
Prerequisites
^24.22.3 || >=26.13.1"type": "module" in its package.jsonStart by installing the required packages:
- npm
- Yarn
- pnpm
- Bun
npm install mailwoman
yarn add mailwoman
pnpm add mailwoman
bun add mailwoman
This exercise parsesaddress parsingThe process of decomposing a free-text postal address string into structured components — house number, street name, locality, region, postcode, and country — so a geocoder can resolve them to coordinates. text and reads no geographic database. Save the following file as route-intersection.ts.
Check the two street components
import { createParser, decodeAsJSON, flattenTreeNodes } from "mailwoman"
await using parser = await createParser()
for (const input of ["5th Avenue and Main Street, Springfield, IL", "5th and Main"]) {
const result = await parser.parse(input)
const { intersection_a: first, intersection_b: second } = decodeAsJSON(result.tree)
const route = result.faults.length
? "review-stage-fault"
: first && second
? "crossing-description-review"
: result.kind.kind === "intersection"
? "request-clarification"
: "other-address-flow"
const alternatives = result.kind.alternatives.map((alternative) => alternative.kind).join(", ")
console.log(`${input}\nkind: ${result.kind.kind} (alternatives: ${alternatives || "none"}), route: ${route}`)
console.table(flattenTreeNodes(result.tree), ["tag", "value", "start", "end"])
}
This application rule requires both intersection_a and intersection_b nodes and an empty faults list. It records the query kindquery kindThe coarse category the kind classifier assigns to the whole input — postcode_only, locality_only, structured_address, intersection, po_box, landmark, or vague — used to route processing. and alternatives for diagnosis. When the top kind is intersection and the tree lacks either crossing-streetstreetThe named linear feature along which house numbers are ordered. Decomposes into a name plus street affixes; one of the Tier 2 fine labels. component, it asks for clarification. The rule decides the route from the component tree and leaves the coordinate unknown.
Run node route-intersection.ts. The script prints the complete output below:
5th Avenue and Main Street, Springfield, IL
kind: structured_address (alternatives: intersection, vague), route: crossing-description-review
┌─────────┬──────────────────┬───────────────┬───────┬─────┐
│ (index) │ tag │ value │ start │ end │
├─────────┼──────────────────┼───────────────┼───────┼─────┤
│ 0 │ 'intersection_a' │ '5th Avenue' │ 0 │ 10 │
│ 1 │ 'intersection_b' │ 'Main Street' │ 15 │ 26 │
│ 2 │ 'locality' │ 'Springfield' │ 28 │ 39 │
│ 3 │ 'region' │ 'IL' │ 41 │ 43 │
└─────────┴──────────────────┴───────────────┴───────┴─────┘
5th and Main
kind: intersection (alternatives: landmark, structured_address, vague), route: request-clarification
┌─────────┬─────────┬────────────────┬───────┬─────┐
│ (index) │ tag │ value │ start │ end │
├─────────┼─────────┼────────────────┼───────┼─────┤
│ 0 │ 'venue' │ '5th and Main' │ 0 │ 12 │
└─────────┴─────────┴────────────────┴───────┴─────┘
For 5th Avenue and Main Street, Springfield, IL, the returned kind is structured_address, and the tree contains intersection_a: "5th Avenue" and intersection_b: "Main Street". The application sends those two strings for crossing-description review. For 5th and Main, the returned kind is intersection, and the tree contains only venue: "5th and Main". The application asks for clarification.
The script ran no geographic lookup, so the crossing coordinate stays unknown for both results. A localitylocalityThe city / town / settlement component of an address: a populated place sitting between region and neighborhood in the hierarchy. and a pair of streetstreetThe named linear feature along which house numbers are ordered. Decomposes into a name plus street affixes; one of the Tier 2 fine labels. names describe a crossing. A verified crossing point needs a supported geographic source, a tested lookup for the exact input, and evidence that the point represents the crossing. Check the data prerequisites, result schema, and the confidence and limits explanation before adding that workflow.