1 /*************************************************************************/ 2 /* */ 3 /* Language Technologies Institute */ 4 /* Carnegie Mellon University */ 5 /* Copyright (c) 2000 */ 6 /* All Rights Reserved. */ 7 /* */ 8 /* Permission is hereby granted, free of charge, to use and distribute */ 9 /* this software and its documentation without restriction, including */ 10 /* without limitation the rights to use, copy, modify, merge, publish, */ 11 /* distribute, sublicense, and/or sell copies of this work, and to */ 12 /* permit persons to whom this work is furnished to do so, subject to */ 13 /* the following conditions: */ 14 /* 1. The code must retain the above copyright notice, this list of */ 15 /* conditions and the following disclaimer. */ 16 /* 2. Any modifications must be clearly marked as such. */ 17 /* 3. Original authors' names are not deleted. */ 18 /* 4. The authors' names are not used to endorse or promote products */ 19 /* derived from this software without specific prior written */ 20 /* permission. */ 21 /* */ 22 /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */ 23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */ 24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */ 25 /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */ 26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */ 27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */ 28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */ 29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */ 30 /* THIS SOFTWARE. */ 31 /* */ 32 /*************************************************************************/ 33 /* Author: Alan W Black (awb@cs.cmu.edu) */ 34 /* Date: August 2000 */ 35 /*************************************************************************/ 36 /* */ 37 /* Viterbi support */ 38 /* */ 39 /*************************************************************************/ 40 #ifndef _CST_VITERBI_H__ 41 #define _CST_VITERBI_H__ 42 43 #include "cst_file.h" 44 #include "cst_math.h" 45 #include "cst_utterance.h" 46 47 typedef struct cst_vit_cand_struct { 48 int score; 49 cst_val *val; 50 int ival, pos; 51 cst_item *item; 52 struct cst_vit_cand_struct *next; 53 } cst_vit_cand; 54 cst_vit_cand *new_vit_cand(); 55 void vit_cand_set(cst_vit_cand *vc, cst_val *val); 56 void vit_cand_set_int(cst_vit_cand *vc, int ival); 57 void delete_vit_cand(cst_vit_cand *vc); 58 59 typedef struct cst_vit_path_struct { 60 int score; 61 int state; 62 cst_vit_cand *cand; 63 cst_features *f; 64 struct cst_vit_path_struct *from; 65 struct cst_vit_path_struct *next; 66 } cst_vit_path; 67 cst_vit_path *new_vit_path(); 68 void delete_vit_path(cst_vit_path *vp); 69 70 typedef struct cst_vit_point_struct { 71 cst_item *item; 72 int num_states; 73 int num_paths; 74 cst_vit_cand *cands; 75 cst_vit_path *paths; 76 cst_vit_path **state_paths; 77 struct cst_vit_point_struct *next; 78 } cst_vit_point; 79 cst_vit_point *new_vit_point(); 80 void delete_vit_point(cst_vit_point *vp); 81 82 struct cst_viterbi_struct; 83 84 /* Functions for user call back, to find candiates at a point, and 85 to join (and score) paths */ 86 typedef cst_vit_cand *(cst_vit_cand_f_t)(cst_item *s, 87 struct cst_viterbi_struct *vd); 88 typedef cst_vit_path *(cst_vit_path_f_t)(cst_vit_path *p, 89 cst_vit_cand *c, 90 struct cst_viterbi_struct *vd); 91 92 typedef struct cst_viterbi_struct { 93 int num_states; 94 cst_vit_cand_f_t *cand_func; 95 cst_vit_path_f_t *path_func; 96 int big_is_good; 97 98 cst_vit_point *timeline; 99 cst_vit_point *last_point; 100 cst_features *f; 101 } cst_viterbi; 102 103 104 cst_viterbi *new_viterbi(cst_vit_cand_f_t *cand_func, 105 cst_vit_path_f_t *path_func); 106 void delete_viterbi(cst_viterbi *vd); 107 108 void viterbi_initialise(cst_viterbi *vd,cst_relation *r); 109 void viterbi_decode(cst_viterbi *vd); 110 int viterbi_result(cst_viterbi *vd, const char *n); 111 void viterbi_copy_feature(cst_viterbi *vd,const char *featname); 112 113 #endif 114