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

📄 zidongfencidlg.cpp

📁 这个是我们的中文信息处理的作业
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			{
				temp1=zxresult.Mid((m-i)*2,2);
				temp2=fxresult.Mid((m-i)*2,2);
				if(temp1=="。"&&temp2=="。")
				{
					mark2f=i;
					jh2++;
				}
				if(temp1==temp2)
				{
					continue;
				}
				else
				{
					mark2=i;
					mark2=mark2f-jh2;
					break;
				}
			}
			qiyi=sentence.Mid(mark1*2,length-mark2*2-mark1*2);
			
		}
		
	
		GetDlgItem(IDC_EDIT4)->SetWindowText(qiyi);
		MessageBox("   !分词结束!");

	}
	else
	{
		MessageBox("请先做完正向和反向匹配!");
		return;
	}
	
}

void CZidongfenciDlg::OnRadio1() 
{
	// TODO: Add your control notification handler code here
	if(!everytime)
	{
		((CButton *)GetDlgItem(IDC_RADIO1))->SetCheck(FALSE);
		everytime=true;
	}
	else
	{
		everytime=false;
		((CButton *)GetDlgItem(IDC_RADIO1))->SetCheck(TRUE);
	}
}

void CZidongfenciDlg::OnButton4() 
{
	Copenfile file(TRUE, "", NULL, 
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT, 
		"TXT文本(三次取消后返回)(*.txt)|*.txt|所有文件(*.*)|*.*||",
		AfxGetMainWnd());
		CString strFile;
		int count=0;
		while(file.DoModal () != IDOK)
		{
			count++;
			if(count==3)
			{
				return;
			}
		}
		POSITION pos = file.GetStartPosition();
		strFile = file.GetNextPathName(pos);
		filename=strFile;
		browse();
}

void CZidongfenciDlg::browse()
{
	CString word="";
	CString temp1="",temp2="";
	CStdioFile file;
	int place=0;
	file.Open(filename,CFile::modeRead);
	m_list2.ResetContent();
	while(file.Read(word.GetBuffer(2),2))
	{
		if(word==","||word=="。"||word==":"||word==";")
		{
			temp1.Format("%s%s",temp2,word);
			temp2=temp1;
			//m_list2.AddString(temp2);
			m_list2.InsertString(place,temp2);
			place++;
			temp1=temp2="";
			MessageBox("ff");
		}
		else
		{
			temp1.Format("%s%s",temp2,word);
			temp2=temp1;	
		}
		word="";
	}

	file.Close();
}

void CZidongfenciDlg::OnRadio2() 
{
	if(savehang==0)
	{
		savehang=1;
		((CButton *)GetDlgItem(IDC_RADIO2))->SetCheck(TRUE);
	}
	else
	{
		savehang=0;
		((CButton *)GetDlgItem(IDC_RADIO2))->SetCheck(FALSE);
	}
}



void CZidongfenciDlg::OnButton5() 
{
	CString	temp,temp1;
	CString zhresult,fanresult,qiyi;
	int time;
	time=m_list2.GetCount();
	m_list3.ResetContent();
	m_list4.ResetContent();
	m_list5.ResetContent();

	for(int i=0;i<time;i++)
	{
		m_list2.GetText(i,temp);
		temp1=temp;
		zhresult=zhxfenci(temp);
		fanresult=fanxfenci(temp1);
	//	MessageBox(zhresult);
		m_list4.AddString(zhresult);
		m_list5.AddString(fanresult);
		
		qiyi=qiyiqufen(zhresult,fanresult,temp);
		m_list3.AddString(qiyi);
	}
	CString savename;
	CString f1,f2;
	f1=filename.Mid(0,filename.GetLength()-4);
	f2=filename.Mid(filename.GetLength()-4,4);
	savename.Format("%s%s%s",f1,"歧义结果",f2);
	int line=m_list3.GetCount();
	CString temp2;
	CStdioFile file;
	file.Open(savename,CFile::modeCreate);
	file.Close();
	file.Open(savename,CFile::modeWrite);
	for(i=0;i<line;i++)
	{	
		m_list3.GetText(i,temp1);		
		temp2=temp1.Mid(0,temp1.GetLength());
		file.WriteString(temp2);
		if(savehang)
		{
			file.WriteString("\n");
		}
	}
	file.Close();
	
}

CString CZidongfenciDlg::zhxfenci(CString juzi)
{
	int m;
	int shang ,zhong ,xia;
	CString head,headjia;
	CString temp ,temp2,temp3;
	m=juzi.GetLength()/2;
	shang=zhong=xia=0;
	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=i+1;j<=m;j++)
		{
			head=juzi.Mid(shang,(j-i)*2);
			if(j==m)
			{
				head=head+"、";
				temp3=temp3+head;
				return temp3;
			}
			else
			{
				headjia=juzi.Mid(shang,(j-i+1)*2);
			}

			temp.Format("select * from word where word like '%s%s'",headjia,"%");
	
			pRst=pConn->Execute(_bstr_t(temp),NULL,adCmdText);
			if(pRst->rsEOF)
			{
				head=head+"、";
				temp3=temp3+head;
				i=j-1;
				break;
			}
			else
			{
				continue;
			}

		}
	}

	/*
	for(int i=0;i<m;i++)
	{
		shang=i*2;

		for(int j=m;j>i;j--)
		{
			head=juzi.Mid(shang,(j-i)*2);
			temp.Format("select * from word where word='%s'",head);
	
			pRst=pConn->Execute(_bstr_t(temp),NULL,adCmdText);
			if(pRst->rsEOF)
			{
				continue;
			}
			else
			{
				temp2=juzi.Mid(i*2,head.GetLength());
				CString out=temp2;
				temp2=temp2+"、";
				temp3=temp3+temp2;
				i=j-1;
			
				break;
			}	
		
		}
	}
*/
	
	pRst->Close();
	pConn->Close();
	pRst.Release();
	pConn.Release();
	CoUninitialize();
	return temp3;		
}

CString CZidongfenciDlg::fanxfenci(CString juzi)
{
	int m;
	m=juzi.GetLength()/2;
	int shang,zhong,xia;
	shang=zhong=xia=0;
	CString temp,tail,temp2,temp3,tailjia;
	//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=i-1;j>=0;j--)
		{
			tail=juzi.Mid(j*2,xia-j*2);
			if(j==0)
			{
				tail=tail+"、";
				temp3=tail+temp3;
				return temp3;
			}
			else
			{
				tailjia=juzi.Mid((j-1)*2,xia-(j-1)*2);
			}

			temp.Format("select * from word where word like '%s%s'","%",tailjia);
	
			pRst=pConn->Execute(_bstr_t(temp),NULL,adCmdText);
			if(pRst->rsEOF)
			{
				tail=tail+"、";
				temp3=tail+temp3;
				i=j+1;
				break;
			}
			else
			{
				continue;
			}

		}
		
	}

	/*for(int i=m;i>0;i--)
	{
		xia=i*2;

		for(int j=0;j<i;j=j++)
		{
			tail=juzi.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)
			{
				continue;
			}
			else
			{
				temp2=juzi.Mid(j*2,(i-j)*2);
				CString out=temp2;
				temp2=temp2+"、";
				temp3=temp2+temp3;
				i=j+1;
				//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");
	return temp3;

}

CString CZidongfenciDlg::qiyiqufen(CString s1, CString s2,CString s)
{
		CString temp1,temp2,temp3,qiyi;
		int m,len1,len2;
		int mark1,mark2,mark1f,mark2f;
		int length;
		int jh1,jh2;
		CString qiyiju;
		len1=s1.GetLength();
		len2=s2.GetLength();
		m=len1>len2?len2:len1;
		m=m/2;
		mark1=mark2=0;
		mark1f=mark2f=0;
		jh1=jh2=0;
		length=s.GetLength();
		for(int i=1;i<m;i++)
		{
			temp1=s1.Mid(2*(i-1),2);
			temp2=s2.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++)
			{
				temp1=s1.Mid((m-i)*2,2);
				temp2=s2.Mid((m-i)*2,2);
				if(temp1=="、"&&temp2=="、")
				{
					mark2f=i;
					jh2++;
				}
				if(temp1==temp2)
				{
					continue;
				}
				else
				{
					mark2=i;
					mark2=mark2f-jh2;
					break;
				}
			}
			qiyi=s.Mid(mark1*2,length-mark2*2-mark1*2);
			CString head=s.Mid(0,mark1*2);
			CString tail=s.Mid(mark1*2+qiyi.GetLength(),length-mark1*2-qiyi.GetLength());
			
			qiyiju.Format("%s%s%s%s%s",head," [",qiyi,"] ",tail);
			
		}
		
	
		return qiyiju;
}

⌨️ 快捷键说明

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