PocketSphinx  5prealpha
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 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 #if 0
56 }
57 #endif
58 
62 typedef struct ps_lattice_s ps_lattice_t;
63 
70 typedef struct ps_latnode_s ps_latnode_t;
71 
75 typedef struct ps_latnode_s ps_latnode_iter_t; /* pay no attention to the man behind the curtain */
76 
83 typedef struct ps_latlink_s ps_latlink_t;
84 
89 
90 /* Forward declaration needed to avoid circular includes */
91 struct ps_decoder_s;
92 
100 POCKETSPHINX_EXPORT
102  char const *file);
103 
113 POCKETSPHINX_EXPORT
115 
121 POCKETSPHINX_EXPORT
122 int ps_lattice_free(ps_lattice_t *dag);
123 
129 POCKETSPHINX_EXPORT
130 int ps_lattice_write(ps_lattice_t *dag, char const *filename);
131 
137 POCKETSPHINX_EXPORT
138 int ps_lattice_write_htk(ps_lattice_t *dag, char const *filename);
139 
148 POCKETSPHINX_EXPORT
149 logmath_t *ps_lattice_get_logmath(ps_lattice_t *dag);
150 
151 
161 POCKETSPHINX_EXPORT
163 
169 POCKETSPHINX_EXPORT
171 
176 POCKETSPHINX_EXPORT
178 
182 POCKETSPHINX_EXPORT
184 
193 POCKETSPHINX_EXPORT
194 int ps_latnode_times(ps_latnode_t *node, int16 *out_fef, int16 *out_lef);
195 
203 POCKETSPHINX_EXPORT
204 char const *ps_latnode_word(ps_lattice_t *dag, ps_latnode_t *node);
205 
213 POCKETSPHINX_EXPORT
214 char const *ps_latnode_baseword(ps_lattice_t *dag, ps_latnode_t *node);
215 
222 POCKETSPHINX_EXPORT
224 
231 POCKETSPHINX_EXPORT
233 
245 POCKETSPHINX_EXPORT
246 int32 ps_latnode_prob(ps_lattice_t *dag, ps_latnode_t *node,
247  ps_latlink_t **out_link);
248 
255 POCKETSPHINX_EXPORT
257 
262 POCKETSPHINX_EXPORT
264 
268 POCKETSPHINX_EXPORT
270 
281 POCKETSPHINX_EXPORT
282 int ps_latlink_times(ps_latlink_t *link, int16 *out_sf);
283 
291 POCKETSPHINX_EXPORT
293 
301 POCKETSPHINX_EXPORT
302 char const *ps_latlink_word(ps_lattice_t *dag, ps_latlink_t *link);
303 
311 POCKETSPHINX_EXPORT
312 char const *ps_latlink_baseword(ps_lattice_t *dag, ps_latlink_t *link);
313 
320 POCKETSPHINX_EXPORT
322 
333 POCKETSPHINX_EXPORT
334 int32 ps_latlink_prob(ps_lattice_t *dag, ps_latlink_t *link, int32 *out_ascr);
335 
340 POCKETSPHINX_EXPORT
342  int32 score, int32 ef);
343 
359 POCKETSPHINX_EXPORT
361 
369 POCKETSPHINX_EXPORT
371 
382 POCKETSPHINX_EXPORT
384 
392 POCKETSPHINX_EXPORT
394 
403 POCKETSPHINX_EXPORT
404 ps_latlink_t *ps_lattice_bestpath(ps_lattice_t *dag, ngram_model_t *lmset,
405  float32 lwf, float32 ascale);
406 
414 POCKETSPHINX_EXPORT
415 int32 ps_lattice_posterior(ps_lattice_t *dag, ngram_model_t *lmset,
416  float32 ascale);
417 
429 POCKETSPHINX_EXPORT
430 int32 ps_lattice_posterior_prune(ps_lattice_t *dag, int32 beam);
431 
432 #ifdef NOT_IMPLEMENTED_YET
433 
439 POCKETSPHINX_EXPORT
440 int32 ps_lattice_ngram_expand(ps_lattice_t *dag, ngram_model_t *lm);
441 #endif
442 
449 POCKETSPHINX_EXPORT
451 
452 #ifdef __cplusplus
453 }
454 #endif
455 
456 #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:779
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:387
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:270
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:822
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:682
POCKETSPHINX_EXPORT ps_latlink_iter_t * ps_latnode_entries(ps_latnode_t *node)
Iterate over entries to this node.
Definition: ps_lattice.c:755
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:1117
POCKETSPHINX_EXPORT void ps_latlink_iter_free(ps_latlink_iter_t *itor)
Stop iterating over links.
Definition: ps_lattice.c:767
POCKETSPHINX_EXPORT int ps_lattice_n_frames(ps_lattice_t *dag)
Get the number of frames in the lattice.
Definition: ps_lattice.c:633
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:1091
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:732
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:1446
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:726
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:808
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:1215
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:694
POCKETSPHINX_EXPORT int ps_lattice_write(ps_lattice_t *dag, char const *filename)
Write a lattice to disk.
Definition: ps_lattice.c:210
POCKETSPHINX_EXPORT ps_latlink_t * ps_latlink_pred(ps_latlink_t *link)
Get predecessor link in best path.
Definition: ps_lattice.c:816
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:761
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:800
POCKETSPHINX_EXPORT ps_latnode_t * ps_latnode_iter_node(ps_latnode_iter_t *itor)
Get node from iterator.
Definition: ps_lattice.c:706
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:793
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:1148
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:720
POCKETSPHINX_EXPORT void ps_latnode_iter_free(ps_latnode_iter_t *itor)
Stop iterating over nodes.
Definition: ps_lattice.c:700
POCKETSPHINX_EXPORT ps_lattice_t * ps_lattice_retain(ps_lattice_t *dag)
Retain a lattice.
Definition: ps_lattice.c:658
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:1173
POCKETSPHINX_EXPORT ps_latnode_iter_t * ps_latnode_iter(ps_lattice_t *dag)
Start iterating over nodes in the lattice.
Definition: ps_lattice.c:688
POCKETSPHINX_EXPORT int ps_lattice_free(ps_lattice_t *dag)
Free a lattice.
Definition: ps_lattice.c:665
POCKETSPHINX_EXPORT ps_latlink_iter_t * ps_latnode_exits(ps_latnode_t *node)
Iterate over exits from this node.
Definition: ps_lattice.c:749
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 &quot;from&quot; and &quot;to&quot; 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:712
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:1524
POCKETSPHINX_EXPORT ps_latlink_t * ps_latlink_iter_link(ps_latlink_iter_t *itor)
Get link from iterator.
Definition: ps_lattice.c:773