def _load_lexicons()

in expanded_checklist/checklist/editor.py [0:0]


    def _load_lexicons(self, language):
        cur_folder = os.path.dirname(__file__)
        folder = os.path.abspath(os.path.join(cur_folder, "data", 'lexicons'))
        for f in os.listdir(folder):
            self.lexicons.update(json.load(open(os.path.join(folder, f))))
        self.data['names'] = json.load(open(os.path.join(cur_folder, 'data', 'names.json')))
        self.data['names'] = {x:set(self.data['names'][x]) for x in self.data['names']}
        make_munch = lambda x: munch.Munch(x) if type(x) == dict else x
        for x in self.lexicons:
            self.lexicons[x] = [make_munch(x) for x in self.lexicons[x]]

        language = get_language_code(language)
        wikidata = pickle.load(open(os.path.join(cur_folder, 'data', 'wikidata.pkl'), 'rb'))
        get_ln = lambda d: d.get(language, d.get('en'))
        self.lexicons['male'] = get_ln(wikidata.mnames)
        self.lexicons['female'] = get_ln(wikidata.fnames)
        self.lexicons['first_name'] = [y for x in zip(self.lexicons['male'], self.lexicons['female']) for y in x]
        self.lexicons['last_name'] = get_ln(wikidata.lnames)
        self.lexicons['country'] =  [get_ln(x.label) for x in wikidata.countries]
        # united states by default
        self.lexicons['city'] =  [get_ln(x.label) for x in wikidata.countries[2].cities]
        # Most populous country that has language as official language
        for country in wikidata.countries:
            if country.primary_lang == language:
                self.lexicons['city'] = [get_ln(x.label) for x in country.cities]
                break
        self.lexicons['country_city'] = munch.Munch()
        for country in wikidata.countries:
            l = country.label.en.replace(' ', '_')
            self.lexicons['country_city'][l] = [get_ln(x.label) for x in country.cities]
        self.lexicons['male_from'] = wikidata.male_by_country
        self.lexicons['female_from'] = wikidata.female_by_country
        self.lexicons['last_from'] = wikidata.last_by_country