# TODO
# Address normalization:
# Using geopy.geocoders Nominatim to submit the address as we know it to
# openstreetmap to return an address and geoip coordinates.
# The results are 'best guess' so we keep the lines of the address we have that
# we trust (postcode, first line, equiv to road) and use the region fields from
# osm.
# The problem we have is that we don't know which line has the postcode.
# https://github.com/datamade/usaddress can be trained using training data:
# https://github.com/datamade/usaddress/blob/master/training/labeled.xml
# or just apply a regex:
# (GIR|([A-Z-[QVX][0-9][0-9]?)|(([A-Z-[QVX][A-Z-[IJZ][0-9][0-9]?)|
# (([A-Z-[QVX][0-9][A-HJKSTUW])|([A-Z-[QVX][A-Z-[IJZ][0-9][ABEHMNPRVWXY]))))i
# (?=( )?[0-9][A-Z-[CIKMOV]{2})
# Validated with: http://api.postcodes.io/postcodes/LL19 9AP which returns json
'''
{
    "result": {
        "admin_county": null,
        "admin_district": "Denbighshire",
        "admin_ward": "Prestatyn East",
        "ccg": "Betsi Cadwaladr University",
        "codes": {
            "admin_county": "W99999999",
            "admin_district": "W06000004",
            "admin_ward": "W05000165",
            "ccg": "W11000023",
            "nuts": "UKL13",
            "parish": "W04000171"
        },
        "country": "Wales",
        "eastings": 306611,
        "european_electoral_region": "Wales",
        "incode": "9AP",
        "latitude": 53.3345259244436,
        "longitude": -3.40389852694343,
        "lsoa": "Denbighshire 002D",
        "msoa": "Denbighshire 002",
        "nhs_ha": "Betsi Cadwaladr University Health Board",
        "northings": 382876,
        "nuts": "Conwy and Denbighshire",
        "outcode": "LL19",
        "parish": "Prestatyn",
        "parliamentary_constituency": "Vale of Clwyd",
        "postcode": "LL19 9AP",
        "primary_care_trust": "Betsi Cadwaladr University",
        "quality": 1,
        "region": null
    },
    "status": 200
}
'''
# https://github.com/datamade/parserator/blob/master/README.md to parse the
# dirty addresses.
#
# NB. You should either limit the number of requests to no more than 1 per
# second or run a docker container with your own nominatim server using data
# from http://download.geofabrik.de/europe-latest.osm.pbf (16GB)

# See ../test/osm_rest-test.py
