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

📄 testtreedlg.cpp

📁 中文信息处理方面的一个源码
💻 CPP
字号:
// TestTreeDlg.cpp : implementation file
// 用树图显示句法分析结果

#include "stdafx.h"
#include "BottomUpParser.h"

#include "TestTreeDlg.h"

#include "parsing.h"

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

extern CObArray edges;
extern int wordNum; // 分析句法结构的同时记录句中词数


//void ShowSubTree(CEdge *e, HTREEITEM hParent); // 显示树结构函数

/////////////////////////////////////////////////////////////////////////////
// CTestTreeDlg dialog


CTestTreeDlg::CTestTreeDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestTreeDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestTreeDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CTestTreeDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestTreeDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTestTreeDlg, CDialog)
	//{{AFX_MSG_MAP(CTestTreeDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestTreeDlg message handlers

void ShowSubTree(CTreeCtrl* pTree, CEdge *e, HTREEITEM hParent)
{
	HTREEITEM ht;
	CString tmp="";
	if(e->Sub1==-1 && e->Sub2==-1) {
		int k=(e->Root).Find("("), m=(e->Root).GetLength();
		if (k>0){
			tmp=e->Root.Mid(k+1,m-k-2); // 将noun(孩子) --> 孩子
		}

		pTree->InsertItem(tmp,hParent,0);
		pTree->Expand(hParent,TVE_EXPAND);
	}

	CEdge *e1,*e2;
	
	if (e->Sub1>=0)
	{
		e1=(CEdge *)edges[e->Sub1];
		ht=pTree->InsertItem(e1->GetRoot(), hParent,0);
		pTree->Expand(hParent,TVE_EXPAND);
		ShowSubTree(pTree,e1,ht);		
	}
	
	if(e->Sub2>=0) {
		e2=(CEdge *)edges[e->Sub2];
		ht=pTree->InsertItem(e2->GetRoot(), hParent, 0);
		pTree->Expand(hParent,TVE_EXPAND);
		ShowSubTree(pTree,e2,ht);		
	}
}

BOOL CTestTreeDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically

	// TODO: Add extra initialization here
	CEdge *e;
	
	CTreeCtrl* pTree=(CTreeCtrl*)GetDlgItem(IDC_TestTree);
	
	HTREEITEM hCurrentNode;
	for (int i=0; i<edges.GetSize(); i++) 
	{
		e=(CEdge *) edges[i];

		if(e->First ==1 && e->Last == wordNum && e->GetRoot() == "S") 
		{
			hCurrentNode=pTree->InsertItem(e->GetRoot(),TVI_ROOT,0);
			pTree->Expand(hCurrentNode,TVE_EXPAND);
			ShowSubTree(pTree,e,hCurrentNode);
		}
	}

	return TRUE;  // return TRUE  unless you set the focus to a control
}

⌨️ 快捷键说明

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