CLucene+ICTCLAS中文分词整合

计算所汉语词法分析系统ICTCLAS,有关它的信息http://sewm.pku.edu.cn/QA/reference/ICTCLAS/FreeICTCLAS/

一、生成动态库DLL或静态库Lib文件,并写好接口函数

bool ICT_INIT(int outputFormat,int operateType);
void ICT_FILEPROC(char *sFileName);
void ICT_SPLITWORDS(char *paremeter,char * &pResult);

二、参考lucene接口的实现,现在clucene的ictclas接口
/***********************************
 ** ictclas.h
/***********************************/
#ifndef _lucene_util_Ictclas_
#define _lucene_util_Ictclas_
#if defined(_LUCENE_PRAGMA_ONCE)
# pragma once
#endif
CL_NS_DEF(util)
class ICTCLAS
{
private: 
 static ICTCLAS *instance;
public:
 ICTCLAS();
 static ICTCLAS* getInstance();
 static void doFile(const char *fileName);
 static void doWord(char *sParagraph,char* &m_sResult);
 ~ICTCLAS();
};
CL_NS_END
#endif

/***********************************
 ** ictclas.cpp
/***********************************/
#include "Ictclas.h"
#ifndef _lucene_analysis_standard_StandardIctclas_
#define _lucene_analysis_standard_StandardIctclas_
#pragma comment(lib,"ICTCLASSLIB.lib")
//#define DLLIMPORT _declspec(dllimport)
#define DLLEXPORT __declspec( dllexport )
DLLEXPORT bool init(int,int);
DLLEXPORT void fileProcess(const char *fileName);
DLLEXPORT void splitWords(char *sParagraph,char* &m_sResult);
#endif
CL_NS_DEF(util)
ICTCLAS* ICTCLAS::instance=NULL;
ICTCLAS::ICTCLAS()
{
 init(0,0);
}
ICTCLAS* ICTCLAS::getInstance(){
 if (instance==NULL)
 {
   instance = new ICTCLAS();
 }
 return instance;
}
void ICTCLAS::doFile(const char *fileName){
 fileProcess(fileName);
}
void ICTCLAS::doWord(char *sParagraph,char* &m_sResult){
 splitWords(sParagraph,m_sResult);
}
ICTCLAS::~ICTCLAS(){
}
原文地址:https://www.cnblogs.com/cy163/p/1214742.html