环境:win7、VS2008、Python2.7.3

第一步:照着文档[2]将NLPIR库封装成Python的扩展;

第二步:新建一个名为“nlpir_demo”的目录,将第一步最后得到的名为“nlpirpy_ext”的文件夹拷贝到“.../nlpir_demo/”目录下;

第三步:在文档[2]尾部提供的“seg.py”基础上,在“.../nlpir_demo/nlpirpy_ext/”目录下,新建一个名为“C_NLPIR_ICTCLAS2013.py”的文件,内容如下,目的是将NLPIR进一步封装成一个Python类;

 #-*- encoding: utf-8 -*-
import NLPIR
import os class C_NLPIR_ICTCLAS2013:
def __init__(self,s_code='GBK'):
dataurl = os.path.join(os.path.dirname(__file__))
isinit = 0
if s_code == 'GBK':
isinit = NLPIR.NLPIR_Init(dataurl,NLPIR.GBK_CODE)
elif s_code == 'UTF-8':
isinit = NLPIR.NLPIR_Init(dataurl,NLPIR.UTF8_CODE)
elif s_code == 'BIG5':
isinit = NLPIR.NLPIR_Init(dataurl,NLPIR.BIG5_CODE)
elif s_code == 'GBK_FANTI':
isinit = NLPIR.NLPIR_Init(dataurl,NLPIR.GBK_FANTI_CODE)
if isinit:
print 'NLPIR 初始化成功'
else:
print 'NLPIR 初始化失败' def stringSeg(self, s_string, i_bPOStagged=0):
"""
Function: Process one string;
Parameters: @s_string - The string to be analyed,
@i_bPOStagged: Judge whether need POS tagging, 0 for no tag; 1 for tagging; default:0.
Return Value: the pointer of result buffer.
"""
return NLPIR.NLPIR_ParagraphProcess(s_string, i_bPOStagged) def fileSeg(self,s_sourceFile,s_targetFile, i_bPOStagged=0):
"""
Function: Process one text file and save the result into one file;
Parameters: @s_sourceFile - The source file name to be analysized,
@s_targetFile - The result file name to store the results.
@i_bPOStagged: Judge whether need POS tagging, 0 for no tag; 1 for tagging; default:0.
Return Value: the processing speed if processing succeed. Otherwise return false.
"""
return NLPIR.NLPIR_FileProcess(s_sourceFile, s_targetFile, i_bPOStagged) def importUserDict(self,s_userDictFile):
"""
Functin: Import user-defined dictionary from a text file;
Parameters: @s_userDictFile - the filename saved user dictionary text;
Return Value: The number of lexical entry imported successfully
???: What's the writting style of the userDicFile ?
"""
return NLPIR.NLPIR_ImportUserDict(s_userDictFile) def addUserWord(self,s_word):
'''
Function: Add a word to the user dictionary;
Parameters: @s_Word - the word added.
Return Value: 1 if add succeed. Otherwise return 0.
'''
return NLPIR.NLPIR_AddUserWord(s_word) def saveTheUserDict(self):
'''
Function: Save the user dictionary to disk.
Parameters: none;
Return Value: 1 if save succeed,otherwise return 0.
???: Where's the file_direction of "disk" ?
'''
return NLPIR.NLPIR_SaveTheUsrDic() def delUserWord(self,s_word):
'''
Function: Delete a word from the user dictionary;
Parameters: @s_word - the word to be deleted;
Return Value: -1 if the word not exist in the user dictionary, otherwise the handle of the word deleted.
'''
return NLPIR.NLPIR_DelUsrWord(s_word) def exit(self):
'''
Return value: true if succeed, otherwise false.
'''
return NLPIR.NLPIR_Exit() if __name__ == '__main__': O_C_NLPIR_ICTCLAS2013 = C_NLPIR_ICTCLAS2013('UTF-8')
raw_input('\n~!')

第四步:在“.../nlpir_demo/”目录下,新建一个名为“NLPIR_demo.py”的文件,内容如下,试着调用“.../nlpir_demo/nlpirpy_ext/C_NLPIR_ICTCLAS2013.py”中定义的类C_NLPIR_ICTCLAS2013;

 #-*-encoding:utf-8-*-
from nlpirpy_ext.C_NLPIR_ICTCLAS2013 import C_NLPIR_ICTCLAS2013 if __name__ == '__main__': o_C_NLPIR_ICTCLAS2013 = C_NLPIR_ICTCLAS2013('UTF-8')
raw_input('\n~!') s_test = '1989年春夏之交的政治风波1989年政治风波24小时降雪量24小时降雨量863计划ABC防护训练APEC会议BB机BP机C2系统C3I系统C3系统C4ISR系统C4I系统CCITT建议'
result = o_C_NLPIR_ICTCLAS2013.stringSeg(s_test) raw_input(result)

第五步:执行文件“.../nlpir_demo/NLPIR_demo.py”,即可~!

说明:关于文档[2]中提到的SWIG,可见文档[1]提供了另外两篇文档~!

参考文档:

[1]Python、Ruby中的SWIG使用案例, http://www.cnblogs.com/chanyin/p/3340780.html

[2]NLPIR(ICTCLAS2013) Python版, http://www.nilday.com/nlpirictclas2013-python%E7%89%88/

python调用NLPIR - ICTCLAS2013实现中文分词的更多相关文章

  1. Python环境下NIPIR(ICTCLAS2014)中文分词系统使用攻略

    一.安装 官方链接:http://pynlpir.readthedocs.org/en/latest/installation.html 官方网页中介绍了几种安装方法,大家根据个人需要,自行参考!我采 ...

  2. python第三方库------jieba库(中文分词)

    jieba“结巴”中文分词:做最好的 Python 中文分词组件 github:https://github.com/fxsjy/jieba 特点支持三种分词模式: 精确模式,试图将句子最精确地切开, ...

  3. Python第三方库jieba(中文分词)入门与进阶(官方文档)

    jieba "结巴"中文分词:做最好的 Python 中文分词组件 github:https://github.com/fxsjy/jieba 特点 支持三种分词模式: 精确模式, ...

  4. Python学习实践------正向最大匹配中文分词

    正向最大匹配分词: 1.加载词典文件到集合中,取词典文件中最大长度词的length 2.每次先在句子中按最大长度分割,然后判断分割的词是否存在字典中,存在则记录此词,调整起始点. 3.不存在则按最大长 ...

  5. Python大数据:jieba 中文分词,词频统计

    # -*- coding: UTF-8 -*- import sys import numpy as np import pandas as pd import jieba import jieba. ...

  6. NLPIR(北理工张华平版中文分词系统)的SDK(C++)调用方法

    一.本文内容简介 二.具体内容 1. 中文分词的基本概念 2.关于NLPIR(北理工张华平版中文分词系统)的基本情况 3.具体SDK模块(C++)的组装方式 ①准备内容: ②开始组装 三.注意事项 一 ...

  7. 中文分词工具简介与安装教程(jieba、nlpir、hanlp、pkuseg、foolnltk、snownlp、thulac)

    2.1 jieba 2.1.1 jieba简介 Jieba中文含义结巴,jieba库是目前做的最好的python分词组件.首先它的安装十分便捷,只需要使用pip安装:其次,它不需要另外下载其它的数据包 ...

  8. 中文分词工具探析(一):ICTCLAS (NLPIR)

    1. 前言 ICTCLAS是张华平在2000年推出的中文分词系统,于2009年更名为NLPIR.ICTCLAS是中文分词界元老级工具了,作者开放出了free版本的源代码(1.0整理版本在此). 作者在 ...

  9. Sphinx中文分词安装配置及API调用

    这几天项目中需要重新做一个关于商品的全文搜索功能,于是想到了用Sphinx,因为需要中文分词,所以选择了Sphinx for chinese,当然你也可以选择coreseek,建议这两个中选择一个,暂 ...

随机推荐

  1. TensorFlow 在android上的Demo(1)

    转载时请注明出处: 修雨轩陈 系统环境说明: ------------------------------------ 操作系统 : ubunt 14.03 _ x86_64 操作系统 内存: 8GB ...

  2. Redis入门学习笔记一

    Redis 简要描述: 1.  Redis 是啥 ? Redis 英文名称全称为: Remote Dictionary Server ,中译为远程字典服务器. 是一款区分于磁盘数据库如(Mysql)的 ...

  3. HTML <span> 标签

    定义和用法: <span>标签被用来组合文档中的行内元素.在行内定义一个区域,也就是一行内可以被<span>划分成好几个区域,从而实现某种特定效果.<span>本身 ...

  4. Transport Block Size, Throughput and Code rate-----http://www.simpletechpost.com/2012/12/transport-block-size-code-rate-protocol.html

    Transport Block Size, Throughput and Code rate   Since the size of transport block is not fixed, oft ...

  5. 无废话WCF入门教程六[一个简单的Demo]

    一.前言 前面的几个章节介绍了很多理论基础,如:什么是WCF.WCF中的A.B.C.WCF的传输模式.本文从零开始和大家一起写一个小的WCF应用程序Demo. 大多框架的学习都是从增.删.改.查开始来 ...

  6. 自己不懂的SQL语句用法

    left  join:是SQL语言中的查询类型,即连接查询.它的全称为左外连接,是外连接的一种. 连接通常可以在select语句的from子句或where子句中建立,其语法格式为: select  c ...

  7. express

    1.基于node.js的web开发框架. 2.express目录结构: node_modules public routes views app.js:项目主文件 package.json 3.获取程 ...

  8. running programmer——spring-01(初谈spring)

    今天主要是通过一个简单的登录程序学习一些spring做基础的配置和功能. I.spring的核心配置applicationContext.xml 关于bean的配置官方给出的最基础的配置文件如下: & ...

  9. flex上下固定中间滚动布局

    传统 pc 端中,子容器高度超出父容器高度,通常使用 overflow:auto 可出现滚动条拖动显示溢出的内容,而移动web开发中,由于浏览器厂商的系统不同.版本不同,导致有部分机型不支持对弹性滚动 ...

  10. HTML引入外部文件,解决统一管理导航栏问题。

    1.IFrame引入,看看下面的代码     <IFRAME NAME="content_frame" width=100% height=30 marginwidth=0 ...