【发布时间】:2018-11-21 08:20:15
【问题描述】:
我正在在线学习使用 python 进行文本清理。 我已经去掉了一些停用词并降低了字母。
但是当我执行这段代码时,它什么也不显示。
我不知道为什么。
# we add some words to the stop word list
texts, article = [], []
for w in doc:
# if it's not a stop word or punctuation mark, add it to our article!
if w.text != '\n' and not w.is_stop and not w.is_punct and not w.like_num and w.text != 'I':
# we add the lematized version of the word
article.append(w.lemma_)
# if it's a new line, it means we're onto our next document
if w.text == '\n':
texts.append(article)
article = []
当我尝试输出文本时,它只是空白。
【问题讨论】:
-
什么是文档?它是如何定义和初始化的?
-
Doc 是纯 txt 文件
-
如何打开文件并从中读取?你能展示那部分吗?此外,最好在 for 循环的开头放置一个
print(w)以查看 w 是否有任何值 -
text = open("BioTest.txt").read()
-
我尝试打印 w,它有价值
标签: python text nlp topic-modeling