2
Copyright (c) 1993-2008, Cognitive Technologies
5
����������� ��������� ��������������� � ������������� ��� � ���� ��������� ����,
6
��� � � �������� �����, � ����������� ��� ���, ��� ���������� ��������� �������:
8
* ��� ��������� ��������������� ��������� ���� ������ ���������� ���������
9
���� ����������� �� ��������� �����, ���� ������ ������� � �����������
11
* ��� ��������� ��������������� ��������� ���� � ������������ �/��� �
12
������ ����������, ������������ ��� ���������������, ������ �����������
13
��������� ���� ���������� �� ��������� �����, ���� ������ ������� �
14
����������� ����� �� ��������.
15
* �� �������� Cognitive Technologies, �� ����� �� ����������� �� �����
16
���� ������������ � �������� �������� ��������� �/��� �����������
17
���������, ���������� �� ���� ��, ��� ���������������� �����������
20
��� ��������� ������������� ����������� ��������� ���� �/��� ������� ������ "���
21
��� ����" ��� ������-���� ���� ��������, ���������� ���� ��� ���������������,
22
������� �������� ������������ �������� � ����������� ��� ���������� ����, �� ��
23
������������� ���. �� �������� ��������� ���� � �� ���� ������ ����, �������
24
����� �������� �/��� �������� �������������� ���������, �� � ���� ������ ��
25
��Ѩ� ���������������, ������� ����� �����, ���������, ����������� ���
26
������������� ������, ��������� � �������������� ��� ���������� ����������
27
������������� ������������� ��������� (������� ������ ������, ��� ������,
28
������� ���������, ��� ������ �/��� ������ �������, ���������� ��-�� ��������
29
������� ��� �/��� ������ ��������� �������� ��������� � ������� �����������,
30
�� �� ������������� ����� ��������), �� �� ������������� ���, ���� ���� �����
31
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
33
Redistribution and use in source and binary forms, with or without modification,
34
are permitted provided that the following conditions are met:
36
* Redistributions of source code must retain the above copyright notice,
37
this list of conditions and the following disclaimer.
38
* Redistributions in binary form must reproduce the above copyright notice,
39
this list of conditions and the following disclaimer in the documentation
40
and/or other materials provided with the distribution.
41
* Neither the name of the Cognitive Technologies nor the names of its
42
contributors may be used to endorse or promote products derived from this
43
software without specific prior written permission.
45
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
46
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
49
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57
//#define _SAVE_INVALID_CLU_
69
#include "cstr.h" // OLEG
79
extern char alphabet[256];
80
extern BYTE decode_ASCII_to_[256][4];
81
static int HndTab=0, HndTabInc=0;
82
static char alpha_str[]="��������������������������������/0123456789��������������������������������#%^()";
83
static char alpha_str_lat[]="QWERTYUIOPASDFGHJKLZXCVBNM/0123456789qwertyuiopasdfghjklzxcvbnm#%^()";
84
static char alpha_str_cap[]="��������������������������������";
85
static char alpha_str_lat_cap[]="QWERTYUIOPASDFGHJKLZXCVBNM";
86
static char alpha_str_all_cap[]="��������������������������������QWERTYUIOPASDFGHJKLZXCVBNM";
87
static char alphabet1[256];
89
void set_alphabet(unsigned char *alpha,unsigned char *letters)
95
alpha[ *letters++ ] = 1;
100
static void print_method(FILE *fp,RecVersions *res,char *s,int ansi)
109
fprintf(fp,"%c(%d)",ansi?stdAnsiToAscii(res->Alt[0].Code):res->Alt[0].Code,res->Alt[0].Prob);
110
for(ii=1;ii<res->lnAltCnt;ii++)
112
fprintf(fp,",%c(%d)",ansi?stdAnsiToAscii(res->Alt[ii].Code):res->Alt[ii].Code,res->Alt[ii].Prob);
118
Bool32 TestFontProtocol(void)
126
LeoFieldSetup fs={0};
132
if( _access("c:\\met.ini",0)==-1 )
135
nClust=FONGetClustCount();
137
set_alphabet(alphabet1, alpha_str);
140
fs.nStyle = LS_PRINT;
141
memcpy(fs.AlphaTable,alphabet1,256);
143
CTB_unlink("CLUST2");
145
fp=fopen(".\\clu_met.pro","wt");
146
for(i=0,nC=numCourier=0;i<nClust;i++)
151
FONGetClusterAsBW(&name,i,jj*25,&rec);
152
CTB_AddRecRaster("CLUST2", &rec,decode_ASCII_to_[name][0]);
153
memset(&ro,0,sizeof(RecObject));
154
memcpy(&ro.recData.recRaster,&rec,REC_MAX_RASTER_SIZE);
156
ro.recData.lwStatus=0;
158
fprintf(fp,"Nclu=%d(%d) let=%c tresh=%d%s\n",i,i*3+jj, name, jj,jj?"":"(default)" );
160
LEORecogPrintChar(&ro);
161
print_method(fp,&ro.recResults," leo : ",1);
164
LEORecogPrnMethod( &ro , REC_METHOD_MSK, 1);
165
print_method(fp,&ro.recResults," msk : ",0);
167
LEORecogCharDebug( &ro );
168
print_method(fp,&ro.recResults," evn+3x5 : ",1);
178
Bool32 TestFontCourier(void)
186
int porog=0; // test !!!
191
Int32 nf=FONGetFontCount();
195
nClust=FONGetClustCount();
201
MSKSetAlphabet ( alphabet );
203
for(i=0,nC=numCourier=0;i<nClust;i++)
206
j=FONGetClusterAsBW(&name,i,porog,&recRast);
210
if( name>'9' && name<128 )
212
clustinfo.let = 0; // from all clusters
213
FONGetClustInfo( &clustinfo, i+1 );
214
if( clustinfo.weight<3 )
217
CTB_AddRecRaster("CLUST2", &recRast,decode_ASCII_to_[name][0]);
219
MSKres.lnAltMax=REC_MAX_VERS;
220
MSKres.Alt[0].Code=(Word8)to_upper((Word8)name);
221
MSKres.Alt[0].Prob=255;
222
MSKres.Alt[1].Code=(Word8)to_lower((Word8)name);
223
MSKres.Alt[1].Prob=255;
225
if(!MSKRecogCharExp( HndTab, &recRast, &MSKres ) )
227
p = MAX(MSKres.Alt[0].Prob,MSKres.Alt[1].Prob);
233
if(numCourier*3 > nC*2)
238
////////////////////////
239
static int curNumFile=0;
240
static Word8 hasNearSame[]="\xa7\xed"; // ��
241
static Word8 NearSame[]="\xed\xa7"; // ��
242
Int32 TestFontClusters(void)
248
int porog=50; // test !!!
251
LeoFieldSetup fs={0};
258
#ifdef _SAVE_INVALID_CLU_
264
nClust=FONGetClustCount();
265
set_alphabet(alphabet1, alpha_str);
267
#ifdef _SAVE_INVALID_CLU_
268
fp=fopen("clust.tst","at");
269
fprintf(fp,"file %d\n",curNumFile);
272
LEOSetPlatform(LEOGetCPU());
273
fs.nStyle = LS_PRINT;
274
memcpy(fs.AlphaTable,alphabet1,256);
277
for(i=0,numInvalid=0;i<nClust;i++)
280
j=FONGetClustInfo(&cluInfo,i+1);
284
if(cluInfo.attr & CTB_PRINT_ITALIC)
287
if(cluInfo.attr & CTB_PRINT_BOLD)
290
// now - test only russian ASCII letters
291
if(cluInfo.let < 128 ||
292
cluInfo.let >= 176 && cluInfo.let < 224 ||
297
addLet=(cluInfo.let < 144 ? cluInfo.let +32 :
298
cluInfo.let < 160 ? cluInfo.let +80 :
299
cluInfo.let < 176 ? cluInfo.let -32 :
305
FONGetClusterAsBW(&name,i,porog,&rec);
307
memset(&ro,0,sizeof(RecObject));
308
memcpy(&ro.recData.recRaster,&rec,sizeof(RecRaster));
310
ro.recData.lwStatus=0;
313
LEORecogPrintChar(&ro);
315
// ������ �������� �� LEO ?
316
if( ro.recResults.lnAltCnt <= 0 ||
317
ro.recResults.Alt[0].Prob < 150
321
for(j=0;j<ro.recResults.lnAltCnt;j++)
323
resLet = stdAnsiToAscii(ro.recResults.Alt[j].Code);
325
if( resLet == cluInfo.let ||
335
resLet = stdAnsiToAscii(ro.recResults.Alt[0].Code);
336
if( !is_lower(resLet) )
337
resLet = to_lower(resLet);
338
if( (qq=strchr(hasNearSame,cluInfo.let)) &&
339
NearSame[qq-(char*)hasNearSame] == resLet
344
// �������� ��� ���-�� ���� ?
345
// ���� ������ �� ������������ - ������ ('�' � sten91)
346
if( j >= ro.recResults.lnAltCnt ||
347
ro.recResults.Alt[j].Prob < 180 ||
348
ro.recResults.Alt[j].Prob < 220 &&
349
ro.recResults.Alt[j].Prob + 25 < ro.recResults.Alt[0].Prob
352
FonTestInfo testInfo[MAXCHECKALT];
355
resLet = stdAnsiToAscii(ro.recResults.Alt[0].Code);
356
j=FONTestChar(&rec,resLet,testInfo,0);
358
if( j <=0 || testInfo[0].prob <= 215 )
360
resLet=(resLet < 144 ? resLet +32 :
361
resLet < 160 ? resLet +80 :
362
resLet < 176 ? resLet -32 :
365
j=FONTestChar(&rec,resLet,testInfo,0);
368
if( j > 0 && testInfo[0].prob > 215 )
371
FONSetClusterInvalid(i+1);
372
#ifdef _SAVE_INVALID_CLU_
373
fprintf(fp," invalid %d (%c -> %c(%d))\n",i+1,cluInfo.let,
374
stdAnsiToAscii(ro.recResults.Alt[0].Code),
375
ro.recResults.Alt[0].Prob);
384
#ifdef _SAVE_INVALID_CLU_
395
Bool32 RecogLEOcap(RecRaster *Rs,Word8 Language,RecVersions *Vs)
398
LeoFieldSetup fs={0};
406
alpha = alpha_str_cap;
409
alpha = alpha_str_lat_cap;
412
alpha = alpha_str_all_cap;
416
set_alphabet(alphabet1, alpha);
419
fs.nStyle = LS_PRINT;
420
memcpy(fs.AlphaTable,alphabet1,256);
423
memset(&ro,0,sizeof(RecObject));
424
memcpy(&ro.recData.recRaster,Rs,REC_MAX_RASTER_SIZE);
426
ro.recData.lwStatus=0;
429
LEORecogPrintChar(&ro);
430
memcpy(Vs,&ro.recResults,sizeof(RecVersions));
435
Bool32 RecogLEO(RecRaster *Rs,Word8 Language,UniVersions *Us)
438
LeoFieldSetup fs={0};
447
set_alphabet(alphabet1, alpha);
450
fs.nStyle = LS_PRINT;
451
memcpy(fs.AlphaTable,alphabet1,256);
454
memset(&ro,0,sizeof(RecObject));
455
memcpy(&ro.recData.recRaster,Rs,REC_MAX_RASTER_SIZE);
457
ro.recData.lwStatus=0;
460
LEORecogPrintChar(&ro);
461
// memcpy(Vs,&ro.recResults,sizeof(RecVersions));
464
c = Us->Alt[0].Liga ;
467
else if( is_lower(c) )
470
Us->lnAltCnt=ro.recResults.lnAltCnt;
471
Us->lnAltMax=REC_MAX_VERS;
473
for(i=0;i<ro.recResults.lnAltCnt;i++)
475
c = stdAnsiToAscii( ro.recResults.Alt[i].Code);
487
cw = stdAsciiToAnsi( c );
488
Us->Alt[i].Code[0]=cw;
489
Us->Alt[i].Code[1]=0;
491
Us->Alt[i].Charset=CSTR_RUSSIAN_CHARSET;
492
Us->Alt[i].Method =REC_METHOD_LEO;
493
Us->Alt[i].Prob = ro.recResults.Alt[i].Prob ;
502
HndTab=MSKInit( NULL, "rec4cour.dat");
503
HndTabInc=MSKInit( NULL, "rec4inc.dat");
508
void p2_msk_done(void)
516
#define MIN_MSK_PROB 207
517
#define MIN_MSK_PROB_SIM 230
518
static char similar_letters[]="����Ꭾ��";
519
Bool32 p2_msk_inc(CSTR_rast rst)
522
Word8 prob=0, name, lim, code;
529
if(language!=LANG_RUSSIAN && language!=LANG_RUSENG )
531
CSTR_GetImage(rst,(Word8*)&rc,CSTR_TYPE_IMAGE_RS);
532
if( !rc.lnPixHeight || !rc.lnPixWidth )
534
MSKSetAlphabet ( alphabet );
536
CSTR_GetCollection(rst,&ver);
538
ver.lnAltMax=REC_MAX_VERS;
539
name = ver.Alt[0].Code;
540
ver.Alt[0].Code=(Word8)to_upper((Word8)name);
542
ver.Alt[1].Code=(Word8)to_lower((Word8)name);
546
ver.Alt[1].Code=(Word8)'�';
547
ver.Alt[2].Code=(Word8)'�';
553
ver.Alt[1].Code=(Word8)'�';
554
ver.Alt[2].Code=(Word8)'�';
558
if( !MSKRecogCharExpPuma( HndTabInc, &rc, &ver,1 ) )
563
for(prob=0, i=0;i<ver.lnAltCnt;i++)
565
if( prob<ver.Alt[i].Prob)
567
prob=ver.Alt[i].Prob ;
568
code=ver.Alt[i].Code;
572
if( strchr(similar_letters,code) )
573
lim = MIN_MSK_PROB_SIM;
581
Bool32 RecogLEO_SetAlphabet(char *letters)
583
set_alphabet(alphabet1, letters);
587
Bool32 RecogLEOall(RecRaster *Rs,RecVersions *Us,Int32 nType)
590
LeoFieldSetup fs={0};
594
fs.nStyle = LS_PRINT;
595
memcpy(fs.AlphaTable,alphabet1,256);
597
memset(&ro,0,sizeof(RecObject));
598
memcpy(&ro.recData.recRaster,Rs,REC_MAX_RASTER_SIZE);
600
ro.recData.lwStatus=0;
605
LEORecogPrintChar(&ro);