资源简介

中文分词一直都是中文自然语言处理领域的基础研究。目前,网络上流行的很多中文分词软件都可以在付出较少的代价的同时,具备较高的正确率。而且不少中文分词软件支持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 : “ << mapDict.size() << endl;
cout << “Load time : “ << interval << endl;
}

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 : “ << str << “  res : “ << bRet << endl;

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

评论

共有 条评论