Python smallseg分词用法实例分析
2015-05-28 12:14
861 查看
#encoding=utf-8 #import psyco #psyco.full() words = [x.rstrip() for x in open("main.dic",mode='r',encoding='utf-8') ] from smallseg import SEG seg = SEG() print('Load dict...') seg.set(words) print("Dict is OK.") def cuttest(text): wlist = seg.cut(text) wlist.reverse() tmp = " ".join(wlist) print(tmp) print("================================") if __name__=="__main__": cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。") cuttest("我不喜欢日本和服。") cuttest("雷猴回归人间。") cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作") cuttest("我需要廉租房") cuttest("永和服装饰品有限公司") cuttest("我爱北京天安门") cuttest("abc") cuttest("隐马尔可夫") cuttest("雷猴是个好网站") cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成") cuttest("草泥马和欺实马是今年的流行词汇") cuttest("伊藤洋华堂总府店") cuttest("中国科学院计算技术研究所") cuttest("罗密欧与朱丽叶") cuttest("我购买了道具和服装")
smallseg分词,在python3.3上运行稍微有些问题。py代码xrange在3.*中已经改名字为range了。另外,3.*中也没有decode函数了。
修改了上面的两个地方,代码就可移植性了。效果还可以。
希望本文所述对大家的Python程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- python动态参数用法实例分析
- python中的对象,方法,类,实例,函数用法分析
- python中sys.argv参数用法实例分析
- Python多进程multiprocessing用法实例分析
- Python中random模块用法实例分析
- Python中random模块用法实例分析
- Python守护进程用法实例分析
- Python中threading模块join函数用法实例分析
- python抽象基类用法实例分析
- python协程用法实例分析
- python下MySQLdb用法实例分析
- Python面向对象之继承和组合用法实例分析
- Python实现程序的单一实例用法分析
- python中enumerate函数用法实例分析
- Python数据分析中Groupby用法之通过字典或Series进行分组的实例
- Python实现的基数排序算法原理与用法实例分析
- python中lambda与def用法对比实例分析
- python中assert用法实例分析
- python生成器generator用法实例分析