对不起,但对我来说很困难: 我有一些基本频率的代码用于某些文本,它代表“most_common”模式下的输出。但它用文字表示。Python的NLTK字词频率在分区
def sym(senten):
stopwords = nltk.corpus.stopwords.words("english")
V = [",", ".", "'", "(", ")", '"', "'", ":", "it", "may", "I", "the", "but", "two", "this", "since", "for", "whether", "and", "?", "if", "even", "Mr.", "also", "at", "p."]
content = [w for w in senten if w not in stopwords and w not in V]
fd = nltk.FreqDist(content)
fdc = fd.most_common(75)
return fdc
为了进一步分析,我需要频率代码,它代表我在sents(句子)中的输出。所以,输出必须向我显示按位置排列的单词频率选择的sents。
我有一些想法用“制表”来实现它。有一个代码(例如):
S= ["proposition", "modus", "logic", "2"] #The most frequent words(for example)
cfd = nltk.ConditionalFreqDist(
(senten, S)
for senten in senten
for S in senten)
print cfd.tabulate(conditions = senten,
samples=S)
它的作品,但也有大约不常用的单词的句子太多毫无意义的数据。
我会感谢您的想法,这可以解决我的问题。
你的意思是* sents *,*句子*! –
原因!我很抱歉。 – mannheim
你可以请示例输入句子和样品输出吗? –