用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
最终运行得到的结果为:
var cpro_id = "u6885494";