hdx.location.adminone

[view_source]

AdminOne Objects

class AdminOne()

[view_source]

AdminOne class which takes in pcodes and then maps names to those pcodes with fuzzy matching if necessary. The input configuration dictionary, admin_config, requires key admin1_info which is a list with values of the form: :: {"iso3": "AFG", "pcode": "AF01", "name": "Kabul"}

Various other keys are optional: countries_fuzzy_try are countries (iso3 codes) for which to try fuzzy matching. Default is all countries. admin1_name_mappings is a dictionary of mappings from name to pcode (for where fuzzy matching fails) admin1_name_replacements is a dictionary of textual replacements to try when fuzzy matching admin1_fuzzy_dont is a list of names for which fuzzy matching should not be tried

Arguments:

  • admin_config Dict - Configuration dictionary

init_matches_errors

def init_matches_errors() -> None

[view_source]

Initialise storage of fuzzy matches, ignored and errors for logging purposes

Returns:

None

convert_pcode_length

def convert_pcode_length(countryiso3: str, pcode: str, scrapername: Optional[str] = None) -> Optional[str]

[view_source]

Standardise pcode length by country and match to an internal pcode

Arguments:

  • countryiso3 str - Iso3 country code
  • pcode str - P code for admin one
  • scrapername Optional[str] - Name of scraper for logging purposes. Defaults to None (don't log).

Returns:

  • Optional[str] - Matched P code or None if no match

fuzzy_pcode

def fuzzy_pcode(countryiso3: str, name: str, scrapername: Optional[str] = None) -> Optional[str]

[view_source]

Fuzzy match name to pcode

Arguments:

  • countryiso3 str - Iso3 country code
  • name str - Name to match
  • scrapername Optional[str] - Name of scraper for logging purposes. Defaults to None (don't log).

Returns:

  • Optional[str] - Matched P code or None if no match

get_pcode

def get_pcode(countryiso3: str, name: str, scrapername: Optional[str] = None) -> Tuple[Optional[str], bool]

[view_source]

Get pcode for a given name

Arguments:

  • countryiso3 str - Iso3 country code
  • name str - Name to match
  • scrapername Optional[str] - Name of scraper for logging purposes. Defaults to None (don't log).

Returns:

Tuple[Optional[str], bool]: (Matched P code or None if no match, True if exact match or False if not)

output_matches

def output_matches() -> List[str]

[view_source]

Output log of matches

Returns:

  • List[str] - List of matches

output_ignored

def output_ignored() -> List[str]

[view_source]

Output log of ignored

Returns:

  • List[str] - List of ignored

output_errors

def output_errors() -> List[str]

[view_source]

Output log of errors

Returns:

  • List[str] - List of errors