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

📄 postag.cpp

📁 计算机英汉机器翻译系统中的英语词性标注方法实现
💻 CPP
字号:
// PosTag.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "PosTag.h"

#include "MainFrm.h"
#include "ChildFrm.h"
#include "PosTagDoc.h"
#include "PosTagView.h"

extern int	MorphorAnalyze(char	*sen);
extern SentenceType	g_objMorSent;


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPosTagApp

BEGIN_MESSAGE_MAP(CPosTagApp, CWinApp)
	//{{AFX_MSG_MAP(CPosTagApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_DICTIONARY_BUILDINDEXSTEP1, OnDictionaryBuildindexstep1)
	ON_COMMAND(ID_DICTIONARY_BUILDINDEXSTEP2, OnDictionaryBuildindexstep2)
	ON_COMMAND(ID_DICTIONARY_BUILDINDEXSTEP3, OnDictionaryBuildindexstep3)
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPosTagApp construction

CPosTagApp::CPosTagApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
bIsInit=false;
m_obDiction=NULL;
m_obSysDiction=NULL;		//系统词典数据
m_obAddtionDiction=NULL;	//系统附加词典数据
m_obUserDiction=NULL;	//用户词典数据
m_fpSysIndexDat=NULL;			//系统词典索引
m_fpAddtionIndexDat=NULL;		//系统附加词典索引
m_fpUserIndexDat=NULL;			//用户词典索引 
	
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CPosTagApp object

CPosTagApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CPosTagApp initialization

BOOL CPosTagApp::InitInstance()
{
	// Initialize OLE libraries
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return FALSE;
	}

	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(
		IDR_POSTAGTYPE,
		RUNTIME_CLASS(CPosTagDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CPosTagView));
	pDocTemplate->SetContainerInfo(IDR_POSTAGTYPE_CNTR_IP);
	AddDocTemplate(pDocTemplate);

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The main window has been initialized, so show and update it.
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
		// No message handlers
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CPosTagApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CPosTagApp commands

void CPosTagApp::OnDictionaryBuildindexstep1() 
{
	// TODO: Add your command handler code here
	CString strMsg;
	strMsg.Format("本函数是对英汉词典重建索引的第一步,\n \
执行本步后,旧的索引文件将被删除.\n继续吗?");
	if ( AfxMessageBox(strMsg,MB_YESNO) == IDYES ) {
		char szInDefineName[] = "DictRes\\define.txt";
		char szOutDefineName[] = "CaimPrg\\DictDef.h";
		char szDicIndexName[] = "DictRes\\EcDict";
		char szCodeTableName[] = "DictRes\\CodeTab.txt";
		char szEngInfoName[] = "DictRes\\EngInfo.txt";
		
		BOOL bResult = BuildIndexStepOne(szInDefineName,szOutDefineName,
								szDicIndexName,szEngInfoName,
								szCodeTableName,"ecdic\\ecdic.dic");

		if ( bResult ) {
			strMsg.Format("重建索引的第一步正确完成!\n \
请对%s文件使用ULTRAEDIT对第一列进行逆序排序 \
(字母z开头的在前,字母a开头的在后), \
排序后按原名保存,并执行第二步",szEngInfoName);
		} else {
			strMsg.Format("重建索引的第一步出现错误!");
		}
		AfxMessageBox( strMsg );
	}
	
}

void CPosTagApp::OnDictionaryBuildindexstep2() 
{
	// TODO: Add your command handler code here
	CString strMsg;
	strMsg.Format("本函数是对英汉词典重建索引的第二步,\n \
注意:在执行本步之前,请先对EngInfo.txt按逆序进行排序.\n继续吗?");
	if ( AfxMessageBox(strMsg,MB_YESNO) == IDYES ) {
		char szEngInfoName[] = "DictRes\\EngInfo.txt";
		char szHuffmanFreqDataName[] = "DictRes\\HuffFreq.dat";
		char szEngHuffName[] = "DictRes\\EngHuff.txt";
		BOOL bResult;
		bResult = BuildIndexStepTwo(szEngInfoName,szHuffmanFreqDataName,
						  szEngHuffName);
		if ( bResult ) {
			strMsg.Format("重建索引的第二步正确完成!\n \
请对%s文件使用ULTRAEDIT对第一列按顺序进行排序, \
排序后按原名保存,并执行第三步",szEngHuffName);
		} else {
			strMsg.Format("重建索引的第二步出现错误!");
		}
		AfxMessageBox( strMsg );
	}
	
}

void CPosTagApp::OnDictionaryBuildindexstep3() 
{
	CString strMsg;
	strMsg.Format("本函数是对英汉词典重建索引的第三步,\n \
注意:在执行本步之前,请先对EngHuff.txt按顺序进行排序.\n继续吗?");
	if ( AfxMessageBox(strMsg,MB_YESNO) == IDYES ) {
		char szEngHuffName[] = "DictRes\\EngHuff.txt";
		char szDicIndexName[] = "DictRes\\EcDict";
		
		BOOL bResult;
		bResult = BuildIndexStepThree(szEngHuffName,szDicIndexName,"ecdic\\Ecdic.dic");
		if ( bResult ) {
			strMsg.Format("重建索引正确完成!\n");
		} else {
			strMsg.Format("重建索引的第三步出现错误!");
		}
		AfxMessageBox( strMsg );
	}
}

⌨️ 快捷键说明

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