Python脚本查找给定文档的词频 [英] Python script to find word frequencies of a given document

查看:123
本文介绍了Python脚本查找给定文档的词频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个简单的脚本,该脚本可以查找给定文档的单词出现频率(可能使用便携式词干提取器).

I am looking for a simple script that can find frequencies of words for a given document (probably by using portable stemmer).

是否执行此过程的任何库或简单脚本?

Is there any library or simple script that does this process?

推荐答案

使用 nltk

import nltk

YOUR_STRING = "Your words"

words = [w for w in YOUR_STRING.split()]
freq_dist = nltk.FreqDist(words)

tokens = freq_dist.keys()

#50 most frequent
most_frequent = tokens[:50]

#50 least frequent
least_frequent = tokens[-50:]

这篇关于Python脚本查找给定文档的词频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆