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>
/*
* 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);
#endif /* __FSG_MODEL_H__ */
fsg_model_s::start_state
int32 start_state
Must be in the range [0..n_state-1].
Definition: fsg_model.h:101
fsg_model_s::refcount
int refcount
Reference count.
Definition: fsg_model.h:92
fsg_model_s::final_state
int32 final_state
Must be in the range [0..n_state-1].
Definition: fsg_model.h:102
fsg_model_s::n_word_alloc
int32 n_word_alloc
Number of words allocated in vocab.
Definition: fsg_model.h:95
fsg_model_s::lw
float32 lw
Language weight that's been applied to transition logprobs.
Definition: fsg_model.h:103
fsg_model_s::link_alloc
listelem_alloc_t * link_alloc
Allocator for FSG links.
Definition: fsg_model.h:106
logmath_s
Definition: logmath.c:49
fsg_model_s::n_word
int32 n_word
Number of unique words in this FSG.
Definition: fsg_model.h:94
fsg_link_s::logs2prob
int32 logs2prob
log(transition probability)*lw
Definition: fsg_model.h:69
gnode_s
A node in a generic list.
Definition: glist.h:100
prim_type.h
Basic type definitions used in Sphinx.
trans_list_s
Adjacency list (opaque) for a state in an FSG.
Definition: fsg_model.c:63
listelem_alloc_s
Fast linked list allocator.
Definition: listelem_alloc.c:65
fsg_arciter_s
Implementation of arc iterator.
Definition: fsg_model.c:71
fsg_link_s
Definition: fsg_model.h:66
listelem_alloc.h
Fast memory allocator for uniformly sized objects.
glist.h
Generic linked-lists maintenance.
fsg_model_s::n_state
int32 n_state
number of states in FSG
Definition: fsg_model.h:100
fsg_model_s::altwords
bitvec_t * altwords
Indicates which words are pronunciation alternates.
Definition: fsg_model.h:98
fsg_model_s::trans
trans_list_t * trans
Transitions out of each state, if any.
Definition: fsg_model.h:105
fsg_link_s::wid
int32 wid
Word-ID; <0 if epsilon or null transition.
Definition: fsg_model.h:70
hash_table.h
Hash table implementation.
fsg_model_s
Word level FSG definition.
Definition: fsg_model.h:91
fsg_model_s::silwords
bitvec_t * silwords
Indicates which words are silence/fillers.
Definition: fsg_model.h:97
logmath.h
Fast integer logarithmic addition operations.
bitvec.h
An implementation of bit vectors.
fsg_model_s::lmath
logmath_t * lmath
Pointer to log math computation object.
Definition: fsg_model.h:99
fsg_model_s::name
char * name
A unique string identifier for this FSG.
Definition: fsg_model.h:93
fsg_model_s::vocab
char ** vocab
Vocabulary for this FSG.
Definition: fsg_model.h:96