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

📄 zidongfencidlg.cpp

📁 这个是我们的中文信息处理的作业
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// zidongfenciDlg.cpp : implementation file
//

#include "stdafx.h"
#include "zidongfenci.h"
#include "zidongfenciDlg.h"
#include "openfile.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// 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)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CZidongfenciDlg dialog

CZidongfenciDlg::CZidongfenciDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CZidongfenciDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CZidongfenciDlg)
	m_edit1 = _T("");
	m_edit2 = _T("");
	m_edit3 = _T("");
	m_edit4 = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	zxover=fxover=false;
	everytime=true;
	seezheng=0;
	seefan=0;
	savehang=0;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CZidongfenciDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CZidongfenciDlg)
	DDX_Control(pDX, IDC_LIST5, m_list5);
	DDX_Control(pDX, IDC_LIST4, m_list4);
	DDX_Control(pDX, IDC_LIST3, m_list3);
	DDX_Control(pDX, IDC_LIST2, m_list2);
	DDX_Text(pDX, IDC_EDIT1, m_edit1);
	DDX_Text(pDX, IDC_EDIT2, m_edit2);
	DDX_Text(pDX, IDC_EDIT3, m_edit3);
	DDX_Text(pDX, IDC_EDIT4, m_edit4);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CZidongfenciDlg, CDialog)
	//{{AFX_MSG_MAP(CZidongfenciDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CZidongfenciDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CZidongfenciDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CZidongfenciDlg::OnPaint() 
{
	
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CZidongfenciDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CZidongfenciDlg::OnButton1() 
{
	UpdateData();
	CString temp;
	CString sentence1;
	CString head;
	CString temp2;
	CString temp3;
	int shang,zhong,xia;
	if(m_edit1=="")
	{
		MessageBox("请先输入要分词的语句!");
		fxover=false;
		return;
	}
	else
	{
		GetDlgItem(IDC_EDIT1)->GetWindowText(m_edit1);
	}
	MessageBox(m_edit1);
	int m;
	m=m_edit1.GetLength()/2;
	sentence1=m_edit1;
	sentence=m_edit1;
	shang=zhong=xia=0;
	CListBox* listpoint;
	listpoint=(CListBox*)(GetDlgItem(IDC_LIST1));


	CoInitialize(NULL);
	_ConnectionPtr pConn(__uuidof(Connection));
	_RecordsetPtr pRst(__uuidof(Recordset));
	pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs";
	pConn->Open("","","",adConnectUnspecified);
	for(int i=0;i<m;i++)
	{
		shang=i*2;

		for(int j=m;j>i;j--)
		{
			head=m_edit1.Mid(shang,(j-i)*2);
			temp.Format("select * from word where word like '%s%s'",head,"%");
	
			pRst=pConn->Execute(_bstr_t(temp),NULL,adCmdText);
			if(pRst->rsEOF)
			{
				if(everytime)
				{
					CString msg;
					msg.Format("%s%s",head,"   没有找到");
					listpoint->ResetContent();
					listpoint->AddString(head);
					//MessageBox(msg);
					MessageBox("   没有找到   ");

				}
				continue;
			}
			else
			{
				temp2=m_edit1.Mid(i*2,head.GetLength());
				CString out=temp2;
				temp2=temp2+"。";
				temp3=temp3+temp2;
				i=j-1;
				if(everytime)
				{
					MessageBox(out);
				}
				listpoint->ResetContent();
				listpoint->AddString((_bstr_t)pRst->GetCollect("word"));
				GetDlgItem(IDC_EDIT2)->SetWindowText(temp3);
				break;
			}	
			//listpoint->ResetContent();
			
			//listpoint->GetText(0,"word");
		}
	}

	
	pRst->Close();
	pConn->Close();
	pRst.Release();
	pConn.Release();
	CoUninitialize();
	zxover=true;
	zxresult=temp3;
	
}

void CZidongfenciDlg::OnButton2() 
{
	

	UpdateData();
	CString temp;
	CString sentence1;
	CString tail;
	CString temp2;
	CString temp3;
	int shang,zhong,xia;
	if(m_edit1=="")
	{
		MessageBox("请先输入要分词的语句!");
		zxover=false;
		return;
	}
	else
	{
		GetDlgItem(IDC_EDIT1)->GetWindowText(m_edit1);
	}
	MessageBox(m_edit1);
	int m;
	m=m_edit1.GetLength()/2;
	sentence1=m_edit1;
	sentence=m_edit1;
	shang=zhong=xia=0;
	CListBox* listpoint;
	listpoint=(CListBox*)(GetDlgItem(IDC_LIST1));


	CoInitialize(NULL);
	_ConnectionPtr pConn(__uuidof(Connection));
	_RecordsetPtr pRst(__uuidof(Recordset));
	pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs";
	pConn->Open("","","",adConnectUnspecified);
	for(int i=m;i>0;i--)
	{
		xia=i*2;

		for(int j=0;j<i;j=j++)
		{
			tail=m_edit1.Mid(j*2,xia-j*2);
			temp.Format("select * from word where word='%s'",tail);
	
			pRst=pConn->Execute(_bstr_t(temp),NULL,adCmdText);
			if(pRst->rsEOF)
			{
				if(everytime)
				{
					CString msg;
					msg.Format("%s%s",tail,"   没有找到   ");
					listpoint->ResetContent();
					listpoint->AddString(tail);
				//	MessageBox(msg);
					MessageBox("   没有找到   ");
				}
				continue;
			}
			else
			{
				temp2=m_edit1.Mid(j*2,(i-j)*2);
				CString out=temp2;
				temp2=temp2+"。";
				temp3=temp2+temp3;
				i=j+1;
				if(everytime)
				{
					MessageBox(out);
				}
				listpoint->ResetContent();
				listpoint->AddString((_bstr_t)pRst->GetCollect("word"));
				GetDlgItem(IDC_EDIT3)->SetWindowText(temp3);
				break;
			}	
	
		}
	}

	
	pRst->Close();
	pConn->Close();
	pRst.Release();
	pConn.Release();
	CoUninitialize();
	//MessageBox("b2");
	fxover=true;
	fxresult=temp3;
}



void CZidongfenciDlg::OnButton3() 
{
	
	if(zxover&&fxover)
	{
		CString temp1,temp2,temp3,qiyi;
		int m,len1,len2;
		int mark1,mark2,mark1f,mark2f;
		int length;
		int jh1,jh2;
		len1=zxresult.GetLength();
		len2=fxresult.GetLength();
		m=len1>len2?len2:len1;
		m=m/2;
		mark1=mark2=0;
		mark1f=mark2f=0;
		jh1=jh2=0;
		length=sentence.GetLength();
		for(int i=1;i<m;i++)
		{
			temp1=zxresult.Mid(2*(i-1),2);
			temp2=fxresult.Mid(2*(i-1),2);
			if(temp1=="。"&&temp2=="。")
			{
				mark1f=i;
				jh1++;	
			}
			if(temp1==temp2)
			{
				
				continue;
			}
			else
			{
				mark1=i;
				break;
			}
			
		}
		if(mark1==0)
		{
			qiyi="没有歧义字段!";
		}
		else
		{
			mark1=mark1f-jh1;
			for(i=1;i<m;i++)

⌨️ 快捷键说明

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