資源簡介
中文分詞一直都是中文自然語言處理領域的基礎研究。目前,網絡上流行的很多中文分詞軟件都可以在付出較少的代價的同時,具備較高的正確率。而且不少中文分詞軟件支持Lucene擴展。但不管實現如何,目前而言的分詞系統絕大多數都是基于中文詞典的匹配算法。其中最為常見的是最大匹配算法 (Maximum Matching,以下簡稱MM算法) 。MM算法有三種:一種正向最大匹配,一種逆向最大匹配和雙向匹配。本程序實現了正向最大匹配算法。

代碼片段和文件信息
//?Dict?handling
#include?“StdAfx.h“
#include?“Dict.h“
#include?
#include?
CDict::CDict()
{
clock_t?c1?c2;
c1?=?clock();
OpenDict();
c2?=?clock();
unsigned?long?interval?=?c2?-?c1;
cout?<“Dict?size?:?“?< cout?<“Load?time?:?“?<}
CDict::~CDict()
{
mapDict.clear();
}
void?CDict::OpenDict()
{
FILE?*fpDict;
if?((fpDict?=?fopen(DICTFILENAME.c_str()?“r“))?==?NULL)?{
cout?<“Can?not?open?the?Dictionary?file!“;
exit(1);
}
??
int?id?freq;
char?word[16];
while?(fscanf(fpDict?“%d?%s?%d“?&id?word?&freq)?!=?EOF)?
{
#ifdef?USE_HASHMAP
mapDict[word]?=?0;
#else
mapDict.insert(map::value_type?(word?0));
#endif
}
??
fclose(fpDict);
}
bool?CDict::IsWord(string&?str)?const
{
bool?bRet?=?false;
if?(mapDict.find(str)?!=?mapDict.end())
{
bRet?=?true;
}
cout?<“?Search?:?“?<
return?bRet;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-02-26?09:28??LBChSeg\
?????目錄???????????0??2013-02-26?09:29??LBChSeg\Debug\
?????目錄???????????0??2013-01-22?16:32??LBChSeg\LBChSeg\
?????目錄???????????0??2013-02-26?09:28??LBChSeg\LBChSeg\Debug\
?????文件??????????94??2013-02-26?09:28??LBChSeg\LBChSeg\Debug\LBChSeg.log
?????文件?????????998??2013-01-23?09:05??LBChSeg\LBChSeg\Dict.cpp
?????文件?????????630??2013-01-22?17:40??LBChSeg\LBChSeg\Dict.h
?????文件?????????451??2013-02-01?08:44??LBChSeg\LBChSeg\LBChSeg.cpp
?????文件????????4520??2013-01-22?16:30??LBChSeg\LBChSeg\LBChSeg.vcxproj
?????文件????????1665??2013-01-22?16:30??LBChSeg\LBChSeg\LBChSeg.vcxproj.filters
?????文件?????????143??2013-01-22?16:26??LBChSeg\LBChSeg\LBChSeg.vcxproj.user
?????文件????????1553??2013-01-22?16:26??LBChSeg\LBChSeg\ReadMe.txt
?????文件????????3241??2013-01-31?20:52??LBChSeg\LBChSeg\Segment.cpp
?????文件?????????235??2013-01-22?16:50??LBChSeg\LBChSeg\Segment.h
?????文件?????????212??2013-01-22?16:26??LBChSeg\LBChSeg\stdafx.cpp
?????文件?????????233??2013-01-22?16:26??LBChSeg\LBChSeg\stdafx.h
?????文件?????????236??2013-01-22?16:26??LBChSeg\LBChSeg\targetver.h
?????文件?????1670880??2004-07-09?23:42??LBChSeg\LBChSeg\words.dict
?????文件?????9392128??2013-02-26?09:28??LBChSeg\LBChSeg.sdf
?????文件?????????888??2013-01-22?16:26??LBChSeg\LBChSeg.sln
?????文件???????13824??2013-02-26?09:28??LBChSeg\LBChSeg.suo
?????目錄???????????0??2013-02-26?09:23??LBChSeg\ipch\
?????目錄???????????0??2013-02-26?09:23??LBChSeg\ipch\lbchseg-92dfd245\
?????文件?????2359296??2013-02-26?09:23??LBChSeg\ipch\lbchseg-92dfd245\lbchseg-a7e47c64.ipch
評論
共有 條評論