当前位置: 首页>>代码示例>>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;未经允许,请勿转载。