fsg_model.h
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* ====================================================================
* Copyright (c) 1999-2004 Carnegie Mellon University. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
* NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
*/
/*
* fsg_model.h -- Word-level finite state graph
*
* **********************************************
* CMU ARPA Speech Project
*
* Copyright (c) 2003 Carnegie Mellon University.
* ALL RIGHTS RESERVED.
* **********************************************
*/
#ifndef __FSG_MODEL_H__
#define __FSG_MODEL_H__
/* System headers. */
#include <stdio.h>
#include <string.h>
/* SphinxBase headers. */
#include <sphinxbase/prim_type.h>
#include <sphinxbase/glist.h>
#include <sphinxbase/logmath.h>
#include <sphinxbase/bitvec.h>
#include <sphinxbase/hash_table.h>
#include <sphinxbase/listelem_alloc.h>
#include <sphinxbase/sphinxbase_export.h>
#ifdef __cplusplus
extern "C" {
#endif
#if 0
/* Fool Emacs. */
}
#endif
/*
* A single transition in the FSG.
*/
typedef struct fsg_link_s {
int32 from_state;
int32 to_state;
int32 logs2prob;
int32 wid;
} fsg_link_t;
/* Access macros */
#define fsg_link_from_state(l) ((l)->from_state)
#define fsg_link_to_state(l) ((l)->to_state)
#define fsg_link_wid(l) ((l)->wid)
#define fsg_link_logs2prob(l) ((l)->logs2prob)
typedef struct trans_list_s trans_list_t;
typedef struct fsg_model_s {
int refcount;
char *name;
int32 n_word;
int32 n_word_alloc;
char **vocab;
bitvec_t *silwords;
bitvec_t *altwords;
logmath_t *lmath;
int32 n_state;
int32 start_state;
int32 final_state;
float32 lw;
trans_list_t *trans;
listelem_alloc_t *link_alloc;
} fsg_model_t;
/* Access macros */
#define fsg_model_name(f) ((f)->name)
#define fsg_model_n_state(f) ((f)->n_state)
#define fsg_model_start_state(f) ((f)->start_state)
#define fsg_model_final_state(f) ((f)->final_state)
#define fsg_model_log(f,p) logmath_log((f)->lmath, p)
#define fsg_model_lw(f) ((f)->lw)
#define fsg_model_n_word(f) ((f)->n_word)
#define fsg_model_word_str(f,wid) (wid == -1 ? "(NULL)" : (f)->vocab[wid])
typedef struct fsg_arciter_s fsg_arciter_t;
#define fsg_model_has_sil(f) ((f)->silwords != NULL)
#define fsg_model_has_alt(f) ((f)->altwords != NULL)
#define fsg_model_is_filler(f,wid) \
(fsg_model_has_sil(f) ? bitvec_is_set((f)->silwords, wid) : FALSE)
#define fsg_model_is_alt(f,wid) \
(fsg_model_has_alt(f) ? bitvec_is_set((f)->altwords, wid) : FALSE)
SPHINXBASE_EXPORT
fsg_model_t *fsg_model_init(char const *name, logmath_t *lmath,
float32 lw, int32 n_state);
SPHINXBASE_EXPORT
fsg_model_t *fsg_model_readfile(const char *file, logmath_t *lmath, float32 lw);
SPHINXBASE_EXPORT
fsg_model_t *fsg_model_read(FILE *fp, logmath_t *lmath, float32 lw);
SPHINXBASE_EXPORT
fsg_model_t *fsg_model_retain(fsg_model_t *fsg);
SPHINXBASE_EXPORT
int fsg_model_free(fsg_model_t *fsg);
SPHINXBASE_EXPORT
int fsg_model_word_add(fsg_model_t *fsg, char const *word);
SPHINXBASE_EXPORT
int fsg_model_word_id(fsg_model_t *fsg, char const *word);
SPHINXBASE_EXPORT
void fsg_model_trans_add(fsg_model_t * fsg,
int32 from, int32 to, int32 logp, int32 wid);
SPHINXBASE_EXPORT
int32 fsg_model_null_trans_add(fsg_model_t * fsg, int32 from, int32 to, int32 logp);
SPHINXBASE_EXPORT
int32 fsg_model_tag_trans_add(fsg_model_t * fsg, int32 from, int32 to,
int32 logp, int32 wid);
SPHINXBASE_EXPORT
glist_t fsg_model_null_trans_closure(fsg_model_t * fsg, glist_t nulls);
SPHINXBASE_EXPORT
glist_t fsg_model_trans(fsg_model_t *fsg, int32 i, int32 j);
SPHINXBASE_EXPORT
fsg_arciter_t *fsg_model_arcs(fsg_model_t *fsg, int32 i);
SPHINXBASE_EXPORT
fsg_link_t *fsg_arciter_get(fsg_arciter_t *itor);
SPHINXBASE_EXPORT
fsg_arciter_t *fsg_arciter_next(fsg_arciter_t *itor);
SPHINXBASE_EXPORT
void fsg_arciter_free(fsg_arciter_t *itor);
SPHINXBASE_EXPORT
fsg_link_t *fsg_model_null_trans(fsg_model_t *fsg, int32 i, int32 j);
SPHINXBASE_EXPORT
int fsg_model_add_silence(fsg_model_t * fsg, char const *silword,
int state, float32 silprob);
SPHINXBASE_EXPORT
int fsg_model_add_alt(fsg_model_t * fsg, char const *baseword,
char const *altword);
SPHINXBASE_EXPORT
void fsg_model_write(fsg_model_t *fsg, FILE *fp);
SPHINXBASE_EXPORT
void fsg_model_writefile(fsg_model_t *fsg, char const *file);
SPHINXBASE_EXPORT
void fsg_model_write_fsm(fsg_model_t *fsg, FILE *fp);
SPHINXBASE_EXPORT
void fsg_model_writefile_fsm(fsg_model_t *fsg, char const *file);
SPHINXBASE_EXPORT
void fsg_model_write_symtab(fsg_model_t *fsg, FILE *file);
SPHINXBASE_EXPORT
void fsg_model_writefile_symtab(fsg_model_t *fsg, char const *file);
#ifdef __cplusplus
}
#endif
#endif /* __FSG_MODEL_H__ */
bitvec.h
An implementation of bit vectors.
glist.h
Generic linked-lists maintenance.
hash_table.h
Hash table implementation.
listelem_alloc.h
Fast memory allocator for uniformly sized objects.
listelem_alloc_t
struct listelem_alloc_s listelem_alloc_t
List element allocator object.
Definition listelem_alloc.h:65
logmath.h
Fast integer logarithmic addition operations.
logmath_t
struct logmath_s logmath_t
Integer log math computation class.
Definition logmath.h:108
prim_type.h
Basic type definitions used in Sphinx.
fsg_arciter_s
Implementation of arc iterator.
Definition fsg_model.c:64
fsg_link_s
Definition fsg_model.h:74
fsg_link_s::logs2prob
int32 logs2prob
log(transition probability)*lw
Definition fsg_model.h:77
fsg_link_s::wid
int32 wid
Word-ID; <0 if epsilon or null transition.
Definition fsg_model.h:78
fsg_model_s
Word level FSG definition.
Definition fsg_model.h:99
fsg_model_s::n_word_alloc
int32 n_word_alloc
Number of words allocated in vocab.
Definition fsg_model.h:103
fsg_model_s::start_state
int32 start_state
Must be in the range [0..n_state-1].
Definition fsg_model.h:109
fsg_model_s::vocab
char ** vocab
Vocabulary for this FSG.
Definition fsg_model.h:104
fsg_model_s::n_state
int32 n_state
number of states in FSG
Definition fsg_model.h:108
fsg_model_s::n_word
int32 n_word
Number of unique words in this FSG.
Definition fsg_model.h:102
fsg_model_s::lmath
logmath_t * lmath
Pointer to log math computation object.
Definition fsg_model.h:107
fsg_model_s::name
char * name
A unique string identifier for this FSG.
Definition fsg_model.h:101
fsg_model_s::silwords
bitvec_t * silwords
Indicates which words are silence/fillers.
Definition fsg_model.h:105
fsg_model_s::link_alloc
listelem_alloc_t * link_alloc
Allocator for FSG links.
Definition fsg_model.h:114
fsg_model_s::trans
trans_list_t * trans
Transitions out of each state, if any.
Definition fsg_model.h:113
fsg_model_s::final_state
int32 final_state
Must be in the range [0..n_state-1].
Definition fsg_model.h:110
fsg_model_s::altwords
bitvec_t * altwords
Indicates which words are pronunciation alternates.
Definition fsg_model.h:106
fsg_model_s::lw
float32 lw
Language weight that's been applied to transition logprobs.
Definition fsg_model.h:111
fsg_model_s::refcount
int refcount
Reference count.
Definition fsg_model.h:100
trans_list_s
Adjacency list (opaque) for a state in an FSG.
Definition fsg_model.c:56