📄 svmclsdoc.cpp
字号:
// svmclsDoc.cpp : implementation of the CSvmclsDoc class
//
#include "stdafx.h"
#include "svmcls.h"
#include "svmclsDoc.h"
#include "leftview.h"
#include "svmclsview.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSvmclsDoc
IMPLEMENT_DYNCREATE(CSvmclsDoc, CDocument)
BEGIN_MESSAGE_MAP(CSvmclsDoc, CDocument)
//{{AFX_MSG_MAP(CSvmclsDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSvmclsDoc construction/destruction
CSvmclsDoc::CSvmclsDoc()
{
// TODO: add one-time construction code here
}
CSvmclsDoc::~CSvmclsDoc()
{
}
BOOL CSvmclsDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
CSvmclsView* pClsView=NULL;
CLeftView *pLeftView=NULL;
POSITION pos = GetFirstViewPosition();
while (pos != NULL)
{
CView *pViews = GetNextView(pos);
if(pViews->IsKindOf(RUNTIME_CLASS(CSvmclsView)))
pClsView=(CSvmclsView*)pViews;
else if(pViews->IsKindOf(RUNTIME_CLASS(CLeftView)))
pLeftView=(CLeftView*)pViews;
}
if((pClsView!=NULL)&&(pLeftView!=NULL))
{
m_strResultPath="";
m_strMatrixName="";
m_straryMatrix.RemoveAll();
m_strClsName="";
m_strTrainName="";
m_strTestName="";
m_strWordName="";
m_nClassierNum=0;
m_nClassierType=2;
m_nMultiSVMType=-1;
pLeftView->ListTrain();
pClsView->SetWindowText(NULL);
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CSvmclsDoc serialization
void CSvmclsDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
CFile *fOut=ar.GetFile();
char szNewLine[]="\r\n";
CString strOut=_T("path=")+m_strResultPath;
fOut->Write(strOut,strOut.GetLength());
fOut->Write(szNewLine,2);
strOut.Format("%d",m_nClassierNum);
strOut=_T("num=")+strOut;
fOut->Write(strOut,strOut.GetLength());
fOut->Write(szNewLine,2);
strOut=_T("matrix=")+m_strMatrixName;
fOut->Write(strOut,strOut.GetLength());
fOut->Write(szNewLine,2);
strOut=_T("catalog=")+m_strClsName;
fOut->Write(strOut,strOut.GetLength());
fOut->Write(szNewLine,2);
strOut=_T("train=")+m_strTrainName;
fOut->Write(strOut,strOut.GetLength());
fOut->Write(szNewLine,2);
strOut=_T("test=")+m_strTestName;
fOut->Write(strOut,strOut.GetLength());
fOut->Write(szNewLine,2);
strOut=_T("feature=")+m_strWordName;
fOut->Write(strOut,strOut.GetLength());
fOut->Write(szNewLine,2);
strOut.Format("%d",m_nClassierType);
strOut=_T("type=")+strOut;
fOut->Write(strOut,strOut.GetLength());
fOut->Write(szNewLine,2);
if(m_nMultiSVMType>=0)
{
strOut.Format("%d",m_nMultiSVMType);
strOut=_T("msvm=")+strOut;
fOut->Write(strOut,strOut.GetLength());
fOut->Write(szNewLine,2);
}
}
else
{
CFile *f=ar.GetFile();
long flen=f->GetLength();
CString buffer;
CStringArray alllines;
f->Read(buffer.GetBuffer(flen),flen);
buffer.ReleaseBuffer();
int linehead=0;
long i;
CString temp;
for(i=0; i<flen; i++)
{
if( buffer.GetAt(i)=='\n')
{
temp=buffer.Mid(linehead,i-linehead-1);
temp.TrimLeft();
temp.TrimRight();
if(!temp.IsEmpty()) alllines.Add(temp);
linehead=i+1;
}
}
if((i-linehead)>0)
{
temp=buffer.Mid(linehead,i-linehead);
temp.TrimLeft();
temp.TrimRight();
if(!temp.IsEmpty())
alllines.Add(temp);
}
if(FindData(alllines,"num",temp))
m_nClassierNum=atoi(temp.GetBuffer(0));
else
m_nClassierNum=0;
char buf[MAX_PATH];
if(!FindData(alllines,"path",m_strResultPath))
{
GetCurrentDirectory(MAX_PATH,buf);
m_strResultPath=buf;
}
if(!FindData(alllines,"catalog",m_strClsName))
m_strClsName=_T("class.txt");
if(!FindData(alllines,"feature",m_strWordName))
m_strWordName=_T("feature.txt");
if(!FindData(alllines,"matrix",m_strMatrixName))
m_strMatrixName=_T("matrix.txt");
if(!FindData(alllines,"train",m_strTrainName))
m_strTrainName=_T("train");
if(!FindData(alllines,"test",m_strTestName))
m_strTestName=_T("test.tst");
if(!FindData(alllines,"type",temp))
m_nClassierType=2;
else
m_nClassierType=atoi(temp);
if(!FindData(alllines,"msvm",temp))
m_nMultiSVMType=-1;
else
m_nMultiSVMType=atoi(temp);
FILE *stream;
char c;
buffer=m_strResultPath+"\\"+m_strMatrixName;
stream=fopen(buffer,"r");
if(stream!=NULL)
{
while(!feof(stream))
{
temp="";
while((c=getc(stream)) != EOF)
{
if(c == '\n')
break;
else
temp=temp+c;
}
if(!temp.IsEmpty()) m_straryMatrix.Add(temp);
}
fclose(stream);
}
}
}
BOOL CSvmclsDoc::FindData(CStringArray &strarray,CString s,CString &t)
{
BOOL rtn=FALSE;
CString temp1,temp2;
int i,pos;
for(i=0;i<strarray.GetSize();i++)
{
temp1=strarray[i];
pos=temp1.Find("=");
if(pos>=0)
{
temp2=temp1.Left(pos);
temp2.TrimLeft();
temp2.TrimRight();
if(temp2.CompareNoCase(s)==0)
{
t=temp1.Right(temp1.GetLength()-pos-1);
t.TrimLeft();
t.TrimRight();
rtn=TRUE;
}
}
}
return rtn;
}
/////////////////////////////////////////////////////////////////////////////
// CSvmclsDoc diagnostics
#ifdef _DEBUG
void CSvmclsDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CSvmclsDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSvmclsDoc commands
BOOL CSvmclsDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
/*POSITION pos = GetFirstViewPosition();
while (pos != NULL)
{
CView* pView = GetNextView(pos);
if(pView->IsKindOf(RUNTIME_CLASS(CLeftView)))
{
((CLeftView*)pView)->ListTrian();
}
}*/
return TRUE;
}
void CSvmclsDoc::SetTitle(LPCTSTR lpszTitle)
{
// TODO: Add your specialized code here and/or call the base class
CDocument::SetTitle("");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -