import json


def get_countries_metadata(fname="countries-readable.json"):
    """Read a database file containing information about different countries.

    Specifically, we are interested in the capital and population of each country, because
    we will use this information to disambiguate records, by giving more weight to certain
    features.
    Source: https://github.com/lorey/list-of-countries/blob/master/json/countries-readable.json
    """
    details = {}
    with open(fname) as f:
        countries = json.load(f)
    for country in countries:
        details[country['name'].lower()] = (country['capital'].lower(), int(country['population']))

    # We replace "South Korea" by "Korea" since "Korea" is a shorthand form many people use.  I'm going to make a
    # political statement and say that unfortunately North Korea is not relevant to github for the time being.
    details['korea'] = details['south korea']
    del details['south korea']
    return details