49 static int align_main(
int argc,
char **argv);
55 int &total,
int &ins,
int &del,
int &sub,
int &correct);
93 int main(
int argc,
char **argv)
96 align_main(argc,argv);
102 static int align_main(
int argc,
char **argv)
113 "Summary: align an hypothesis with a reference string\n"+
114 "-rfile <ifile> Reference file\n"+
115 "-hfile <ifile> Hypothesis file\n"+
116 "-rstring <string> Reference string\n"+
117 "-hstring <string> Hypothesis string\n"+
118 "-format <string>\n"+
119 " Supported formats: strings, nisttool\n",
123 outfile = al.
val(
"-o");
128 format = al.
val(
"-format");
132 if (format ==
"strings")
134 else if (format ==
"nisttool")
137 cout <<
"Unknown or unhandled format: " << format << endl;
145 float ins,
float del,
float sub);
152 int total,ins,del,sub,correct;
154 load_sentence(u,
"ref",refStr);
155 load_sentence(u,
"hypo",hypStr);
156 align(u,
"ref",
"hypo",
"align");
157 align_score(u,
"ref",
"hypo",
"align",total,ins,del,sub,correct);
158 fprintf(stdout,
"words %d\n",total);
159 fprintf(stdout,
"insertions %d\n",ins);
160 fprintf(stdout,
"deletions %d\n",del);
161 fprintf(stdout,
"substitutions %d\n",sub);
162 fprintf(stdout,
"correct %d\n",correct);
163 fprintf(stdout,
"WER %f\n",(100.0 * (
float)(ins+del+sub))/total);
176 int total,ins,del,sub,correct;
177 int s_total,s_ins,s_del,s_sub,s_correct;
181 s_total=s_ins=s_del=s_sub=s_correct=0;
187 load_sentence(u,
"ref",rts);
188 load_sentence(u,
"hypo",hts);
191 if ((!r->name().
matches(
id)) ||
192 (r->name() != h->name()))
194 cerr <<
"Align: failed to match sentence " <<
195 sents <<
" at id " << r->name() << endl;
202 align(u,
"ref",
"hypo",
"align");
209 align_score(u,
"ref",
"hypo",
"align",
210 total,ins,del,sub,correct);
215 s_correct += correct;
222 fprintf(stdout,
"sentences %d\n",sents);
223 fprintf(stdout,
"words %d\n",s_total);
224 fprintf(stdout,
"insertions %d\n",s_ins);
225 fprintf(stdout,
"deletions %d\n",s_del);
226 fprintf(stdout,
"substitutions %d\n",s_sub);
227 fprintf(stdout,
"correct %d\n",s_correct);
228 fprintf(stdout,
"WER %f\n",(100.0 * (
float)(s_ins+s_del+s_sub))/s_total);
240 i->set_name(ts.
get());
242 while ((!ts.
eoln()) && (!ts.
eof()));
251 StringtoStrList(relval, strlist,
" ");
254 for (iter.
begin(strlist); iter; ++iter)
264 int &total,
int &ins,
int &del,
int &sub,
int &correct)
268 total=ins=del=correct=sub=0;
270 for (ri=u.
relation(refrel)->first(),
273 ri=ri->next(),hi=hi->next())
275 for ( ; (as(hi,alignrel) == 0) && hi ; hi=hi->next())
277 fprintf(stdout,
"inserted: %s\n",(
const char *)hi->name());
280 for ( ; (daughter1(ri,alignrel) == 0) && ri; ri=ri->next())
282 fprintf(stdout,
"deleted: %s\n",(
const char *)ri->name());
287 if (name_distance(ri,daughter1(ri,alignrel)) == 0)
289 fprintf(stdout,
"correct: %s\n",(
const char *)ri->name());
294 fprintf(stdout,
"substituted: %s\n",(
const char *)ri->name());
299 for ( ; hi ; hi=hi->next())
301 fprintf(stdout,
"inserted: %s\n",(
const char *)hi->name());
316 if ((rname == hname) ||
317 (downcase(rname) == downcase(hname)))
336 float to_insert,to_del,to_subs;
345 dpt(0,0) = subs_cost * name_distance(ri,hi);
347 for (i=1; i<r_size+1; i++)
349 dpt(i,0) = insdel_cost + dpt(i-1,0);
352 for (j=1; j < h_size+1; j++)
354 dpt(0,j) = insdel_cost + dpt(0,j-1);
359 for (i=1; ri; ri=ri->next(),i++)
362 hi = utt.
relation(hyporel)->first();
363 for (j=1; hi; hi=hi->next(),j++)
365 cost = name_distance(ri,hi);
366 to_insert = insdel_cost + dpt(i,j-1);
367 to_del = insdel_cost + dpt(i-1,j);
368 to_subs = (cost * subs_cost) + dpt(i-1,j-1);
369 if (to_insert < to_del)
371 if (to_insert < to_subs)
373 dpt(i,j) = to_insert;
384 if (to_del < to_subs)
406 for (i=r_size,j=h_size,
409 ri; i--,ri=ri->prev())
411 while (dpp(i,j) == 1)
423 append_daughter(ri,alignrel,hi);