55 #include <sphinxbase/prim_type.h>
56 #include <sphinxbase/err.h>
57 #include <sphinxbase/ckd_alloc.h>
60 #include "fsg_search_internal.h"
61 #include "fsg_history.h"
68 fsg_history_init(fsg_model_t * fsg,
dict_t *dict)
74 h->entries = blkarray_list_init();
77 h->n_ciphone = bin_mdef_n_ciphone(dict->
mdef);
79 (glist_t **) ckd_calloc_2d(fsg_model_n_state(fsg),
80 bin_mdef_n_ciphone(dict->
mdef),
81 sizeof(**h->frame_entries));
84 h->frame_entries = NULL;
97 ns = fsg_model_n_state(h->fsg);
100 for (s = 0; s < ns; s++) {
101 for (lc = 0; lc < np; lc++) {
102 for (gn = h->frame_entries[s][lc]; gn; gn = gnode_next(gn)) {
103 ckd_free(gnode_ptr(gn));
105 glist_free(h->frame_entries[s][lc]);
109 ckd_free_2d(h->frame_entries);
110 blkarray_list_free(h->entries);
118 if (blkarray_list_n_valid(h->entries) != 0) {
119 E_WARN(
"Switching FSG while history not empty; history cleared\n");
120 blkarray_list_reset(h->entries);
123 if (h->frame_entries)
124 ckd_free_2d((
void **) h->frame_entries);
125 h->frame_entries = NULL;
129 h->n_ciphone = bin_mdef_n_ciphone(dict->
mdef);
131 (glist_t **) ckd_calloc_2d(fsg_model_n_state(fsg),
132 bin_mdef_n_ciphone(dict->
mdef),
141 int32 frame, int32 score, int32 pred,
146 gnode_t *gn, *prev_gn;
152 new_entry->fsglink = link;
153 new_entry->frame = frame;
154 new_entry->score = score;
155 new_entry->pred = pred;
159 blkarray_list_append(h->entries, (
void *) new_entry);
163 s = fsg_link_to_state(link);
167 for (gn = h->frame_entries[s][lc]; gn; gn = gnode_next(gn)) {
174 if (FSG_PNODE_CTXT_SUB(&rc, &(entry->rc)) == 0)
183 new_entry->fsglink = link;
184 new_entry->frame = frame;
185 new_entry->score = score;
186 new_entry->pred = pred;
191 h->frame_entries[s][lc] = glist_add_ptr(h->frame_entries[s][lc],
193 prev_gn = h->frame_entries[s][lc];
196 prev_gn = glist_insert_ptr(prev_gn, (
void *) new_entry);
205 if (FSG_PNODE_CTXT_SUB(&(entry->rc), &rc) == 0) {
207 ckd_free((
void *) entry);
208 gn = gnode_free(gn, prev_gn);
229 ns = fsg_model_n_state(h->fsg);
232 for (s = 0; s < ns; s++) {
233 for (lc = 0; lc < np; lc++) {
234 for (gn = h->frame_entries[s][lc]; gn; gn = gnode_next(gn)) {
236 blkarray_list_append(h->entries, (
void *) entry);
239 glist_free(h->frame_entries[s][lc]);
240 h->frame_entries[s][lc] = NULL;
256 blkarray_list_reset(h->entries);
263 return (blkarray_list_n_valid(h->entries));
271 assert(blkarray_list_n_valid(h->entries) == 0);
272 assert(h->frame_entries);
274 ns = fsg_model_n_state(h->fsg);
277 for (s = 0; s < ns; s++) {
278 for (lc = 0; lc < np; lc++) {
279 assert(h->frame_entries[s][lc] == NULL);
294 for (bpidx = 0; bpidx < blkarray_list_n_valid(h->entries); bpidx++) {
296 printf(
"History entry: ");
299 fsg_link_t *fl = fsg_hist_entry_fsglink(hist_entry);
300 char const *baseword;
302 bp = fsg_hist_entry_pred(hist_entry);
303 wid = fsg_link_wid(fl);
308 baseword = fsg_model_word_str(h->fsg, wid);
310 printf(
"%s(%d->%d:%d) ", baseword,
311 fsg_link_from_state(hist_entry->fsglink),
312 fsg_link_to_state(hist_entry->fsglink),
a structure for a dictionary.
#define BETTER_THAN
Is one score better than another?
bin_mdef_t * mdef
Model definition used for phone IDs; NULL if none used.