def save_dict(self): if self.__no_dictionary_update: logger.info("no dictionary update flag set, not saving dictionary") return knownwords_root = E.knownwords(E.entries( *[E.entry(E.word(word), E.syllables(str(syllables))) \ for (word, syllables) in self.__known_words.items()] )) unknownwords_root = E.unknownwords(E.entries( *[E.entry(E.word(word), E.count(str(count))) \ for (word, count) in self.__unknown_words.items()] )) ignoredwords_root = E.ignoredwords(E.entries( *[E.entry(E.word(word), E.count(str(count))) \ for (word, count) in self.__ignored_words.items()] )) try: open(self.__custom_dictionary_file, "w").write(etree.tostring(E.customdictionary( \ knownwords_root,unknownwords_root,ignoredwords_root), pretty_print=True)) except IOError as e: logger.critical("Failed to save customdictionary to file: " + str(e)) logger.info("Successfully saved customdictionary to file")
def buildXmlSubtree(self, root, countOrSyllables, wordList): entries = [E.entry(E.word(word), countOrSyllables(str(count))) for (word, count) in wordList.items()] return root(E.entries(*entries))