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 = a_ptr->next(), ++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 = a_ptr->next())
113 if (a_ptr->f(
"pos")==1)
114 for (b_ptr = b.
head(); b_ptr != 0; b_ptr = b_ptr->next())
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 = a_ptr->next())
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 = r_ptr->next())
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 = r_ptr->next())
397 if (r_ptr->f(
"pos")==1)
401 a = r_ptr->rlink(
"test").first();
406 for (s_ptr = r_ptr->next(); s_ptr != 0; s_ptr = s_ptr->next())
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 = r_ptr->next())
460 if (r_ptr->f(
"pos")==1)
463 for (r_ptr = reflab.
head(); r_ptr != 0; r_ptr = r_ptr->next())
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 = t_ptr->next())
476 if (t_ptr->f(
"pos")==1)
478 for (j = 0, r_ptr = reflab.
head(); r_ptr != 0; r_ptr = r_ptr->next())
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 comparision method" << method << endl;
494 minimise_matrix_by_column(m);
495 minimise_matrix_by_row(m);
496 matrix_ceiling(m, t);
499 for (j = 0, r_ptr = reflab.
head(); r_ptr != 0; r_ptr = r_ptr->next())
501 if (r_ptr->f(
"pos")==1)
503 pos = lowest_pos(m, j);
519 EST_StrList rposlist, tposlist, rminorlist, tminorlist;
520 float ra, rc, mra, mrc;
522 StringtoStrList(rpos, rposlist);
523 StringtoStrList(tpos, tposlist);
524 StringtoStrList(
"m l mrb mfb lrb lfb", rminorlist);
525 StringtoStrList(
"m l mrb mfb lrb lfb", tminorlist);
527 int tot, del, ins, ltot, ldel, lins, lmdel, mdel, lmins, mins;
528 tot = del = ins = mdel = mins = 0;
530 for (pt = tlist.head(); pt; pt = pt->next())
532 pr = RelationList_ptr_extract(rlist, tlist(pt).name(), TRUE);
550 m = matrix_compare(reflab, testlab, method, t, v);
553 ldel = matrix_deletions(m);
554 lmdel = major_matrix_deletions(m, reflab);
555 lins = matrix_insertions(m);
556 lmins = major_matrix_insertions(m, testlab);
558 print_results(reflab, testlab, m, ltot, ldel, lins, v);
569 rc = float(tot - del)/(float)tot * 100.0;
570 ra = float(tot - del -ins)/(float)tot *100.0;
571 mrc = float(tot - mdel)/(float)tot * 100.0;
572 mra = float(tot - mdel - mins)/(float)tot *100.0;
576 cout <<
"Total " << tot <<
" del: " << del <<
" ins: " << ins << endl;
577 cout <<
"Total " << tot <<
" major del " << mdel <<
" major ins" << mins << endl;
579 cout <<
"Correct " << rc <<
"% Accuracy " << ra <<
"%" << endl;
580 cout <<
"Major Correct " << mrc <<
"% Accuracy " << mra <<
"%" << endl;
591 for (i = 0, s = e.
head(); s; s = s->next())
592 if ((
int)s->f(
"pos"))
594 if (column_hit(m, i) >= 0)
602 for (i = 0, s = e.
head(); s; s = s->next())
603 if ((
int)s->f(
"pos"))
605 if (row_hit(m, i) >= 0)
618 for (ptr = a.
list.head(); ptr != 0; ptr= ptr->next())
619 if (a.
val(ptr) == -1)
634 relation_match(ref.stream(name), test.stream(name));
637 function_match(uref, ref.stream(name), test.stream(name));
638 function_match(utest, test.stream(name), ref.stream(name));
640 monotonic_match(uref, utest);
662 for (a_ptr = a.
head(); a_ptr != 0; a_ptr = a_ptr->next())
664 a_ptr->link(b.stream_name())->clear();
665 if ((a_ptr->f(
"pos")==1) && (ua.
val(a_ptr->addr()) != -1))
666 a_ptr->make_link(b.stream_name(), ua.
val(a_ptr->addr()));
668 for (b_ptr = b.
head(); b_ptr != 0; b_ptr = b_ptr->next())
670 b_ptr->link(a.stream_name())->clear();
671 if ((b_ptr->f(
"pos")==1) && (ub.
val(b_ptr->addr()) != -1))
672 b_ptr->make_link(a.stream_name(), ub.
val(b_ptr->addr()));
685 for (a_ptr = a.
head(); a_ptr != 0; a_ptr = a_ptr->next())
687 a_ptr->link(stream_type)->clear();
688 if ((a_ptr->f(
"pos")==1) && (u.
val(a_ptr->addr()) != -1))
689 a_ptr->make_link(stream_type, u.
val(a_ptr->addr()));
706 c = (b == -1) ? -1: ltest.
val(b);
707 d = (c == -1) ? -1: f1.
val(c);
733 EST_II_KVL f2, inv_f2, inv_f1, f1, lref, ltest;
735 compare_labels(ref, test,
"Event", f2, inv_f2);
736 compare_labels(ref, test,
"Syllable", f1, inv_f1);
740 cout <<
"Syllable mapping from ref to test\n" << f1;
741 cout <<
"Syllable mapping from test to ref\n" << inv_f1;
745 cout <<
"Event mapping from ref to test\n" << f2;
746 cout <<
"Event mapping from test to ref\n" << inv_f2;
750 cout <<
"Syllable_insertions: " << insdel(inv_f1) << endl;
752 cout <<
"Syllable_deletions: " << insdel(f1) << endl;
755 cout <<
"Event_insertions: " << insdel(inv_f2) << endl;
757 cout <<
"Event_deletions: " << insdel(f2) << endl;
762 function_match(lref, ref.stream(
"Event"), ref.stream(
"Syllable"));
763 function_match(ltest, test.stream(
"Event"), test.stream(
"Syllable"));
765 if (op.
present(
"print_functions"))
767 cout <<
"Lref\n" << lref;
768 cout <<
"Ltest\n" << ltest;
769 cout <<
"f1\n" << f1;
770 cout <<
"f2\n" << f2;
774 int correct, n_ev, n_syl;
776 correct = n_ev = n_syl = 0;
777 for (a_ptr = ref.stream(
"Event").head(); a_ptr != 0; a_ptr = a_ptr->next())
778 if (a_ptr->f(
"pos")==1)
781 if (lref.
val(a_ptr->addr())
782 == commutate(a_ptr, f1, f2, lref, ltest))
785 for (a_ptr = ref.stream(
"Syllable").head();a_ptr != 0; a_ptr = a_ptr->next())
786 if (a_ptr->f(
"pos")==1)
790 cout <<
"Number_of_Syllables: " << n_syl << endl;
792 cout <<
"Number_of_Events: " << n_ev << endl;
795 cout <<
"Correct_links: " << correct <<endl;
797 if (op.
present(
"print_derivation"))
799 for (a_ptr = ref.stream(
"Event").head();a_ptr!= 0; a_ptr = a_ptr->next())
801 if (a_ptr->f(
"pos")==1)
803 cout <<
"Lr(ei): " << lref.
val(a_ptr->addr()) << endl;
804 cout <<
"f2(ei): " << f2.
val(a_ptr->addr()) << endl;
805 cout <<
"Lt(f2(ei)): " << ltest.
val(f2.
val(a_ptr->addr()))
807 cout <<
"f1(Lt(f2(ei))): "
808 << f1.
val(ltest.
val(f2.
val(a_ptr->addr()))) << endl;
810 cout <<
"Event " << *a_ptr;
811 if ( lref.
val(a_ptr->addr())
812 == f1.
val(ltest.
val(f2.
val(a_ptr->addr()))))
813 cout <<
" is correct\n";
815 cout <<
" is incorrect\n";
823 cout.setf(ios::left,ios::adjustfield);
827 cout <<
"Deletions: ";
829 cout << matrix_deletions(m);
830 cout <<
"Insertions: ";
832 cout<< matrix_insertions(m) << endl;
841 for (r_ptr = ref.
head(); r_ptr != 0; r_ptr = r_ptr->next())
843 if (r_ptr->f(
"pos")==1)
847 cout << r_ptr->name() <<
" ";
849 cout.setf(ios::right);
850 cout<< r_ptr->
F(
"end") <<
" ";
855 for (t_ptr = test.
head(), i = 0; i < a.
num_rows(); t_ptr = t_ptr->next())
857 if (t_ptr->f(
"pos")==1)
859 cout << t_ptr->name() <<
" ";
864 cout.setf(ios::right);
865 cout.setf(ios::fixed, ios::floatfield);
866 cout << a(i, j) <<
" ";
895 int num_b_insertions(
EST_FMatrix &m,
int last,
int current)
898 c1 = column_hit(m, last);
899 c2 = column_hit(m, current);
904 int num_b_deletions(
EST_FMatrix &m,
int last,
int current)
907 c1 = row_hit(m, last);
908 c2 = row_hit(m, current);
935 for (s = a.
head(); s; s = s->next())
937 if (s->f(
"pos") == 0)
939 else if (s->f(
"hit") == 1)
943 s->features().
clear();
951 for (a = lab.
head(); a; a = n)
1052 int del,
int ins,
int v)
1064 cout << basename(ref.
name(),
"") << endl;
1065 print_i_d_scores(m);
1070 cout << basename(ref.
name(),
"") << endl;
1071 print_aligned_trans(ref, test, m);
1072 print_i_d_scores(m);
1077 cout << basename(ref.
name(),
"") << endl;
1078 print_matrix_scores(ref, test, m);
1079 print_i_d_scores(m);
1084 cout << basename(ref.
name(),
"") << endl;
1085 print_matrix_scores(ref, test, m);
1086 print_aligned_trans(ref, test, m);
1087 print_i_d_scores(m);
1092 print_matrix_scores(ref, test, m);
1093 error_location(ref, m, 1);
1094 make_hit_and_miss(ref);
1095 error_location(test, m, 0);
1096 make_hit_and_miss(test);
1097 ref.
save(
"ref.error");
1098 test.
save(
"test.errors");
1102 error_location(ref, m, 1);
1103 make_hit_and_miss(ref);
1104 error_location(test, m, 0);
1105 make_hit_and_miss(test);
1106 ref.
save(
"ref.error");
1107 test.
save(
"test.error");