检测文本(特别是Instagram评论)是否为非英文的最准确方法是什么?我很高兴地使用任何高级语言,比如Python,PHP等检测文本是否为非英文
$ sudo pip2 install guess_language
>>> from guess_language import guessLanguage
>>> guessLanguage('la vita e bella')
'UNKNOWN'
>>> guessLanguage('today is a good day')
'UNKNOWN'
>>> guessLanguage('ボウリング・フォー・コロンバイン(字幕版)')
'ja'
与
$ sudo apt-get install php5.6-mbstring
if(strlen($comment->text) == mb_strlen($comment->text, 'utf-8')) {
echo '- '.$comment->text."\n";
}
我与英文字符很多事情都没有英语: 例子:
- Khoda be khanevadehashon sabr bede tahamol konan
- Akhey...
- Eshghi
- K
- :-)
- Ey khodaa
- ...
- @samaneaghazamani1990 vaaaaay khoda chejoori payam dadan?
- :(
- Elahiiiii
- May Allah please with them and grant higher rank of jannah salutes to the bravehearts @taraneh_alidoosti @fanpagemostafazamani
- Elaaaahiii
- Roohetoon shad.
- :'(
- Roheshon shad!! Yadeshon gerami!!
- .:'(
- :-(
- Oooo
- Awli
我不想使用Google Translate之类的东西,因为我正在处理大量数据。
更新:
$ sudo pip2 install langdetect
>>> from langdetect import detect
>>> detect("War doesn't show who's right, just who's left.")
'en'
>>> detect("today is a good day.")
'so'
>>> detect("la vita e bella!")
'it'
>>> detect("khoobi? khoshi?")
'so'
>>> detect("wow")
'pl'
>>> detect("what a day")
'en'
>>> detect("yay!")
'so'
是 '所以' 指代不明?我期待today is a good day
被认为是en
!
卦通常就够了,即使是相当短的文本。 – pvg
请参阅:https://pypi.python.org/pypi/langdetect/1.0.1 –
@JuanT请参阅更新! –