我有一个python词典,用于NLTK情感分析。扩展词典以包含词频
注意:输入的是纯文本电子邮件内容。
def word_feats(words):
stopset = list(set(stopwords.words('english')))
words_split = words.split()
result = dict([(word, True) for word in words_split if word not in stopset])
return result
我想扩展它以包括字典中的单词频率以及独特的单词。
这是我目前得到:
'To' (4666843744) = {bool} True
'ensure' (4636385096) = {bool} True
'email' (4636383752) = {bool} True
'updates' (4636381960) = {bool} True
'delivered' (4667509936) = {bool} True
'inbox,' (4659135800) = {bool} True
'please' (4659137368) = {bool} True
'add' (4659135016) = {bool} True
我想类似下面的地方在年底的数字是频率。它不必完全像这样,但我希望能够访问每个单词的频率。
'To' (4666843744) = {bool} True, 100
'ensure' (4636385096) = {bool} True, 3
'email' (4636383752) = {bool} True, 40
'updates' (4636381960) = {bool} True, 3
'delivered' (4667509936) = {bool} True, 4
'inbox,' (4659135800) = {bool} True, 20
'please' (4659137368) = {bool} True, 150
'add' (4659135016) = {bool} True, 10
请提供您的'input'和所需'output' –
@KaushikNP谢谢你帮我提高我的问题。 –