-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevalb.c
1538 lines (1284 loc) · 39 KB
/
evalb.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
/*****************************************************************/
/* evalb [-p param_file] [-dh] [-e n] gold-file test-file */
/* */
/* Evaluate bracketing in test-file against gold-file. */
/* Return recall, precision, tagging accuracy. */
/* */
/* <option> */
/* -p param_file parameter file */
/* -d debug mode */
/* -e n number of error to kill (default=10) */
/* -h help */
/* */
/* Satoshi Sekine (NYU) */
/* Mike Collins (UPenn) */
/* */
/* October.1997 */
/* */
/* Please refer README for the update information */
/*****************************************************************/
#include <stdio.h>
#include <stdlib.h> //### added for exit, atoi decls
#include <ctype.h>
#include <string.h>
//# #include <malloc.h>
/* Internal Data format -------------------------------------------*/
/* */
/* (S (NP (NNX this)) (VP (VBX is) (NP (DT a) (NNX pen))) (SYM .)) */
/* */
/* wn=5 */
/* word label */
/* terminal[0] = this NNX */
/* terminal[1] = is VBX */
/* terminal[2] = a DT */
/* terminal[3] = pen NNX */
/* terminal[4] = . SYM */
/* */
/* bn=4 */
/* start end label */
/* bracket[0] = 0 5 S */
/* bracket[1] = 0 0 NP */
/* bracket[2] = 1 4 VP */
/* bracket[3] = 2 4 NP */
/* */
/* matched bracketing */
/* Recall = --------------------------- */
/* # of bracket in ref-data */
/* */
/* matched bracketing */
/* Recall = --------------------------- */
/* # of bracket in test-data */
/* */
/*-----------------------------------------------------------------*/
/******************/
/* constant macro */
/******************/
#define MAX_SENT_LEN 5000
#define MAX_WORD_IN_SENT 200
#define MAX_BRACKET_IN_SENT 200
#define MAX_WORD_LEN 100
#define MAX_LABEL_LEN 30
#define MAX_QUOTE_TERM 20
#define MAX_DELETE_LABEL 100
#define MAX_EQ_LABEL 100
#define MAX_EQ_WORD 100
#define MAX_LINE_LEN 500
#define DEFAULT_MAX_ERROR 10
#define DEFAULT_CUT_LEN 40
/*************/
/* structure */
/*************/
typedef struct ss_terminal {
char word[MAX_WORD_LEN];
char label[MAX_LABEL_LEN];
int result; /* 0:unmatch, 1:match, 9:undef */
} s_terminal;
typedef struct ss_term_ind {
s_terminal term;
int index;
int bracket;
int endslen;
int ends[MAX_BRACKET_IN_SENT];
} s_term_ind;
typedef struct ss_bracket {
int start;
int end;
unsigned int buf_start;
unsigned int buf_end;
char label[MAX_LABEL_LEN];
int result; /* 0: unmatch, 1:match, 5:delete 9:undef */
} s_bracket;
typedef struct ss_equiv {
char *s1;
char *s2;
} s_equiv;
/****************************/
/* global variables */
/* gold-data: suffix = 1 */
/* test-data: suffix = 2 */
/****************************/
/*---------------*/
/* Sentence data */
/*---------------*/
int wn1, wn2; /* number of words in sentence */
int r_wn1; /* number of words in sentence */
/* which only ignores labels in */
/* DELETE_LABEL_FOR_LENGTH */
s_terminal terminal1[MAX_WORD_IN_SENT]; /* terminal information */
s_terminal terminal2[MAX_WORD_IN_SENT];
s_term_ind quotterm1[MAX_QUOTE_TERM]; /* special terminals ("'","POS") */
s_term_ind quotterm2[MAX_QUOTE_TERM];
int bn1, bn2; /* number of brackets */
int r_bn1, r_bn2; /* number of brackets */
/* after deletion */
s_bracket bracket1[MAX_BRACKET_IN_SENT]; /* bracket information */
s_bracket bracket2[MAX_BRACKET_IN_SENT];
/*------------*/
/* Total data */
/*------------*/
int TOTAL_bn1, TOTAL_bn2, TOTAL_match; /* total number of brackets */
int TOTAL_sent; /* No. of sentence */
int TOTAL_error_sent; /* No. of error sentence */
int TOTAL_skip_sent; /* No. of skip sentence */
int TOTAL_comp_sent; /* No. of complete match sent */
int TOTAL_word; /* total number of word */
int TOTAL_crossing; /* total crossing */
int TOTAL_no_crossing; /* no crossing sentence */
int TOTAL_2L_crossing; /* 2 or less crossing sentence */
int TOTAL_correct_tag; /* total correct tagging */
int TOT_cut_len = DEFAULT_CUT_LEN; /* Cut-off length in statistics */
/* data for sentences with len <= CUT_LEN */
/* Historically it was 40. */
int TOT40_bn1, TOT40_bn2, TOT40_match; /* total number of brackets */
int TOT40_sent; /* No. of sentence */
int TOT40_error_sent; /* No. of error sentence */
int TOT40_skip_sent; /* No. of skip sentence */
int TOT40_comp_sent; /* No. of complete match sent */
int TOT40_word; /* total number of word */
int TOT40_crossing; /* total crossing */
int TOT40_no_crossing; /* no crossing sentence */
int TOT40_2L_crossing; /* 2 or less crossing sentence */
int TOT40_correct_tag; /* total correct tagging */
/*------------*/
/* miscallous */
/*------------*/
int Line; /* line number */
int Error_count = 0; /* Error count */
int Status; /* Result status for each sent */
/* 0: OK, 1: skip, 2: error */
/*-------------------*/
/* stack manuplation */
/*-------------------*/
int stack_top;
int stack[MAX_BRACKET_IN_SENT];
/************************************************************/
/* User parameters which can be specified in parameter file */
/************************************************************/
/*------------------------------------------*/
/* Debug mode */
/* print out data for individual sentence */
/*------------------------------------------*/
int DEBUG=0;
/*------------------------------------------*/
/* MAX error */
/* Number of error to stop the process. */
/* This is useful if there could be */
/* tokanization error. */
/* The process will stop when this number*/
/* of errors are accumulated. */
/*------------------------------------------*/
int Max_error = DEFAULT_MAX_ERROR;
/*------------------------------------------*/
/* Cut-off length for statistics */
/* int TOT_cut_len = DEFAULT_CUT_LEN; */
/* (Defined above) */
/*------------------------------------------*/
/*------------------------------------------*/
/* unlabeled or labeled bracketing */
/* 0: unlabeled bracketing */
/* 1: labeled bracketing */
/*------------------------------------------*/
int F_label = 1;
/*------------------------------------------*/
/* Delete labels */
/* list of labels to be ignored. */
/* If it is a pre-terminal label, delete */
/* the word along with the brackets. */
/* If it is a non-terminal label, just */
/* delete the brackets (don't delete */
/* childrens). */
/*------------------------------------------*/
char *Delete_label[MAX_DELETE_LABEL];
int Delete_label_n = 0;
/*------------------------------------------*/
/* Delete labels for length calculation */
/* list of labels to be ignored for */
/* length calculation purpose */
/*------------------------------------------*/
char *Delete_label_for_length[MAX_DELETE_LABEL];
int Delete_label_for_length_n = 0;
/*------------------------------------------*/
/* Labels to be considered for misquote */
/* (could be possesive or quote) */
/*------------------------------------------*/
char *Quote_term[MAX_QUOTE_TERM];
int Quote_term_n = 0;
/*------------------------------------------*/
/* Equivalent labels, words */
/* the pairs are considered equivalent */
/* This is non-directional. */
/*------------------------------------------*/
s_equiv EQ_label[MAX_EQ_LABEL];
int EQ_label_n = 0;
s_equiv EQ_word[MAX_EQ_WORD];
int EQ_word_n = 0;
/************************/
/* Function return-type */
/************************/
int main();
void init_global();
void print_head();
void init();
void read_parameter_file();
void set_param();
int narg();
int read_line();
void pushb();
int popb();
int stackempty();
void calc_result(unsigned char *buf1,unsigned char *buf);
void fix_quote();
void reinsert_term();
void massage_data();
void modify_label();
void individual_result();
void print_total();
void dsp_info();
int is_terminator();
int is_deletelabel();
int is_deletelabel_for_length();
int is_quote_term();
int word_comp();
int label_comp();
void Error();
void Fatal();
void Usage();
/* ### provided by std headers
int fprintf();
int printf();
int atoi();
int fclose();
int sscanf();
*/
/***********/
/* program */
/***********/
#define ARG_CHECK(st) if(!(*++(*argv) || (--argc && *++argv))){ \
fprintf(stderr,"Missing argument: %s\n",st); \
}
int
main(argc,argv)
int argc;
char *argv[];
{
char *filename1, *filename2;
FILE *fd1, *fd2;
unsigned char buff[5000];
unsigned char buff1[5000];
filename1=NULL;
filename2=NULL;
for(argc--,argv++;argc>0;argc--,argv++){
if(**argv == '-'){
while(*++(*argv)){
switch(**argv){
case 'h': /* help */
Usage();
exit(1);
case 'd': /* debug mode */
DEBUG = 1;
goto nextarg;
case 'D': /* debug mode */
DEBUG = 2;
goto nextarg;
case 'c': /* cut-off length */
ARG_CHECK("cut-off length for statistices");
TOT_cut_len = atoi(*argv);
goto nextarg;
case 'e': /* max error */
ARG_CHECK("number of error to kill");
Max_error = atoi(*argv);
goto nextarg;
case 'p': /* parameter file */
ARG_CHECK("parameter file");
read_parameter_file(*argv);
goto nextarg;
default:
Usage();
exit(0);
}
}
} else {
if(filename1==NULL){
filename1 = *argv;
}else if(filename2==NULL){
filename2 = *argv;
}
}
nextarg: continue;
}
init_global();
if((fd1 = fopen(filename1,"r"))==NULL){
Fatal("Can't open gold file (%s)\n",filename1);
}
if((fd2 = fopen(filename2,"r"))==NULL){
Fatal("Can't open test file (%s)\n",filename2);
}
print_head();
for(Line=1;fgets(buff,5000,fd1)!=NULL;Line++){
init();
/* READ 1 */
r_wn1 = read_line(buff,terminal1,quotterm1,&wn1,bracket1,&bn1);
strcpy(buff1,buff);
/* READ 2 */
if(fgets(buff,5000,fd2)==NULL){
Error("Number of lines unmatch (too many lines in gold file)\n");
break;
}
read_line(buff,terminal2,quotterm2,&wn2,bracket2,&bn2);
/* Calculate result and print it */
calc_result(buff1,buff);
if(DEBUG>=1){
dsp_info();
}
}
if(fgets(buff,5000,fd2)!=NULL){
Error("Number of lines unmatch (too many lines in test file)\n");
}
print_total();
return (0);
}
/*-----------------------------*/
/* initialize global variables */
/*-----------------------------*/
void
init_global()
{
TOTAL_bn1 = TOTAL_bn2 = TOTAL_match = 0;
TOTAL_sent = TOTAL_error_sent = TOTAL_skip_sent = TOTAL_comp_sent = 0;
TOTAL_word = TOTAL_correct_tag = 0;
TOTAL_crossing = 0;
TOTAL_no_crossing = TOTAL_2L_crossing = 0;
TOT40_bn1 = TOT40_bn2 = TOT40_match = 0;
TOT40_sent = TOT40_error_sent = TOT40_skip_sent = TOT40_comp_sent = 0;
TOT40_word = TOT40_correct_tag = 0;
TOT40_crossing = 0;
TOT40_no_crossing = TOT40_2L_crossing = 0;
}
/*------------------*/
/* print head title */
/*------------------*/
void
print_head()
{
printf(" Sent. Matched Bracket Cross Correct Tag\n");
printf(" ID Len. Stat. Recal Prec. Bracket gold test Bracket Words Tags Accracy\n");
printf("============================================================================\n");
}
/*-----------------------------------------------*/
/* initialization at each individual computation */
/*-----------------------------------------------*/
void
init()
{
int i;
wn1 = 0;
wn2 = 0;
bn1 = 0;
bn2 = 0;
r_bn1 = 0;
r_bn2 = 0;
for(i=0;i<MAX_WORD_IN_SENT;i++){
terminal1[i].word[0] = '\0';
terminal1[i].label[0] = '\0';
terminal1[i].result = 9;
terminal2[i].word[0] = '\0';
terminal2[i].label[0] = '\0';
terminal2[i].result = 9;
}
for(i=0;i<MAX_QUOTE_TERM;i++){
quotterm1[i].term.word[0] = '\0';
quotterm1[i].term.label[0] = '\0';
quotterm1[i].term.result = 9;
quotterm1[i].index = -1;
quotterm1[i].bracket = -1;
quotterm2[i].term.word[0] = '\0';
quotterm2[i].term.label[0] = '\0';
quotterm2[i].term.result = 9;
quotterm2[i].index = -1;
quotterm2[i].bracket = -1;
}
for(i=0;i<MAX_BRACKET_IN_SENT;i++){
bracket1[i].start = -1;
bracket1[i].end = -1;
bracket1[i].label[0] = '\0';
bracket1[i].result = 9;
bracket2[i].start = -1;
bracket2[i].end = -1;
bracket2[i].label[0] = '\0';
bracket2[i].result = 9;
}
Status = 0;
}
/*----------------*/
/* parameter file */
/*----------------*/
void
read_parameter_file(filename)
char *filename;
{
char buff[MAX_LINE_LEN];
FILE *fd;
int line;
int i;
if((fd=fopen(filename,"r"))==NULL){
Fatal("Can't open parameter file (%s)\n",filename);
}
for(line=1;fgets(buff,MAX_LINE_LEN,fd)!=NULL;line++){
/* clean up the tail and find unvalid line */
/*-----------------------------------------*/
for(i=strlen(buff)-1;i>0 && (isspace(buff[i]) || buff[i]=='\n');i--){
buff[i]='\0';
}
if(buff[0]=='#' || /* comment-line */
strlen(buff)<3){ /* too short, just ignore */
continue;
}
/* place the parameter and value */
/*-------------------------------*/
for(i=0;!isspace(buff[i]);i++);
for(;isspace(buff[i]) && buff[i]!='\0';i++);
if(buff[i]=='\0'){
fprintf(stderr,"Empty value in parameter file (%d)\n",line);
}
/* set parameter and value */
/*-------------------------*/
set_param(buff,buff+i);
}
fclose(fd);
}
#define STRNCMP(s) (strncmp(param,s,strlen(s))==0 && \
(param[strlen(s)]=='\0' || isspace(param[strlen(s)])))
void
set_param(param,value)
char *param, *value;
{
char l1[MAX_LABEL_LEN], l2[MAX_LABEL_LEN];
if(STRNCMP("DEBUG")){
DEBUG = atoi(value);
}else if(STRNCMP("MAX_ERROR")){
Max_error = atoi(value);
}else if(STRNCMP("CUTOFF_LEN")){
TOT_cut_len = atoi(value);
}else if(STRNCMP("LABELED")){
F_label = atoi(value);
}else if(STRNCMP("DELETE_LABEL")){
Delete_label[Delete_label_n] = (char *)malloc(strlen(value)+1);
strcpy(Delete_label[Delete_label_n],value);
Delete_label_n++;
}else if(STRNCMP("DELETE_LABEL_FOR_LENGTH")){
Delete_label_for_length[Delete_label_for_length_n] = (char *)malloc(strlen(value)+1);
strcpy(Delete_label_for_length[Delete_label_for_length_n],value);
Delete_label_for_length_n++;
}else if(STRNCMP("QUOTE_LABEL")){
Quote_term[Quote_term_n] = (char *)malloc(strlen(value)+1);
strcpy(Quote_term[Quote_term_n],value);
Quote_term_n++;
}else if(STRNCMP("EQ_LABEL")){
if(narg(value)!=2){
fprintf(stderr,"EQ_LABEL requires two values\n");
return;
}
sscanf(value,"%s %s",l1,l2);
EQ_label[EQ_label_n].s1 = (char *)malloc(strlen(l1)+1);
strcpy(EQ_label[EQ_label_n].s1,l1);
EQ_label[EQ_label_n].s2 = (char *)malloc(strlen(l2)+1);
strcpy(EQ_label[EQ_label_n].s2,l2);
EQ_label_n++;
}else if(STRNCMP("EQ_WORD")){
if(narg(value)!=2){
fprintf(stderr,"EQ_WORD requires two values\n");
return;
}
sscanf(value,"%s %s",l1,l2);
EQ_word[EQ_word_n].s1 = (char *)malloc(strlen(l1)+1);
strcpy(EQ_word[EQ_word_n].s1,l1);
EQ_word[EQ_word_n].s2 = (char *)malloc(strlen(l2)+1);
strcpy(EQ_word[EQ_word_n].s2,l2);
EQ_word_n++;
}else{
fprintf(stderr,"Unknown keyword (%s) in parameter file\n",param);
}
}
int
narg(s)
char *s;
{
int n;
for(n=0;*s!='\0';){
for(;isspace(*s);s++);
if(*s=='\0'){
break;
}
n++;
for(;!isspace(*s);s++){
if(*s=='\0'){
break;
}
}
}
return(n);
}
/*-----------------------------*/
/* Read line and gather data. */
/* Return langth of sentence. */
/*-----------------------------*/
int
read_line(buff, terminal, quotterm, wn, bracket, bn)
char *buff;
s_terminal terminal[];
s_term_ind quotterm[];
int *wn;
s_bracket bracket[];
int *bn;
{
char *p, *q, label[MAX_LABEL_LEN], word[MAX_WORD_LEN];
int qt; /* quote term counter */
int wid, bid; /* word ID, bracket ID */
int n; /* temporary remembering the position */
int b; /* temporary remembering bid */
int i;
int len; /* length of the sentence */
len = 0;
stack_top=0;
for(p=buff,qt=0,wid=0,bid=0;*p!='\0';){
if(isspace(*p)){
p++;
continue;
/* open bracket */
/*--------------*/
}else if(*p=='('){
n=wid;
for(p++,i=0;!is_terminator(*p);p++,i++){
label[i]=*p;
}
label[i]='\0';
/* Find terminals */
q = p;
if(isspace(*q)){
for(q++;isspace(*q);q++);
for(i=0;!is_terminator(*q);q++,i++){
word[i]=*q;
}
word[i]='\0';
/* compute length */
if(*q==')' && !is_deletelabel_for_length(label)==1){
len++;
}
if (DEBUG>1)
printf("label=%s, word=%s, wid=%d\n",label,word,wid);
/* quote terminal */
if(*q==')' && is_quote_term(label,word)==1){
strcpy(quotterm[qt].term.word,word);
strcpy(quotterm[qt].term.label,label);
quotterm[qt].index = wid;
quotterm[qt].bracket = bid;
quotterm[qt].endslen = stack_top;
//quotterm[qt].ends = (int*)malloc(stack_top*sizeof(int));
memcpy(quotterm[qt].ends,stack,stack_top*sizeof(int));
qt++;
}
/* delete terminal */
if(*q==')' && is_deletelabel(label)==1){
p = q+1;
continue;
/* valid terminal */
}else if(*q==')'){
strcpy(terminal[wid].word,word);
strcpy(terminal[wid].label,label);
wid++;
p = q+1;
continue;
/* error */
}else if(*q!='('){
Error("More than two elements in a bracket\n");
}
}
/* otherwise non-terminal label */
bracket[bid].start = wid;
bracket[bid].buf_start = p-buff;
strcpy(bracket[bid].label,label);
pushb(bid);
bid++;
/* close bracket */
/*---------------*/
}else if(*p==')'){
b = popb();
bracket[b].end = wid;
bracket[b].buf_end = p-buff;
p++;
/* error */
/*-------*/
}else{
Error("Reading sentence\n");
}
}
if(!stackempty()){
Error("Bracketing is unbalanced (too many open bracket)\n");
}
*wn = wid;
*bn = bid;
return(len);
}
/*----------------------*/
/* stack operation */
/* for bracketing pairs */
/*----------------------*/
void
pushb(item)
int item;
{
stack[stack_top++]=item;
}
int
popb()
{
int item;
item = stack[stack_top-1];
if(stack_top-- < 0){
Error("Bracketing unbalance (too many close bracket)\n");
}
return(item);
}
int
stackempty()
{
if(stack_top==0){
return(1);
}else{
return(0);
}
}
/*------------------*/
/* calculate result */
/*------------------*/
void
calc_result(unsigned char *buf1,unsigned char *buf)
{
int i, j, l;
int match, crossing, correct_tag;
int last_i = -1;
char my_buf[1000];
int match_found = 0;
char match_j[200];
for (j = 0; j < bn2; ++j) {
match_j[j] = 0;
}
/* ML */
if (DEBUG>1)
printf("\n");
/* Find skip and error */
/*---------------------*/
if(wn2==0){
Status = 2;
individual_result(0,0,0,0,0,0);
return;
}
if(wn1 != wn2){
//if (DEBUG>1)
//Error("Length unmatch (%d|%d)\n",wn1,wn2);
fix_quote();
if(wn1 != wn2){
Error("Length unmatch (%d|%d)\n",wn1,wn2);
individual_result(0,0,0,0,0,0);
return;
}
}
for(i=0;i<wn1;i++){
if(word_comp(terminal1[i].word,terminal2[i].word)==0){
Error("Words unmatch (%s|%s)\n",terminal1[i].word,
terminal2[i].word);
individual_result(0,0,0,0,0,0);
return;
}
}
/* massage the data */
/*------------------*/
massage_data();
/* matching brackets */
/*-------------------*/
match = 0;
for(i=0;i<bn1;i++){
for(j=0;j<bn2;j++){
if (DEBUG>1)
printf("1.res=%d, 2.res=%d, 1.start=%d, 2.start=%d, 1.end=%d, 2.end=%d\n",bracket1[i].result,bracket2[j].result,bracket1[i].start,bracket2[j].start,bracket1[i].end,bracket2[j].end);
// does bracket match?
if(bracket1[i].result != 5 &&
bracket2[j].result == 0 &&
bracket1[i].start == bracket2[j].start && bracket1[i].end == bracket2[j].end) {
// (1) do we not care about the label or (2) does the label match?
if (F_label==0 || label_comp(bracket1[i].label,bracket2[j].label)==1) {
bracket1[i].result = bracket2[j].result = 1;
match++;
match_found = 1;
break;
} else {
if (DEBUG>1) {
printf(" LABEL[%d-%d]: ",bracket1[i].start,bracket1[i].end-1);
l = bracket1[i].buf_end-bracket1[i].buf_start;
strncpy(my_buf,buf1+bracket1[i].buf_start,l);
my_buf[l] = '\0';
printf("%s\n",my_buf);
}
match_found = 1;
match_j[j] = 1;
}
}
}
if (!match_found && bracket1[i].result != 5 && DEBUG>1) {
/* ### ML 09/28/03: gold bracket with no corresponding test bracket */
printf(" BRACKET[%d-%d]: ",bracket1[i].start,bracket1[i].end-1);
l = bracket1[i].buf_end-bracket1[i].buf_start;
strncpy(my_buf,buf1+bracket1[i].buf_start,l);
my_buf[l] = '\0';
printf("%s\n",my_buf);
}
match_found = 0;
}
for(j=0;j<bn2;j++){
if (bracket2[j].result==0 && !match_j[j] && DEBUG>1) {
/* test bracket with no corresponding gold bracket */
printf(" EXTRA[%d-%d]: ",bracket2[j].start,bracket2[j].end-1);
l = bracket2[j].buf_end-bracket2[j].buf_start;
strncpy(my_buf,buf+bracket2[j].buf_start,l);
my_buf[l] = '\0';
printf("%s\n",my_buf);
}
}
/* crossing */
/*----------*/
crossing = 0;
/* crossing is counted based on the brackets */
/* in test rather than gold file (by Mike) */
for(j=0;j<bn2;j++){
for(i=0;i<bn1;i++){
if(bracket1[i].result != 5 &&
bracket2[j].result != 5 &&
((bracket1[i].start < bracket2[j].start &&
bracket1[i].end > bracket2[j].start &&
bracket1[i].end < bracket2[j].end) ||
(bracket1[i].start > bracket2[j].start &&
bracket1[i].start < bracket2[j].end &&
bracket1[i].end > bracket2[j].end))){
/* ### ML 09/01/03: get details on cross-brackettings */
if (i != last_i) {
if (DEBUG>1) {
printf(" CROSSING[%d-%d]: ",bracket1[i].start,bracket1[i].end-1);
l = bracket1[i].buf_end-bracket1[i].buf_start;
strncpy(my_buf,buf1+bracket1[i].buf_start,l);
my_buf[l] = '\0';
printf("%s\n",my_buf);
/* ML
printf("\n CROSSING at bracket %d:\n",i-1);
printf(" GOLD (tokens %d-%d): ",bracket1[i].start,bracket1[i].end-1);
l = bracket1[i].buf_end-bracket1[i].buf_start;
strncpy(my_buf,buf1+bracket1[i].buf_start,l);
my_buf[l] = '\0';
printf("%s\n",my_buf);
*/
}
last_i = i;
}
/* ML
printf(" TEST (tokens %d-%d): ",bracket2[j].start,bracket2[j].end-1);
l = bracket2[j].buf_end-bracket2[j].buf_start;
strncpy(my_buf,buf+bracket2[j].buf_start,l);
my_buf[l] = '\0';
printf("%s\n",my_buf);
*/
crossing++;
break;
}
}
}
/* Tagging accuracy */
/*------------------*/
correct_tag=0;
for(i=0;i<wn1;i++){
if(label_comp(terminal1[i].label,terminal2[i].label)==1){
terminal1[i].result = terminal2[i].result = 1;
correct_tag++;
} else {
terminal1[i].result = terminal2[i].result = 0;
}
}
individual_result(wn1,r_bn1,r_bn2,match,crossing,correct_tag);
}
void
fix_quote()
{
int i,j,k;
if (DEBUG>1) {
for(i=0;i<MAX_QUOTE_TERM;i++){
if (quotterm1[i].index!=-1)
printf("%d: %s - %s\n",quotterm1[i].index,
quotterm1[i].term.label,
quotterm1[i].term.word);
if (quotterm2[i].index!=-1)
printf("%d: %s - %s\n",quotterm2[i].index,
quotterm2[i].term.label,
quotterm2[i].term.word);
}
}
for(i=0;i<MAX_QUOTE_TERM;i++) {
int ind = quotterm2[i].index;
if (ind!=-1) {
for(j=0;j<MAX_QUOTE_TERM;j++){
if (quotterm1[j].index==ind &&
strcmp(quotterm1[j].term.label,
quotterm2[i].term.label)!=0) {