對不起,但對我來說很困難: 我有一些基本頻率的代碼用於某些文本,它代表「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
你可以請示例輸入句子和樣品輸出嗎? –