?? mainfrm.cpp
字號(hào):
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "BottomUpParser.h"
#include "MainFrm.h"
#include "parsing.h"
#include "TestTreeDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CObArray rules, edges; // 規(guī)則、線圖全局變量
extern int wordNum; // 分析句法結(jié)構(gòu)的同時(shí)記錄句中詞數(shù)
extern CString myTrace;
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_BottomUp, OnBottomUp)
ON_COMMAND(ID_OpenRuleSet, OnOpenRuleSet)
ON_COMMAND(ID_ShowTree, OnShowTree)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnBottomUp()
{// 自底向上句法分析方法
// TODO: Add your command handler code here
if (rules.GetSize()==0) {
AfxMessageBox("您沒(méi)有打開(kāi)規(guī)則庫(kù)");
return;
}
CFileDialog dlg(TRUE,"","*.*",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"詞性標(biāo)注文件|*.pos|所有文件||");
if(dlg.DoModal()!=IDOK)
return;
FILE *in, *out;
in=fopen((const char *)dlg.GetPathName(),"rt");
if(!in) {
AfxMessageBox("無(wú)法打開(kāi)輸入文件");
return;
}
out=fopen((const char *)(dlg.GetPathName()+".parse"),"wt");
if(!out) {
AfxMessageBox("無(wú)法創(chuàng)建輸出文件");
fclose(in);
return;
}
CStdioFile inFile(in),outFile(out);
CString line;
while(inFile.ReadString(line)) {
CString tmp, tmp1;
line.TrimLeft();
line.TrimRight();
if (line!="") {// 不是空串,才進(jìn)行分析
tmp="\n\n當(dāng)前輸入句子:"+line;
line=Parsing(line);
if (line.Find("句子不合語(yǔ)法")>=0)
AfxMessageBox(tmp+"\n句子不合語(yǔ)法!");
else
OnShowTree(); // 顯示句法樹(shù)
tmp1.Format("%d",wordNum);
tmp=tmp+" (共 "+tmp1+" 個(gè)詞)"+"\n\n";
outFile.WriteString(tmp);
}
outFile.WriteString(line);
// 在結(jié)果文件中記錄中間分析過(guò)程,2002-12-18
if (myTrace!="" && tmp!="") {
myTrace = "序號(hào)\t根\t起點(diǎn)\t終點(diǎn)\t成分\n" + myTrace;
outFile.WriteString(myTrace);
}
}
inFile.Close();
outFile.Close();
AfxMessageBox("全部句子分析完畢");
}
void CMainFrame::OnOpenRuleSet()
{
// TODO: Add your command handler code here
CFileDialog dlg(TRUE,"txt","*.txt",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"詞性標(biāo)注文件|*.pos|所有文件||");
if(dlg.DoModal()!=IDOK) {
AfxMessageBox("您沒(méi)有打開(kāi)規(guī)則庫(kù)");
return;
}
FILE *rf;
rf=fopen((const char *)dlg.GetPathName(),"rt"); //打開(kāi)規(guī)則文件
if(!rf) {
AfxMessageBox("無(wú)法打開(kāi)規(guī)則庫(kù)文件");
return;
}
CStdioFile ruleFile(rf);
CString line;
CRule * r=NULL;
for(int i=0;i<rules.GetSize();i++)
if(rules[i]!=NULL)
delete rules[i];
rules.RemoveAll();
while(ruleFile.ReadString(line)) {
int i=line.Find(';');
if(i<0)
continue;
line=line.Left(i);
line.TrimLeft();
r=new CRule(line);
rules.Add(r);
}
ruleFile.Close();
}
void CMainFrame::OnShowTree()
{
// TODO: Add your command handler code here
CTestTreeDlg myDlg;
myDlg.DoModal();
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -