Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python脚本,用于查找给定文档的词频_Python_Information Retrieval - Fatal编程技术网

Python脚本,用于查找给定文档的词频

Python脚本,用于查找给定文档的词频,python,information-retrieval,Python,Information Retrieval,我正在寻找一个简单的脚本,可以找到一个给定文档的单词频率(可能通过使用便携式词干分析器) 是否有任何库或简单脚本执行此过程?使用 你应该会数词。根据需要使用集合计数器或dict。这一部分很容易,但如果不是,你可以通过搜索自己来找到答案 我想您还需要Porter词干分析器,它在google上有一个Python版本,用于nltk词干分析。或搜索堆栈溢出:。如果您遇到问题,请在此处发布问题。collections.Counter(re.findall(r'\w+',document)中的i.lower

我正在寻找一个简单的脚本,可以找到一个给定文档的单词频率(可能通过使用便携式词干分析器)

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

使用


你应该会数词。根据需要使用
集合计数器
dict
。这一部分很容易,但如果不是,你可以通过搜索自己来找到答案


我想您还需要Porter词干分析器,它在google上有一个Python版本,用于nltk词干分析。或搜索堆栈溢出:。如果您遇到问题,请在此处发布问题。
collections.Counter(re.findall(r'\w+',document)中的i.lower()表示i)
Dup@JBernardo:您的解决方案将“counting”和“counted”作为两个独立的单词计算。使用词干分析器的库会将它们一起计算。同一词干分析器的较新版本在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:]