【发布时间】:2019-09-22 11:38:51
【问题描述】:
处理 NLP 上的问题并陷入下面给出的 TASK。
以下是需要按顺序执行的语句。
我已完成以下步骤,但壁画平台不接受解决方案。
请让我知道我在以下代码和步骤中做错了什么
任务
1.导入文本语料棕色
-
提取与属于 新闻类型。将结果存储在变量 news_words 中。
-
将列表 news_words 中的每个单词转换为小写,并存储 结果是 lc_news_words。
-
计算列表 lc_news_words 的二元组,并将其存储在变量中 lc_news_bigrams。
-
从 lc_news_bigrams,过滤两个单词都只包含的二元组 字母字符。将结果存储在 lc_news_alpha_bigrams 中。
-
提取与语料库停用词相关的单词列表。存储 结果是 stop_words。
-
将列表 stop_words 中的每个单词转换为小写,并存储 结果是 lc_stop_words。
-
仅过滤来自 lc_news_alpha_bigrams 中的单词所在的二元组 不属于 lc_stop_words。将结果存储在 lc_news_alpha_nonstop_bigrams。
-
打印过滤的二元组总数。
下面是我到目前为止所做的代码。但是fresco平台不接受输出。
import nltk
import nltk.corpus
from nltk.corpus import brown
from nltk.util import bigrams
from nltk.corpus import stopwords
news_words = brown.words(categories='news')
lc_news_words = [w.lower() for w in news_words]
lc_news_bigrams = list(nltk.bigrams(lc_news_words))
lc_news_alpha_bigrams = [(word1, word2) for word1, word2 in lc_news_bigrams if (word1.isalpha() and word2.isalpha()) ]
stop_words = stopwords.words('english')
lc_stop_words = [w.lower() for w in stop_words ]
lc_news_alpha_nonstop_bigrams = [ (w1, w2) for w1, w2 in lc_news_alpha_bigrams if (w1.lower() not in lc_stop_words and w2.lower() not in lc_stop_words) ]
len((lc_news_alpha_nonstop_bigrams))
【问题讨论】:
标签: nlp nltk python-3.7