• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

include/ngram_model.h

Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
00002 /* ====================================================================
00003  * Copyright (c) 2007 Carnegie Mellon University.  All rights
00004  * reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer. 
00012  *
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in
00015  *    the documentation and/or other materials provided with the
00016  *    distribution.
00017  *
00018  * This work was supported in part by funding from the Defense Advanced 
00019  * Research Projects Agency and the National Science Foundation of the 
00020  * United States of America, and the CMU Sphinx Speech Consortium.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 
00023  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00024  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00025  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
00026  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * ====================================================================
00035  *
00036  */
00043 #ifndef __NGRAM_MODEL_H__
00044 #define __NGRAM_MODEL_H__
00045 
00046 /* Win32/WinCE DLL gunk */
00047 #include <sphinxbase_export.h>
00048 #include <prim_type.h>
00049 #include <cmd_ln.h>
00050 #include <logmath.h>
00051 #include <mmio.h>
00052 #include <stdarg.h>
00053 
00054 #ifdef __cplusplus
00055 extern "C" {
00056 #endif
00057 #if 0
00058 /* Fool Emacs. */
00059 }
00060 #endif
00061 
00065 typedef struct ngram_model_s ngram_model_t;
00066 
00070 typedef struct ngram_class_s ngram_class_t;
00071 
00075 typedef enum ngram_file_type_e {
00076     NGRAM_AUTO,  
00077     NGRAM_ARPA,  
00078     NGRAM_DMP,   
00079     NGRAM_DMP32  
00080 } ngram_file_type_t;
00081 
00082 #define NGRAM_INVALID_WID -1 
00104 SPHINXBASE_EXPORT
00105 ngram_model_t *ngram_model_read(cmd_ln_t *config,
00106                                 const char *file_name,
00107                                 ngram_file_type_t file_type,
00108                                 logmath_t *lmath);
00109 
00117 SPHINXBASE_EXPORT
00118 int ngram_model_write(ngram_model_t *model, const char *file_name,
00119                       ngram_file_type_t format);
00120 
00126 SPHINXBASE_EXPORT
00127 ngram_model_t *ngram_model_retain(ngram_model_t *model);
00128 
00134 SPHINXBASE_EXPORT
00135 int ngram_model_free(ngram_model_t *model);
00136 
00153 SPHINXBASE_EXPORT
00154 int ngram_model_recode(ngram_model_t *model, const char *from, const char *to);
00155 
00167 SPHINXBASE_EXPORT
00168 int ngram_model_apply_weights(ngram_model_t *model,
00169                               float32 lw, float32 wip, float32 uw);
00170 
00179 SPHINXBASE_EXPORT
00180 float32 ngram_model_get_weights(ngram_model_t *model, int32 *out_log_wip,
00181                                 int32 *out_log_uw);
00182 
00215 SPHINXBASE_EXPORT
00216 int32 ngram_score(ngram_model_t *model, const char *word, ...);
00217 
00221 SPHINXBASE_EXPORT
00222 int32 ngram_tg_score(ngram_model_t *model,
00223                      int32 w3, int32 w2, int32 w1,
00224                      int32 *n_used);
00225 
00229 SPHINXBASE_EXPORT
00230 int32 ngram_bg_score(ngram_model_t *model,
00231                      int32 w2, int32 w1,
00232                      int32 *n_used);
00233 
00237 SPHINXBASE_EXPORT
00238 int32 ngram_ng_score(ngram_model_t *model, int32 wid, int32 *history,
00239                      int32 n_hist, int32 *n_used);
00240 
00251 SPHINXBASE_EXPORT
00252 int32 ngram_prob(ngram_model_t *model, const char *word, ...);
00253 
00260 SPHINXBASE_EXPORT
00261 int32 ngram_ng_prob(ngram_model_t *model, int32 wid, int32 *history,
00262                     int32 n_hist, int32 *n_used);
00263 
00275 SPHINXBASE_EXPORT
00276 int32 ngram_score_to_prob(ngram_model_t *model, int32 score);
00277 
00281 SPHINXBASE_EXPORT
00282 int32 ngram_wid(ngram_model_t *model, const char *word);
00283 
00287 SPHINXBASE_EXPORT
00288 const char *ngram_word(ngram_model_t *model, int32 wid);
00289 
00303 SPHINXBASE_EXPORT
00304 int32 ngram_unknown_wid(ngram_model_t *model);
00305 
00309 SPHINXBASE_EXPORT
00310 int32 ngram_zero(ngram_model_t *model);
00311 
00315 SPHINXBASE_EXPORT
00316 int32 ngram_model_get_size(ngram_model_t *model);
00317 
00321 SPHINXBASE_EXPORT
00322 int32 const *ngram_model_get_counts(ngram_model_t *model);
00323 
00324 
00337 SPHINXBASE_EXPORT
00338 int32 ngram_model_add_word(ngram_model_t *model,
00339                            const char *word, float32 weight);
00340 
00354 SPHINXBASE_EXPORT
00355 int32 ngram_model_read_classdef(ngram_model_t *model,
00356                                 const char *file_name);
00357 
00366 SPHINXBASE_EXPORT
00367 int32 ngram_model_add_class(ngram_model_t *model,
00368                             const char *classname,
00369                             float32 classweight,
00370                             char **words,
00371                             const float32 *weights,
00372                             int32 n_words);
00373 
00383 SPHINXBASE_EXPORT
00384 int32 ngram_model_add_class_word(ngram_model_t *model,
00385                                  const char *classname,
00386                                  const char *word,
00387                                  float32 weight);
00388 
00413 SPHINXBASE_EXPORT
00414 ngram_model_t *ngram_model_set_init(cmd_ln_t *config,
00415                                     ngram_model_t **models,
00416                                     char **names,
00417                                     const float32 *weights,
00418                                     int32 n_models);
00419 
00450 SPHINXBASE_EXPORT
00451 ngram_model_t *ngram_model_set_read(cmd_ln_t *config,
00452                                     const char *lmctlfile,
00453                                     logmath_t *lmath);
00454 
00458 SPHINXBASE_EXPORT
00459 int32 ngram_model_set_count(ngram_model_t *set);
00460 
00464 typedef struct ngram_model_set_iter_s ngram_model_set_iter_t;
00465 
00471 SPHINXBASE_EXPORT
00472 ngram_model_set_iter_t *ngram_model_set_iter(ngram_model_t *set);
00473 
00479 SPHINXBASE_EXPORT
00480 ngram_model_set_iter_t *ngram_model_set_iter_next(ngram_model_set_iter_t *itor);
00481 
00485 void ngram_model_set_iter_free(ngram_model_set_iter_t *itor);
00486 
00494 SPHINXBASE_EXPORT
00495 ngram_model_t *ngram_model_set_iter_model(ngram_model_set_iter_t *itor,
00496                                           char const **lmname);
00497 
00504 SPHINXBASE_EXPORT
00505 ngram_model_t *ngram_model_set_select(ngram_model_t *set,
00506                                       const char *name);
00507 
00514 SPHINXBASE_EXPORT
00515 ngram_model_t *ngram_model_set_lookup(ngram_model_t *set,
00516                                       const char *name);
00517 
00521 SPHINXBASE_EXPORT
00522 const char *ngram_model_set_current(ngram_model_t *set);
00523 
00531 SPHINXBASE_EXPORT
00532 ngram_model_t *ngram_model_set_interp(ngram_model_t *set,
00533                                       const char **names,
00534                                       const float32 *weights);
00535 
00548 SPHINXBASE_EXPORT
00549 ngram_model_t *ngram_model_set_add(ngram_model_t *set,
00550                                    ngram_model_t *model,
00551                                    const char *name,
00552                                    float32 weight,
00553                                    int reuse_widmap);
00554 
00563 SPHINXBASE_EXPORT
00564 ngram_model_t *ngram_model_set_remove(ngram_model_t *set,
00565                                       const char *name,
00566                                       int reuse_widmap);
00567 
00571 SPHINXBASE_EXPORT
00572 void ngram_model_set_map_words(ngram_model_t *set,
00573                                const char **words,
00574                                int32 n_words);
00575 
00583 SPHINXBASE_EXPORT
00584 int32 ngram_model_set_current_wid(ngram_model_t *set,
00585                                   int32 set_wid);
00586 
00596 SPHINXBASE_EXPORT
00597 int32 ngram_model_set_known_wid(ngram_model_t *set, int32 set_wid);
00598 
00606 SPHINXBASE_EXPORT
00607 void ngram_model_flush(ngram_model_t *lm);
00608 
00609 #ifdef __cplusplus
00610 }
00611 #endif
00612 
00613 
00614 #endif /* __NGRAM_MODEL_H__ */

Generated on Fri Jan 14 2011 for SphinxBase by  doxygen 1.7.1