V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
yucongo
V2EX  ›  Python

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

  •  
  •   yucongo · 2017-06-17 13:42:05 +08:00 · 2898 次点击
    这是一个创建于 2497 天前的主题,其中的信息可能已经有所发展或是发生改变。

    语言检测,如'你好啊...'=>'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。

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

    6 条回复    2017-06-19 14:07:34 +08:00
    0asis
        1
    0asis  
       2017-06-17 13:46:27 +08:00 via iPhone
    分词还是分句?
    yucongo
        2
    yucongo  
    OP
       2017-06-17 13:52:42 +08:00
    @0asis 分句
    natforum
        3
    natforum  
       2017-06-17 16:11:42 +08:00
    结巴分词不好用吗
    Jackeriss
        4
    Jackeriss  
       2017-06-17 19:02:58 +08:00
    yucongo
        5
    yucongo  
    OP
       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
        6
    holajamc  
       2017-06-19 14:07:34 +08:00
    检测文本语言可以使用 NGram 来做,我在毕设中用到过,效果还是不错的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5260 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 05:43 · PVG 13:43 · LAX 22:43 · JFK 01:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.