📄 lex.cpp
字号:
CstrFormat("all record word num :",nRecAllWordNum,cstrShow,15);
filWrite.WriteString(cstrShow);
filWrite.WriteString("\n");
if(bHaveUnkownTag)
filWrite.WriteString("Have Unknown Tag");
else
filWrite.WriteString("Not Have Unkown Tag");
filWrite.WriteString("\n");
filWrite.WriteString("\n");
int nRecWordSum;
int nAllWordSum;
TitleFormat(cstrShow);
filWrite.WriteString(cstrShow);
filWrite.WriteString("\n");
nAllWordSum = AllWordNumFormat(cstrShow);
// 想加数组liblexic.m_aryAllWordTagNum[i]
filWrite.WriteString(cstrShow);
filWrite.WriteString("\n");
nRecWordSum = RecWordNumFormat(cstrShow);
// 想加数组liblexic.m_aryRecWordTagNum[i]
filWrite.WriteString(cstrShow);
filWrite.WriteString("\n");
TitleHyphenFormat(cstrShow);
filWrite.WriteString(cstrShow);
filWrite.WriteString("\n");
AllSubRecNumFormat(cstrShow);
filWrite.WriteString(cstrShow);
filWrite.WriteString("\n");
CstrFormat("所有的单词数 :",nAllWordSum,cstrShow,30);
filWrite.WriteString(cstrShow);
filWrite.WriteString("\n");
CstrFormat("所有已记录的单词数 :",nRecWordSum,cstrShow,30);
filWrite.WriteString(cstrShow);
filWrite.WriteString("\n");
filRead.Close();
filWrite.Close();
}
void TitleFormat(char* cstrShow)
{
char cstr[1024]="";
char cstr1[10];
int i;
CstrFormatChar(cstr,"Unknown",cstrShow,0);
strcpy(cstr,cstrShow);
for(i=0; i<61; i++)
{
strcpy(cstr1,CTagConst::m_strTags[i].c_str());
CstrFormatChar(cstr,cstr1,cstrShow,(i+1)*10);
strcpy(cstr,cstrShow);
}
}
void TitleHyphenFormat(char* cstrShow)
{
char cstr[1024]="";
char cstr1[11] = "----------";
int i;
for(i=0; i<62; i++)
{
CstrFormatChar(cstr,cstr1,cstrShow,i*10);
strcpy(cstr,cstrShow);
}
}
int AllWordNumFormat(char* cstrShow)
{
int i;
int nRet=0;
char cstr[1024]="";
for(i=0; i<62; i++)
{
CstrFormat(cstr,liblexic.m_aryAllWordTagNum[i],cstrShow,i*10);
strcpy(cstr,cstrShow);
nRet += liblexic.m_aryAllWordTagNum[i];
}
return nRet;
}
int RecWordNumFormat(char* cstrShow)
{
int i;
int nRet=0;
char cstr[1024]="";
for(i=0; i<62; i++)
{
CstrFormat(cstr,liblexic.m_aryRecWordTagNum[i],cstrShow,i*10);
strcpy(cstr,cstrShow);
nRet += liblexic.m_aryRecWordTagNum[i];
}
return nRet;
}
int AllSubRecNumFormat(char* cstrShow)
{
int i;
int nRet=0;
char cstr[1024]="";
for(i=0; i<62; i++)
{
CstrFormat(cstr,
liblexic.m_aryAllWordTagNum[i] - liblexic.m_aryRecWordTagNum[i],
cstrShow,i*10);
strcpy(cstr,cstrShow);
nRet += liblexic.m_aryAllWordTagNum[i] - liblexic.m_aryRecWordTagNum[i];
}
return nRet;
}
int SumWordFreq(CLexBTree::SCell& cell)
{
int i;
int sum;
for(i=0,sum=0; i<TAGNUM_IN_CELL; i++)
{
if(0 == cell.aryTag[i]){ // 表示已无已存在的标记,到了空白标记处了
break;
}
else {
sum += cell.aryTagCount[i];
}
}
return sum;
}
bool HaveTagUnknown(CLexBTree::SCell& cell)
{
int i;
bool bHave;
for(i=0,bHave=false;
(i<TAGNUM_IN_CELL) && !bHave;
i++)
{
if(0 == cell.aryTag[i]){ // 表示已无已存在的标记,到了空白标记处了
break;
}
else if(CTagConst::tagUNKNOWN == cell.aryTag[i]) {
bHave = true;
}
}
return bHave;
}
int SumCellTagNum(CLexBTree::SCell& cell)
{
int i;
int sum;
for(i=0,sum=0; i<TAGNUM_IN_CELL; i++)
{
if(0 == cell.aryTag[i]){ // 表示已无已存在的标记,到了空白标记处了
break;
}
else {
sum ++;
}
}
return sum;
}
//void CstrFormat(char* cstrSrc,int nSrc,char* cstrDest,int dist)
//{
// int i,j;
// int len;
// char cstrIntReverse[12];
// len = strlen(cstrSrc);
// for(i=0; i<len; i++)
// {
// cstrDest[i] = cstrSrc[i];
// }
// for(; i<dist; i++)
// {
// cstrDest[i] = '\040';
// }
// if(0==nSrc) {
// cstrIntReverse[0] = '0';
// cstrIntReverse[1] = '\0';
// }
// else {
// for(j=0; nSrc!=0; )
// {
// cstrIntReverse[j++] = nSrc%10 + '0';
// nSrc = nSrc/10;
// }
// cstrIntReverse[j] = '\0';
// }
//
// len = strlen(cstrIntReverse);
// for(j=len-1; j>=0; i++,j--)
// {
// cstrDest[i] = cstrIntReverse[j];
// }
// cstrDest[i] = '\0';
//
//}
void CstrFormat(char* cstrSrc,int nSrc,char* cstrDest,int dist)
{
char cstrInt[128];
itoa(nSrc,cstrInt,10);
CstrFormatChar(cstrSrc,cstrInt,cstrDest,dist);
}
void CstrFormatEx(char* cstrSrc,int nSrc,char* cstrDest,int dist)
{
char cstrInt[128];
itoa(nSrc,cstrInt,10);
CstrFormatCharEx(cstrSrc,cstrInt,cstrDest,dist);
}
void CstrFormatChar(char* cstrSrc1,char* cstrSrc2,char* cstrDest,int dist)
{
int i,j;
int len;
len = strlen(cstrSrc1);
for(i=0; i<len; i++)
{
cstrDest[i] = cstrSrc1[i];
}
for(; i<dist; i++)
{
cstrDest[i] = '\040';
}
len = strlen(cstrSrc2);
for(j=0; j<len; i++,j++)
{
cstrDest[i] = cstrSrc2[j];
}
cstrDest[i] = '\0';
}
void CstrFormatCharEx(char* cstrSrc1,char* cstrSrc2,char* cstrDest,int dist)
{
int i,j;
int len;
len = strlen(cstrSrc1);
for(i=0; i<len; i++)
{
cstrDest[i] = cstrSrc1[i];
}
len = strlen(cstrSrc2);
for(; i<dist-len; i++)
{
cstrDest[i] = '\040';
}
for(j=0; j<len; i++,j++)
{
cstrDest[i] = cstrSrc2[j];
}
cstrDest[i] = '\0';
}
void ShowToFile1(void)
{
char cstrShow[120];
CLexBTree::SPage page;
int naddr,i;
CFile filRead("lexdict.dat",CFile::modeRead);
CStdioFile filDot("dot.txt",CFile::modeCreate|CFile::modeWrite);
CStdioFile filHavedot("hdot.txt",CFile::modeCreate|CFile::modeWrite);
CStdioFile filHyphen("hyphen.txt",CFile::modeCreate|CFile::modeWrite);
CStdioFile filPhrase("phrase.txt",CFile::modeCreate|CFile::modeWrite);
int len;
for(naddr=0; naddr!=-1; )
{
filRead.Seek(naddr* sizeof(CLexBTree::SPage),CFile::begin);
filRead.Read((void*) &page,sizeof(CLexBTree::SPage));
for(i=0; i<page.used_cell_slot_sum; i++) {
len = strlen(page.cell_ary[i].word);
if(strchr(page.cell_ary[i].word,'\040') != NULL) {
CstrFormat(page.cell_ary[i].word,SumWordFreq(page.cell_ary[i]),
cstrShow,35);
filPhrase.WriteString(cstrShow);
filPhrase.WriteString("\n");
}
else if(page.cell_ary[i].word[len-1] == '-') {
CstrFormat(page.cell_ary[i].word,SumWordFreq(page.cell_ary[i]),
cstrShow,35);
filHyphen.WriteString(cstrShow);
filHyphen.WriteString("\n");
}
else if(page.cell_ary[i].word[len-1] == '.') {
CstrFormat(page.cell_ary[i].word,SumWordFreq(page.cell_ary[i]),
cstrShow,35);
filDot.WriteString(cstrShow);
filDot.WriteString("\n");
}
else if(strchr(page.cell_ary[i].word,'.') != NULL) {
CstrFormat(page.cell_ary[i].word,SumWordFreq(page.cell_ary[i]),
cstrShow,35);
filHavedot.WriteString(cstrShow);
filHavedot.WriteString("\n");
}
}
naddr = page.next_page_naddr;
}
filDot.Close();
filHavedot.Close();
filHyphen.Close();
filPhrase.Close();
filRead.Close();
}
//这个函数里用到MFC 的 CFile类
void exec(char * cstr_fname)
{
CStdioFile mfc_finput(cstr_fname,CFile::modeRead);
string str,strWord;
char cstr[MAX_CHARS_LINE];
vector<SWordTag>::iterator iter;
while(mfc_finput.ReadString(cstr,MAX_CHARS_LINE)) {
if(cstr[strlen(cstr)-1]=='\n') {
cstr[strlen(cstr)-1] = 0; //ReadString会把回车符也算在字符串内
}
str = cstr;
if(liblexic.Analyse(str)) {
for(iter=liblexic.m_vecWordTag.begin();
iter!=liblexic.m_vecWordTag.end();
iter++)
{
strWord = (*iter).cstrWord;
pBT->Manipulate(strWord,(*iter).nTag);
}
}
}
mfc_finput.Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -