python - 返回给定字符串语言的最佳方法

标签 python algorithm string

更具体地说,我正在尝试检查给定的字符串(一个句子)是否为土耳其语。

我可以检查字符串是否包含土耳其语字符,例如 Ç、Ş、Ü、Ö、Ğ 等。但是这不是很可靠,因为在我收到字符串之前这些字符可能会被转换为 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')

使用更复杂的标记集进行训练会加强结果。有关贝叶斯分类的更多信息,see herehere .

关于python - 返回给定字符串语言的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/383966/

相关文章:

python - pyqtgraph 轴显示不正确

python - 如何在Python动画函数中返回未知数量的对象

javascript - 在javascript ES6中寻找更高效的排序算法

c - 在函数中修改字符串 (char*) 后,除非在函数内部打印,否则该值不会显示

c - 从 C 中的字符串中删除所有 '\'

python - 如果 key 在 dict 中具有假值,则获取默认值

python - 使用 Python 'export' 运行 'subprocess' 命令不起作用

python - 递归二叉搜索树插入

用于确定最大值峰值的 R 代码

c - 如何在c中垂直打印一个字符串?