资源简介
中文分词 正想最大匹配 结合词典所完成的分词系统 C++代码

代码片段和文件信息
#include “stdafx.h“
#include “ContextStat.h“
#include “Utility.h“
#include
#include
#include
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CContextStat::CContextStat()
{
m_pSymbolTable=0;//new buffer for symbol
m_pContext=0;//init with empty
}
CContextStat::~CContextStat()
{
delete [] m_pSymbolTable;
PMYCONTEXT pCur=m_pContextpTemp;
while(pCur!=NULL)
{//delete the context array
pTemp=pCur->next;
for(int i=0;i delete [] pCur->aContextArray[i];
delete [] pCur->aContextArray;
delete [] pCur->aTagFreq;
delete pCur;
pCur=pTemp;
}
}
bool CContextStat::SetSymbol(int *nSymbol)
{
memcpy(m_pSymbolTablenSymbolsizeof(int)*m_nTableLen);
return true;
}
bool CContextStat::Add(int nKey int nPrevSymbol int nCurSymbol int nFrequency)
{//Add the context symbol to the array
PMYCONTEXT pRetItempNew;
int nPrevIndexnCurIndex;
if(!GetItem(nKey&pRetItem))//Not get it
{
pNew=new MYCONTEXT;
pNew->nKey=nKey;
pNew->nTotalFreq=0;
pNew->next=NULL;
pNew->aContextArray=new int*[m_nTableLen];
pNew->aTagFreq=new int[m_nTableLen];
memset(pNew->aTagFreq0sizeof(int)*m_nTableLen);
for(int i=0;i {//new buffer for every dimension
pNew->aContextArray[i]=new int[m_nTableLen];
memset(pNew->aContextArray[i]0sizeof(int)*m_nTableLen);//Init the frequency
}
if(pRetItem==NULL)//Empty the new item is head
m_pContext=pNew;
else//link the new item between pRetItem and its next item
{
pNew->next=pRetItem->next;
pRetItem->next=pNew;
}
pRetItem=pNew;
}
nPrevIndex=BinarySearch(nPrevSymbolm_pSymbolTablem_nTableLen);
if(nPrevSymbol>256&&nPrevIndex==-1)//Not find just for ‘nx‘ and other uncommon POS
nPrevIndex=BinarySearch(nPrevSymbol-nPrevSymbol%256m_pSymbolTablem_nTableLen);
nCurIndex=BinarySearch(nCurSymbolm_pSymbolTablem_nTableLen);
if(nCurSymbol>256&&nCurIndex==-1)//Not find just for ‘nx‘ and other uncommon POS
nCurIndex=BinarySearch(nCurSymbol-nCurSymbol%256m_pSymbolTablem_nTableLen);
if(nPrevIndex==-1||nCurIndex==-1)//error finding the symbol
return false;
pRetItem->aContextArray[nPrevIndex][nCurIndex]+=nFrequency;//Add the frequency
pRetItem->aTagFreq[nPrevIndex]+=nFrequency;
pRetItem->nTotalFreq+=nFrequency;
return true;
}
bool CContextStat::Save(char *sFilename)
{
FILE *fp*fp1;
PMYCONTEXT pCur;
char sFileShow[100];
int i;
if((fp=fopen(sFilename“wb“))==NULL)
{
return false;
}
strcpy(sFileShowsFilename);
strcat(sFileShow“.shw“);
if((fp1=fopen(sFileShow“wb“))==NULL)
{
return false;
}
fwrite(&m_nTableLensizeof(m_nTableLen)1fp);//write the table length
fwrite(m_pSymbolTablesizeof(int)m_nTableLenfp);//write the symbol table
fprintf(fp1“Table Len=
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6986 2009-05-28 20:37 源代码\ContextStat.cpp
文件 1160 2009-05-28 20:37 源代码\ContextStat.h
文件 172642 2012-05-16 12:56 源代码\Debug\detours.lib
文件 7544244 2002-09-13 13:47 源代码\Debug\dic\BigramDict.dct
文件 1565689 2002-09-13 13:47 源代码\Debug\dic\coreDict.dct
文件 10412 2002-09-13 13:47 源代码\Debug\dic\lexical.ctx
文件 1032 2002-09-13 13:51 源代码\Debug\dic\nr.ctx
文件 113780 2002-09-13 13:51 源代码\Debug\dic\nr.dct
文件 408 2002-09-13 13:55 源代码\Debug\dic\ns.ctx
文件 54278 2002-09-13 13:55 源代码\Debug\dic\ns.dct
文件 408 2002-09-13 13:55 源代码\Debug\dic\tr.ctx
文件 64000 2002-09-13 13:55 源代码\Debug\dic\tr.dct
目录 0 2010-04-10 21:36 源代码\Debug\dic
文件 196695 2012-05-16 13:20 源代码\Debug\GraduationDesign.exe
文件 19800 2012-05-16 13:09 源代码\Debug\SkinMagic.lib
文件 1021820 2008-03-17 20:09 源代码\Debug\SkinMagicLib.lib
..A.SH. 5120 2009-06-15 10:15 源代码\Debug\Thumbs.db
目录 0 2012-05-16 13:23 源代码\Debug
文件 172642 2012-05-16 12:56 源代码\detours.lib
文件 31454 2010-04-10 21:08 源代码\Devior.smf
文件 7544244 2002-09-13 13:47 源代码\dic\BigramDict.dct
文件 1565689 2002-09-13 13:47 源代码\dic\coreDict.dct
文件 10412 2002-09-13 13:47 源代码\dic\lexical.ctx
文件 1032 2002-09-13 13:51 源代码\dic\nr.ctx
文件 113780 2002-09-13 13:51 源代码\dic\nr.dct
文件 408 2002-09-13 13:55 源代码\dic\ns.ctx
文件 54278 2002-09-13 13:55 源代码\dic\ns.dct
文件 408 2002-09-13 13:55 源代码\dic\tr.ctx
文件 64000 2002-09-13 13:55 源代码\dic\tr.dct
目录 0 2010-04-10 20:38 源代码\dic
............此处省略48个文件信息
相关资源
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
- c++ 画图(14Qt-XPS)
- c++多边形交并差运算
评论
共有 条评论