当前位置:   article > 正文

python语法错误修改_Python-65 自然语言处理NLP初探:用nltk实现对错误语句的修改 2020-09-14...

[nltk_data] downloading package punkt to /root/nltk_data...

用nltk实现对错误语句的修改,经常可以用于输入错误,修订等。因此有很多用处。

具体代码与解释如下:

#pip install nltk

import nltk

#nltk.download('punkt')

#nltk.download('stop')

#nltk.download('stopwords')

#> [nltk_data] Downloading package punkt to /root/nltk_data...

#> [nltk_data] Unzipping tokenizers/punkt.zip.

#> [nltk_data] Error loading stop: Package 'stop' not found in index

#> [nltk_data] Downloading package stopwords to /root/nltk_data...

#> [nltk_data] Unzipping corpora/stopwords.zip.

#> True

# Import and load model

text="He is a gret person. He beleives in bod"

# Import textblob

#pip install textblob

from textblob import TextBlob

# Using textblob's correct() function

text=TextBlob(text)

print("Original text:",text)

print('\n')

print("Revised text:",text.correct())

原始语句为:text="He is a gret person. He beleives in bod"

运行后得到的语句为:Revised text: He is a great person. He believes in god

最终运行得到的结果为:

2bf3fe47567e

image.png

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/377558
推荐阅读
相关标签
  

闽ICP备14008679号