-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstract.c
1266 lines (1231 loc) · 36.7 KB
/
abstract.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#undef _DEBUG /* Release build */
#include "abstract.h"
/********************** Lexicography utility functions ************************/
/* Return char* duplicate */
char *mystrdup(char *Buffer)
{
char *ptrDupBuffer = NULL;
/* Anything to duplicate? */
if(Buffer != NULL)
{
/* Alloc a new buffer and then ..*/
if((ptrDupBuffer = (char*)malloc(strlen(Buffer) + 1)) != NULL)
strcpy(ptrDupBuffer, Buffer);/* duplicate Buffer! */
}
/* Return. */
return ptrDupBuffer;
}
/* Turn Char (Greek or English) to Uppercase Char and retun it */
/* On impossible conversion, return Char unchanged. */
int toupperGr(unsigned char Char)
{
/* Conversion table */
unsigned char Win1253L[34] = "áâãäåæçèéêëìíîïðñóôõö÷øùÜÝÞßüýþúûò",
Win1253U[34] = "ÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÓÔÕÖ×ØÙ¢¸¹º¼¾¿ÚÛÓ",
*ptrCharP = NULL;
/* Search for Char in lowercase table */
ptrCharP = (char*)memchr(Win1253L, Char, sizeof(Win1253L));
/* Anything found? */
if(ptrCharP == NULL)
{
/* No, could it be an English one? */
if(isalpha(Char))
return toupper(Char); /* Yes, toupper it! */
else
return Char; /* No, return it unchanged */
}
else/* Yes, return the appropriate uppercase Char from uppercase table */
return Win1253U[ptrCharP - Win1253L];
}
/* Turn Char (Greek or English) to Lowercase Char and retun it */
/* On impossible conversion, return Char unchanged. */
int tolowerGr(unsigned char Char)
{
/* Conversion table */
unsigned char Win1253L[34] = "áâãäåæçèéêëìíîïðñóôõö÷øùÜÝÞßüýþúûò",
Win1253U[34] = "ÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÓÔÕÖ×ØÙ¢¸¹º¼¾¿ÚÛÓ",
*ptrCharP = NULL;
/* Search for Char in lowercase table */
ptrCharP = (char*)memchr(Win1253U, Char, sizeof(Win1253L));
/* Anything found? */
if(ptrCharP == NULL)
{
/* No, could it be an English one? */
if(isalpha(Char))
return tolower(Char); /* Yes, toupper it! */
else
return Char; /* No, return it unchanged */
}
else
/* Yes, return the appropriate uppercase Char from uppercase table */
return Win1253L[ptrCharP - Win1253U];
}
/* Return S uppercased */
char *struprGr(char *S)
{
int Count;
/* Anything to process? */
if(S != NULL)
{
/* Byte to byte processing */
for(Count = 0; Count < (int)strlen(S); Count++)
S[Count] = toupperGr(S[Count]);
}
return S;
}
/* Return S lowercased */
char *strlwrGr(char *S)
{
int Count;
/* Anything to process? */
if(S != NULL)
{
/* Byte to byte processing */
for(Count = 0; Count < (int)strlen(S); Count++)
S[Count] = tolowerGr(S[Count]);
}
/* Return. */
return S;
}
/* Return a new S with no accent symbols (else returns a S duplicate!) */
char *strnoaccent(const char *S)
{
char *ptrS = NULL;
/* Copy S to ptrS */
if((ptrS = mystrdup((char*)S)) == NULL)
{
perror("strnoaccent:mystrdup");
free(ptrS);
ptrS = NULL;
}
else
{
int Count;
/* Conversion table */
//unsigned char UpperAccent[9] = "¢¸¹º¼¾¿ÚÛ";
//unsigned char UpperSimple[9] = "ÁÅÇÉÏÕÙÉÕ";
/*------------------------------------------------1st change--------------------------------*/
char UpperAccent[9] = "¢¸¹º¼¾¿ÚÛ";
char UpperSimple[9] = "ÁÅÇÉÏÕÙÉÕ";
/*------------------------------------------------1st change--------------------------------*/
/* Convert ptrS to uppercase */
ptrS = struprGr(ptrS);
/* Remove Greek accent symbols */
for(Count = 0; Count < (int)strlen(ptrS); Count++)
{
/* Is ptrS[Count] char .. */
char *ptrCharP = memchr(UpperAccent, ptrS[Count], sizeof(UpperAccent));
/* ..accented? */
if(ptrCharP == NULL)
continue; /* No */
/* Yes! Remove its accent */
ptrS[Count] = UpperSimple[ptrCharP - UpperAccent];
}
}
/* Return a new, unaccented, ptrS */
return ptrS;
}
/* Return 1 if S is the name of a known Greek Day else 0 (-1 on error!) */
int isday(const char *S)
{
const unsigned char *DayName[] =
{ "ÄÅÕÔÅÑÁ", "ÔÑÉÔÇ", "ÔÅÔÁÑÔÇ", "ÐÅÌÐÔÇ", "ÐÁÑÁÓÊÅÕÇ", "ÓÁÂÂÁÔÏ", "ÊÕÑÉÁÊÇ" };
return isstr((char*)S, (unsigned char**)DayName, sizeof(DayName)/sizeof(unsigned char*));
}
/* Return 1 if S is the name of a known Greek Month else 0 (-1 on error!) */
int ismonth(const char *S)
{
const unsigned char *MonthName[] = {
"ÉÁÍÏÕÁÑÉÏÓ", "ÖÅÂÑÏÕÁÑÉÏÓ", "ÌÁÑÔÉÏÓ",
"ÁÐÑÉËÉÏÓ" , "ÌÁÉÏÓ" , "ÉÏÕÍÉÏÓ",
"ÉÏÕËÉÏÓ" , "ÁÕÃÏÕÓÔÏÓ" , "ÓÅÐÔÅÌÂÑÉÏÓ",
"ÏÊÔÏÂÑÉÏÓ" , "ÍÏÅÌÂÑÉÏÓ" , "ÄÅÊÅÌÂÑÉÏÓ",
"ÉÁÍÏÕÁÑÇÓ" , "ÖÅÂÑÏÕÁÑÇÓ" , "ÌÁÑÔÇÓ",
"ÁÐÑÉËÇÓ" , "ÌÁÇÓ" , "ÉÏÕÍÇÓ",
"ÉÏÕËÇÓ" , "ÓÅÐÔÅÌÂÑÇÓ" , "ÏÊÔÙÂÑÇÓ",
"ÍÏÅÌÂÑÇÓ" , "ÄÅÊÅÌÂÑÇÓ" , "ÖËÅÂÁÑÇÓ",
"ÉÁÍÏÕÁÑÉÏÕ", "ÖÅÂÑÏÕÁÑÉÏÕ", "ÌÁÑÔÉÏÕ" ,
"ÁÐÑÉËÉÏÕ" , "ÌÁÉÏÕ" , "ÉÏÕÍÉÏÕ" ,
"ÉÏÕËÉÏÕ" , "ÁÕÃÏÕÓÔÏÕ" , "ÓÅÐÔÅÌÂÑÉÏÕ",
"ÏÊÔÙÂÑÉÏÕ" , "ÍÏÅÌÂÑÉÏÕ" , "ÄÅÊÅÌÂÑÉÏÕ",
"ÖËÅÂÁÑÉÏÕ" , "ÉÁÍ" , "ÖÅÂ" ,
"ÌÁÑ" , "ÁÐÑ" , "ÌÁÉ" ,
"ÉÏÕ" , "ÉÏÕË" , "ÁÕÃ" ,
"ÓÅÐ" , "ÏÊÔ" , "ÍÏÅ" ,
"ÄÅÊ"};
return isstr((char*)S, (unsigned char**)MonthName, sizeof(MonthName)/sizeof(unsigned char*));
}
/* Return 1 if S is numeric else 0 */
int isnumeric(const char *S)
{
return (S != NULL && strlen(S)) ? strspn(S, "0123456789") == strlen(S): 0;
}
/* Return 1 if S is a year abbreviation (like '60 '70 '80 etc) else 0 (on error return -1) */
int isabbrevyear(const char *S)
{
/* Anything to process? */
if(S != NULL)
{
char *ptrAbbrevPos = NULL;
int AbbrevPos;
/* Year abbrevation should be in form 'nn (3 chars wide) */
if(strlen(S) == 3)
{
/* Abbrevation char ' position? */
if((ptrAbbrevPos = memchr(S, '\'', strlen(S))) == NULL)
return 0; /* Not found */
/* Found, convert it to int for easier reference */
AbbrevPos = ptrAbbrevPos - S;
/* After abbrevation char should follow a numeric .. */
return (AbbrevPos + 1 < (int)strlen(S))? isnumeric(&S[AbbrevPos + 1]): 0;
}
}
/* Nothing! */
return 0;
}
/* Return 1 if S begins with a capital letter else 0 */
int issemantictoken(const char *S)
{
if(S != NULL && strlen(S))
{
/* Capital letters table */
unsigned char Caps[64] = "ÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÓÔÕÖ×ØÙ¢¸¹º¼¾¿ÚÛQWERTYUIOPASDFGHJKLZXCVBNM";
/* Is first S letter capital? */
return memchr(Caps, S[0], strlen(Caps)) != NULL;
}
/* Return. */
return 0;
}
/* Return 1 if S is a Greek atom token else 0 */
int islowergramtoken(const char *S)
{
/* Greek pronouns */
const unsigned char *ptrPronouns[] =
{ "ÅÃÙ" ,"ÅÌÅÍÁ","ÅÌÅÉÓ","ÅÌÁÓ","ÌÏÕ" ,"ÌÅ" ,"ÌÁÓ" ,"ÅÓÕ" ,"ÅÓÅÍÁ" ,
"ÅÓÁÓ" ,"ÓÏÕ" ,"ÓÅ" ,"ÓÁÓ" ,"ÁÕÔÏÓ","ÁÕÔÏÕ","ÁÕÔÏÉ","ÁÕÔÙÍ","ÁÕÔÏÕÓ",
"ÔÏÓ" ,"ÔÏÕ" ,"ÔÏÍ" ,"ÔÏÉ" ,"ÔÏÕÓ" ,"ÁÕÔÇ" ,"ÁÕÔÇÓ","ÁÕÔÇÍ","ÁÕÔÅÓ" ,
"ÔÇ" ,"ÔÇÓ" ,"ÔÇÍ" ,"ÔÅÓ" ,"ÔÏÕÓ" ,"ÔÉÓ" ,"ÁÕÔÏ" ,"ÁÕÔÏÕ","ÁÕÔÁ" ,
"ÔÏ" ,"ÔÏÕ" ,"ÔÁ" ,"ÔÏÕÓ","ÅÓÅÉÓ","ÁÕÔÁ" ,"ÓÔÇÍ" ,"ÓÔÇ" ,"ÓÔÁ" ,
"ÓÔÏ" ,"ÓÔÏÍ" ,"ÓÔÏÕÓ","ÓÔÙÍ","ÓÔÉÓ"
};
/* Greek articles */
const unsigned char *ptrArticles[] =
{ "Ï" ,"Ç" ,"ÔÏ" ,
"ÏÉ" ,"ÔÙÍ","ÔÏÕÓ",
"Ç" ,"ÔÇÓ","ÔÇ" ,
"ÔÉÓ","ÔÏÕ","ÔÁ" ,
"ÔÏÍ","ÔÇÍ"
};
/* Greek prepositions (Ancient & Modern since they sometimes "interpolate" among texts) */
const unsigned char *ptrPrepositions[] =
{ "ÁÍÁ" , "ÐÁÑÁ" , "ÊÁÔÁ" , "ÄÉÁ" , "ÌÅÔÁ" , "ÁÍÔÉ" , "ÁÌÖÉ", "ÐÅÑÉ", "ÅÐÉ", "ÁÐÏ",
"ÕÐÏ" , "ÕÐÅÑ" , "ÅÉÓ" , "ÅÍ" , "ÅÊ" , "ÅÎ" , "ÐÑÏ" , "ÐÑÏÓ", "ÓÕÍ", "Á×ÑÉ",
"ÌÅ×ÑÉ" , "ÁÍÅÕ" , "×ÙÑÉÓ" , "ÐËÇÍ", "ÅÍÅÊÁ", "ÅÍÅÊÅÍ", "ÌÁ" , "ÍÇ" ,
"ÅÍÁÍÔÉÏÍ", "ÅÍÁÍÔÉ", "ÅÍÁÍÔÉÁ"
};
/* Greek atoms */
const unsigned char *ptrAtoms[] =
{ "ÙÓ", "ÓÁÍ", "ÃÉÁ", "ÅÙÓ", "ÐÑÏÔÏÕ", "ÍÁ", "ÁÍ", "ÈÁ", "ÅÉÍÁÉ", "ÇÔÁÍ" };
int R = 0;
/* Remove accent and uppercase S to ptrS */
char *ptrS = strnoaccent(S);
/* Count Word Freq */
R += isstr(ptrS, (unsigned char**)ptrPronouns, sizeof(ptrPronouns)/sizeof(char*));
R += isstr(ptrS, (unsigned char**)ptrArticles, sizeof(ptrArticles)/sizeof(char*));
R += isstr(ptrS, (unsigned char**)ptrPrepositions, sizeof(ptrPrepositions)/sizeof(char*));
R += isstr(ptrS, (unsigned char**)ptrAtoms, sizeof(ptrAtoms)/sizeof(char*));
/* Free local resources */
free(ptrS);
/* Return. */
return R;
}
/* Return 1 if S match any of *Data else 0 (on error -1) */
int isstr(char *S, unsigned char **Data, int nrSize)
{
int R = 0;
/* Anything to process? */
if(S != NULL && strlen(S))
{
int Count;
unsigned char *ptrS = NULL;
/* Remove any accent from S and capitalize it */
if((ptrS = strnoaccent(S)) == NULL)
return -1; /* Memory error? */
/* Search abbrevation table.. */
for(Count = 0; Count < nrSize; Count++)
if(!strcmp(ptrS, Data[Count])) /* Anything? */
{
R = 1;
break;
}
/* Free local resources */
free(ptrS);
}
return R; /* Not a known Greek abbrevation */
}
/* Return 1 if S is an abbreviated Greek word else 0 (on error -1) */
int isabbrevword(const char *S)
{
int R = 0;
/* Anything to process? */
if(S != NULL && strlen(S))
{
int R;
/* Most common Greek abbrevations */
const unsigned char *ptrAbbrev[] =
{ /*"Ê.Ê.", "ÊËÐ", "ÊÔË", "Ì.×.", "Ð.×.", "Ê.Á.", "Ê.", "*/
"ÁÃÃË." , "ÁÅÑÏÍÁÕÔ." , "ÁÈË." , "ÁÉÃÕÐÔ." , "ÁÉÔ." , "ÁÉÔÉÏË.",
"ÁÊË." , "ÁËÂ." , "ÁËË." , "ÁÍÁÄÉÐË.", "ÁÍÁÄÑ." , "ÁÍÁË." ,
"ÁÍÁÐÔ." , "ÁÍÁÓÕËË." , "ÁÍÁÔ." , "ÁÍÁÔÏË." , "ÁÍÁÖ." , "ÁÍÈÑ." ,
"ÁÍÈÑÙÐÏË.", "ÁÍÑÈÙÐÙÍ." , "ÁÍÏÌ." , "ÁÍÔ." , "ÁÍÔÄ." , "ÁÍÔÉÈ." ,
"ÁÍÔÉÊ." , "ÁÍÔÉÌÅÔÁÈ.", "ÁÍÔÙÍ.", "ÁÏÑ." , "ÁÐÁÑÅÌÖ." , "ÁÐÁÑ×." ,
"ÁÐËÏË." , "ÁÐËÏÐ." , "ÁÐÏÂ." , "ÁÐÏÄ." , "ÁÐÏÇ×ÇÑÏÐ.", "ÁÐÏÈ." ,
"ÁÐÏË." , "ÁÐÑÏÓ." , "ÁÑÁÂ." , "ÁÑÁÌ." , "ÁÑÈÑ." , "ÁÑÉÈÌÔ.",
"ÁÑÊÔÉÊÏË.", "ÁÑÌÅÍ." , "ÁÑÍ." , "ÁÑÍÇÔ." , "ÁÑÓ." , "ÁÑ×." ,
"ÁÑÓ." , "ÄÏÔ." , "ÄÙÑ." , "ÅÂÑ." , "ÅÈÍ." , "ÅÈÍÏË." ,
"ÅÉÄ." , "ÅÉÄÊÏÔ." , "ÅÉÑ." , "ÅÊ." , "ÅÊÊË." , "ÅÊÖÑ." ,
"ÅËËÇÍ." , "ÅËÍÓÔ." , "ÅÌØ." , "ÅÍ." , "ÅÍÁËË." , "ÅÍÅÑÃ." ,
"ÅÍÅÓÔ." , "ÅÍÍ." , "ÅÎÁÊÏË.","ÅÎÅË." , "ÅÎÏÌÁË." , "ÅÐÁÃÃÅËÌ.",
"ÅÐÁÍÁË." , "ÅÐÅÊÔ." , "ÅÐÉÄÑ.", "ÅÐÉÈ." , "ÅÐÉÑÑ." , "ÅÐÉÓ." ,
"ÅÐÉÓÔ." , "ÅÐÉÔÁÔ." , "ÅÐÉÖ." , "ÅÐÙÍ." , "ÅÑÑÉÍÏÐ." , "ÅÑÙÔ." ,
"ÅÔÕÌ." , "ÅÕÖ." , "ÆÙÃÑÖ.", "ÆÙÏË." , "ÇÈ." , "ÇËÅÊÔÑÏË.",
"ÇËÅÊÔÑÏÍ.", "ÇÌÉÖ." , "Ç×." , "Ç×ÇÑ." , "Ç×ÇÑÏÐ." , "Ç×ÏÌÉÌ.",
"È." , "ÈÅÁÔÑ." , "ÈÅÏË." , "ÈÅÔ." , "ÈÇË." , "ÈÑÇÓÊÅÉÏË.",
"ÉÁÐÙÍ." , "ÉÁÔÑ." , "ÉÄ." , "ÌÔÖÑÄ." , "ÌÔ×." , "ÌÕÈ.",
"Ì.×." , "ÍÁÕÔ." , "ÍÅÏÅËË.","ÍÅÏË." , "ÍÅÏÔ." , "ÍËÁÔ.",
"ÍÏÌ." , "ÍÏÔ." , "ÏÉÊ." , "ÏÉÊÏÄ." , "ÏÉÊÏË." , "ÏÉÊÏÍ.",
"ÏËËÁÍÄ." , "ÏÌ." , "ÏÍ." , "ÏÍÏÌ." , "ÏÐÔ." , "ÏÑÈÏÃÑ.",
"ÏÑÉÓÔ." , "ÏÑÕÊÔ." , "ÏÕÄ." , "ÏÕÓ." , "ÏÕÓÉÁÓÔÉÊÏÐ.","ÐÁÈ.","ÐÁÉÄ." ,
"ÐÁË." , "ÐÁËÁÉÏÍÔ.","ÐÁËÁÉÏÔ.", "ÐÁÑ." ,"ÐÁÑÁÃ.",
"ÐÁÑÁË." , "ÐÁÑÁËË." , "ÐÁÑÅÔÕÌ.", "ÖÑ." , "ÐÅÑÔÕÌ." ,"ÐÁÑÙ×.",
"Ð.Ä." , "ÐÅÑÉË." , "ÐÅÑÓ." , "ÐËÇÈ." , "ÐËÇÑÏÖ." ,"ÐÏÄ.",
"ÐÏÉÇÔ." , "ÐÏË." , "ÐÏËËÁÐË.","ÐÏÑÔÏÃÁË.","ÐÏÓ." ,"ÐÑÂ.",
"ÐÑÃ." , "ÐÑÊ." , "ÐÑÏÅË.", "ÐÑÏÇÃ." , "ÐÑÏÈ." ,"ÓÕÍÔÅË.",
"ÓÕÍÔÏÌÏÃÑ.","Ó×." , "Ó×ÇÌ." , "Ô." , "ÔÁÊÔ." ,"ÔÅË." ,
"ÔÅ×Í." , "ÔÅ×ÍÏË." , "ÔÇËÅÏÑ.","Ô.Ì." , "ÔÏÓÊ." ,"ÔÏÕÑÊ." ,
"ÔÑÏÐ." , "ÔÑÏÐÏÐ." , "ÔÓÉÃÃ." ,"ÔÕÐ." , "ÕÂÑ." ,"ÕÐ." ,
"ÕÐÅÑ." , "ÕÐÅÑÈ." , "ÕÐÅÑÓ." ,"ÕÐÏÈ." , "ÕÐÏÊÏÑ." ,"ÁÑ×ÁÉÏË.",
"ÁÑ×ÉÔ." , "ÁÓÔÑÏË." , "ÁÓÔÑÏÍ.","ÁÔ." , "ÁÔÔ." ,"ÁÕÔÏÐ.",
"ÁÖÇÑ." , "ÏÖÏÌ." , "ÁØ." ,"ÂÅÂ." , "ÂÅÍ." ,"ÂÉÏË." ,
"ÂÉÏ×ÇÌ." , "ÂË." , "ÂËÁ×." ,"ÂÏÑ." , "ÂÏÔ." ,"ÂÏÕËÃ.",
"ÃÁËË." , "ÃÅÍÉÊÏÔ." , "ÃÅÍÏÂ." ,"ÃÅÑÌ." , "ÃÅÙÑÃ." ,"ÃÅÙË.",
"ÃÅÙÌ." , "ÃÅÙÐ." , "ÃË." ,"ÃËÕÐÔ." , "ÃËÙÓÓ." ,"ÃÍÙÌ.",
"ÃÑÁÌÌ." , "ÃÕÌÍ." , "ÄÁÍ." ,"ÄÅÉÊÔ." , "ÄÇË." ,"ÄÇÌÏÔ.",
"ÄÉÁÊÑ." , "ÄÉÁË." , "ÄÉÁËÅÊÔ.","ÄÉÁÓÐ." , "ÄÉÁÖ." ,"ÄÉÁ×." ,
"ÄÉÅÈ." , "ÄÉÊ." , "ÄÉÓÔ." , "ÄÉÖÈ." , "ÄÉÖÈÏÃÃÏÐ." ,"ÉÍÄ." ,
"ÉÓÐÁÍ." , "ÉÓÔ." , "ÉÓ×ÕÑÏÐ.","ÉÔÁË." , "ÉÙÍ." ,"Ê.Á." ,
"ÊÁÔÁË." , "ÊÁÔÁÔ." , "Ê.Ä." , "Ê.Å." , "ÊÉÍÇÌ." ,"ÊËÇÔ.",
"ÊËÉÔ." , "ÊÏÉÍÙÍ." , "Ê.Ï.Ê." , "ÊÐ." , "ÊÔ." ,"ÊÔÃ." ,
"ÊÔÇÔ." , "ÊÔË." , "ÊÕÑ." , "ÊÕÑÉÏË.", "ËÁÉÊ." ,"ËÁÉÊÏÔÑ.",
"ËÁÏÃÑ." , "ËÁÔ." , "ËÏÃ." , "ËÏÃÉÓÔ.", "ËÏÃÏÔ." ,"ÌÁÃÅÉÑ.",
"ÌÁÈÇÌ." , "ÌÅÃÅÈ." , "ÌÅÅ." , "Ì.Ì.Å." , "ÌÅÉÙÔ." ,"ÌÅËË.",
"ÌÅÓÏÖ." , "ÌÅÔÁÈ." , "ÌÅÔÁÊ." , "ÌÅÔÁÐË.", "ÌÅÔÁÑ." ,"ÌÅÔÅÐÉÈ.",
"ÌÅÔÅÐÉÑÑ.", "ÌÅÔÅÙÑ." , "ÌÅÔÏÍ." , "ÌÅÔÏÕÓ.", "ÌÅÔÑ." ,"ÌÇ×.",
"ÌÇ×ÁÍÏË." , "ÌÏÑÖÏË." , "ÌÏÕÓ." , "ÌÐÅ." , "ÌÐÐ." ,"ÌÓÍ.",
"ÌÓÍËÁÔ." , "ÌÔÖ." , "ÐÑÏÐÁÑÁË.","ÐÑÏÓ." , "ÐÑÏÓÁÑÌ." ,"ÐÑÏÓÔ.",
"ÐÑÏÓÖÙÍ." , "ÐÑÏÔ." , "ÐÑÏÔÁÊÔ.","ÐÑÏ×ÙÑ.", "ÐÑÏÖ." ,"ÐÑÔ.",
"ÐÔ." , "Ð.×." , "ÑÇÌÁÔ." ,"ÑÇÔÏÑ." , "ÑÉÍ." ,"ÑÏÕÌ.",
"ÑÙÓ." , "ÓÁÍÓÊÑ." , "ÓÅË." ,"ÓÇÌÁÓÉÏË.","ÓÇÌÄ." ,"ÓÇÌÅÑ.",
"ÓÇÌÉÔ." , "ÓÊÙÐÔ." , "ÓËÁÂ." ,"ÓÐÁÍ." , "ÓÐÁÍÉÏÔ." ,"ÓÔÁÔ.",
"ÓÔÅÑ." , "ÓÔÉÃÌ." , "ÓÔÑÁÔ." ,"ÓÕÃÃ." , "ÓÕÃÊÑ." ,"ÓÕÌÐÅÑ.",
"ÓÕÌÐË." , "ÓÕÌÐËÅÊÔ." , "ÓÕÌÐÑÏÖ.","ÓÕÌÐÔ." , "ÓÕÌÖ." ,"ÓÕÌÖÕÑ.",
"ÓÕÍ." , "ÓÕÍÁÉÑ." , "ÓÕÍÁÉÓÈ.","ÓÕÍÄ." , "ÓÕÍÅÊÄ." ,"ÓÕÍÇÈ.",
"ÓÕÍÇÑ." , "ÓÕÍÈ." , "ÓÕÍÉÆ." ,"ÓÕÍÏÐÔ.", "ÓÕÍÔ." ,"ÕÐÏÊÙÑ.",
"ÕÐÏË." , "ÕÐÏÔ." , "ÕÐÏ×ÙÑ." ,"ÕÓÔËÁÔ.", "ÖÁÑÌ." ,"ÖÉËÏË.",
"ÖÉËÏÓ." , "ÖÉËÏÔ." , "ÖÏÉÍÉÊ." ,"ÖÑ." , "ÖÕÓ." ,"ÖÕÓÉÏË.",
"ÖÙÍ." , "ÖÙÍÇÅÍÔ." , "ÖÙÍÇÔ." ,"ÖÙÍÏË." , "ÖÙÔÏÃÑÖ." ,"×ÁÓÌ." ,
"×ÃÖ." , "×ÅÉË." , "×ÇÌ." ,"×ËÅÕ." , "×Ñ." ,"×ÑÏÍ." ,
"ØÕ×." , "ØÕ×ÁÍ." , "ØÕ×ÉÁÔÑ.","Ê." , "Ê.Ê" ,"ÊÁ." ,
"ÊÏÓ." , "ÊÊ." , "ÃÅÍ.", "Ä.", "ÅÕÁÃ.", "ÌÉ×.", "ÉÙÁÍ.", "Ã.",
"ÖÉË.", "ÄÇÌ.", "ÂÁÓ.", "ÊÙÍ.", "ÁÍÄÑ."
};
#ifdef _DEBUG
int D = isstr(S, ptrAbbrev, sizeof(ptrAbbrev) / sizeof(char*));
fprintf(stderr, "AbbrevWord Input: \"%s\"\n", S);
fprintf(stderr, "AbbrevWord Ret. : %d\n", D);
return D;
#else
/* Match abbrevation */
return isstr((char*)S, (unsigned char**)ptrAbbrev, sizeof(ptrAbbrev) / sizeof(char*));
#endif
}
/* Return. */
return 0;
}
/*********************** Sentence handling functions **************************/
/* Store Contents from file into a Buffer. */
char *LoadFileContents(const char *filename, char *Contents)
{
/* Filename Provided. */
if(!filename)
{
fprintf(stderr,"{NULL} file name:%s\n", strerror(errno));
return NULL;
}
else
{
/* File Pointer. */
FILE *file = NULL;
/* Buffer. */
char FileBuffer[BUFSIZ] = "";
int nLen = 0, Index = 0;
/* Test for file operation. */
if((file = fopen(filename,"rt")) == NULL)
{
fprintf(stderr,"Open Error: Can not open %s file: %s\n", filename,
strerror(errno));
return NULL;
}
for(;;)
{
if((fgets(FileBuffer, BUFSIZ, file)) == NULL)
break;
/* Now trim it. */
if(FileBuffer[strlen(FileBuffer)-1] == '\n')
FileBuffer[strlen(FileBuffer)-1] = '\0'; /* Not trim the '\n' but replace it with ' '. */
/* Test if zero length. */
if(!strlen(FileBuffer))
continue;
/* In each iteration. */
if((Contents = (char*)realloc(Contents, (nLen += strlen(FileBuffer)+1) * sizeof(char))) == NULL)
{
fprintf(stderr,"Buffer Memory Reallocation Fault:%s\n", strerror(errno));
fclose(file);
return NULL;
}
/* Put into the Contents the line read or append it. */
!Index ? strcpy(Contents, FileBuffer) : strcat(Contents,FileBuffer); Index++;
memset(FileBuffer, 0, sizeof(FileBuffer));
}
/* Close file. */
fclose(file);
/* Return. */
return Contents;
}
}
/* Splits the input buffer that hold the file contents into an array of valid
* sentences. The number of sentences stored is returned as an extra parameter.
* Any Error will be reported to *Error variable.
*/
Sentence *GetTextSentences(const char *FileContents, int *nrSentences, int *Error)
{
if(!FileContents)
{
fprintf(stderr,"GetTextSentences:{NULL} file contents:%s\n", strerror(errno));
return NULL;
}
else
{
/* Index for our structure array. */
int Index = 0, i = 0;
int LetterCount = 0;
int nLen = 0, skippedChars = 0;
/* Default start point. */
int startPoint = 0;
/* Sentence structure to be returned. */
Sentence *s = NULL;
/* Pointer to next of the next character. */
unsigned char *ptrToNextNextChar = NULL;
unsigned char *ptrToPreviousPreviousChar = NULL;
unsigned char *oldStatePtr = NULL;
unsigned char *next = NULL;
unsigned char *previous = NULL;
unsigned char *ptrToChar = (char*)FileContents;
/* Test for abrevword. */
unsigned char *Abrev = NULL;
unsigned char AbrevWord[BUFSIZ] = "";
/* Init Error to zero. */
*Error = 0;
/* Do we have any trailing whitespace chars in the first line. */
while(isspace((int)*ptrToChar))
{
skippedChars++;
ptrToChar++;
}
/* Main Loop. */
for(i = 0; i < (int)strlen(FileContents); i++)
{
/* Store character from file. */
unsigned char Char = FileContents[i];
/* Get the next char. */
ptrToChar = (char*)&FileContents[i];
Abrev = (char*)&FileContents[i];
next = i < (int)strlen(FileContents)-1 ? ptrToChar+1 : NULL;
previous = i > 1 ? ptrToChar-1 : NULL;
/* Check two letters farther. */
ptrToNextNextChar = i < (int)strlen(FileContents)-2 ? ptrToChar+2 : NULL;
/* Check two letters before. */
ptrToPreviousPreviousChar = i > 2 ? ptrToChar-2 : NULL;
if(Char == '.')
{
/*Advance once to get to the next char. */
ptrToChar++;
/* Save oldstate. */
oldStatePtr = ptrToChar;
/* Check two places front or two places before for another dot. */
if(ptrToNextNextChar != NULL && *ptrToNextNextChar == '.' || ptrToPreviousPreviousChar != NULL && *ptrToPreviousPreviousChar == '.')
continue;
if(next != NULL && isdigit((int)*next) && previous != NULL && isdigit((int)*previous))
continue;
/* Test for abrevword. */
if(ptrToNextNextChar != NULL && *ptrToNextNextChar == '.')
Abrev = ptrToNextNextChar;
while(!isspace((int)*Abrev))
{
LetterCount++;
Abrev--;
}
/* Advance to skip the space. */
if(isspace((int)*Abrev))
Abrev++;
/* Copy to buffer the string. */
strncpy(AbrevWord, Abrev, LetterCount);
AbrevWord[LetterCount] = '\0';
if(isabbrevword(AbrevWord))
{
LetterCount = 0;
memset(AbrevWord, 0 , sizeof(AbrevWord));
continue;
}
LetterCount = 0;
/* We have a valid dot here. */
while(isspace(((int)*ptrToChar)))
ptrToChar++;
/* We have skipped unwanted characters till the first valid letter. */
if(issemantictoken((char*)ptrToChar) || *ptrToChar == '\0')
{
/* Allocate a sentence. */
/* Get space for the new sentence. */
if((s = realloc(s,(Index+1)*sizeof(Sentence))) == NULL)
{
fprintf(stderr,"GetTextSentences:Memory Reallocation Fault:%s\n",
strerror(errno));
return NULL;
}
/* If we carry skipped chars from the begining. Calculate the sentence length. */
nLen = i - startPoint - skippedChars + 1;
/* Get space for the sentence to get stored. */
if((s[Index].Str =(char*)calloc(nLen+1, sizeof(char))) == NULL)
{
fprintf(stderr,"GetTextSentences:Allocation Fault:%s\n",
strerror(errno));
*Error = 1;
break;
}
/* Save sentence. */
strncpy(s[Index].Str,&FileContents[startPoint+skippedChars], nLen);
s[Index].Str[nLen] = '\0';
s[Index].Score = 0;
/* Advance and set new indexes values. */
Index++;
startPoint = i+1;
/* Reset skipped chars. */
skippedChars = 0;
/* Calculate skipped characters. */
ptrToChar = oldStatePtr;
while(isspace((int)*ptrToChar))
{
skippedChars++;
ptrToChar++;
}
}
/* We did not find any Cap letter. */
else
{
fprintf(stderr,"GetTextSentences: Capital letter was not found after the dot. Invalid input.\n");
*Error = 1;
break;
}
}
}
/* Exit loop. */
/* Error, Clean the mess. */
if(*Error)
{
for(Index = Index-1; Index >=0; Index--)
{
/* There must be a sentence to free it. */
if(s)
{
if(s[Index].Str)
{
free(s[Index].Str);
s[Index].Str = NULL;
}
}
}
/* Free the whole sentence array. */
if(s)
{
free(s);
s = NULL;
*nrSentences = 0;
return NULL;
}
}
/* Case no Error reported return safely. */
*nrSentences = Index;
return s;
}
}
/* Fill a Tokeniser Structure with the content - words from the sentence,
* this structure will be used to find the correct score of the sentence
* according to the criteria used.
*/
Tokeniser *FillTokeniserBySentence(char *inputSent, int ignoreCharacters,const char *delim, int *Tokens)
{
if(!inputSent)
{
fprintf(stderr,"FillTokeniserBySentence:{NULL} input sentence:%s\n", strerror(errno));
return NULL;
}
else
{
/* Index counter. */
int Index = 0, TokenIndex = 0, pointerIndex = 0;
/* Pointer to token. */
char *pToken = NULL;
char *inputSentDup = mystrdup(inputSent);
/* Tokeniser return value. */
Tokeniser *t = NULL;
/* Test for token with strtok. */
if(!(pToken = strtok(inputSentDup, delim == NULL ? " " : delim)))
{
/* Case one token and less than 3 chars no need to save anything. */
if((int)strlen(inputSentDup) < ignoreCharacters)
return NULL;
/* Return the whole sentence, must be a word. */
if(!(t = calloc(Index+1, sizeof(Tokeniser))))
{
fprintf(stderr,"FillTokeniserBySentence: Memory Allocation Fault: %s\n", strerror(errno));
return NULL;
}
else
{
if(!(t->token = calloc(Index, sizeof(char*))))
{
fprintf(stderr,"FillTokeniserBySentence: Memory Pointer String Allocation Fault: %s\n", strerror(errno));
free(t); t = NULL;
return NULL;
}
if(!(t->token[TokenIndex] = calloc(strlen(inputSentDup)+1, sizeof(char))))
{
fprintf(stderr,"FillTokeniserBySentence: Memory String Allocation Fault: %s\n", strerror(errno));
free(t->token); t->token = NULL;
free(t); t = NULL;
return NULL;
}
/* Save the token and return safely. */
else
{
strcpy(t->token[TokenIndex], inputSentDup);
t->tokencount = TokenIndex+1;
/* Tokens. */
*Tokens = TokenIndex+1;
return t;
}
}
}
else
{
/* Get memory for the structure. */
/* Return the whole sentence, must be a word. */
if(!(t = calloc(Index+1, sizeof(Tokeniser))))
{
fprintf(stderr,"FillTokeniserBySentence: Memory Allocation Fault:%s\n", strerror(errno));
return NULL;
}
/* Loop to get the tokens, ignore small non special ones. */
/* Code can be replaced with small tokens specified by the user, should check. */
do
{
/* Ignore. */
if((int)strlen(pToken) < ignoreCharacters)
continue;
/* Get the pointer. */
if(!(t->token = realloc(t->token,(pointerIndex+1)*sizeof(char*))))
{
fprintf(stderr,"FillTokeniserBySentence: Memory Pointer String Allocation Fault: %s\n", strerror(errno));
free(t); t = NULL;
return NULL;
}
/* Get space for the token. */
if(!(t->token[pointerIndex] = calloc((int)strlen(pToken)+1, sizeof(char))))
{
fprintf(stderr,"FillTokeniserBySentence: Memory String Allocation Fault: %s\n", strerror(errno));
for(Index = 0; Index < pointerIndex+1; Index++)
{
if(t->token[Index])
{
free(t->token[Index]);
t->token[Index] = NULL;
}
}
free(t); t = NULL;
return NULL;
}
/* Copy the token into the tokeniser. */
else
{
strcpy(t->token[pointerIndex], pToken);
/* Advance pointers. */
pointerIndex++;
}
}while((pToken = strtok(NULL, delim == NULL ? " " : delim)) != NULL);
}/* End for else. */
/* Return. */
*Tokens = pointerIndex;
t->tokencount = pointerIndex;
free(inputSentDup);
return t;
}
}
/* Free a Sentences array */
void FreeTextSentences(Sentence *S, const int nrSentences)
{
/* Anything to process? */
if(S != NULL)
{
int Count;
/* Free each S item */
for(Count = 0; Count < nrSentences; Count++)
free(S[Count].Str);
/* Free S it self */
free(S); S = NULL;
}
}
/* Free a Tokeniser structure from memory. */
void FreeTokeniser(Tokeniser *t)
{
if(t)
{
int Index = 0;
for(Index = 0; Index < t->tokencount; Index++)
{
if(t->token[Index])
{
free(t->token[Index]);
t->token[Index] = NULL;
}
}
free(t->token); t->token = NULL;
free(t); t = NULL;
}
}
/****************************** Database Functions ****************************/
/* qsort function for Name database functions */
int _DBQCmp(const void *A, const void *B)
{
NameEntry *ptrA = (NameEntry*)A,
*ptrB = (NameEntry*)B;
return strcmp(ptrA->Name, ptrB->Name);
}
/* Return 1 if Name exists in the database Container records else 0, on error -1 */
int IsDBStr(NameEntry *Container, const int nrWords, const char *Name)
{
/* Anything to process? */
if(Container != NULL && nrWords > 0)
{
NameEntry Key;
/* Duplicate Name into as a NameEntry key */
if((Key.Name = mystrdup((char*)Name)) != NULL)
{
/* Store bsearch result to ptrR */
char *ptrR = bsearch(&Key, Container, nrWords, sizeof(NameEntry), _DBQCmp);
/* Free local resources */
free(Key.Name); Key.Name = NULL;
/* Return bsearch result */
return ptrR != NULL;
}
else
return -1;
}
else
return 0;
}
/* Works like IsDBStr but accepts Tokeniser* instead of const char* (-1 on error) */
int IsDBToken(NameEntry *Container, const int nrWords, Tokeniser *Tok)
{
int TokCount,
Count = 0;
char *ptrNoAccTok = NULL;
/* Iterate Tokeniser->token char* and if token is a person-name increase count by 1 */
for(TokCount = 0; TokCount < Tok->tokencount; TokCount++)
{
/* Remove accents and capitalize Tok->token */
if((ptrNoAccTok = strnoaccent(Tok->token[TokCount])) == NULL)
return -1;
/* Is Tok->token in database container? */
if(IsDBStr(Container, nrWords, ptrNoAccTok))
Count++; /* Yes, increase it's count */
/* Free local resources */
free(ptrNoAccTok); ptrNoAccTok = NULL;
}
/* Return found person-names */
return Count;
}
/* Free NameEntry* */
void FreeDB(NameEntry *Container, const int nrWords)
{
if(Container != NULL)
{
int Count;
for(Count = 0; Count < nrWords; Count++)
free(Container[Count].Name);
free(Container); Container = NULL;
}
}
/* Append Word to a in-memory NameEntry DB Container */
NameEntry *InsertWordToMemDB(NameEntry *Container, char *Word, int *nrWords, int *Error)
{
/* No error */
*Error = 0;
/* Anything to process? */
if(Word != NULL && strlen(Word))
{
int Count;
NameEntry Key;
char *ptrNoAccentWord = NULL;
/* Calculate Container Length */
int ContainerLen = *nrWords? (*nrWords + 1) * sizeof(NameEntry): sizeof(NameEntry);
/* Remove Word accent & uppercase it */
if((ptrNoAccentWord = strnoaccent(Word)) == NULL)
{
*Error = 1;
return Container;
}
/* Is Container non-empty? */
if(Container != NULL && *nrWords)
/* Conduct linear search before append word */
for(Count = 0; Count < *nrWords; Count++)
if(!strcmp(Container[Count].Name, ptrNoAccentWord))
{
/* Special case - word exists */
*Error = 2;
/* Free local resources */
free(ptrNoAccentWord);
/* Return. */
return Container;
}
/* Grow database memory container */
if((Container = (NameEntry*)realloc(Container, ContainerLen)) == NULL)
{
*Error = 1;
perror("InsertWordToMemDB:realloc");
}
else
{
/* Allocate a large enough buffer to store database record */
if((Container[*nrWords].Name = (char*)calloc(strlen(ptrNoAccentWord) + 1, sizeof(char))) == NULL)
{
*Error = 1;
perror("InsertWordToMemDB:calloc");
}
/* Append Word to Container */
strcpy(Container[*nrWords].Name, ptrNoAccentWord);
/* Increase Word count */
*nrWords += 1;
}
/* Free local resources */
free(ptrNoAccentWord);
}
return Container;
}
/* Sort Container, on error return 0 else 1 */
int SortMemDB(NameEntry *Container, const int nrWords)
{
/* Anything to process? */
if(Container != NULL && nrWords)
{
/* Q-Sort! */
qsort(Container, nrWords, sizeof(NameEntry), _DBQCmp);
/* Ok! */
return 1;
}
/* Return. */
return 0;
}
/* Return 1 on success else 0 on error */
/* We do not count Greek Articles & Numerics */
int SentenceWordScore(Sentence *s)
{
/* Anything to process? */
if(s != NULL && strlen(s->Str))
{
int nrTok;
/* Tokenise s */
Tokeniser *ptrTok = FillTokeniserBySentence(s->Str, 3, DELIM, &nrTok);
/* Any token? */
if(ptrTok != NULL)
{
int nrCount;
/* Reset nrTok */
nrTok = 0;
/* Count tokens excluding numerics */
for(nrCount = 0; nrCount < ptrTok->tokencount; nrCount++)
{
/* Is Numeric? */
if(!isnumeric(ptrTok->token[nrCount]))
nrTok++;
}
}
else
return 0; /* No tokens found! */
/* Is nrTok >= 12? */
if(nrTok > 12)
s->Score -= 7; /* Yes! Decrease sentence score! (was 10)*/
/* Free local resources */
FreeTokeniser(ptrTok);
}
/* Return. */
return 1;
}
/* Return 1 on success else 0 on error */
int SentenceProperNamesScore(Sentence *s)
{
/* Anything to process? */
if(s != NULL && strlen(s->Str))
{
int TokLen, TokCount;
Tokeniser *ptrTok = NULL;
/* Tokenise s to ptrTok */
if((ptrTok = FillTokeniserBySentence(s->Str, 4, DELIM, &TokLen)) == NULL)
return 0;
for(TokCount = 0; TokCount < TokLen; TokCount++)
{
/* Load ptrTok->token[TokCount] into ptrToken for easy reference */
char *ptrToken = ptrTok->token[TokCount];
/* First Letter must be Capital and not the First Token */
if(TokCount && issemantictoken(ptrToken))
{
int CharCount,
TrueSemantic = 1;
/* Check if rest characters are lowercased.. */
for(CharCount = 1; CharCount < (int)strlen(ptrToken); CharCount++)
{
if(issemantictoken(&ptrToken[CharCount]))
{
TrueSemantic = 0;
break;
}
}
/* ..are? */
if(!TrueSemantic)
continue; /* No! Ignore it */
/* Could it be a day or a month name? */
if(isday(ptrToken) || ismonth(ptrToken))
continue; /* Yes, ignore it */
/* The Letter conforms with "Proper Names" rule */
s->Score += 5;
/* For debugging */
#ifdef _DEBUG
printf("S:%s\n", ptrToken);
#endif
}
}
/* Free local resources */
FreeTokeniser(ptrTok);
}
/* Return. */
return 1;
}
/* +5 for sentences containg 1 numeric data, -5 for sentences with 2+ numeric data */
/* Return 1 on success 0 on error */
int SentenceNumericDataScore(Sentence *s)
{
/* Anything to process? */
if(s != NULL && strlen(s->Str))
{
Tokeniser *ptrTok = NULL;
int TokSize, TokCount = 0, NumericDataCount = 0;
/* Tokenise s to ptrTok */
if((ptrTok = FillTokeniserBySentence(s->Str, 4, DELIM, &TokSize)) == NULL)
return 0;
/* Count Tokeniser numeric data */
for(TokCount = 0; TokCount < TokSize; TokCount++)
if(isnumeric(ptrTok->token[TokCount]))
NumericDataCount++;
/* Free local resource */
FreeTokeniser(ptrTok);
/* Score estimation */
if(NumericDataCount == 1)
s->Score += 5;
if(NumericDataCount >= 2)
s->Score -= 5;
/* Return success. */
return 1;
}
/* Return failure. */
return 0;
}
/* +5 for sentences with day or dates */
int SentenceDateScore(Sentence *s)
{
/* Anything to process? */
if(s != NULL && strlen(s->Str))