client.address_cleanse
Cleanse Address
Returns the closest matching address for a freeform address input, with Match Level indicators describing how closely each element of the suggested address matches the input. The more impaired the input address, the harder it is to cleanse.
A cleanse that returns a match costs a lookup. A no-match response is free.
Countries
Cleanse defaults to the UK. Pass context with an ISO 3166-1 alpha-3 country code to cleanse an address elsewhere, e.g. context=USA or context=FRA. The address datasets your key is licensed for decide which countries it can cleanse.
The response shape is the same for every country: a standardised address in match, the raw source record in match.native and the same confidence, fit and Match Level indicators. The Match Levels and confidence score are at their most discriminating for the UK, where cleanse runs against purpose-built indexes; elsewhere they are computed from the country's address dataset.
Confidence Score
Each incorrect, missing or misspelled element subtracts from the overall confidence score.
Deciding on an Acceptable Confidence Score Threshold
Inputs differ widely between address cleanse projects. Within a project, though, they tend to repeat the same errors. Some datasets are keyed in by hand and prone to typos. Others have a persistently missing datapoint such as organisation name or postcode. There is no absolute Confidence Score threshold. Set the acceptable score project by project, based on the systematic errors in the data and your business goals.
To set a threshold, load a subset of the dataset into a spreadsheet application like Excel and sort on the score. Scrolling from top to bottom shows matches from best to worst. As you reach the lower quality searches you can judge roughly:
- Which confidence scores indicate ambiguous matches (i.e. up to building level only)
- Which confidence scores indicate a poor or no match (i.e. the nearest matching address is too far from the input address)
Depending on your business goals, you can also use the Match Levels to determine an acceptable match. You may need to match only up to the thoroughfare or building name, or accurate organisation names may matter.
Endpoint
POST /cleanse/addresses
See the API reference for this endpoint.
Signature
def address_cleanse(
query:,
tags: nil,
remove_organisation: nil,
context: nil,
postcode: nil,
post_town: nil,
county: nil
)
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
keywords | keyword arguments | yes | One per query parameter and body field, named as the API names them. A keyword left out or nil is not sent. |
Query Parameters
Pass these as keyword arguments.
| Name | Type | Required | Description |
|---|---|---|---|
tags | String, Array<String> | no | Tags |
remove_organisation | String | no | Remove Organisation |
context | String | no | Identify the country of the address to cleanse. Defaults to UK (GBR) |
Request Body
Pass these as keyword arguments too; the SDK sends them as the JSON body.
| Name | Type | Required | Description |
|---|---|---|---|
query | String | yes | Freeform address input to cleanse |
postcode | String | no | Optionally specify the postal code for the address. |
post_town | String | no | Optionally specify the city or town of the address. |
county | String | no | Optionally specify the county of the address. |
Response
IdealPostcodes::Responses::CleanseResponse. Read fields with readers named as the API names them, such as response.result, or with response["result"]. to_h returns the decoded body.
Errors
An HTTP error raises IdealPostcodes::ApiError with the HTTP status, the API error code and the decoded body. A transport failure raises IdealPostcodes::TransportError. See error handling.
Example
require "ideal_postcodes"
client = IdealPostcodes::Client.new(api_key: "ak_test")
response = client.address_cleanse(query: "9 Malyons Rd, Swanley, BR8", postcode: "BR8 7RE")
result = response.result
if result.is_a?(IdealPostcodes::Types::GbrCleanseMatch)
puts "#{result.match.line_1}, #{result.match.postcode}"
puts "Confidence: #{result.confidence}"
puts "Postcode match: #{result.postcode_match}"
else
puts "No match for #{result.query}"
end