Создание исследовательского прототипа системы идентификации табличных данных
Рефераты >> Программирование и компьютеры >> Создание исследовательского прототипа системы идентификации табличных данных

int String1Compare(AnsiString Str1,AnsiString Str2);

int IsWordInString(AnsiString Word,AnsiString Str,int MaxPayLet);

bool IsQuantity(AnsiString Word);

void ToLists();

TList *BaseL,*DocL;

void nFind(int Index);

AnsiString BaseF,DocF;

bool Compare();

bool GetInfo();

int B[FlowNum][FlowNum];

int D[FlowNum][FlowNum];

int Ids[3][FlowNum];

int United[FlowNum][FlowNum][MaxID];

int Unind[FlowNum][FlowNum];

int FromBaseToDoc[FlowNum][2];

AnsiString MUs[3][FlowNum];

AnsiString Prefix[MUPNum][3];

AnsiString FMU[FlowNum][2*(MUPNum+1)][2];

int PositionsCompare(TPositions Fst,TPositions Snd,int &Numbers);

int StringCompare(int f1,int f2,TPositions Fst,TPositions Snd);

int NumberCompare(int f1,int f2,TPositions Fst,TPositions Snd);

int AnalizeUnitWithMU(AnsiString Unit,int MUIndex,int&Multiplier);

int AnalizePosWithMU(TPositions Fst,int Flow,int MUIndex,int &PosIndex,int &Multiplier);

fastcall TfCompare(TComponent* Owner);

};

int FileSize(AnsiString FileName);

//---------------------------------------------------------------------------

extern PACKAGE TfCompare *fCompare;

//---------------------------------------------------------------------------

#endif

//---------------------------------------------------------------------------

#include <vcl.h>

#pragma hdrstop

#include "Compare.h"

#include "PositionTree.h"

#include "Position.h"

#include "math.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma resource "*.dfm"

const int N=20;

const int X=50;

TfCompare *fCompare;

//---------------------------------------------------------------------------

fastcall TfCompare::TfCompare(TComponent* Owner)

: TForm(Owner)

{

}

//---------------------------------------------------------------------------

void fastcall TfCompare::FormResize(TObject *Sender)

{

sg->DefaultColWidth=(sg->ClientWidth-2)/2;

}

//---------------------------------------------------------------------------

void fastcall TfCompare::Button1Click(TObject *Sender)

{

if(od->Execute()){

ProgressBar1->Max=FileSize(od->FileName);

if(Base)

delete Base;

Base=Load(od->FileName,ProgressBar1);

}

BaseF=od->FileName;

}

//---------------------------------------------------------------------------

void fastcall TfCompare::Button2Click(TObject *Sender)

{

if(od->Execute()){

ProgressBar1->Max=FileSize(od->FileName);

if(Doc)

delete Doc;

Doc=Load(od->FileName,ProgressBar1);

}

DocF=od->FileName;

}

//---------------------------------------------------------------------------

int TfCompare::CheckSum(AnsiString E1,AnsiString E2,int MaxPayLet)

{

int M1[N][N],M2[N][N],Mc2[N][N],Mc1[N][N];

for(int j=0;j<N;j++)

for(int i=0;i<N;i++)

{M1[j][i]=0;M2[j][i]=0;

Mc1[j][i]=0;Mc2[j][i]=0;}

int d1=E1.Length();

int d2=E2.Length();

int da;

int MinIm=min(min(2,max(d1-1,1)),max(d2-1,1));

int MaxMov=(min(d1,d2)*X)/100;

int MinSumIm=MaxMov;

int MinPay=MaxPayLet/(MaxMov+1);

int Oc[N];

for(int i=MaxMov;i>=0;i--) Oc[i]=MinPay*(MaxMov+1-i);

Oc[0]=MaxPayLet;

AnsiString abc=AnsiString();

for(int i=1;i<=d1;i++)

if(E2.Pos(E1[i])!=0&&abc.Pos(E1[i])==0)

abc+=E1[i];

da=abc.Length();

if(da<MaxMov) return(0);

int A[N];

for (int i=1;i<=d1;i++)

M1[i-1][abc.Pos(E1[i])]=1;

for (int i=1;i<=d2;i++)

M2[i-1][abc.Pos(E2[i])]=1;

for(int sd=-MaxMov;sd<=MaxMov;sd++){

for(int j=1;j<=da;j++)

for(int i=max(0,sd);i<min(N,N+sd);i++)

if (M1[i][j]!=0&&M2[i-sd][j]!=0)

{ if(sd>=0) Mc1 [sd][i]++;

if(sd<0) Mc2[-sd][i-sd]++;

}

}

int Mac[N];int Sz1,Sz2;

for(int i=0;i<=MaxMov;i++)

{Mac[i]=0;Sz1=0;Sz2=0;

for(int j=0;j<N;j++)

{if(Mc1[i][j]!=0) Sz1++;

else {Mac[i]+=(Sz1*(Sz1>=MinIm));Sz1=0;}

if(Mc2[i][j]!=0) Sz2++;

else {Mac[i]+=(Sz2*(Sz2>=MinIm));Sz2=0;}

}

}

int Res=0;

for(int i=0;i<=MaxMov;i++) Res=Res+Mac[i];

if(Res<MinSumIm) return(0);

Res=0;

for(int i=0;i<=MaxMov;i++) Res=Res+Mac[i]*Oc[i];

return(Res);

}

bool TfCompare::IsQuantity(AnsiString Word)

{AnsiString Numbers=AnsiString("0527413689");

for(int i=1;i<=Word.Length();i++)

if(Numbers.Pos(Word[i])!=0) return(true);

return(false);

}

int TfCompare::IsWordInString(AnsiString Word,AnsiString Str,int MaxPayLet)

{ int Sum=0;

int SpaceInd=0;

int BestSum=0;

AnsiString Pie;

while(!Str.IsEmpty()){

Str.TrimLeft();

SpaceInd=Str.Pos(' ');

if(SpaceInd!=0){

Pie=Str.SubString(1,Str.Pos(' '));

Str.Delete(1,SpaceInd);

}else{

Pie=Str.Trim();

Str=AnsiString();

}

if(Pie.Trim().IsEmpty()) continue;

Sum=CheckSum(Word,Pie,MaxPayLet);

if(Sum>BestSum) BestSum=Sum;

}

return(BestSum);

}

int TfCompare::String1Compare(AnsiString Str1,AnsiString Str2)

{ AnsiString Pie;

int SpaceInd=0;

int Sum=0;

Str1.Trim();

Str2.Trim();

int Len1=Str1.Length();

int Len2=Str2.Length();

int Base=min(Len1,Len2);

int MaxPayLet=1000/Base;

while(!Str1.IsEmpty()){

Str1.TrimLeft();

SpaceInd=Str1.Pos(' ');

if(SpaceInd!=0){

Pie=Str1.SubString(1,Str1.Pos(' '));

Str1.Delete(1,SpaceInd);

}else{

Pie=Str1.Trim();

Str1=AnsiString();

}

if(Pie.Trim().IsEmpty()) continue;

Sum=Sum+IsWordInString(Pie,Str2,MaxPayLet);

}

return(Sum);

}

int FileSize(AnsiString FileName){

if(!FileExists(ChangeFileExt(FileName,".hdr")))

return(0);

TStringList * Y=new TStringList();

Y->LoadFromFile(ChangeFileExt(FileName,".hdr"));

Y->CommaText=Y->Strings[0];

int R=Y->Strings[1].ToInt();

delete Y;

return(R);

}

void TfCompare::ToLists(){

ProgressBar1->Max=FileSize(DocF);

if(!Base||!Doc)

return;

BaseL->Clear();

DocL->Clear();

Base->TreeWalk(aToList,BaseL);

Doc->TreeWalk(aToList,DocL);

for(int i=0;i<DocL->Count;i++){

ProgressBar1->Position++;

sg->Cells[0][sg->RowCount-1]=((TPositionTree *)DocL->Items[i])->OP();

sg->RowCount++;

}

ProgressBar1->Position=0;

}

void fastcall TfCompare::Button3Click(TObject *Sender)

{

ToLists();

}

//---------------------------------------------------------------------------

void fastcall TfCompare::FormCreate(TObject *Sender)

{

BaseL =new TList();


Страница: