Keep answers inside one country
Use this guide when every address your application handles is in one countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head., and you want an ambiguous place nametoponymA proper name for a geographic place. to resolve there.
By default mailwoman geocode treats the countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head. of its localelocaleThe combination of language and country an address comes from. en-US and fr-FR are the locales Mailwoman ships weights for. as a preference that evidence in the address can overrule. With the default localelocaleThe combination of language and country an address comes from. en-US and fr-FR are the locales Mailwoman ships weights for. en-US, 12 Oak St, Paris answers Paris, France, because that Paris is the larger place of the name. A configured countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head. keeps the answer in the United States.
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
1. See the default
Run the address with zero flags and zero config file:
mailwoman geocode "12 Oak St, Paris" --json
The answer is the admin point of Paris, France:
"lat": 48.858705,
"lon": 2.342865,
"resolution_tier": "admin",
"locality": "Paris",
The localelocaleThe combination of language and country an address comes from. en-US and fr-FR are the locales Mailwoman ships weights for.'s countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head. stops applying in two cases. The first is a localitylocalityThe city / town / settlement component of an address: a populated place sitting between region and neighborhood in the hierarchy. whose largest namesake is in another countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head.. The second is an address that finds zero place inside the localelocaleThe combination of language and country an address comes from. en-US and fr-FR are the locales Mailwoman ships weights for.'s countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head.. 1001 Boulevard Saint-Laurent, Montréal answers Montréal, Canada, for the first reason.
2. State the country in a config file
Save this as mailwoman.config.json in the directory you run the command from:
{
"geocode": {
"defaultCountry": "US"
}
}
Run the same command again:
mailwoman geocode "12 Oak St, Paris" --json
The answer is now Paris, Texas:
"lat": 33.659317,
"lon": -95.561576,
"resolution_tier": "admin",
"locality": "Paris",
A stated countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head. is a filter that never yields. With this file, 1001 Boulevard Saint-Laurent, Montréal answers Montreal, Wisconsin, at 46.433871, -90.232951. Use it only when zero address you handle lies outside the countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head..
The command reads one mailwoman.config.* file from the working directory, in JSON, YAML, TOML, or a JavaScript or TypeScript module with a default export. --config <path> reads a file from another place. A typed flag overrules the file, and the file overrules the built-in default.
3. Choose between the two settings
Two settings keep answers inside one countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head..
| Choice | Config file | Flag | CountrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head. it uses |
|---|---|---|---|
| A stated countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head. | "defaultCountry": "US" | --default-country US | The one you state |
| The localelocaleThe combination of language and country an address comes from. en-US and fr-FR are the locales Mailwoman ships weights for.'s countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head., always | "countryScope": "locale" | --country-scope locale | The regionregionThe first-level administrative subdivision of a country — a US state, a French region, a province. The component between country and locality. of --locale, such as US for en-US |
Both gave the same two answers above. State the countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head. when your localelocaleThe combination of language and country an address comes from. en-US and fr-FR are the locales Mailwoman ships weights for. and your countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head. differ, such as an en-GB weightsparameterA single learned number inside a model — one weight or bias. Mailwoman's encoder has roughly 30 million of them; training is the search for good values. package over Irish addresses.
"countryScope": "none" removes the localelocaleThe combination of language and country an address comes from. en-US and fr-FR are the locales Mailwoman ships weights for.'s countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head. from the decision. A bare postcodepostcodeThe country-specific postcode (US ZIP, French code postal, etc.). Mailwoman handles postcode parsing entirely by rule classifier — a regex problem, not an ML one. such as 90210 then has zero countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head. to prefer among the countries that hold it.
4. Check which setting applied
The debug view prints one row for the localelocaleThe combination of language and country an address comes from. en-US and fr-FR are the locales Mailwoman ships weights for. and the countrycountryThe top-level address component (an ISO country). Closed-vocabulary, so it is best handled by a deterministic matcher feeding a proposal rather than a retrained model head. that reached the resolverresolverThe component that converts parsed address components (locality, region, postcode) into coordinates by looking them up in the gazetteer. The resolver ranks candidates by name match, population, and proximity, and returns the best-matching place with its centroid or polygon., with the source of each:
mailwoman geocode "12 Oak St, Paris" --debug
With the config file above, the row reports a US scope from the caller:
applied locale en-US (default) scope US hard (caller)
With zero config, it reports that the inferred scope was withheld and gives the reason:
applied locale en-US (default) scope none withheld US (larger_namesake_abroad)