Posted on 2006年9月15日 1:39
昨天抽空把ICTCLAS编译成DLL,导出了3个函数,并用ctypes成功调用。
# -*- coding: cp936 -*-
from ctypes import *
def main():
ICTCLAS_Init = cdll.ictclas.ICTCLAS_Init
ICTCLAS_Exit = cdll.ictclas.ICTCLAS_Exit
ICTCLAS_ParagraphProcess = cdll.ictclas.ICTCLAS_ParagraphProcess
#print ICTCLAS_Init
#print ICTCLAS_Exit
#print ICTCLAS_ParagraphProcess
bInit= ICTCLAS_Init()
if not bInit:
print '初始化失败!'
raise WinError()
lpText = '计算所汉语词法分析系统ICTCLAS调用测试'
buffer_size = len(lpText) * 3
buffer = create_string_buffer(buffer_size)
pbuffer = addressof(buffer)
bSuccess = ICTCLAS_ParagraphProcess(lpText, pbuffer)
s = string_at(pbuffer, buffer_size)
print s
ICTCLAS_Exit()
if __name__ == '__main__':
main()
Technorati : Chinese Word Segmenter, Python, 中文分词