【问题标题】:Spelling correction with Textblob for whole text file使用 Textblob 对整个文本文件进行拼写更正
【发布时间】:2016-05-02 12:03:44
【问题描述】:

我一直在尝试在整个文件上使用 Textblob 的正确功能,并具有以下代码。

import codecs
import os

f = codecs.open("Source", "r", encoding="utf-8")
lines = f.readlines()

from textblob import TextBlob

tweet1 = TextBlob(lines[0])
tweet2 = TextBlob(lines[-1])


print(tweet1.correct())
print(tweet2.correct())

但我不知道如何使它更正文件的每一行?

感谢您的帮助, 哈尔

【问题讨论】:

    标签: python codec textblob


    【解决方案1】:
    for line in lines:
        # TextBlob is providing correct method
        print(TextBlob(line).correct())
    

    如果您不熟悉循环,则需要先回到基础知识。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-03
      • 2018-06-25
      • 1970-01-01
      相关资源
      最近更新 更多