static int search_cb(search_t *search, search_event_t *evt, void *udata) { batch_decoder_t *bd = (batch_decoder_t *) udata; dict_t *d = search_factory_d2p(bd->sf)->dict; double delta = get_time_delta(bd); double frate = cmd_ln_int32_r(search_config(search), "-frate"); FILE *hypfh = NULL; void *val; if (hash_table_lookup(bd->hypfiles, search_name(search), &val) == 0) hypfh = val; else hypfh = stdout; fprintf(hypfh, "time delta %f ", delta); switch (evt->event) { case SEARCH_PARTIAL_RESULT: { int32 score; seg_iter_t *seg = search_seg_iter(search, &score); fprintf(hypfh, "partial: "); for (; seg; seg = seg_iter_next(seg)) { int sf, ef; seg_iter_times(seg, &sf, &ef); fprintf(hypfh, "%s:%.3f ", dict_basestr(d, seg_iter_wid(seg)), (double) ef / frate); } fprintf(hypfh, "(%s)\n", search_uttid(search)); break; } case SEARCH_START_UTT: fprintf(hypfh, "start %s\n", search_uttid(search)); break; case SEARCH_END_UTT: fprintf(hypfh, "end %s\n", search_uttid(search)); break; case SEARCH_FINAL_RESULT: { int32 score; seg_iter_t *seg = search_seg_iter(search, &score); fprintf(hypfh, "full: "); for (; seg; seg = seg_iter_next(seg)) { int sf, ef; seg_iter_times(seg, &sf, &ef); fprintf(hypfh, "%s:%.3f ", dict_basestr(d, seg_iter_wid(seg)), (double) ef / frate); } fprintf(hypfh, "(%s)\n", search_uttid(search)); break; } } return 0; }
static int write_ctm(FILE *fh, ps_decoder_t *ps, ps_seg_t *itor, char const *uttid, int32 frate) { logmath_t *lmath = ps_get_logmath(ps); char *dupid, *show, *channel, *c; double ustart = 0.0; /* We have semi-standardized on comma-separated uttids which * correspond to the fields of the STM file. So if there's a * comma in the uttid, take the first two fields as show and * channel, and also try to find the start time. */ show = dupid = ckd_salloc(uttid ? uttid : "(null)"); if ((c = strchr(dupid, ',')) != NULL) { *c++ = '\0'; channel = c; if ((c = strchr(c, ',')) != NULL) { *c++ = '\0'; if ((c = strchr(c, ',')) != NULL) { ustart = atof_c(c + 1); } } } else { channel = NULL; } while (itor) { int32 prob, sf, ef, wid; char const *w; /* Skip things that aren't "real words" (FIXME: currently * requires s3kr3t h34d3rz...) */ w = ps_seg_word(itor); wid = dict_wordid(ps->dict, w); if (wid >= 0 && dict_real_word(ps->dict, wid)) { prob = ps_seg_prob(itor, NULL, NULL, NULL); ps_seg_frames(itor, &sf, &ef); fprintf(fh, "%s %s %.2f %.2f %s %.3f\n", show, channel ? channel : "1", ustart + (double)sf / frate, (double)(ef - sf) / frate, /* FIXME: More s3kr3tz */ dict_basestr(ps->dict, wid), logmath_exp(lmath, prob)); } itor = ps_seg_next(itor); } ckd_free(dupid); return 0; }
int dict_altid(dict_t *d, int32 wid) { char const *basestr, *wordstr, *c; if (wid < 0 || wid >= d->n_word) return 0; if (wid == dict_basewid(d, wid)) return 1; /* FIXME: the order in which they appear in nextalt is unrelated * to the actual alterate indices in the words... */ wordstr = dict_wordstr(d, wid); basestr = dict_basestr(d, wid); assert(strlen(wordstr) > strlen(basestr)); c = wordstr + strlen(basestr); assert(*c == '('); ++c; return atoi(c); }