root / trunk / Linux / addons / ofxASR / libs / sphinx / include / sphinx3 / word_graph.h @ 59

View | Annotate | Download (5.3 KB)

1 59 jimbo
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 59 jimbo
/* ====================================================================
3 59 jimbo
 * Copyright (c) 1995-2004 Carnegie Mellon University.  All rights
4 59 jimbo
 * reserved.
5 59 jimbo
 *
6 59 jimbo
 * Redistribution and use in source and binary forms, with or without
7 59 jimbo
 * modification, are permitted provided that the following conditions
8 59 jimbo
 * are met:
9 59 jimbo
 *
10 59 jimbo
 * 1. Redistributions of source code must retain the above copyright
11 59 jimbo
 *    notice, this list of conditions and the following disclaimer.
12 59 jimbo
 *
13 59 jimbo
 * 2. Redistributions in binary form must reproduce the above copyright
14 59 jimbo
 *    notice, this list of conditions and the following disclaimer in
15 59 jimbo
 *    the documentation and/or other materials provided with the
16 59 jimbo
 *    distribution.
17 59 jimbo
 *
18 59 jimbo
 * This work was supported in part by funding from the Defense Advanced
19 59 jimbo
 * Research Projects Agency and the National Science Foundation of the
20 59 jimbo
 * United States of America, and the CMU Sphinx Speech Consortium.
21 59 jimbo
 *
22 59 jimbo
 * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23 59 jimbo
 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 59 jimbo
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 59 jimbo
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26 59 jimbo
 * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 59 jimbo
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 59 jimbo
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 59 jimbo
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 59 jimbo
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 59 jimbo
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 59 jimbo
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 59 jimbo
 *
34 59 jimbo
 * ====================================================================
35 59 jimbo
 *
36 59 jimbo
 */
37 59 jimbo
38 59 jimbo
/*
39 59 jimbo
 * word_graph.h -- Library for word graph a linked-based DAG.
40 59 jimbo
 *
41 59 jimbo
 * **********************************************
42 59 jimbo
 * CMU ARPA Speech Project
43 59 jimbo
 *
44 59 jimbo
 * Copyright (c) 1996 Carnegie Mellon University.
45 59 jimbo
 * ALL RIGHTS RESERVED.
46 59 jimbo
 * **********************************************
47 59 jimbo
 * HISTORY
48 59 jimbo
 *
49 59 jimbo
 * $Log$
50 59 jimbo
 * Revision 1.1  2006/04/05  20:27:30  dhdfu
51 59 jimbo
 * A Great Reorganzation of header files and executables
52 59 jimbo
 *
53 59 jimbo
 * Revision 1.2  2006/02/23 05:15:12  arthchan2003
54 59 jimbo
 * Merged from branch SPHINX3_5_2_RCI_IRII_BRANCH: Word graphs with word attached to links. Now mainly used in conversion from Sphinx to IBM format
55 59 jimbo
 *
56 59 jimbo
 * Revision 1.1.2.1  2005/11/17 06:39:30  arthchan2003
57 59 jimbo
 * Added a structure for linked-based lattice.
58 59 jimbo
 *
59 59 jimbo
 */
60 59 jimbo
61 59 jimbo
62 59 jimbo
#ifndef _WORD_GRAPH_H_
63 59 jimbo
#define _WORD_GRAPH_H_
64 59 jimbo
65 59 jimbo
#include <stdio.h>
66 59 jimbo
67 59 jimbo
#include <logmath.h>
68 59 jimbo
#include <glist.h>
69 59 jimbo
#include <s3types.h>
70 59 jimbo
#include <dag.h>
71 59 jimbo
#include <dict.h>
72 59 jimbo
#include <lm.h>
73 59 jimbo
74 59 jimbo
75 59 jimbo
#ifdef __cplusplus
76 59 jimbo
extern "C" {
77 59 jimbo
#endif
78 59 jimbo
#if 0
79 59 jimbo
/* Fool Emacs. */
80 59 jimbo
}
81 59 jimbo
#endif
82 59 jimbo
83 59 jimbo
/*
84 59 jimbo
 *  word_graph_t is a linked-based word graph.  That is the word-ID
85 59 jimbo
 *  lies on the arc of the graph.  (As opposed to dag_t which
86 59 jimbo
 *  essentially link segments together or node-based)
87 59 jimbo
 *
88 59 jimbo
 */
89 59 jimbo
90 59 jimbo
#define INVALID_START_FRAME -1
91 59 jimbo
#define INVALID_START_INDEX -1
92 59 jimbo
93 59 jimbo
#define OUTLATFMT_SPHINX3 0
94 59 jimbo
#define OUTLATFMT_IBM 1
95 59 jimbo
#define dag_node_mark(d) d->reachable
96 59 jimbo
97 59 jimbo
/**
98 59 jimbo
 * \struct word_graph_link_t
99 59 jimbo
 *
100 59 jimbo
 * A link in the word_graph
101 59 jimbo
 */
102 59 jimbo
typedef struct{
103 59 jimbo
    int32 srcidx; /**< Start Node Idx */
104 59 jimbo
    int32 tgtidx; /**< End Node Idx */
105 59 jimbo
    int32 wid;   /**< Word ID */
106 59 jimbo
    float64 ascr; /**< Acoustic Score */
107 59 jimbo
    float64 lscr; /**< Language Score */
108 59 jimbo
    float64 cscr; /**< Confidence Score */
109 59 jimbo
    int32 linkidx; /**< The index for this node */
110 59 jimbo
} word_graph_link_t;
111 59 jimbo
112 59 jimbo
/**
113 59 jimbo
 * \struct word_graph_node_t
114 59 jimbo
 *
115 59 jimbo
 * A node in the word_graph
116 59 jimbo
 */
117 59 jimbo
118 59 jimbo
typedef struct{
119 59 jimbo
    int32 time;  /**< The time moment of this node */
120 59 jimbo
    int32 nodeidx; /**< The index for this node */
121 59 jimbo
    glist_t child_node_list; /**< The list of all children. */
122 59 jimbo
} word_graph_node_t;
123 59 jimbo
124 59 jimbo
/**
125 59 jimbo
 * \struct word_graph_t
126 59 jimbo
 *
127 59 jimbo
 * The word graph structure. (linked-based word graph)
128 59 jimbo
 */
129 59 jimbo
typedef struct{
130 59 jimbo
    glist_t link; /**< List of link */
131 59 jimbo
    glist_t node; /**< List of node */
132 59 jimbo
    int32 n_link; /**< Number of node */
133 59 jimbo
    int32 n_node; /**< Number of node */
134 59 jimbo
135 59 jimbo
} word_graph_t;
136 59 jimbo
137 59 jimbo
/**
138 59 jimbo
 * Print a word_graph structure
139 59 jimbo
 */
140 59 jimbo
void print_wg(FILE *fp,  /**< File pointer */
141 59 jimbo
              word_graph_t *wg,  /**< Word graph */
142 59 jimbo
              dict_t *dict,
143 59 jimbo
              int32 fmt  /**<
144 59 jimbo
                            Format of the word graph
145 59 jimbo
                            fmt=0: simple format
146 59 jimbo
                            fmt=1: IBM format.
147 59 jimbo
                         */
148 59 jimbo
    );
149 59 jimbo
150 59 jimbo
/**
151 59 jimbo
   Convert a dag to wordgraph.
152 59 jimbo
*/
153 59 jimbo
word_graph_t* dag_to_wordgraph (dag_t* dag,  /**< a DAG structure */
154 59 jimbo
                                int32 *senscale, /**< Scaling factor of the acoustic score */
155 59 jimbo
                                lm_t* lm, /**< LM */
156 59 jimbo
                                dict_t* dict /**< Dict */
157 59 jimbo
    );
158 59 jimbo
159 59 jimbo
160 59 jimbo
/**
161 59 jimbo
   Dump the word graph. This is similar to s3flat_fwd_dag_dump interface.
162 59 jimbo
*/
163 59 jimbo
164 59 jimbo
void word_graph_dump(char *dir, /**< Directory name*/
165 59 jimbo
                     char *uttfile,  /**< Utterance Filename */
166 59 jimbo
                     char *id,  /**< Utterance ID */
167 59 jimbo
                     char *latfile_ext,  /**< Lattice file Extension */
168 59 jimbo
                     dag_t *dag,   /**< DAG */
169 59 jimbo
                     dict_t *dict,  /**< Dictionary */
170 59 jimbo
                     lm_t *lm,     /**< LM */
171 59 jimbo
                     int32 *senscale /**< Senone scale */
172 59 jimbo
    );
173 59 jimbo
174 59 jimbo
175 59 jimbo
/**
176 59 jimbo
   Free wordgraph.
177 59 jimbo
*/
178 59 jimbo
void wordgraph_free(word_graph_t *wg /**< Word graph */
179 59 jimbo
    );
180 59 jimbo
181 59 jimbo
#ifdef __cplusplus
182 59 jimbo
}
183 59 jimbo
#endif
184 59 jimbo
185 59 jimbo
186 59 jimbo
#endif  /*_WORD_GRAPH_H_*/