cst_viterbi.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #include "cst_file.h"
  43. #include "cst_math.h"
  44. #include "cst_utterance.h"
  45. typedef struct cst_vit_cand_struct {
  46. int score;
  47. cst_val *val;
  48. int ival, pos;
  49. cst_item *item;
  50. struct cst_vit_cand_struct *next;
  51. } cst_vit_cand;
  52. cst_vit_cand *new_vit_cand();
  53. void vit_cand_set(cst_vit_cand *vc, cst_val *val);
  54. void vit_cand_set_int(cst_vit_cand *vc, int ival);
  55. void delete_vit_cand(cst_vit_cand *vc);
  56. typedef struct cst_vit_path_struct {
  57. int score;
  58. int state;
  59. cst_vit_cand *cand;
  60. cst_features *f;
  61. struct cst_vit_path_struct *from;
  62. struct cst_vit_path_struct *next;
  63. } cst_vit_path;
  64. cst_vit_path *new_vit_path();
  65. void delete_vit_path(cst_vit_path *vp);
  66. typedef struct cst_vit_point_struct {
  67. cst_item *item;
  68. int num_states;
  69. int num_paths;
  70. cst_vit_cand *cands;
  71. cst_vit_path *paths;
  72. cst_vit_path **state_paths;
  73. struct cst_vit_point_struct *next;
  74. } cst_vit_point;
  75. cst_vit_point *new_vit_point();
  76. void delete_vit_point(cst_vit_point *vp);
  77. struct cst_viterbi_struct;
  78. /* Functions for user call back, to find candiates at a point, and
  79. to join (and score) paths */
  80. typedef cst_vit_cand *(cst_vit_cand_f_t)(cst_item *s,
  81. struct cst_viterbi_struct *vd);
  82. typedef cst_vit_path *(cst_vit_path_f_t)(cst_vit_path *p,
  83. cst_vit_cand *c,
  84. struct cst_viterbi_struct *vd);
  85. typedef struct cst_viterbi_struct {
  86. int num_states;
  87. cst_vit_cand_f_t *cand_func;
  88. cst_vit_path_f_t *path_func;
  89. int big_is_good;
  90. cst_vit_point *timeline;
  91. cst_vit_point *last_point;
  92. cst_features *f;
  93. } cst_viterbi;
  94. cst_viterbi *new_viterbi(cst_vit_cand_f_t *cand_func,
  95. cst_vit_path_f_t *path_func);
  96. void delete_viterbi(cst_viterbi *vd);
  97. void viterbi_initialise(cst_viterbi *vd,cst_relation *r);
  98. void viterbi_decode(cst_viterbi *vd);
  99. int viterbi_result(cst_viterbi *vd, const char *n);
  100. void viterbi_copy_feature(cst_viterbi *vd,const char *featname);
  101. #endif