00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 #ifndef _S3_VITHIST_H_
00125 #define _S3_VITHIST_H_
00126
00127 #include <stdio.h>
00128
00129 #include <s3types.h>
00130 #include <cmd_ln.h>
00131 #include <logmath.h>
00132 #include <glist.h>
00133 #include "kbcore.h"
00134 #include "search.h"
00135 #include "dict.h"
00136 #include "lm.h"
00137 #include "fillpen.h"
00138
00139 #include "dag.h"
00140 #include "ctxt_table.h"
00141
00150 #ifdef __cplusplus
00151 extern "C" {
00152 #endif
00153 #if 0
00154 }
00155 #endif
00156
00162 typedef union vh_lmstate_u {
00163 struct {
00164 s3lmwid32_t lwid[2];
00165 } lm3g;
00166 } vh_lmstate_t;
00167
00168
00169 typedef struct backpointer_s {
00170 int32 score;
00171 int32 pred;
00172 } backpointer_t;
00173
00177 typedef struct {
00178 backpointer_t path;
00179 vh_lmstate_t lmstate;
00180 s3wid_t wid;
00181 s3frmid_t sf, ef;
00182 int32 ascr;
00183 int32 lscr;
00184 int16 type;
00185 int16 valid;
00186 backpointer_t *rc;
00187 int32 n_rc;
00188 } vithist_entry_t;
00189
00191 #define vithist_entry_wid(ve) ((ve)->wid)
00192
00194 #define vithist_entry_sf(ve) ((ve)->sf)
00195
00197 #define vithist_entry_ef(ve) ((ve)->ef)
00198
00200 #define vithist_entry_ascr(ve) ((ve)->ascr)
00201
00203 #define vithist_entry_lscr(ve) ((ve)->lscr)
00204
00206 #define vithist_entry_score(ve) ((ve)->path.score)
00207 #define vithist_entry_pred(ve) ((ve)->path.pred)
00208 #define vithist_entry_valid(ve) ((ve)->valid)
00209
00210
00222 typedef struct {
00223 int32 state;
00224 int32 vhid;
00225 vithist_entry_t *ve;
00226 glist_t children;
00228 } vh_lms2vh_t;
00229
00230
00238 typedef struct {
00239 vithist_entry_t **entry;
00240 int32 *frame_start;
00242 int32 n_entry;
00243 int32 n_frm;
00244 int32 n_ci;
00245 int32 bghist;
00248 int32 wbeam;
00250 int32 *bestscore;
00251 int32 *bestvh;
00253 vh_lms2vh_t **lms2vh_root;
00254 glist_t lwidlist;
00255 } vithist_t;
00256
00257
00258 #define VITHIST_BLKSIZE 16384
00259 #define VITHIST_MAXBLKS 256
00260 #define VITHIST_ID2BLK(i) ((i) >> 14)
00261 #define VITHIST_ID2BLKOFFSET(i) ((i) & 0x00003fff)
00262
00266 #define vithist_id2entry(vh,id) ((vh)->entry[VITHIST_ID2BLK(id)] + VITHIST_ID2BLKOFFSET(id))
00267
00269 #define vithist_n_entry(vh) ((vh)->n_entry)
00270
00272 #define vithist_bestscore(vh) ((vh)->bestscore)
00273
00275 #define vithist_bestvh(vh) ((vh)->bestvh)
00276
00278 #define vithist_lms2vh_root(vh,w) ((vh)->lms2vh_root[w])
00279
00281 #define vithist_lwidlist(vh) ((vh)->lwidlist)
00282
00284 #define vithist_first_entry(vh,f) ((vh)->frame_start[f])
00285
00287 #define vithist_last_entry(vh,f) ((vh)->frame_start[f+1] - 1)
00288
00289
00296 vithist_t *vithist_init (kbcore_t *kbc,
00297 int32 wbeam,
00298 int32 bghist,
00299 int32 report
00300 );
00301
00302
00307 int32 vithist_utt_begin (vithist_t *vh,
00308 kbcore_t *kbc
00309 );
00310
00311
00317 int32 vithist_utt_end (vithist_t *vh,
00318 kbcore_t *kbc
00319 );
00320
00321
00326 int32 vithist_partialutt_end (vithist_t *vh,
00327 kbcore_t *kbc
00328 );
00329
00330
00331 void vithist_utt_reset (vithist_t *vh
00332 );
00333
00334
00339 glist_t vithist_backtrace (vithist_t *vh,
00340 int32 id,
00341 dict_t *dict
00342 );
00343
00344
00349 void vithist_enter(vithist_t * vh,
00350 kbcore_t * kbc,
00351 vithist_entry_t * tve,
00352 int32 comp_rc
00353 );
00354
00362 void vithist_rescore (vithist_t *vh,
00363 kbcore_t *kbc,
00364 s3wid_t wid,
00365 int32 ef,
00366 int32 score,
00367 int32 pred,
00368 int32 type,
00369 int32 rc
00370 );
00371
00372
00374 void vithist_frame_windup (vithist_t *vh,
00375 int32 frm,
00376 FILE *fp,
00378 kbcore_t *kbc
00380 );
00381
00386 void vithist_prune (vithist_t *vh,
00387 dict_t *dict,
00388 int32 frm,
00389 int32 maxwpf,
00390 int32 maxhist,
00391 int32 beam
00392 );
00393
00397 void vithist_dump (vithist_t *vh,
00398 int32 frm,
00400 kbcore_t *kbc,
00401 FILE *fp
00402 );
00403
00407 dag_t *vithist_dag_build(vithist_t * vh, glist_t hyp, dict_t * dict, int32 endid,
00408 cmd_ln_t *config, logmath_t *logmath);
00409
00413 int32 vithist_dag_write(vithist_t *vithist,
00414 const char *filename,
00415 dag_t * dag,
00416 lm_t * lm,
00417 dict_t * dict);
00418
00423 void vithist_free(vithist_t *vh
00424 );
00425
00426
00431 void vithist_report(vithist_t *vh
00432 );
00433
00438 void vh_lmstate_display(vh_lmstate_t *vhl,
00439 dict_t *dict
00440 );
00441
00445 void vithist_entry_display(vithist_entry_t *ve,
00446 dict_t* dict
00447 );
00448
00449
00459 typedef struct lattice_s {
00460 s3wid_t wid;
00461 s3frmid_t frm;
00462 s3latid_t history;
00464 int32 ascr;
00465 int32 lscr;
00467 int32 score;
00468 int32 *rcscore;
00469 dagnode_t *dagnode;
00470 } lattice_t;
00471
00472
00473 #define LAT_ALLOC_INCR 32768
00474
00475 #define LATID2SF(hist,l) (IS_S3LATID(hist->lattice[l].history) ? \
00476 hist->lattice[hist->lattice[l].history].frm + 1 : 0)
00477
00489
00490
00491
00492
00493 typedef struct {
00494
00495 lattice_t *lattice;
00496 s3latid_t *frm_latstart;
00498 int32 lat_alloc;
00499 int32 n_lat_entry;
00500 int32 n_cand;
00505 int32 n_frms_alloc;
00506 int32 n_frm;
00508 } latticehist_t;
00509
00510
00511 #define latticehist_n_cand(hist) ((hist)->n_cand)
00512 #define latticehist_lat_alloc(hist) ((hist)->lat_alloc)
00513 #define latticehist_n_lat_entry(hist) ((hist)->n_lat_entry)
00514
00515
00520 latticehist_t *latticehist_init(int32 init_alloc_size,
00521 int32 num_frames
00522 );
00523
00527 void latticehist_free(latticehist_t *lat
00528 );
00529
00530
00531
00532
00533
00534 void latticehist_reset(latticehist_t *lat
00535 );
00536
00540 void latticehist_dump (latticehist_t *lathist,
00541 FILE *fp,
00542 dict_t *dict,
00543 ctxt_table_t *ct,
00544 int32 dumpRC
00545 );
00546
00550 void lattice_entry (latticehist_t *lathist,
00551 s3wid_t w,
00552 int32 f,
00553 int32 score,
00554 s3latid_t history,
00555 int32 rc,
00556 ctxt_table_t *ct,
00557 dict_t *dict
00558 );
00559
00560
00561 void two_word_history (latticehist_t *lathist,
00562 s3latid_t l, s3wid_t *w0, s3wid_t *w1, dict_t *dict);
00563
00569 int32 lat_pscr_rc (latticehist_t *lathist,
00570 s3latid_t l,
00571 s3wid_t w_rc,
00572 ctxt_table_t *ct,
00573 dict_t *dict
00574 );
00575
00580 s3latid_t lat_pscr_rc_history (latticehist_t *lathist,
00581 s3latid_t l,
00582 s3wid_t w_rc,
00583 ctxt_table_t *ct,
00584 dict_t *dict
00585 );
00586
00587 int32 lat_seg_lscr (latticehist_t *lathist,
00588 s3latid_t l,
00589 lm_t *lm,
00590 dict_t *dict,
00591 ctxt_table_t *ct,
00592 fillpen_t *fillpen,
00593 int32 isCand);
00594
00595
00600 void lat_seg_ascr_lscr (latticehist_t *lathist,
00601 s3latid_t l,
00602 s3wid_t w_rc,
00603 int32 *ascr,
00604 int32 *lscr,
00605 lm_t *lm,
00606 dict_t *dict,
00607 ctxt_table_t *ct,
00608 fillpen_t *fillpen
00609 );
00610
00611
00615 s3latid_t lat_final_entry ( latticehist_t* lathist,
00616 dict_t* dict,
00617 int32 curfrm,
00618 char* uttid
00619 );
00620
00624 srch_hyp_t *lattice_backtrace (latticehist_t *lathist,
00625 s3latid_t l,
00626 s3wid_t w_rc,
00627 srch_hyp_t **hyp,
00628 lm_t *lm,
00629 dict_t *dict,
00630 ctxt_table_t *ct,
00631 fillpen_t *fillpen
00632 );
00633
00646 dag_t * latticehist_dag_build(latticehist_t * vh, glist_t hyp, dict_t * dict,
00647 lm_t *lm, ctxt_table_t *ctxt, fillpen_t *fpen,
00648 int32 endid, cmd_ln_t *config, logmath_t *logmath);
00649
00653 int32 latticehist_dag_write (latticehist_t *lathist,
00654 const char *filename,
00655 dag_t *dag,
00656 lm_t *lm,
00657 dict_t *dict,
00658 ctxt_table_t *ct,
00659 fillpen_t *fillpen
00660 );
00661
00662 #if 0
00663 {
00664 #endif
00665 #ifdef __cplusplus
00666 }
00667 #endif
00668
00669 #endif