當前位置: 首頁>>代碼示例>>Python>>正文


Python Dictionary.add_word方法代碼示例

本文整理匯總了Python中Dictionary.Dictionary.add_word方法的典型用法代碼示例。如果您正苦於以下問題:Python Dictionary.add_word方法的具體用法?Python Dictionary.add_word怎麽用?Python Dictionary.add_word使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Dictionary.Dictionary的用法示例。


在下文中一共展示了Dictionary.add_word方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_dictionary

# 需要導入模塊: from Dictionary import Dictionary [as 別名]
# 或者: from Dictionary.Dictionary import add_word [as 別名]
 def get_dictionary( ):
     """ Build a Dictionary based on the Diceware data. """
     
     dicto = Dictionary()
     
     print 'Parsing Diceware data...'
     i = 0;
     nLines = 7780
     
     # open file for reading
     with open(Diceware.fname, 'r') as fid:    
         for line in fid:
             tokens = Diceware.parse_line(line)
             if tokens is None:
                 continue
             
             # save data to list
             word = Word(tokens['word'], -1, -1, i);
             dicto.add_word(word)
             
             # increment counter and show progress
             i = i + 1;
             progress = float(i) / float(nLines)
             if (progress % 0.05) < 1e-4:
                 sys.stdout.write("\r%2.2f%%" %(progress*100))
                 sys.stdout.flush()
                 
     print '\nDone.'
     
     return dicto
開發者ID:watsonboyett,項目名稱:Sandbox,代碼行數:32,代碼來源:Diceware.py

示例2: preproc

# 需要導入模塊: from Dictionary import Dictionary [as 別名]
# 或者: from Dictionary.Dictionary import add_word [as 別名]
    def preproc(self):
        """ normalize the data (clean/remove problematic characters) for processing """

        print 'Pre-processing dictionary...'
        
        # remove words that contain non-alphanumeric characters
        dicto_new = Dictionary()
        alpha = re.compile('[\W]')
        num = re.compile('[0-9]')
        for word in self.dicto.get_words_iter():
            word_str = word.string
            
            # remove numbers from words
            word_str = num.sub('', word_str)
            if len(word_str) <= 0:
                continue
            
            if not alpha.search(word_str):
                word.set_string(word_str)
                dicto_new.add_word(word)
                
        print 'Done.'
        
        self.dicto = dicto_new
開發者ID:watsonboyett,項目名稱:Sandbox,代碼行數:26,代碼來源:DictoMiner.py


注:本文中的Dictionary.Dictionary.add_word方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。