kb.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 1999-2004 Carnegie Mellon University. All rights
4  * reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * This work was supported in part by funding from the Defense Advanced
19  * Research Projects Agency and the National Science Foundation of the
20  * United States of America, and the CMU Sphinx Speech Consortium.
21  *
22  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * ====================================================================
35  *
36  */
37 /*
38  * kb.h -- Knowledge bases, search parameters, and auxiliary structures for decoding
39  *
40  * **********************************************
41  * CMU ARPA Speech Project
42  *
43  * Copyright (c) 1999 Carnegie Mellon University.
44  * ALL RIGHTS RESERVED.
45  * **********************************************
46  *
47  * HISTORY
48  * $Log$
49  * Revision 1.1 2006/04/05 20:27:30 dhdfu
50  * A Great Reorganzation of header files and executables
51  *
52  * Revision 1.18 2006/02/23 05:44:59 arthchan2003
53  * Merged from the branch SPHINX3_5_2_RCI_IRII_BRANCH.
54  * 1, Added temp_init_vithistory, this will choose to initialize the correct viterbi history given the mode.
55  * 2, Moved most of the code in kb_setmllr to adaptor.c
56  *
57  * Revision 1.17.4.2 2005/09/18 01:21:18 arthchan2003
58  * 1, Add a latticehist_t into kb_t, use a temporary method to allow polymorphism of initialization of vithist_t and latticehist_t. 2, remove the logic kb_set_mllr and put it to adapt_set_mllr
59  *
60  * Revision 1.17.4.1 2005/07/03 23:00:58 arthchan2003
61  * Free stat_t, histprune_t and srch_t correctly.
62  *
63  * Revision 1.17 2005/06/21 23:21:58 arthchan2003
64  * Log. This is a big refactoring for kb.c and it is worthwhile to give
65  * words on why and how things were done. There were generally a problem
66  * that the kb structure itself is too flat. That makes it has to
67  * maintained many structure that could be maintained by smaller
68  * structures. For example, the count of A and the array of A should
69  * well be put into the same structure to increase readability and
70  * modularity. One can explain why histprune_t, pl_t, stat_t and
71  * adapt_am_t were introduced with that line of reasoning.
72  *
73  * In srch_t, polymorphism of implementation is also one important
74  * element in separting all graph related members from kb_t to srch_t.
75  * One could probably implement the polymorphism as an interface of kb
76  * but it is not trivial from the semantic meaning of kb. That is
77  * probably why srch_t is introduced as the gateway of search interfaces.
78  *
79  * Another phenonemon one could see in the code was bad interaction
80  * between modules. This is quite serious in two areas: logging and
81  * checking. The current policy is unless something required cross
82  * checking two structures, they would be done internally inside a module
83  * initialization.
84  *
85  * Finally, kb_setlm is now removed and is replaced by ld_set_lm (by
86  * users) or srch_set_lm (by developers). I think this is quite
87  * reasonable.
88  *
89  * Revision 1.10 2005/06/19 19:41:23 archan
90  * Sphinx3 to s3.generic: Added multiple regression class for single stream MLLR. Enabled MLLR for livepretend and decode.
91  *
92  * Revision 1.9 2005/05/11 06:10:38 archan
93  * Code for lattice and back track pointer table dumping is now wrapped in reg_result_dump. The function is shared across mode 4 and mode 5. Possibly later for mode 3 and mode 6 as well.
94  *
95  * Revision 1.8 2005/04/25 23:53:35 archan
96  * 1, Some minor modification of vithist_t, vithist_rescore can now support optional LM rescoring, vithist also has its own reporting routine. A new argument -lmrescore is also added in decode and livepretend. This can switch on and off the rescoring procedure. 2, I am reaching the final difficulty of mode 5 implementation. That is, to implement an algorithm which dynamically decide which tree copies should be entered. However, stuffs like score propagation in the leave nodes and non-leaves nodes are already done. 3, As briefly mentioned in 2, implementation of rescoring , which used to happened at leave nodes are now separated. The current implementation is not the most clever one. Wish I have time to change it before check-in to the canonical.
97  *
98  * Revision 1.7 2005/04/20 03:36:18 archan
99  * Remove setlm from kb entirely, refactor it to search implementations, do the corresponding change for the changes in ascr and pl
100  *
101  * Revision 1.6 2005/03/30 01:22:47 archan
102  * Fixed mistakes in last updates. Add
103  *
104  *
105  * 14-Jun-2004 Yitao Sun (yitao@cs.cmu.edu) at Carnegie Mellon University
106  * Modified struct kb_t to save the last hypothesis.
107  *
108  * 07-Jul-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
109  * Added kb_t.ci_active.
110  *
111  * 02-Jun-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
112  * Started.
113  */
114 
115 
116 #ifndef _S3_KB_H_
117 #define _S3_KB_H_
118 
119 #include <stdio.h>
120 
121 #include <s3types.h>
122 #include <cmd_ln.h>
123 #include <fe.h>
124 #include "kbcore.h"
125 #include "ascr.h"
126 #include "fast_algo_struct.h"
127 #include "stat.h"
128 #include "adaptor.h"
129 
135 #ifdef __cplusplus
136 extern "C" {
137 #endif
138 #if 0
139 } /* Fool Emacs into not indenting things. */
140 #endif
141 
142 
143 /*
144  * ARCHAN :20040229. Starting from s3.4, we accept users to specify mutliple LMs
145  * using -lmctlfile. To avoid potential overhead caused by rebuilding the trees
146  * at every sentence. We allocate all lexical trees in the intialization. If we
147  * assume the number of words to be less than 64k and the number of LMs is smaller
148  * than 100. This memory loss should be fine. Later: We should allow users to specify
149  * the memory address mode by their own discretion.
150  */
151 
152 
153 /* The wrapper structure of all operation in the Sphinx 3.X decoder.
154  *
155  */
156 typedef struct {
165  fe_t *fe;
166  mfcc_t **mfcc;
167  float32 ***feat;
173  pl_t *pl;
181  FILE *matchfp;
182  FILE *matchsegfp;
183  FILE *hmmdumpfp;
185  /* The only variable I intend to make it be alone in the whole
186  structure. It has its own uniqueness. (dhuggins: I have no idea
187  what that means) */
188  int32 op_mode;
189  char *uttid;
190  char *uttfile;
193  void *srch;
194 } kb_t;
195 
196 
199 void kb_init(kb_t *kb,
200  cmd_ln_t *config
201  );
202 
203 
206 void kb_free (kb_t *kb
207  ); /* RAH 4.16.01 */
208 
211 void kb_setmllr(const char* mllrname,
212  const char* cb2mllrname,
213  kb_t *kb
214  ); /* ARCHAN 20040724 */
215 
218 void kb_set_uttid(const char *uttid,
219  const char *uttfile,
220  kb_t *kb
221  ); /* ARCHAN 20041111 */
222 
223 
224 #if 0
225 { /* Stop indent from complaining */
226 #endif
227 #ifdef __cplusplus
228 }
229 #endif
230 
231 #endif