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


Python FreqDist.iterkeys方法代码示例

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


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

示例1: len

# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import iterkeys [as 别名]
        freq_dists[(team['name'], team['year'])] = fdist
        for (word, count) in fdist.iteritems():
            if word not in freq_dist_background:
                freq_dist_background[word] = count
            else:
                freq_dist_background[word] += count
            freq_dist_background_sum += count
    except KeyError:
        pass
    print >> sys.stderr, "\r%d / %d" % (i, len(data)),
    i += 1

for team in data:
    try:
        fdist = freq_dists[(team['name'], team['year'])]
        for w in fdist.iterkeys():
            fdist[w] = (fdist[w] / float(fdist.N())) / (freq_dist_background[w] / float(freq_dist_background_sum))
        words = fdist.keys()
        words.sort(lambda x,y: cmp(fdist[x], fdist[y]))
        team['topwords'] = {word : fdist[word] for word in words[0:options.numberwords]}
    except KeyError:
        pass

print >> sys.stderr, "\n",

if options.outfile == '-':
    outfile = sys.stdout
else:
    outfile = open(options.outfile, 'w')
outfile.write(json.dumps(data, indent=4, ensure_ascii=False, encoding="utf-8").encode("utf-8"))
outfile.close()
开发者ID:igemsoftware,项目名称:Heidelberg_2013,代码行数:33,代码来源:postprocessing.py


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