示例#1
0
 def save_dict(self):
   knownwords_root = self.buildXmlSubtree(E.knownwords, E.syllables, self.__known_words)
   unknownwords_root = self.buildXmlSubtree(E.unknownwords, E.count, self.__unknown_words)
   ignoredwords_root = self.buildXmlSubtree(E.ignoredwords, E.count, self.__ignored_words) 
   
   with open(self.__custom_dictionary_file, "w") as f:
     f.write(
       etree.tostring(E.customdictionary(knownwords_root,unknownwords_root,ignoredwords_root), 
       pretty_print=True))
     
   logging.info("Saved customdictionary to file")
示例#2
0
  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")