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

📄 tool.cpp

📁 将最大熵的数据格式转为SVM分类器所需的数据格式
💻 CPP
字号:
// Tool.cpp: implementation of the Tool class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TransData.h"
#include "Tool.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Tool::Tool()
{

}

Tool::~Tool()
{

}

void Tool::Initialize()
{
	CStdioFile fData("data.txt",CFile::modeRead);
	CString strLine;
	while(fData.ReadString(strLine))
	{
		int pos1=strLine.Find(" ");
		int pos2;
		while((pos2=strLine.Find(":",pos1+1))!=-1)
		{
			CString strTemp=strLine.Mid(pos1+1,pos2-pos1-1);
			m_setData.insert(strTemp);
			pos1=strLine.Find(" ",pos2);
			if (pos1==-1||pos1==(strLine.GetLength()-1)) break;
			else
			{
				while(strLine.GetAt(pos1+1)==' ')
				pos1++;
			}
		}
     }
	set<CString>::iterator iterSet=m_setData.begin();
    int count=1;
	for(;iterSet!=m_setData.end();iterSet++,count++)
	{
		CString strCount;
		strCount.Format("%d",count);
		m_mapData.insert(make_pair(*iterSet,strCount));
	}

}

void Tool::Trans()
{
	CStdioFile fOut("data_svm.txt",CFile::modeCreate|CFile::modeWrite);
	CStdioFile fIn("data.txt",CFile::modeRead);
    CString strLine;
	CString strOutLine="";
	while(fIn.ReadString(strLine))
	{
		int pos1=strLine.Find(" ");
		CString strLabel=strLine.Left(pos1);
		if(strLabel=="+1") strLabel="1";
		strOutLine+=strLabel;
        int pos2;
		while((pos2=strLine.Find(":",pos1+1))!=-1)
		{
			CString strTemp1=strLine.Mid(pos1+1,pos2-pos1-1);
			int posTemp=strLine.Find(" ",pos2);
			CString strTemp2=strLine.Mid(pos2+1,posTemp-pos2-1);
			map<CString,CString>::iterator iter=m_mapData.begin();
			iter=m_mapData.find(strTemp1);
			strOutLine=strOutLine+" "+iter->second+":"+strTemp2;
			pos1=strLine.Find(" ",pos2);
			if (pos1==-1||pos1==(strLine.GetLength()-1)) break;
			else
			{
				while(strLine.GetAt(pos1+1)==' ')
					pos1++;
			}

		}
		strOutLine+="\n";
		fOut.WriteString(strOutLine);
		strOutLine="";
	}

    
}

⌨️ 快捷键说明

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