⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dictment.cpp

📁 计算机英汉机器翻译系统中的英语词性标注方法实现
💻 CPP
📖 第 1 页 / 共 3 页
字号:
				if ( !SetChiPartOfWordItem(pszCurrSite) )
					return FALSE;
			} else {
				// 本词有原形和兼类
				bIsFirstGetChiWhenHaveOrig = FALSE;

				pszCurrSite = szSouLine + 1;

				m_pFirstChinese = new ChinesePart;
				
				m_pFirstChinese->m_pszChinese = NULL;
				m_pFirstChinese->m_pszCate = NULL;
				m_pFirstChinese->m_pszHead = NULL;
				
				m_pFirstChinese->m_nChineseLen = 0;
				m_pFirstChinese->m_pFirstSlot = NULL;
				m_pFirstChinese->m_pLastSlot = NULL;
				m_pFirstChinese->m_pCurrSlot = NULL;

				m_pFirstChinese->m_pNextPart = NULL;

				m_pLastChinese = m_pFirstChinese;
				
				m_pCurrChinese = m_pFirstChinese;

				if ( !SetChiPartOfWordItem(pszCurrSite) )
					return FALSE;
			}
			break;
		case '$':
			bNoFinishCurWord = FALSE;
			break;
		default:
			CString strMsg;
			strMsg.Format("ERROR 26,第%d行",
				m_pszDicName,m_nCurrReadLineNum);
			if ( m_bIsWriteLog ) {
				fputs(strMsg,m_fpErrLogFile);
				fputs("\r\n",m_fpErrLogFile);
			} else
				AfxMessageBox(strMsg);

			if ( m_bIsWriteErrToDic ) {
				fputs(strMsg,m_fpTarDic);
				fputs("\r\n",m_fpTarDic);
			}
			return FALSE;
		}
	} while ( bNoFinishCurWord );
	return TRUE;
}

void COneWord::FreeSlotLink(Slot *pFirstSlot)
{
	if ( pFirstSlot == NULL ) return;

	Slot *pCurrSlot = pFirstSlot,*pNextSlot;
	do {
		pNextSlot = pCurrSlot->m_pNextSlot;
		if ( pCurrSlot->m_pszSlotName != NULL )
			delete pCurrSlot->m_pszSlotName;
		if ( pCurrSlot->m_pszSlotValue != NULL )
			delete pCurrSlot->m_pszSlotValue;

		delete pCurrSlot;
		pCurrSlot = pNextSlot;
	} while ( pCurrSlot != NULL );
}

void COneWord::FreeChineseLink()
{
	if ( m_pFirstChinese == NULL ) return;

	ChinesePart *pCurrPart = m_pFirstChinese,*pNextPart;
	do {
		pNextPart = pCurrPart->m_pNextPart;
		if ( pCurrPart->m_pszChinese != NULL )
			delete pCurrPart->m_pszChinese;
		if ( pCurrPart->m_pszCate != NULL )
			delete pCurrPart->m_pszCate;
		if ( pCurrPart->m_pszHead != NULL )
			delete pCurrPart->m_pszHead;
		FreeSlotLink(pCurrPart->m_pFirstSlot);
	
		pCurrPart->m_pFirstSlot = NULL;
		pCurrPart->m_pLastSlot = NULL;
		pCurrPart->m_pCurrSlot = NULL;

		delete pCurrPart;
		pCurrPart = pNextPart;
	} while ( pCurrPart != NULL );
}

void COneWord::EmptyWordContent()
{
	delete m_pszEnglish;
	m_pszEnglish = NULL;

	if ( m_pszOrig != NULL )
		delete m_pszOrig;
	m_pszOrig = NULL;
	m_nOrigLen = 0;

	m_bIsExistOrig = FALSE;

	if ( m_pszAmbig != NULL )
		delete m_pszAmbig;
	m_pszAmbig = NULL;

	m_nAmbigLen = 0;
	m_bIsExistAmbig = FALSE;

	FreeChineseLink();

	m_pFirstChinese = NULL;
	m_pLastChinese = NULL;
	m_pCurrChinese = NULL;
}

void COneWord::GotoNextWordBegin(FILE *fpSouFile)
{
	char szSouLine[MAX_SOU_LINE_LEN];
	do {
		fgets(szSouLine,MAX_SOU_LINE_LEN,fpSouFile);
		
		if ( m_bIsWriteErrToDic )
			fputs(szSouLine,m_fpTarDic);

		m_nCurrReadLineNum ++;
		if ( szSouLine[0] == '$' )
			break;
		if ( feof(fpSouFile ) ) {
			CString strMsg;
			strMsg.Format("ERROR 19,第%d行: 找不到 $ ",
				m_pszDicName,m_nCurrReadLineNum);
			if ( m_bIsWriteLog ) {
				fputs(strMsg,m_fpErrLogFile);
				fputs("\r\n",m_fpErrLogFile);
			} else
				AfxMessageBox(strMsg);

			if ( m_bIsWriteErrToDic ) {
				fputs(strMsg,m_fpTarDic);
				fputs("\r\n",m_fpTarDic);
			}
			break;
		}
	} while ( TRUE );
}

void COneWord::GetEnglish(LPSTR &pszEnglish,int &nEngLen)
{
	pszEnglish = m_pszEnglish;
	nEngLen = m_nEnglishLen;
}

#include "direct.h"
//yys 98.5.14 Bgn
//添加一个形参szDicName
BOOL FormatCheck(LPSTR pszLogFile,LPSTR pszDefineName,LPSTR pszErrLineInfo,char *szDicName)
//yys 98.5.14 End
// pszLogFile 错误位置说明文件
// pszDefineName 保留字定义文件
{
	static nIndex = 1;
	BOOL bResult = TRUE;

	COneWord OneWord;
	//char szDicName[100] = "Ecdic\\Ecdic.dic";  //被形参代替 yys 98.5.14
	char szTarDicName[100] = "dictres\\ecdic.tar";
	
	
	//char sExeFilePath[1024];
	
	//GetModuleFileName(NULL,sExeFilePath,1024);
	//_chdir(sExeFilePath);
	OneWord.m_fpErrLogFile = fopen(pszLogFile,"wb");
	if ( OneWord.m_fpErrLogFile == NULL ) {
		AfxMessageBox("无法创建错误纪录文件!");
		return FALSE;
	}
	OneWord.m_bIsWriteLog = TRUE;
	
	OneWord.m_bIsWriteErrToDic = TRUE;

	// 初始化
	OneWord.Init(pszDefineName);
	
	FILE *fpSouFile,*fpTarDic;

	BOOL bIsNoError;
	BOOL bIsEof;

	fpSouFile = fopen(szDicName,"rb");
	if ( fpSouFile == NULL ) {
		AfxMessageBox("无法打开词典文件!");
		fclose(OneWord.m_fpErrLogFile);
		return FALSE;
	}
	
	if ( OneWord.m_bIsWriteErrToDic ) {
		fpTarDic = fopen(szTarDicName,"wb");
		if ( fpTarDic == NULL ) {
			AfxMessageBox("无法创建文件!");
			fclose(fpSouFile);
			fclose(OneWord.m_fpErrLogFile);
			return FALSE;
		}
		OneWord.m_fpTarDic = fpTarDic;
	}

	OneWord.m_nCurrReadLineNum = 0;
	do {
		bIsNoError = OneWord.ReadWordFromSouDict(fpSouFile,szDicName,
							fpTarDic,bIsEof);
		//yys 98.5.26 Bgn
		if( !bIsNoError )
			bResult = FALSE;
		//yys 98.5.26 End
		if ( !bIsNoError )
			OneWord.GotoNextWordBegin(fpSouFile);
		OneWord.EmptyWordContent();
	} while ( !bIsEof );
	fclose(fpSouFile);

	if ( OneWord.m_bIsWriteErrToDic )
		fclose(fpTarDic);
	
	// 释放保留字数组占用的空间
	OneWord.ExitInit();

	fclose(OneWord.m_fpErrLogFile);

	return bResult;
}

void DumpSlot(Slot *pCurrSlot,FILE *fpSlotName,
			  FILE *fpSlotValue,FILE *fpNoValuSlot,FILE *fpRule)
{
	do {
		if ( pCurrSlot->m_bIsTranRule ) {
			fputs(pCurrSlot->m_pszSlotName,fpRule);
			fputs("\r\n",fpRule);
		} else {
			if ( pCurrSlot->m_pszSlotValue == NULL ) {
				fputs(pCurrSlot->m_pszSlotName,fpNoValuSlot);
				fputs("\r\n",fpNoValuSlot);
			} else {
				fputs(pCurrSlot->m_pszSlotName,fpSlotName);
				fputs("\r\n",fpSlotName);

				fputs(pCurrSlot->m_pszSlotValue,fpSlotValue);
				fputs("\r\n",fpSlotValue);
			}
		}
		pCurrSlot = pCurrSlot->m_pNextSlot;
	} while ( pCurrSlot != NULL );
}

void DumpChinesePart(ChinesePart *pCurrChinese,
					 FILE *fpCate,FILE *fpHead,FILE *fpSlotName,
					 FILE *fpSlotValue,FILE *fpNoValuSlot,FILE *fpRule)
{
	do {
		if ( pCurrChinese->m_pszCate != NULL ) {
			fputs(pCurrChinese->m_pszCate,fpCate);
			fputs("\r\n",fpCate);
		}
		if ( pCurrChinese->m_pszHead != NULL ) {
			fputs(pCurrChinese->m_pszHead,fpHead);
			fputs("\r\n",fpHead);
		}
		if ( pCurrChinese->m_pFirstSlot != NULL ) {
			DumpSlot(pCurrChinese->m_pFirstSlot,fpSlotName,
					 fpSlotValue,fpNoValuSlot,fpRule);
		}
		pCurrChinese = pCurrChinese->m_pNextPart;
	} while ( pCurrChinese != NULL );
}

void DumpDict(BOOL bIsWriteErrorToLog,LPSTR pszLogFile,LPSTR pszDefineName)
// pszLogFile 错误位置说明文件
// pszDefineName 保留字定义文件
{
	char szEngName[] = "English.txt";
	char szOrigName[] = "Origin.txt";
	char szAmbigName[] = "Ambig.txt";
	char szCateName[] = "Cate.txt";
	char szHeadName[] = "Head.txt";
	char szSlotName[] = "SlotName.txt";
	char szSlotValue[] = "SlotValu.txt";
	char szNoValuSlot[] = "NoValSlo.txt";
	char szRule[] = "Rule.txt";
	
	FILE *fpEng,*fpOrig,*fpAmbig,*fpCate,*fpHead,*fpSlotName,*fpSlotValue;
	FILE *fpNoValuSlot,*fpRule;
	fpEng = fopen( szEngName,"wb");
	if ( fpEng == NULL ) {
		AfxMessageBox("Cann't Create file!");
		return;
	}
	fpOrig = fopen( szOrigName,"wb");
	if ( fpOrig == NULL ) {
		AfxMessageBox("Cann't Create file!");
		return;
	}
	fpAmbig = fopen( szAmbigName,"wb");
	if ( fpAmbig == NULL ) {
		AfxMessageBox("Cann't Create file!");
		return;
	}
	fpCate = fopen( szCateName,"wb");
	if ( fpCate == NULL ) {
		AfxMessageBox("Cann't Create file!");
		return;
	}
	fpHead = fopen( szHeadName,"wb");
	if ( fpHead == NULL ) {
		AfxMessageBox("Cann't Create file!");
		return;
	}
	fpSlotName = fopen( szSlotName,"wb");
	if ( fpSlotName == NULL ) {
		AfxMessageBox("Cann't Create file!");
		return;
	}
	fpSlotValue = fopen( szSlotValue,"wb");
	if ( fpSlotValue == NULL ) {
		AfxMessageBox("Cann't Create file!");
		return;
	}
	fpNoValuSlot = fopen( szNoValuSlot,"wb");
	if ( fpNoValuSlot == NULL ) {
		AfxMessageBox("Cann't Create file!");
		return;
	}
	fpRule = fopen( szRule,"wb");
	if ( fpRule == NULL ) {
		AfxMessageBox("Cann't Create file!");
		return;
	}

	static nIndex = 1;

	COneWord OneWord;
	char szDicName[100];
	
	OneWord.m_fpErrLogFile = fopen(pszLogFile,"wb");
	if ( OneWord.m_fpErrLogFile == NULL ) {
		AfxMessageBox("Cann't Create File!");
		return;
	}
	OneWord.m_bIsWriteLog = TRUE;
	
	OneWord.m_bIsWriteErrToDic = FALSE;

	// 初始化
	OneWord.Init(pszDefineName);
	
	FILE *fpSouFile;

	BOOL bIsNoError;
	BOOL bIsEof;

	for ( int Loop=nIndex;Loop<= MAX_DIC_NUM;Loop++ ) {
		sprintf(szDicName,"ecdic\\ec%03d.dic",Loop);

		fpSouFile = fopen(szDicName,"rb");
		if ( fpSouFile == NULL ) {
			AfxMessageBox("Cann't Open Diction!");
			return;
		}
		
		OneWord.m_nCurrReadLineNum = 0;
		do {
			bIsNoError = OneWord.ReadWordFromSouDict(fpSouFile,szDicName,NULL,
							bIsEof);
			if ( !bIsNoError )
				OneWord.GotoNextWordBegin(fpSouFile);
			else { // 将词典的内容放到多个文件中
				if ( bIsEof == FALSE ) {
					if ( OneWord.m_pszEnglish != NULL ) {
						fputs(OneWord.m_pszEnglish,fpEng);
						fputs("\r\n",fpEng);
					}
					
					if ( OneWord.m_bIsExistOrig ) {
						fputs(OneWord.m_pszOrig,fpOrig);
						fputs("\r\n",fpOrig);
					}
									
					if ( OneWord.m_bIsExistAmbig ) {
						fputs(OneWord.m_pszAmbig,fpAmbig);
						fputs("\r\n",fpAmbig);
					}
					if ( OneWord.m_pFirstChinese != NULL ) {
						DumpChinesePart(OneWord.m_pFirstChinese,
								fpCate,fpHead,fpSlotName,
								fpSlotValue,fpNoValuSlot,fpRule);
					}
				}
			}
			OneWord.EmptyWordContent();
		} while ( !bIsEof );
		fclose(fpSouFile);
	}
			
	if ( OneWord.m_bIsWriteLog )
		fclose(OneWord.m_fpErrLogFile);

	// 释放保留字数组占用的空间
	OneWord.ExitInit();

	fclose(fpEng);
	fclose(fpOrig);
	fclose(fpAmbig);
	fclose(fpCate);
	fclose(fpHead);
	fclose(fpSlotName);
	fclose(fpSlotValue);
	fclose(fpNoValuSlot);
	fclose(fpRule);
}

BOOL RemoveErrorInfoFromDict()
// 从词典中将提示错误信息去掉
{
	FILE *fpSouDic,*fpTarDic;
	char szSouDicName[100];
	char szTarDicName[100];
	
	if ( AfxMessageBox("Warning:\n All the Dictionaries will be erased!!",MB_YESNO) != IDYES ) 
		return FALSE;
	char szLine[MAX_SOU_LINE_LEN];

	for ( int Loop=1;Loop<= MAX_DIC_NUM;Loop++ ) {
		sprintf(szSouDicName,"dictres\\ec%03d.dic",Loop);
		sprintf(szTarDicName,"ecdic\\ec%03d.dic",Loop);

		fpSouDic = fopen(szSouDicName,"rb");
		if ( fpSouDic == NULL ) {
			CString strMsg;
			strMsg.Format("Cann't Open Dictionary %s!",szSouDicName);
			AfxMessageBox(strMsg);
			return FALSE;
		}

		fpTarDic = fopen(szTarDicName,"wb");
		if ( fpSouDic == NULL ) {
			CString strMsg;
			strMsg.Format("Cann't Create Dictionary %s!",szTarDicName);
			AfxMessageBox(strMsg);
			return FALSE;
		}
		do {
			fgets(szLine,MAX_SOU_LINE_LEN,fpSouDic);
			if ( feof( fpSouDic ) ) {
				break;
			}
			if ( strncmp(szLine,"ERROR ",6) != 0 ) {
				fputs(szLine,fpTarDic);
			}
		} while ( TRUE );
		fclose(fpSouDic);
		fclose(fpTarDic);
	}

	AfxMessageBox("Finish!");
	return TRUE;	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -