|
| 1 | +package addressparser |
| 2 | + |
| 3 | +import "errors" |
| 4 | + |
| 5 | +var ErrAddressUnparsable = errors.New("address is unparsable") |
| 6 | + |
| 7 | +// Address is a struct for an address |
| 8 | +type Address struct { |
| 9 | + // venue name e.g. "Brooklyn Academy of Music", and building names e.g. "Empire State Building" |
| 10 | + House string `json:"house,omitempty"` |
| 11 | + // for category queries like "restaurants", etc. |
| 12 | + Category string `json:"category,omitempty"` |
| 13 | + // phrases like "in", "near", etc. used after a category phrase to help with parsing queries like "restaurants in Brooklyn" |
| 14 | + Near string `json:"near,omitempty"` |
| 15 | + // usually refers to the external (street-facing) building number. In some countries this may be a compount, hyphenated number which also includes an apartment number, or a block number (a la Japan), but libpostal will just call it the house_number for simplicity. |
| 16 | + HouseNumber string `json:"house_number,omitempty"` |
| 17 | + // street name(s) |
| 18 | + Road string `json:"road,omitempty"` |
| 19 | + // an apartment, unit, office, lot, or other secondary unit designator |
| 20 | + Unit string `json:"unit,omitempty"` |
| 21 | + // expressions indicating a floor number e.g. "3rd Floor", "Ground Floor", etc. |
| 22 | + Level string `json:"level,omitempty"` |
| 23 | + // numbered/lettered staircase |
| 24 | + Staircase string `json:"staircase,omitempty"` |
| 25 | + // numbered/lettered entrance |
| 26 | + Entrance string `json:"entrance,omitempty"` |
| 27 | + // post office box: typically found in non-physical (mail-only) addresses |
| 28 | + PoBox string `json:"po_box,omitempty"` |
| 29 | + // postal codes used for mail sorting |
| 30 | + Postcode string `json:"postcode,omitempty"` |
| 31 | + // usually an unofficial neighborhood name like "Harlem", "South Bronx", or "Crown Heights" |
| 32 | + Suburb string `json:"suburb,omitempty"` |
| 33 | + // these are usually boroughs or districts within a city that serve some official purpose e.g. "Brooklyn" or "Hackney" or "Bratislava IV" |
| 34 | + CityDistrict string `json:"city_district,omitempty"` |
| 35 | + // any human settlement including cities, towns, villages, hamlets, localities, etc. |
| 36 | + City string `json:"city,omitempty"` |
| 37 | + // named islands e.g. "Maui" |
| 38 | + Island string `json:"island,omitempty"` |
| 39 | + // usually a second-level administrative division or county. |
| 40 | + StateDistrict string `json:"state_district,omitempty"` |
| 41 | + // a first-level administrative division. Scotland, Northern Ireland, Wales, and England in the UK are mapped to "state" as well (convention used in OSM, GeoPlanet, etc.) |
| 42 | + State string `json:"state,omitempty"` |
| 43 | + // informal subdivision of a country without any political status |
| 44 | + CountryRegion string `json:"country_region,omitempty"` |
| 45 | + // sovereign nations and their dependent territories, anything with an ISO-3166 code. |
| 46 | + Country string `json:"country,omitempty"` |
| 47 | + // currently only used for appending “West Indies” after the country name, a pattern frequently used in the English-speaking Caribbean e.g. “Jamaica, West Indies” |
| 48 | + WorldRegion string `json:"world_region,omitempty"` |
| 49 | +} |
| 50 | + |
| 51 | +// AddressParserInput is a struct for the input to the address parser |
| 52 | +type AddressParserInput struct { |
| 53 | + // the address to parse |
| 54 | + Address string `json:"address" validate:"required"` |
| 55 | + // the language of the address. Leave empty if you don't know |
| 56 | + Language string `json:"language,omitempty"` |
| 57 | + // the country of the address. Leave empty if you don't know |
| 58 | + Country string `json:"country,omitempty"` |
| 59 | + // if true then the responses will be title Cased. Default behavior of libpostal is not to do that. |
| 60 | + TitleCase bool `json:"title_case,omitempty"` |
| 61 | +} |
| 62 | + |
| 63 | +// AddressParser is an interface for the address parser |
| 64 | +type AddressParser interface { |
| 65 | + Parse(input AddressParserInput) (Address, error) |
| 66 | +} |
0 commit comments