SphinxBase  0.6
ngram_model.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 2007 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  */
43 #ifndef __NGRAM_MODEL_H__
44 #define __NGRAM_MODEL_H__
45 
46 #include <stdarg.h>
47 
48 /* Win32/WinCE DLL gunk */
49 #include <sphinxbase/sphinxbase_export.h>
50 #include <sphinxbase/prim_type.h>
51 #include <sphinxbase/cmd_ln.h>
52 #include <sphinxbase/logmath.h>
53 #include <sphinxbase/mmio.h>
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 #if 0
59 /* Fool Emacs. */
60 }
61 #endif
62 
67 
72 
76 typedef enum ngram_file_type_e {
83 
84 #define NGRAM_INVALID_WID -1
106 SPHINXBASE_EXPORT
108  const char *file_name,
109  ngram_file_type_t file_type,
110  logmath_t *lmath);
111 
117 SPHINXBASE_EXPORT
118 int ngram_model_write(ngram_model_t *model, const char *file_name,
119  ngram_file_type_t format);
120 
126 SPHINXBASE_EXPORT
127 ngram_file_type_t ngram_file_name_to_type(const char *file_name);
128 
134 SPHINXBASE_EXPORT
135 ngram_file_type_t ngram_str_to_type(const char *str_name);
136 
143 SPHINXBASE_EXPORT
144 char const *ngram_type_to_str(int type);
145 
151 SPHINXBASE_EXPORT
153 
159 SPHINXBASE_EXPORT
160 int ngram_model_free(ngram_model_t *model);
161 
178 SPHINXBASE_EXPORT
179 int ngram_model_recode(ngram_model_t *model, const char *from, const char *to);
180 
184 typedef enum ngram_case_e {
185  NGRAM_UPPER,
186  NGRAM_LOWER
187 } ngram_case_t;
188 
195 SPHINXBASE_EXPORT
196 int ngram_model_casefold(ngram_model_t *model, int kase);
197 
209 SPHINXBASE_EXPORT
211  float32 lw, float32 wip, float32 uw);
212 
221 SPHINXBASE_EXPORT
222 float32 ngram_model_get_weights(ngram_model_t *model, int32 *out_log_wip,
223  int32 *out_log_uw);
224 
257 SPHINXBASE_EXPORT
258 int32 ngram_score(ngram_model_t *model, const char *word, ...);
259 
263 SPHINXBASE_EXPORT
264 int32 ngram_tg_score(ngram_model_t *model,
265  int32 w3, int32 w2, int32 w1,
266  int32 *n_used);
267 
271 SPHINXBASE_EXPORT
272 int32 ngram_bg_score(ngram_model_t *model,
273  int32 w2, int32 w1,
274  int32 *n_used);
275 
279 SPHINXBASE_EXPORT
280 int32 ngram_ng_score(ngram_model_t *model, int32 wid, int32 *history,
281  int32 n_hist, int32 *n_used);
282 
293 SPHINXBASE_EXPORT
294 int32 ngram_prob(ngram_model_t *model, const char *word, ...);
295 
302 SPHINXBASE_EXPORT
303 int32 ngram_ng_prob(ngram_model_t *model, int32 wid, int32 *history,
304  int32 n_hist, int32 *n_used);
305 
317 SPHINXBASE_EXPORT
318 int32 ngram_score_to_prob(ngram_model_t *model, int32 score);
319 
323 SPHINXBASE_EXPORT
324 int32 ngram_wid(ngram_model_t *model, const char *word);
325 
329 SPHINXBASE_EXPORT
330 const char *ngram_word(ngram_model_t *model, int32 wid);
331 
345 SPHINXBASE_EXPORT
346 int32 ngram_unknown_wid(ngram_model_t *model);
347 
351 SPHINXBASE_EXPORT
352 int32 ngram_zero(ngram_model_t *model);
353 
357 SPHINXBASE_EXPORT
358 int32 ngram_model_get_size(ngram_model_t *model);
359 
363 SPHINXBASE_EXPORT
364 int32 const *ngram_model_get_counts(ngram_model_t *model);
365 
369 typedef struct ngram_iter_s ngram_iter_t;
370 
379 SPHINXBASE_EXPORT
381 
385 SPHINXBASE_EXPORT
386 ngram_iter_t *ngram_iter(ngram_model_t *model, const char *word, ...);
387 
391 SPHINXBASE_EXPORT
392 ngram_iter_t *ngram_ng_iter(ngram_model_t *model, int32 wid, int32 *history, int32 n_hist);
393 
402 SPHINXBASE_EXPORT
403 int32 const *ngram_iter_get(ngram_iter_t *itor,
404  int32 *out_score,
405  int32 *out_bowt);
406 
412 SPHINXBASE_EXPORT
414 
418 SPHINXBASE_EXPORT
420 
424 SPHINXBASE_EXPORT
425 void ngram_iter_free(ngram_iter_t *itor);
426 
439 SPHINXBASE_EXPORT
441  const char *word, float32 weight);
442 
456 SPHINXBASE_EXPORT
458  const char *file_name);
459 
468 SPHINXBASE_EXPORT
470  const char *classname,
471  float32 classweight,
472  char **words,
473  const float32 *weights,
474  int32 n_words);
475 
485 SPHINXBASE_EXPORT
487  const char *classname,
488  const char *word,
489  float32 weight);
490 
515 SPHINXBASE_EXPORT
517  ngram_model_t **models,
518  char **names,
519  const float32 *weights,
520  int32 n_models);
521 
552 SPHINXBASE_EXPORT
554  const char *lmctlfile,
555  logmath_t *lmath);
556 
560 SPHINXBASE_EXPORT
562 
567 
573 SPHINXBASE_EXPORT
575 
581 SPHINXBASE_EXPORT
583 
587 SPHINXBASE_EXPORT
589 
597 SPHINXBASE_EXPORT
599  char const **lmname);
600 
607 SPHINXBASE_EXPORT
609  const char *name);
610 
617 SPHINXBASE_EXPORT
619  const char *name);
620 
624 SPHINXBASE_EXPORT
625 const char *ngram_model_set_current(ngram_model_t *set);
626 
634 SPHINXBASE_EXPORT
636  const char **names,
637  const float32 *weights);
638 
651 SPHINXBASE_EXPORT
653  ngram_model_t *model,
654  const char *name,
655  float32 weight,
656  int reuse_widmap);
657 
666 SPHINXBASE_EXPORT
668  const char *name,
669  int reuse_widmap);
670 
674 SPHINXBASE_EXPORT
676  const char **words,
677  int32 n_words);
678 
686 SPHINXBASE_EXPORT
688  int32 set_wid);
689 
699 SPHINXBASE_EXPORT
700 int32 ngram_model_set_known_wid(ngram_model_t *set, int32 set_wid);
701 
709 SPHINXBASE_EXPORT
711 
712 #ifdef __cplusplus
713 }
714 #endif
715 
716 
717 #endif /* __NGRAM_MODEL_H__ */