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

📄 segmentview.cpp

📁 对一个文件可以分词的系统
💻 CPP
字号:
// SegmentView.cpp : implementation of the CSegmentView class
//

#include "stdafx.h"
#include "Segment.h"

#include "SegmentDoc.h"
#include "SegmentView.h"
#include "RMMAPI.h"
bool g_bIsSucc=false;
#include "SefFileDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSegmentView

IMPLEMENT_DYNCREATE(CSegmentView, CFormView)

BEGIN_MESSAGE_MAP(CSegmentView, CFormView)
	//{{AFX_MSG_MAP(CSegmentView)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_COMMAND(ID_SEGFILE, OnSegfile)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSegmentView construction/destruction

CSegmentView::CSegmentView()
	: CFormView(CSegmentView::IDD)
{
	//{{AFX_DATA_INIT(CSegmentView)
	m_strToSeg = _T("");
	m_strSeged = _T("");
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CSegmentView::~CSegmentView()
{
	if ( g_bIsSucc ){
		RMMExit();
	}
}

void CSegmentView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSegmentView)
	DDX_Control(pDX, IDC_LIST1, m_ctrResult);
	DDX_Text(pDX, IDC_EDIT1, m_strToSeg);
	DDX_Text(pDX, IDC_EDIT2, m_strSeged);
	//}}AFX_DATA_MAP
}

BOOL CSegmentView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CSegmentView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
	if ( RMMInit("segment.idx","segment.dat") ){
		g_bIsSucc=true;
	}
}

/////////////////////////////////////////////////////////////////////////////
// CSegmentView printing

BOOL CSegmentView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CSegmentView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CSegmentView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CSegmentView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CSegmentView diagnostics

#ifdef _DEBUG
void CSegmentView::AssertValid() const
{
	CFormView::AssertValid();
}

void CSegmentView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CSegmentDoc* CSegmentView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSegmentDoc)));
	return (CSegmentDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSegmentView message handlers

void CSegmentView::OnButton1() 
{
	UpdateData(true);
	if ( m_strToSeg.IsEmpty() ){
		AfxMessageBox("请输入待切分句子");
		return;
	}
	char szSeged[1024];
	RMMMain(m_strToSeg.GetBuffer(1024),szSeged);
	m_strSeged=szSeged;
	UpdateData(false);
	
}

void CSegmentView::OnButton2() 
{
	UpdateData(true);
	if ( !m_strSeged.IsEmpty() ){
		if ( m_ctrResult.FindString(-1,m_strSeged) == LB_ERR )
			m_ctrResult.AddString(m_strSeged);
	}
	UpdateData(false);
	
}

void CSegmentView::OnSegfile() 
{
	CSefFileDlg obSefFileDlg;
	if ( obSefFileDlg.DoModal() == IDOK ){
		char psInp[1024];
		char psOut[1024];
		strcpy(psInp,obSefFileDlg.m_strInp);
		strcpy(psOut,obSefFileDlg.m_strOut);

        FILE* fp=fopen(psInp,"rb");
        FILE* fpO=fopen(psOut,"wb");
        if(!fp) return;
        
        char sWord[2000];
        char sSegmented[2000];

        while(!feof(fp)){
            fscanf(fp,"%s",sWord);
            RMMMain(sWord,sSegmented);
            fprintf(fpO,"%s\r\n",sSegmented);
        }
        fclose(fp);
        fclose(fpO);
		
		sprintf(sSegmented,"notepad.exe %s",psOut);
		WinExec(sSegmented,SW_SHOW);
	}
	
}

⌨️ 快捷键说明

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