def load_sysnonym(self, synonym_file, encoding='utf-8'): u""" Load a synonym file. Receive as parameters a name (with relative or full path) of a synonym file, and their encoding. Default encoding is utf-8. Synonym file must have at least one element. Contains a list of lists. The patterns are loaded in ``_synonyms`` """ try: plain_text = codecs.open(synonym_file, 'rb', encoding).read() data = yaml.load(plain_text) except IOError: raise exceptions.FileNotFound(synonym_file) for synonyms in data: if len(synonyms) < 2: raise exceptions.InvalidTagValue( u'Synonym list must have more than one element.') key = remove_accents(synonyms[0]).lower() vals = [remove_accents(value).lower() for value in synonyms[1:]] if key in self._synonyms: raise exceptions.DuplicatedSynonym(key, synonym_file) self._synonyms[key] = vals
def load_meaning(self, meaning_file, encoding='utf-8'): u""" Load a meaning file. Receive as parameters a name (with relative or full path) of a meaning file, and their encoding. Default encoding is utf-8. Meaning file must have at least one element. Contains a list of lists. The patterns are loaded in ``_meanings`` """ try: plain_text = codecs.open(meaning_file, 'rb', encoding).read() data = yaml.load(plain_text) except IOError: raise exceptions.FileNotFound(meaning_file) for meanings, values in data.items(): if len(values) == 0: raise exceptions.InvalidTagValue( u'Meaning list must have one or more element.') key = remove_accents(meanings).lower() vals = [normalize_input(v, self._environ['synonyms']).lower() for v in values] if key in self._meanings: raise exceptions.DuplicatedMeaning(key, meaning_file) self._meanings[key] = vals