檢測文本(特別是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請參閱更新! –