更具体地说,我正在尝试检查给定的字符串(一个句子)是否为土耳其语。
我可以检查字符串是否包含土耳其语字符,例如 Ç、Ş、Ü、Ö、Ğ 等。但是这不是很可靠,因为在我收到字符串之前这些字符可能会被转换为 C、S、U、O、G .
另一种方法是使用土耳其语中最常用的 100 个单词,然后检查句子中是否包含这些单词中的任何/部分。我可以结合这两种方法并使用积分系统。
你认为用 Python 解决我的问题最有效的方法是什么?
相关问题:(human) Language of a document (Perl,谷歌翻译 API)
最佳答案
一种选择是使用贝叶斯分类器,例如 Reverend . Reverend 主页为朴素的语言检测器提供了以下建议:
from reverend.thomas import Bayes
guesser = Bayes()
guesser.train('french', 'le la les du un une je il elle de en')
guesser.train('german', 'der die das ein eine')
guesser.train('spanish', 'el uno una las de la en')
guesser.train('english', 'the it she he they them are were to')
guesser.guess('they went to el cantina')
guesser.guess('they were flying planes')
guesser.train('english', 'the rain in spain falls mainly on the plain')
guesser.save('my_guesser.bay')
关于python - 返回给定字符串语言的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/383966/