PocketSphinx  0.6
ps_lattice.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 2008 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  */
37 
42 #ifndef __PS_LATTICE_H__
43 #define __PS_LATTICE_H__
44 
45 /* SphinxBase headers. */
46 #include <sphinxbase/prim_type.h>
47 #include <sphinxbase/ngram_model.h>
48 
49 /* PocketSphinx headers. */
50 #include <pocketsphinx_export.h>
51 
55 typedef struct ps_lattice_s ps_lattice_t;
56 
63 typedef struct ps_latnode_s ps_latnode_t;
64 
68 typedef struct ps_latnode_s ps_latnode_iter_t; /* pay no attention to the man behind the curtain */
69 
76 typedef struct ps_latlink_s ps_latlink_t;
77 
82 
83 /* Forward declaration needed to avoid circular includes */
84 struct ps_decoder_s;
85 
93 POCKETSPHINX_EXPORT
95  char const *file);
96 
106 POCKETSPHINX_EXPORT
108 
114 POCKETSPHINX_EXPORT
115 int ps_lattice_free(ps_lattice_t *dag);
116 
122 POCKETSPHINX_EXPORT
123 int ps_lattice_write(ps_lattice_t *dag, char const *filename);
124 
130 POCKETSPHINX_EXPORT
131 int ps_lattice_write_htk(ps_lattice_t *dag, char const *filename);
132 
141 POCKETSPHINX_EXPORT
142 logmath_t *ps_lattice_get_logmath(ps_lattice_t *dag);
143 
144 
154 POCKETSPHINX_EXPORT
156 
162 POCKETSPHINX_EXPORT
164 
169 POCKETSPHINX_EXPORT
171 
175 POCKETSPHINX_EXPORT
177 
186 POCKETSPHINX_EXPORT
187 int ps_latnode_times(ps_latnode_t *node, int16 *out_fef, int16 *out_lef);
188 
196 POCKETSPHINX_EXPORT
197 char const *ps_latnode_word(ps_lattice_t *dag, ps_latnode_t *node);
198 
206 POCKETSPHINX_EXPORT
207 char const *ps_latnode_baseword(ps_lattice_t *dag, ps_latnode_t *node);
208 
215 POCKETSPHINX_EXPORT
217 
224 POCKETSPHINX_EXPORT
226 
238 POCKETSPHINX_EXPORT
239 int32 ps_latnode_prob(ps_lattice_t *dag, ps_latnode_t *node,
240  ps_latlink_t **out_link);
241 
248 POCKETSPHINX_EXPORT
250 
255 POCKETSPHINX_EXPORT
257 
261 POCKETSPHINX_EXPORT
263 
274 POCKETSPHINX_EXPORT
275 int ps_latlink_times(ps_latlink_t *link, int16 *out_sf);
276 
284 POCKETSPHINX_EXPORT
286 
294 POCKETSPHINX_EXPORT
295 char const *ps_latlink_word(ps_lattice_t *dag, ps_latlink_t *link);
296 
304 POCKETSPHINX_EXPORT
305 char const *ps_latlink_baseword(ps_lattice_t *dag, ps_latlink_t *link);
306 
313 POCKETSPHINX_EXPORT
315 
326 POCKETSPHINX_EXPORT
327 int32 ps_latlink_prob(ps_lattice_t *dag, ps_latlink_t *link, int32 *out_ascr);
328 
333 POCKETSPHINX_EXPORT
335  int32 score, int32 ef);
336 
352 POCKETSPHINX_EXPORT
354 
362 POCKETSPHINX_EXPORT
364 
375 POCKETSPHINX_EXPORT
377 
385 POCKETSPHINX_EXPORT
387 
396 POCKETSPHINX_EXPORT
397 ps_latlink_t *ps_lattice_bestpath(ps_lattice_t *dag, ngram_model_t *lmset,
398  float32 lwf, float32 ascale);
399 
407 POCKETSPHINX_EXPORT
408 int32 ps_lattice_posterior(ps_lattice_t *dag, ngram_model_t *lmset,
409  float32 ascale);
410 
422 POCKETSPHINX_EXPORT
423 int32 ps_lattice_posterior_prune(ps_lattice_t *dag, int32 beam);
424 
425 #ifdef NOT_IMPLEMENTED_YET
426 
432 POCKETSPHINX_EXPORT
433 int32 ps_lattice_ngram_expand(ps_lattice_t *dag, ngram_model_t *lm);
434 #endif
435 
442 POCKETSPHINX_EXPORT
444 
445 #endif /* __PS_LATTICE_H__ */
POCKETSPHINX_EXPORT int ps_latlink_times(ps_latlink_t *link, int16 *out_sf)
Get start and end times from a lattice link.
Definition: ps_lattice.c:802
POCKETSPHINX_EXPORT ps_lattice_t * ps_lattice_read(struct ps_decoder_s *ps, char const *file)
Read a lattice from a file on disk.
Definition: ps_lattice.c:410
POCKETSPHINX_EXPORT int ps_lattice_write_htk(ps_lattice_t *dag, char const *filename)
Write a lattice to disk in HTK format.
Definition: ps_lattice.c:293
POCKETSPHINX_EXPORT int32 ps_latlink_prob(ps_lattice_t *dag, ps_latlink_t *link, int32 *out_ascr)
Get acoustic score and posterior probability from a lattice link.
Definition: ps_lattice.c:845
POCKETSPHINX_EXPORT logmath_t * ps_lattice_get_logmath(ps_lattice_t *dag)
Get the log-math computation object for this lattice.
Definition: ps_lattice.c:705
POCKETSPHINX_EXPORT ps_latlink_iter_t * ps_latnode_entries(ps_latnode_t *node)
Iterate over entries to this node.
Definition: ps_lattice.c:778
POCKETSPHINX_EXPORT ps_latlink_t * ps_lattice_traverse_next(ps_lattice_t *dag, ps_latnode_t *end)
Get the next link in forward traversal.
Definition: ps_lattice.c:1140
POCKETSPHINX_EXPORT void ps_latlink_iter_free(ps_latlink_iter_t *itor)
Stop iterating over links.
Definition: ps_lattice.c:790
POCKETSPHINX_EXPORT int ps_lattice_n_frames(ps_lattice_t *dag)
Get the number of frames in the lattice.
Definition: ps_lattice.c:656
POCKETSPHINX_EXPORT ps_latlink_t * ps_lattice_traverse_edges(ps_lattice_t *dag, ps_latnode_t *start, ps_latnode_t *end)
Start a forward traversal of edges in a word graph.
Definition: ps_lattice.c:1114
POCKETSPHINX_EXPORT int32 ps_latnode_prob(ps_lattice_t *dag, ps_latnode_t *node, ps_latlink_t **out_link)
Get best posterior probability and associated acoustic score from a lattice node. ...
Definition: ps_lattice.c:755
POCKETSPHINX_EXPORT int32 ps_lattice_posterior(ps_lattice_t *dag, ngram_model_t *lmset, float32 ascale)
Calculate link posterior probabilities on a word graph.
Definition: ps_lattice.c:1408
POCKETSPHINX_EXPORT char const * ps_latnode_baseword(ps_lattice_t *dag, ps_latnode_t *node)
Get base word string for this node.
Definition: ps_lattice.c:749
POCKETSPHINX_EXPORT char const * ps_latlink_baseword(ps_lattice_t *dag, ps_latlink_t *link)
Get base word string from a lattice link.
Definition: ps_lattice.c:831
Decoder object.
POCKETSPHINX_EXPORT ps_latlink_t * ps_lattice_bestpath(ps_lattice_t *dag, ngram_model_t *lmset, float32 lwf, float32 ascale)
Do N-Gram based best-path search on a word graph.
Definition: ps_lattice.c:1238
POCKETSPHINX_EXPORT ps_latnode_iter_t * ps_latnode_iter_next(ps_latnode_iter_t *itor)
Move to next node in iteration.
Definition: ps_lattice.c:717
POCKETSPHINX_EXPORT int ps_lattice_write(ps_lattice_t *dag, char const *filename)
Write a lattice to disk.
Definition: ps_lattice.c:233
POCKETSPHINX_EXPORT ps_latlink_t * ps_latlink_pred(ps_latlink_t *link)
Get predecessor link in best path.
Definition: ps_lattice.c:839
POCKETSPHINX_EXPORT ps_latlink_iter_t * ps_latlink_iter_next(ps_latlink_iter_t *itor)
Get next link from a lattice link iterator.
Definition: ps_lattice.c:784
Word graph structure used in bestpath/nbest search.
POCKETSPHINX_EXPORT char const * ps_latlink_word(ps_lattice_t *dag, ps_latlink_t *link)
Get word string from a lattice link.
Definition: ps_lattice.c:823
POCKETSPHINX_EXPORT ps_latnode_t * ps_latnode_iter_node(ps_latnode_iter_t *itor)
Get node from iterator.
Definition: ps_lattice.c:729
POCKETSPHINX_EXPORT ps_latnode_t * ps_latlink_nodes(ps_latlink_t *link, ps_latnode_t **out_src)
Get destination and source nodes from a lattice link.
Definition: ps_lattice.c:816
POCKETSPHINX_EXPORT ps_latlink_t * ps_lattice_reverse_edges(ps_lattice_t *dag, ps_latnode_t *start, ps_latnode_t *end)
Start a reverse traversal of edges in a word graph.
Definition: ps_lattice.c:1171
POCKETSPHINX_EXPORT char const * ps_latnode_word(ps_lattice_t *dag, ps_latnode_t *node)
Get word string for this node.
Definition: ps_lattice.c:743
POCKETSPHINX_EXPORT void ps_latnode_iter_free(ps_latnode_iter_t *itor)
Stop iterating over nodes.
Definition: ps_lattice.c:723
POCKETSPHINX_EXPORT ps_lattice_t * ps_lattice_retain(ps_lattice_t *dag)
Retain a lattice.
Definition: ps_lattice.c:681
POCKETSPHINX_EXPORT ps_latlink_t * ps_lattice_reverse_next(ps_lattice_t *dag, ps_latnode_t *start)
Get the next link in reverse traversal.
Definition: ps_lattice.c:1196
POCKETSPHINX_EXPORT ps_latnode_iter_t * ps_latnode_iter(ps_lattice_t *dag)
Start iterating over nodes in the lattice.
Definition: ps_lattice.c:711
POCKETSPHINX_EXPORT int ps_lattice_free(ps_lattice_t *dag)
Free a lattice.
Definition: ps_lattice.c:688
POCKETSPHINX_EXPORT ps_latlink_iter_t * ps_latnode_exits(ps_latnode_t *node)
Iterate over exits from this node.
Definition: ps_lattice.c:772
POCKETSPHINX_EXPORT void ps_lattice_link(ps_lattice_t *dag, ps_latnode_t *from, ps_latnode_t *to, int32 score, int32 ef)
Create a directed link between "from" and "to" nodes, but if a link already exists, choose one with the best link_scr.
Definition: ps_lattice.c:65
POCKETSPHINX_EXPORT int ps_latnode_times(ps_latnode_t *node, int16 *out_fef, int16 *out_lef)
Get start and end time range for a node.
Definition: ps_lattice.c:735
POCKETSPHINX_EXPORT int32 ps_lattice_posterior_prune(ps_lattice_t *dag, int32 beam)
Prune all links (and associated nodes) below a certain posterior probability.
Definition: ps_lattice.c:1477
POCKETSPHINX_EXPORT ps_latlink_t * ps_latlink_iter_link(ps_latlink_iter_t *itor)
Get link from iterator.
Definition: ps_lattice.c:796