Home > Backend Development > Python Tutorial > Python中文分词实现方法(安装pymmseg)

Python中文分词实现方法(安装pymmseg)

WBOY
Release: 2016-06-16 08:47:52
Original
1182 people have browsed it

本文实例讲述了Python中文分词实现方法。分享给大家供大家参考,具体如下:

在Python这pymmseg-cpp 还是十分方便的!

环境 ubuntu10.04 , python2.65

步骤:

1 下载mmseg-cpp的源代码 http://code.google.com/p/pymmseg-cpp/

2 执行:

tar -zxf pymmseg-cpp*.tar.gz //解压后得到pymmseg 目录
cd pymmseg\mmseg-cpp
python build.py   #生成 mmseg.so文件

Copy after login

3 将 pymmseg 目录复制到 /usr/local/lib/python2.6/dist-packages 中

4 测试有没有成功:

test.py文件:

from pymmseg import mmseg
mmseg.dict_load_defaults()
text = '今天的天气真好啊,我们一起出去玩一下吧'
algor = mmseg.Algorithm(text)
for tok in algor:
  print '%s [%d..%d]' % (tok.text, tok.start, tok.end)

Copy after login

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python图片操作技巧总结》、《Python数据结构与算法教程》、《Python Socket编程技巧总结》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》

希望本文所述对大家Python程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template