📄 liesamplerecognise.cpp
字号:
// Liesamplerecognise.cpp : implementation of the CLieSampleRecognise class
//
#include "stdafx.h"
#include "Rset.h"
//#include "msflexgrid.h"
//#include "afximpl.h"
#include "Liesamplerecognise.h"
#include "fstream.h"
#include <math.h>
#include <stdlib.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define MAX 30
/////////////////////////////////////////////////////////////////////////////
// CLieSampleRecognise
/////////////////////////////////////////////////////////////////////////////
// CLieSampleRecognise construction/destruction
CLieSampleRecognise::CLieSampleRecognise()
{
// TODO: add one-time construction code here
pIntTable = NULL;
pFloatTable = NULL;
pStringTable = NULL;
pRuleTable = NULL;
pBlockTable = NULL;
pRecogniseResultTable = NULL;
pAttName = NULL;
pDataType = NULL;
pAttReduce = NULL;
struCutRecord = NULL;
iChar = 0;
iFloat = 0;
iInteger = 0;
iRecordNum = 0;
iAttNum = 0;
iRuleNum = 0;
iBlockNum = 0;
iTestNum = 0;
iStringCol = 0;
iStringRow = 0;
iStage = -1;
iTestConflict = 0;
iTestRight = 0;
iTestError = 0;
iDentifyRight = 0;
iDentifyError = 0;
iDentifyNone = 0;
bDiscrete = FALSE;
bIncompletion = FALSE;
bSaveTempResult = FALSE;
bBatch = FALSE;
bCuts = FALSE;
bTest = FALSE;
bBlock = FALSE;
iCol = 0;
iRow = 0;
atb=0;
}
CLieSampleRecognise::~CLieSampleRecognise()
{
TRACE("~liesamplerecognise\n");
// TODO: Add your specialized code here and/or call the base class
//释放pStringTable
if(pStringTable != NULL)
{
for(int i = 0;i < iStringRow;i++)
{
for(int j = 0;j < iStringCol;j++)
delete[] pStringTable[i][j];
}//end for
for(i = 0;i < iStringRow;i++)
delete[] pStringTable[i];
delete[] pStringTable;
}//end if
//释放pFloatTable
if(pFloatTable != NULL)
{
for(int i = 0;i < iRecordNum;i++)
delete[] pFloatTable[i];
delete[] pFloatTable;
}//end if
//释放pIntTable
if(pIntTable != NULL)
{
for(int i = 0;i < iRecordNum;i++)
delete[] pIntTable[i];
delete[] pIntTable;
}//end if
//释放pAttName
if(pAttName != NULL)
{
for(int i = 0;i < iAttNum+1;i++)
delete[] pAttName[i];
delete[] pAttName;
}//end if
//释放pDataType
if(pDataType != NULL)
{
for(int i = 0;i < iAttNum+1;i++)
delete[] pDataType[i];
delete[] pDataType;
}
//释放struCutRecord
struct CutRecord* pHead;
while(struCutRecord != NULL)
{
pHead = struCutRecord->p;
for(int i = 0;i < struCutRecord->iCuts;i++)
delete[] struCutRecord->cpCut[i];
delete[] struCutRecord->cpCut;
delete struCutRecord;
struCutRecord = pHead;
}
//释放pRuleTable
if(pRuleTable != NULL)
{
for(int i = 0;i < iRuleNum;i++)
{
for(int j = 0;j < iAttNum+4;j++)
delete[] pRuleTable[i][j];
}//end for
for(i = 0;i < iRuleNum;i++)
delete[] pRuleTable[i];
delete[] pRuleTable;
}//end if
//释放pBlockTable
if(pBlockTable != NULL)
{
for(int i = 0;i < iBlockNum;i++)
{
for(int j = 0;j < iAttNum+1;j++)
delete[] pBlockTable[i][j];
}//end for
for(i = 0;i < iBlockNum;i++)
delete[] pBlockTable[i];
delete[] pBlockTable;
}//end if
if(pRecogniseResultTable!=NULL)
{
for(int i=0;i<iTestNum;i++)
{
delete[] pRecogniseResultTable[i][0];
delete[] pRecogniseResultTable[i][1];
delete[] pRecogniseResultTable[i];
}
delete [] pRecogniseResultTable;
}
if(atb)
delete[] atb;
}
/////////////////////////////////////////////////////////////////////////////
// CLieSampleRecognise serialization
/////////////////////////////////////////////////////////////////////////////
// CLieSampleRecognise diagnostics
#ifdef _DEBUG
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CLieSampleRecognise commands
BOOL CLieSampleRecognise::LoadRuleFile(LPCTSTR lpszPathName)
{//将规则文件读入
TRACE("load rule file\n");
FILE* fp;
if((fp = fopen(lpszPathName,"r")) == NULL)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Couldn't open the file",MB_OK|MB_ICONSTOP);
return FALSE;
}//end if
fscanf(fp,"Style:%s\n",cStyle);
fscanf(fp,"Stage:%d\n",&iStage);
fscanf(fp,"Condition attributes number:%d\n",&iAttNum);
fscanf(fp,"The Number of Condition attributes deleted: %d\n",&atbcount);
fscanf(fp,"The position of Condition attributes deleted:");
// char p;
// fscanf(fp,"%c",&p);
// while(p!=':')
// fscanf(fp," %c",&p);
if(atbcount!=0)
{
atb=new int[atbcount];
for(int n=0;n<atbcount;n++)
fscanf(fp," %d",&atb[n]);
}
//////////////////////////////////
if(_stricmp(cStyle,"rule") == 0)
{
fscanf(fp," Rules number:%d\n",&iRuleNum);
fscanf(fp," Blocks number:%d\n",&iBlockNum);
if(atbcount!=0)
{
if(!SetAttName1(fp,atbcount+iAttNum+1,atb,atbcount))
{//atb:删除了的属性表 atbcount:删除了的属性数目
fclose(fp);
return FALSE;
}
if(!SetDataType1(fp,atbcount+iAttNum+1,atb,atbcount))
{
fclose(fp);
return FALSE;
}
iAttNum=iAttNum+atbcount;//得到属性数目为原始的属性数目
SetRuleTable1(fp,iAttNum+4,iRuleNum,atb,atbcount);//设置规则表
char temp[MAX];
if(fscanf(fp,"%s",temp) == -1)
{//文件结束
fclose(fp);
return TRUE;
}
if(strcmp(temp,"[Blocks]") != 0)
{//没有封锁事实
fclose(fp);
return TRUE;
}
if(iBlockNum != 0)
{//封锁事实数目不为0
bBlock = TRUE;
SetBlockTable1(fp,iAttNum+1,iBlockNum,atb,atbcount);//设置封锁事实表
}
iStringCol = iAttNum + 1;
}
else//删除属性数目为0
{
if(!SetAttName(fp,iAttNum+1))
{
fclose(fp);
return FALSE;
}
if(!SetDataType(fp,iAttNum+1))
{
fclose(fp);
return FALSE;
}
SetRuleTable(fp,iAttNum+4,iRuleNum);
char temp[MAX];
if(fscanf(fp,"%s",temp) == -1)
{
fclose(fp);
return TRUE;
}
if(strcmp(temp,"[Blocks]") != 0)
{
fclose(fp);
return TRUE;
}
if(iBlockNum != 0)
{
bBlock = TRUE;
SetBlockTable(fp,iAttNum+1,iBlockNum);
}
iStringCol = iAttNum + 1;//列数,为条件属性和决策属性
}
}//end if
else//不为rule,报错!
{
AfxMessageBox("not correct rule file!",MB_OK|MB_ICONSTOP);
TRACE("not correct rule file!");
return FALSE;
}//end else
fclose(fp);
return TRUE;
}
BOOL CLieSampleRecognise::LoadInputFile(LPCTSTR lpszPathName)
{//读入输入的待识别样本文件'Input'类型
TRACE("InitDoc\n");
FILE* fp;
if((fp = fopen(lpszPathName,"r")) == NULL)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Couldn't open the file",MB_OK|MB_ICONSTOP);
return FALSE;
}//end if
fscanf(fp,"Style:%s\n",cStyle);
fscanf(fp,"Stage:%d\n",&iStage);
fscanf(fp,"Condition attributes number:%d\n",&iAttNum);
if(stricmp(cStyle,"input")==0)
{//待识别样本文件
fscanf(fp,"Tests number:%d\n",&iTestNum);
//释放pStringTable
if(pStringTable != NULL)
{//释放表空间,重新初始化
for(int i = 0;i < iStringRow;i++)
{
for(int j = 0;j < iStringCol;j++)
delete[] pStringTable[i][j];
}//end for
for(i = 0;i < iStringRow;i++)
delete[] pStringTable[i];
delete[] pStringTable;
}//end if
pStringTable = NULL;
if(atbcount!=0)//规则中删除了的属性数目不为0
{
if(!SetAttName1(fp,iAttNum,0,0))
{
fclose(fp);
return FALSE;
}
if(!SetDataType1(fp,iAttNum,0,0))
{
fclose(fp);
return FALSE;
}
SetStringTable(fp,iAttNum,iTestNum);
iStringCol = iAttNum;//行为属性数目
iStringRow = iTestNum;//列为测试样本数目
}
else
{//atbcount==0
if(!SetAttName(fp,iAttNum))
{
fclose(fp);
return FALSE;
}
if(!SetDataType(fp,iAttNum))
{
fclose(fp);
return FALSE;
}
SetStringTable(fp,iAttNum,iTestNum);
iStringCol = iAttNum;
iStringRow = iTestNum;
}
}
else
{//输入文件类型错误
AfxMessageBox("Line 1 of the file has error!",MB_OK|MB_ICONSTOP);
fclose(fp);
return FALSE;
}//end else
fclose(fp);
return TRUE;
}
BOOL CLieSampleRecognise::LoadTestFile(LPCTSTR lpszPathName)
{//读入测试文件.类型为:'test'
TRACE("InitDoc\n");
FILE* fp;
if((fp = fopen(lpszPathName,"r")) == NULL)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Couldn't open the file",MB_OK|MB_ICONSTOP);
return FALSE;
}//end if
fscanf(fp,"Style:%s\n",cStyle);
fscanf(fp,"Stage:%d\n",&iStage);
fscanf(fp,"Condition attributes number:%d\n",&iAttNum);
if(_stricmp(cStyle,"test") == 0)
{
fscanf(fp,"Tests number:%d\n",&iTestNum);
//释放pStringTable
if(pStringTable != NULL)
{
for(int i = 0;i < iStringRow;i++)
{
for(int j = 0;j < iStringCol;j++)
delete[] pStringTable[i][j];
}//end for
for(i = 0;i < iStringRow;i++)
delete[] pStringTable[i];
delete[] pStringTable;
}//end if
pStringTable = NULL;
//改变了函数的数值
if(atbcount!=0)
{
if(!SetAttName1(fp,iAttNum+1,0,0))
{
fclose(fp);
return FALSE;
}
if(!SetDataType1(fp,iAttNum+1,0,0))
{
fclose(fp);
return FALSE;
}
SetStringTable(fp,iAttNum+1,iTestNum);
iStringCol = iAttNum + 1;
iStringRow = iTestNum;
}
else
{
if(!SetAttName(fp,iAttNum+1))
{
fclose(fp);
return FALSE;
}
if(!SetDataType(fp,iAttNum+1))
{
fclose(fp);
return FALSE;
}
SetStringTable(fp,iAttNum+1,iTestNum);
iStringCol = iAttNum + 1;
iStringRow = iTestNum;
}
}
else
{
AfxMessageBox("Line 1 of the file has error!",MB_OK|MB_ICONSTOP);
fclose(fp);
return FALSE;
}//end else
fclose(fp);
return TRUE;
}
BOOL CLieSampleRecognise::SetStringTable(FILE* fp, int column, int row)
{
TRACE("SetStringTable\n");
long int i,j;
if(pStringTable == NULL)
{
try
{
pStringTable = new char**[row];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of memory12!",MB_OK|MB_ICONSTOP);
e->Delete();
return FALSE;//FALSE:0
}
for(i = 0;i < row;i++)
{
try
{
pStringTable[i] = new char*[column];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of memory0!",MB_OK|MB_ICONSTOP);
e->Delete();
return FALSE;
}
for(j = 0;j < column;j++)
{
try
{
pStringTable[i][j] = new char[20];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of memory1!",MB_OK|MB_ICONSTOP);
e->Delete();
return FALSE;
}
strcpy(pStringTable[i][j]," ");//初始化
}//end for
}//end for
}//end if
for(i = 0;i < row;i++)
for(j = 0;j < column;j++)
{
fscanf(fp,"%s",pStringTable[i][j]);//以字符串形式读入数据
if(j==column)
{int k=0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -