#ifdef linux classCNLPIR { #else class__declspec(dllexport) CNLPIR { #endif
3)编译代码
python setup.py build_ext --inplace
4、编写 PyNLPIR.py
为了方便使用对生成的 NLPIR.py 进行重封装。
#!/usr/bin/env python #coding:utf-8 ''' Created on Fri 19, 2013 @author: killua @e-mail: [email protected] @Decription: Python for NLPIR ''' import NLPIR import os
defnlpir_init(init_dir = '.', code_type = 'GBK'): ''' Init the analyzer and prepare necessary data for NLPIR according the configure file. ''' if code_type == 'GBK': is_succeed = NLPIR.NLPIR_Init(init_dir, NLPIR.GBK_CODE) elif code_type == 'UTF-8'or code_type == 'UTF8': is_succeed = NLPIR.NLPIR_Init(init_dir, NLPIR.UTF8_CODE) elif code_type == 'BIG5': is_succeed = NLPIR.NLPIR_Init(init_dir, NLPIR.BIG5_CODE) elif code_type == 'GBK_FANTI': is_succeed = NLPIR.NLPIR_Init(init_dir, NLPIR.GBK_FANTI_CODE) if is_succeed: print'NLPIR Successful.' else: print'NLPIR Failed.'
defnlpir_exit(): ''' Exit the program and free all resources and destroy all working buffer used in NLPIR. ''' return NLPIR.NLPIR_Exit()
defnlpir_import_user_dict(user_dict): ''' Import user-defined dictionary from a text file. ''' return NLPIR.NLPIR_ImportUserDict(user_dict)
defnlpir_paragraph_process(text, is_pos_tagged = False): ''' Process a paragraph ''' return NLPIR.NLPIR_ParagraphProcess(text, is_pos_tagged)
defnlpir_file_process(source_file, target_file, is_pos_tagged = False): ''' Process a text file ''' return NLPIR.NLPIR_FileProcess(source_file, target_file, is_pos_tagged)
defnlpir_add_user_word(word): ''' Add a word to the user dictionary. ''' return NLPIR.NLPIR_AddUserWord(word)
defnlpir_save_user_dict(): ''' Save the user dictionary to disk. ''' return NLPIR.NLPIR_SaveTheUsrDic()
defnlpir_delete_user_word(word): ''' Delete a word from the user dictionary. ''' return NLPIR.NLPIR_DelUsrWord(word)