欢迎来到天天文库
浏览记录
ID:57313512
大小:24.00 KB
页数:6页
时间:2020-08-11
《中文分词处理源代码C++.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#include#includeusingnamespacestd;constintSTART1=0XB0,START2=0XA1,END1=0XF8,END2=0XFF;constintMAXWORDLEN=48;ifstreamfin("segdict.txt");ofstreamout("out1.txt");//---------------------建树部分----------------------structNode
2、3{stringS;boolIsWord;Node3*L,*R;Node3(strings="",boolisWord=0,Node3*l=0,Node3*r=0):S(s),IsWord(isWord),L(l),R(r){}};structNode2{stringS;boolIsWord;Node3*Child;Node2(strings="",boolisWord=0,Node3*child=0):S(s),IsWord(isWord),Child(child){}};structNode{stringS;vector3、e2>v;};vectorDic;intHASH[END1-START1][END2-START2];voidBegin()//初始化{for(inti=0;i4、3(t,(len==2),0,0);else{while(LAST->L!=0)LAST=LAST->L;if(LAST->S!=t){LAST->L=newNode3(t,(len==2),0,0);LAST=LAST->L;}}if(len>2)BuildTree(s.substr(2,MAXWORDLEN),LAST->R);}voidDictionary()//构造整个结构{Begin();strings;intN,k=0;while(fin>>s){Noden;n.S=s.substr(0,2);intm1=(unsign5、edchar)s[0]-START1;intm2=(unsignedchar)s[1]-START2;HASH[m1][m2]=k++;out<>N;out<>s;out<6、7、(SIZE>0&&n.v[SIZE-1].8、S!=t))n.v.push_back(Node2(t,(Len==4),0));SIZE=n.v.size();if(Len>4)BuildTree(s.substr(4,MAXWORDLEN),n.v[SIZE-1].Child);}Dic.push_back(n);}out<<"ENDHASH"<Dest;intBinarySearch(intx,stringSec)//二分查找第二个9、字{intL=0,R=Dic[x].v.size()-1;while(L<=R){intmid=(L+R)>>1;if(Dic[x].v[mid].S==Sec)returnmid;elseif(Dic[x].v[mid].SS==cc)returnp;elsep=p->L;}return0;}unsignedCharToInt(ch10、arc){returnunsigned((unsignedchar)c);}boolIsCC(charc){unsignedval=CharToInt(c);returnval>=START1&&val
3、e2>v;};vectorDic;intHASH[END1-START1][END2-START2];voidBegin()//初始化{for(inti=0;i4、3(t,(len==2),0,0);else{while(LAST->L!=0)LAST=LAST->L;if(LAST->S!=t){LAST->L=newNode3(t,(len==2),0,0);LAST=LAST->L;}}if(len>2)BuildTree(s.substr(2,MAXWORDLEN),LAST->R);}voidDictionary()//构造整个结构{Begin();strings;intN,k=0;while(fin>>s){Noden;n.S=s.substr(0,2);intm1=(unsign5、edchar)s[0]-START1;intm2=(unsignedchar)s[1]-START2;HASH[m1][m2]=k++;out<>N;out<>s;out<6、7、(SIZE>0&&n.v[SIZE-1].8、S!=t))n.v.push_back(Node2(t,(Len==4),0));SIZE=n.v.size();if(Len>4)BuildTree(s.substr(4,MAXWORDLEN),n.v[SIZE-1].Child);}Dic.push_back(n);}out<<"ENDHASH"<Dest;intBinarySearch(intx,stringSec)//二分查找第二个9、字{intL=0,R=Dic[x].v.size()-1;while(L<=R){intmid=(L+R)>>1;if(Dic[x].v[mid].S==Sec)returnmid;elseif(Dic[x].v[mid].SS==cc)returnp;elsep=p->L;}return0;}unsignedCharToInt(ch10、arc){returnunsigned((unsignedchar)c);}boolIsCC(charc){unsignedval=CharToInt(c);returnval>=START1&&val
4、3(t,(len==2),0,0);else{while(LAST->L!=0)LAST=LAST->L;if(LAST->S!=t){LAST->L=newNode3(t,(len==2),0,0);LAST=LAST->L;}}if(len>2)BuildTree(s.substr(2,MAXWORDLEN),LAST->R);}voidDictionary()//构造整个结构{Begin();strings;intN,k=0;while(fin>>s){Noden;n.S=s.substr(0,2);intm1=(unsign
5、edchar)s[0]-START1;intm2=(unsignedchar)s[1]-START2;HASH[m1][m2]=k++;out<>N;out<>s;out<6、7、(SIZE>0&&n.v[SIZE-1].8、S!=t))n.v.push_back(Node2(t,(Len==4),0));SIZE=n.v.size();if(Len>4)BuildTree(s.substr(4,MAXWORDLEN),n.v[SIZE-1].Child);}Dic.push_back(n);}out<<"ENDHASH"<Dest;intBinarySearch(intx,stringSec)//二分查找第二个9、字{intL=0,R=Dic[x].v.size()-1;while(L<=R){intmid=(L+R)>>1;if(Dic[x].v[mid].S==Sec)returnmid;elseif(Dic[x].v[mid].SS==cc)returnp;elsep=p->L;}return0;}unsignedCharToInt(ch10、arc){returnunsigned((unsignedchar)c);}boolIsCC(charc){unsignedval=CharToInt(c);returnval>=START1&&val
6、
7、(SIZE>0&&n.v[SIZE-1].
8、S!=t))n.v.push_back(Node2(t,(Len==4),0));SIZE=n.v.size();if(Len>4)BuildTree(s.substr(4,MAXWORDLEN),n.v[SIZE-1].Child);}Dic.push_back(n);}out<<"ENDHASH"<Dest;intBinarySearch(intx,stringSec)//二分查找第二个
9、字{intL=0,R=Dic[x].v.size()-1;while(L<=R){intmid=(L+R)>>1;if(Dic[x].v[mid].S==Sec)returnmid;elseif(Dic[x].v[mid].SS==cc)returnp;elsep=p->L;}return0;}unsignedCharToInt(ch
10、arc){returnunsigned((unsignedchar)c);}boolIsCC(charc){unsignedval=CharToInt(c);returnval>=START1&&val
此文档下载收益归作者所有