当前位置: 首页>>代码示例>>Python>>正文


Python Dictionary.docFreq[wordId]方法代码示例

本文整理汇总了Python中gensim.corpora.dictionary.Dictionary.docFreq[wordId]方法的典型用法代码示例。如果您正苦于以下问题:Python Dictionary.docFreq[wordId]方法的具体用法?Python Dictionary.docFreq[wordId]怎么用?Python Dictionary.docFreq[wordId]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gensim.corpora.dictionary.Dictionary的用法示例。


在下文中一共展示了Dictionary.docFreq[wordId]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: loadDictionary

# 需要导入模块: from gensim.corpora.dictionary import Dictionary [as 别名]
# 或者: from gensim.corpora.dictionary.Dictionary import docFreq[wordId] [as 别名]
 def loadDictionary(fname, mapping_only = True):
     """
     Load previously stored mapping between words and their ids.
     
     The result can be used as the `id2word` parameter for input to transformations.
     """
     if mapping_only:
         result = {}
         for lineNo, line in enumerate(open(fname)):
             cols = line[:-1].split('\t')
             if len(cols) == 2:
                 wordId, word = cols
             elif len(cols) == 3:
                 wordId, word, docFreq = cols
             else:
                 raise ValueError("invalid line in dictionary file %s: %s" % (fname, line.strip()))
             result[int(wordId)] = word # docFreq not used
     else:
         result = Dictionary()
         for lineNo, line in enumerate(open(fname)):
             cols = line[:-1].split('\t')
             if len(cols) == 3:
                 wordId, word, docFreq = cols
             else:
                 raise ValueError("invalid line in dictionary file %s: %s" % (fname, line.strip()))
             wordId = int(wordId)
             result.token2id[word] = wordId
             result.docFreq[wordId] = int(docFreq)
         
     return result
开发者ID:beibeiyang,项目名称:Latent-Dirichlet-Allocation,代码行数:32,代码来源:wikicorpus.py


注:本文中的gensim.corpora.dictionary.Dictionary.docFreq[wordId]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。