【发布时间】:2020-12-04 08:38:31
【问题描述】:
我是 Python 和编码的新手,所以请多多包涵。
我在我的 IDE 中安装了 TextBlob 插件,它在检测字符串语言时就像一个魅力。请参阅下面的代码和底部的输出。
我需要做的是让它检测文本文件的语言,而不仅仅是我输入的字符串。所以基本上我需要用任何语言的文本文件替换文本行,并添加代码来打开/读取文件并让 TextBlob 做它的事情。
有什么想法吗?
from textblob import TextBlob
text1 = TextBlob('I looked for Mary and Samantha at the bus station')
a = text1.detect_language()
print(a)
text2 = TextBlob('Appliquer un nom , une dénomination , un mot , une phrase à une personne , à une chose')
b = text2.detect_language()
print(b)
text3 = TextBlob('Escribe un ejemplo para mostrar el significado de la palabra de vocabulario.')
c = text3.detect_language()
print(c)
>>> %Run 'NLP TextBlob.py'
en
fr
es
>>>
【问题讨论】:
标签: python text-files textblob language-detection