第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用文本搭配計算 ngram 詞頻

使用文本搭配計算 ngram 詞頻

翻翻過去那場雪 2021-10-26 16:32:59
我想計算已轉(zhuǎn)換為標記的文本文件中特定單詞前后三個單詞的頻率。from nltk.tokenize import sent_tokenizefrom nltk.tokenize import word_tokenizefrom nltk.util import ngramswith open('dracula.txt', 'r', encoding="ISO-8859-1") as textfile:    text_data = textfile.read().replace('\n', ' ').lower()tokens = nltk.word_tokenize(text_data)text = nltk.Text(tokens)grams = nltk.ngrams(tokens, 4)freq = Counter(grams)freq.most_common(20)我不知道如何搜索字符串 'dracula' 作為過濾詞。我也試過:text.collocations(num=100)text.concordance('dracula')所需的輸出看起來像這樣的計數(shù):“dracula”之前的三個詞,排序計數(shù)(('and', 'he', 'saw', 'dracula'), 4),(('one', 'cannot', 'see', 'dracula'), 2)'dracula' 后面的三個詞,排序計數(shù)(('dracula', 'and', 'he', 'saw'), 4),(('dracula', 'one', 'cannot', 'see'), 2)中間包含 'dracula' 的三元組,排序計數(shù)(('count', 'dracula', 'saw'), 4),(('count', 'dracula', 'cannot'), 2)預先感謝您的任何幫助。
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 203 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號