我如何知道纯文本文件是用哪种语言编写的? [英] How do I tell what language is a plain-text file written in?

查看:107
本文介绍了我如何知道纯文本文件是用哪种语言编写的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个包含以下内容的文本文件: "Je suis un beau homme ..."

Suppose we have a text file with the content: "Je suis un beau homme ..."

另一个: 我是个勇敢的人"

another with: "I am a brave man"

第三个带有德语文本的内容: "Gutenmorgen.Wiegeht的?"

the third with a text in German: "Guten morgen. Wie geht's ?"

我们如何编写一个函数来告诉我们:以这样的概率第一个文本 文件是英语,第二个是法语等?

How do we write a function that would tell us: with such a probability the text in the first file is in English, in the second we have French etc?

欢迎链接到书籍/开箱即用的解决方案.我用Java编写,但是如果需要,我可以学习Python.

Links to books / out-of-the-box solutions are welcome. I write in Java, but I can learn Python if needed.

我的评论

  1. 我需要添加一条小评论.文本可能包含不同语言的短语,这些短语可能是整体的一部分,也可能是由于错误而导致的.在经典文学中,我们有很多例子,因为贵族成员会说多种语言.因此,这种可能性更好地描述了这种情况,因为文本的大部分使用一种语言,而其他部分则可能用另一种语言编写.
  2. Google API-Internet连接.我宁愿不使用远程功能/服务,因为我需要自己做或使用可下载的库.我想对该主题进行研究.

推荐答案

有一个名为 JLangDetect的程序包似乎完全符合您的要求:

There is a package called JLangDetect which seems to do exactly what you want:

langof("un texte en français") = fr : OK
langof("a text in english") = en : OK
langof("un texto en español") = es : OK
langof("un texte un peu plus long en français") = fr : OK
langof("a text a little longer in english") = en : OK
langof("a little longer text in english") = en : OK
langof("un texto un poco mas largo en español") = es : OK
langof("J'aime les bisounours !") = fr : OK
langof("Bienvenue à Montmartre !") = fr : OK
langof("Welcome to London !") = en : OK
// ...


正如Kevin指出的那样,该软件包提供的 Nutch项目中有类似的功能. org.apache.nutch.analysis.lang .


as Kevin pointed out, there is similar functionality in the Nutch project provided by the package org.apache.nutch.analysis.lang.

这篇关于我如何知道纯文本文件是用哪种语言编写的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆