【问题标题】:Text Cleaning Issues文本清理问题
【发布时间】: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


【解决方案1】:

我相信“文本”列表和“文章”列表引用相同的内容,因此,清除一个列表的内容也会清除另一个列表。

这是一个类似问题的链接:Python: Append a list to another list and Clear the first list

请看上面有没有用。

【讨论】:

    猜你喜欢
    • 2021-03-15
    • 2013-01-07
    • 1970-01-01
    • 2023-04-07
    • 2011-06-07
    • 2013-02-15
    • 2013-10-21
    • 1970-01-01
    相关资源
    最近更新 更多