我正在开发一个应用程序,它要求我从会话流中提取关键字(并最终生成这些单词的标记云)。我正在考虑以下步骤:
标记每个原始会话(输出存储为strings)
到目前为止,nltk提供了所有的工具,我need.After这一点,但我需要在某种程度上“排序”这些词,并提出最重要的词。有人能建议我从nltk那里用什么工具来做这个吗?
谢谢尼希特
发布于 2011-06-08 11:16:50
我想这取决于你对“重要”的定义。如果你谈论的是频率,那么你就可以用单词(或词干)作为键来构建一个字典,然后将其算作值。之后,您可以根据它们的计数对字典中的键进行排序。
类似于(未测试):
from collections import defaultdict
#Collect word statistics
counts = defaultdict(int)
for sent in stemmed_sentences:
for stem in sent:
counts[stem] += 1
#This block deletes all words with count <3
#They are not relevant and sorting will be way faster
pairs = [(x,y) for x,y in counts.items() if y >= 3]
#Sort (stem,count) pairs based on count
sorted_stems = sorted(pairs, key = lambda x: x[1])https://stackoverflow.com/questions/6277350
复制相似问题