43 #include "EST_types.h"
44 #include "EST_FMatrix.h"
45 #include "ling_class/EST_Relation.h"
46 #include "EST_Token.h"
47 #include "EST_string_aux.h"
48 #include "ling_class/EST_relation_aux.h"
49 #include "ling_class/EST_relation_compare.h"
50 #include "EST_io_aux.h"
55 return ((start(&b) < a.
F(
"end")) && (start(&a) < b.
F(
"end")));
63 for (ptr = a.
list.head(); ptr != 0; ptr = ptr->next())
73 for (ptr = b.
list.head(); ptr != 0; ptr = ptr->next())
95 for (i = 0, a_ptr = a.
head(); a_ptr != 0; a_ptr = inext(a_ptr), ++i)
97 if (a_ptr->f(
"pos")==1)
100 for (i_ptr = a_ptr->link(b.stream_name())->head(); i_ptr != 0;
101 i_ptr = i_ptr->next())
102 u.
change_val(a_ptr->addr(), a_ptr->link(b.stream_name())->item(i_ptr));
112 for (a_ptr = a.
head(); a_ptr != 0; a_ptr = inext(a_ptr))
113 if (a_ptr->f(
"pos")==1)
114 for (b_ptr = b.
head(); b_ptr != 0; b_ptr = inext(b_ptr))
116 if ((b_ptr->f(
"pos")==1)
117 &&(close_enough(*a_ptr, *b_ptr)))
121 link(*a_ptr, *b_ptr);
135 relation_match(reflab, testlab);
137 cout <<
"Ref\n" << reflab;
138 cout <<
"Test\n" << testlab;
140 function_match(uref, reflab, testlab);
141 function_match(utest, testlab, reflab);
143 cout <<
"Ref\n" << reflab;
144 cout <<
"Test\n" << testlab;
145 cout <<
"Keyval REF\n" << uref;
146 cout <<
"Keyval TEST\n" << utest;
151 monotonic_match(uref, utest);
153 reassign_links(reflab, uref, testlab.name());
154 reassign_links(testlab, utest, reflab.name());
155 cout <<
"Keyval REF\n" << uref;
156 cout <<
"Keyval TEST\n" << utest;
160 cout.setf(ios::left,ios::adjustfield);
164 cout << uref.length();
165 cout <<
"Deletions: ";
167 cout << insdel(uref);
168 cout <<
"Insertions: ";
170 cout<< insdel(utest) << endl;
177 for (a_ptr = a.
head(); a_ptr != 0; a_ptr = inext(a_ptr))
178 if (a_ptr->f(
"pos") == 1)
192 s = fabs(start(&ref) - start(&test));
193 e = fabs(ref.
F(
"end") - test.
F(
"end"));
195 return (s + e) / duration(&ref);
204 s = (start(&test) < start(&ref)) ? start(&ref) - start(&test) : 0;
205 e = (ref.
F(
"end") < test.
F(
"end")) ?
206 test.
F(
"end") - ref.
F(
"end") : 0;
208 return (s + e) / duration(&ref);
217 if ((m(i, j) > -0.01) && (m(i, j) < val))
251 if ((m(i, j) < val) && (m(i, j) > -0.01))
291 s = nthpos(ref_lab, i);
293 if (s->f(
"minor") == 1)
324 s = nthpos(ref_lab, j);
326 if (s->f(
"minor") == 1)
337 int lowest_pos(
float *m,
int n)
342 for (i = 0; i < n; ++i)
361 for (r_ptr = reflab.
head(); r_ptr != 0; r_ptr = inext(r_ptr))
362 if (r_ptr->f(
"pos")==1)
366 cout <<
"score is" << score << endl;
368 a = r_ptr->rlink(
"blank").first();
369 cout <<
"score is" << score <<
" address: " << a << endl;
394 score =
new float[reflab.
length()];
396 for (r_ptr = reflab.
head(); r_ptr != 0; r_ptr = inext(r_ptr))
397 if (r_ptr->f(
"pos")==1)
401 a = r_ptr->rlink(
"test").first();
406 for (s_ptr = inext(r_ptr); s_ptr != 0; s_ptr = inext(s_ptr))
407 if (s_ptr->f(
"pos")==1)
408 if (s_ptr->rlink(
"test").first() == a)
411 cout <<
"la: " << la;
415 for (i = 0, p = la.head(); p!= 0; p = p->next(), ++i)
417 t_ptr = reflab.item(la.item(p));
422 pos = lowest_pos(score, i);
424 cout <<
"best is " << pos << endl;
426 for (i = 0, p = la.head(); p!= 0; p = p->next(), ++i)
429 t_ptr = reflab.item(la.item(p));
430 t_ptr->rlink(
"test").clear();
451 int num_ref, num_test;
456 num_ref = num_test = 0;
459 for (r_ptr = testlab.
head(); r_ptr != 0; r_ptr = inext(r_ptr))
460 if (r_ptr->f(
"pos")==1)
463 for (r_ptr = reflab.
head(); r_ptr != 0; r_ptr = inext(r_ptr))
464 if (r_ptr->f(
"pos")==1)
469 if ((m.num_rows() == 0) || (m.num_columns() == 0))
475 for (i = 0, t_ptr = testlab.
head(); t_ptr != 0; t_ptr = inext(t_ptr))
476 if (t_ptr->f(
"pos")==1)
478 for (j = 0, r_ptr = reflab.
head(); r_ptr != 0; r_ptr = inext(r_ptr))
479 if (r_ptr->f(
"pos")==1)
482 m(i, j) = label_distance1(*r_ptr, *t_ptr);
483 else if (method == 2)
484 m(i, j) = label_distance2(*r_ptr, *t_ptr);
486 cerr <<
"Unknown comparison method" << method << endl;
494 minimise_matrix_by_column(m);
495 minimise_matrix_by_row(m);
496 matrix_ceiling(m, t);
501 for (j = 0, r_ptr = reflab.
head(); r_ptr != 0; r_ptr = inext(r_ptr))
503 if (r_ptr->f(
"pos")==1)
505 pos = lowest_pos(m, j);
522 EST_StrList rposlist, tposlist, rminorlist, tminorlist;
523 float ra, rc, mra, mrc;
525 StringtoStrList(rpos, rposlist);
526 StringtoStrList(tpos, tposlist);
527 StringtoStrList(
"m l mrb mfb lrb lfb", rminorlist);
528 StringtoStrList(
"m l mrb mfb lrb lfb", tminorlist);
530 int tot, del, ins, ltot, ldel, lins, lmdel, mdel, lmins, mins;
531 tot = del = ins = mdel = mins = 0;
533 for (pt = tlist.head(); pt; pt = pt->next())
535 pr = RelationList_ptr_extract(rlist, tlist(pt).name(), TRUE);
553 m = matrix_compare(reflab, testlab, method, t, v);
556 ldel = matrix_deletions(m);
557 lmdel = major_matrix_deletions(m, reflab);
558 lins = matrix_insertions(m);
559 lmins = major_matrix_insertions(m, testlab);
561 print_results(reflab, testlab, m, ltot, ldel, lins, v);
572 rc = float(tot - del)/(float)tot * 100.0;
573 ra = float(tot - del -ins)/(float)tot *100.0;
574 mrc = float(tot - mdel)/(float)tot * 100.0;
575 mra = float(tot - mdel - mins)/(float)tot *100.0;
579 cout <<
"Total " << tot <<
" del: " << del <<
" ins: " << ins << endl;
580 cout <<
"Total " << tot <<
" major del " << mdel <<
" major ins" << mins << endl;
582 cout <<
"Correct " << rc <<
"% Accuracy " << ra <<
"%" << endl;
583 cout <<
"Major Correct " << mrc <<
"% Accuracy " << mra <<
"%" << endl;
594 for (i = 0, s = e.
head(); s; s = inext(s))
595 if ((
int)s->f(
"pos"))
597 if (column_hit(m, i) >= 0)
605 for (i = 0, s = e.
head(); s; s = inext(s))
606 if ((
int)s->f(
"pos"))
608 if (row_hit(m, i) >= 0)
621 for (ptr = a.
list.head(); ptr != 0; ptr= ptr->next())
622 if (a.
val(ptr) == -1)
637 relation_match(ref.stream(name), test.stream(name));
640 function_match(uref, ref.stream(name), test.stream(name));
641 function_match(utest, test.stream(name), ref.stream(name));
643 monotonic_match(uref, utest);
665 for (a_ptr = a.
head(); a_ptr != 0; a_ptr = inext(a_ptr))
667 a_ptr->link(b.stream_name())->clear();
668 if ((a_ptr->f(
"pos")==1) && (ua.
val(a_ptr->addr()) != -1))
669 a_ptr->make_link(b.stream_name(), ua.
val(a_ptr->addr()));
671 for (b_ptr = b.
head(); b_ptr != 0; b_ptr = inext(b_ptr))
673 b_ptr->link(a.stream_name())->clear();
674 if ((b_ptr->f(
"pos")==1) && (ub.
val(b_ptr->addr()) != -1))
675 b_ptr->make_link(a.stream_name(), ub.
val(b_ptr->addr()));
688 for (a_ptr = a.
head(); a_ptr != 0; a_ptr = inext(a_ptr))
690 a_ptr->link(stream_type)->clear();
691 if ((a_ptr->f(
"pos")==1) && (u.
val(a_ptr->addr()) != -1))
692 a_ptr->make_link(stream_type, u.
val(a_ptr->addr()));
709 c = (b == -1) ? -1: ltest.
val(b);
710 d = (c == -1) ? -1: f1.
val(c);
736 EST_II_KVL f2, inv_f2, inv_f1, f1, lref, ltest;
738 compare_labels(ref, test,
"Event", f2, inv_f2);
739 compare_labels(ref, test,
"Syllable", f1, inv_f1);
743 cout <<
"Syllable mapping from ref to test\n" << f1;
744 cout <<
"Syllable mapping from test to ref\n" << inv_f1;
748 cout <<
"Event mapping from ref to test\n" << f2;
749 cout <<
"Event mapping from test to ref\n" << inv_f2;
753 cout <<
"Syllable_insertions: " << insdel(inv_f1) << endl;
755 cout <<
"Syllable_deletions: " << insdel(f1) << endl;
758 cout <<
"Event_insertions: " << insdel(inv_f2) << endl;
760 cout <<
"Event_deletions: " << insdel(f2) << endl;
765 function_match(lref, ref.stream(
"Event"), ref.stream(
"Syllable"));
766 function_match(ltest, test.stream(
"Event"), test.stream(
"Syllable"));
768 if (op.
present(
"print_functions"))
770 cout <<
"Lref\n" << lref;
771 cout <<
"Ltest\n" << ltest;
772 cout <<
"f1\n" << f1;
773 cout <<
"f2\n" << f2;
777 int correct, n_ev, n_syl;
779 correct = n_ev = n_syl = 0;
780 for (a_ptr = ref.stream(
"Event").head(); a_ptr != 0; a_ptr = inext(a_ptr))
781 if (a_ptr->f(
"pos")==1)
784 if (lref.
val(a_ptr->addr())
785 == commutate(a_ptr, f1, f2, lref, ltest))
788 for (a_ptr = ref.stream(
"Syllable").head();a_ptr != 0; a_ptr = inext(a_ptr))
789 if (a_ptr->f(
"pos")==1)
793 cout <<
"Number_of_Syllables: " << n_syl << endl;
795 cout <<
"Number_of_Events: " << n_ev << endl;
798 cout <<
"Correct_links: " << correct <<endl;
800 if (op.
present(
"print_derivation"))
802 for (a_ptr = ref.stream(
"Event").head();a_ptr!= 0; a_ptr = inext(a_ptr))
804 if (a_ptr->f(
"pos")==1)
806 cout <<
"Lr(ei): " << lref.
val(a_ptr->addr()) << endl;
807 cout <<
"f2(ei): " << f2.
val(a_ptr->addr()) << endl;
808 cout <<
"Lt(f2(ei)): " << ltest.
val(f2.
val(a_ptr->addr()))
810 cout <<
"f1(Lt(f2(ei))): "
811 << f1.
val(ltest.
val(f2.
val(a_ptr->addr()))) << endl;
813 cout <<
"Event " << *a_ptr;
814 if ( lref.
val(a_ptr->addr())
815 == f1.
val(ltest.
val(f2.
val(a_ptr->addr()))))
816 cout <<
" is correct\n";
818 cout <<
" is incorrect\n";
826 cout.setf(ios::left,ios::adjustfield);
830 cout <<
"Deletions: ";
832 cout << matrix_deletions(m);
833 cout <<
"Insertions: ";
835 cout<< matrix_insertions(m) << endl;
844 for (r_ptr = ref.
head(); r_ptr != 0; r_ptr = inext(r_ptr))
846 if (r_ptr->f(
"pos")==1)
850 cout << r_ptr->name() <<
" ";
852 cout.setf(ios::right);
853 cout<< r_ptr->
F(
"end") <<
" ";
858 for (t_ptr = test.
head(), i = 0; i < a.
num_rows(); t_ptr = inext(t_ptr))
860 if (t_ptr->f(
"pos")==1)
862 cout << t_ptr->name() <<
" ";
867 cout.setf(ios::right);
868 cout.setf(ios::fixed, ios::floatfield);
869 cout << a(i, j) <<
" ";
898 int num_b_insertions(
EST_FMatrix &m,
int last,
int current)
901 c1 = column_hit(m, last);
902 c2 = column_hit(m, current);
907 int num_b_deletions(
EST_FMatrix &m,
int last,
int current)
910 c1 = row_hit(m, last);
911 c2 = row_hit(m, current);
938 for (s = a.
head(); s; s = inext(s))
940 if (s->f(
"pos") == 0)
942 else if (s->f(
"hit") == 1)
946 s->features().
clear();
954 for (a = lab.
head(); a; a = n)
1055 int del,
int ins,
int v)
1067 cout << basename(ref.
name(),
"") << endl;
1068 print_i_d_scores(m);
1073 cout << basename(ref.
name(),
"") << endl;
1074 print_aligned_trans(ref, test, m);
1075 print_i_d_scores(m);
1080 cout << basename(ref.
name(),
"") << endl;
1081 print_matrix_scores(ref, test, m);
1082 print_i_d_scores(m);
1087 cout << basename(ref.
name(),
"") << endl;
1088 print_matrix_scores(ref, test, m);
1089 print_aligned_trans(ref, test, m);
1090 print_i_d_scores(m);
1095 print_matrix_scores(ref, test, m);
1096 error_location(ref, m, 1);
1097 make_hit_and_miss(ref);
1098 error_location(test, m, 0);
1099 make_hit_and_miss(test);
1100 ref.
save(
"ref.error");
1101 test.
save(
"test.errors");
1105 error_location(ref, m, 1);
1106 make_hit_and_miss(ref);
1107 error_location(test, m, 0);
1108 make_hit_and_miss(test);
1109 ref.
save(
"ref.error");
1110 test.
save(
"test.error");