我是Python和编码的新手,所以请耐心听我说
我将TextBlob插件安装到我的IDE中,当检测字符串的语言时,它就像一个符咒。请参阅下面底部的代码和输出
我需要做的是让它检测文本文件的语言,而不仅仅是我输入的字符串。所以本质上我需要用任何语言的文本文件替换文本行,并添加代码来打开/读取文件,让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
>>>
如果将来有人质疑这一点,我会想办法解决的。最后非常简单,并提供了与以前相同的输出,但我的字符串位于文本文件中,而不是打印出来的
相关问题 更多 >
编程相关推荐