(离线)检测文本语言什么包好用?中文及非中文分句用什么 Python 包?

2017-06-17 13:42:05 +08:00
 yucongo

语言检测,如'你好啊...'=>'zh', 'good morning'=>'en', 'guten tag'=> 'de' 'bonsoir'=>'fr' 我只知道 langid 和 langdetect,都不是太好用,初始时间太长,短一点的中文会被检测为韩文或日文等等。

中文分句,正则再稍微处理一下大致可以用。另外,smallseg 好像也可以用,smallseg 的字典数据文件 几个 M,好像有点大。

非中文分句,nltk 里的 tokenizer 可处理各种语言(其实是用 nltk 里的 pickle 文件),可惜用了 nltk 的 Python 程序生成 exe 包时麻烦多多,因为 nltk 的 data 目录结构不在 python lib 下。另外 github 上有个 segtok 项目,好像还可以用,但性能不如 nltk。

各位高人语言检测、文本分句都用什么包?请各位分享一下,先感谢……

2905 次点击
所在节点    Python
6 条回复
0asis
2017-06-17 13:46:27 +08:00
分词还是分句?
yucongo
2017-06-17 13:52:42 +08:00
@0asis 分句
natforum
2017-06-17 16:11:42 +08:00
结巴分词不好用吗
Jackeriss
2017-06-17 19:02:58 +08:00
yucongo
2017-06-18 10:19:03 +08:00
@Jackeriss 感谢。

不过 snownlp 的分句逗号处也分了。

zh = snownlp.SnowNLP('非中文分句,nltk 里的 tokenizer 可处理各种语言(其实是用 nltk 里的 pickle 文件),可惜用了 nltk 的 Python 程序生成 exe 包时麻烦多多,因为 nltk 的 data 目录结构不在 python lib 下。另外 github 上有个 segtok 项目,好像还可以用,但性能不如 nltk。')
zh.sentences
['非中文分句',
'nltk 里的 tokenizer 可处理各种语言(其实是用 nltk 里的 pickle 文件)',
'可惜用了 nltk 的 Python 程序生成 exe 包时麻烦多多',
'因为 nltk 的 data 目录结构不在 python lib 下',
'另外 github 上有个 segtok 项目',
'好像还可以用',
'但性能不如 nltk']

而且标点符号也没了。估计是简单用 re.split 做的。

snwonlp 想做成中文版 textblob, 可惜在分句上没做足功夫。

textblob 的分句:
blob = textblob.TextBlob('The rider sits on and operates these vehicles like a motorcycle, but the extra wheels give more stability at slower speeds. Although equipped with three or four wheels, six-wheel models exist for specialized applications. Engine sizes of ATVs currently for sale in the United States, (as of 2008 products), range from 49 to 1,000 cc (3 to 61 cu in).')
blob.sentences
[Sentence("The rider sits on and operates these vehicles like a motorcycle, but the extra wheels give more stability at slower speeds."),
Sentence("Although equipped with three or four wheels, six-wheel models exist for specialized applications."),
Sentence("Engine sizes of ATVs currently for sale in the United States, (as of 2008 products), range from 49 to 1,000 cc (3 to 61 cu in).")]
holajamc
2017-06-19 14:07:34 +08:00
检测文本语言可以使用 NGram 来做,我在毕设中用到过,效果还是不错的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/369095

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX