ps_lattice.h
Go to the documentation of this file.
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* ====================================================================
* Copyright (c) 2008 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 work was supported in part by funding from the Defense Advanced
* Research Projects Agency and the National Science Foundation of the
* United States of America, and the CMU Sphinx Speech Consortium.
*
* 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.
*
* ====================================================================
*
*/
#ifndef __PS_LATTICE_H__
#define __PS_LATTICE_H__
/* SphinxBase headers. */
#include <sphinxbase/prim_type.h>
#include <sphinxbase/ngram_model.h>
/* PocketSphinx headers. */
#include <pocketsphinx_export.h>
#ifdef __cplusplus
extern "C" {
#endif
#if 0
}
#endif
typedef struct ps_lattice_s ps_lattice_t;
typedef struct ps_latnode_s ps_latnode_t;
typedef struct ps_latnode_s ps_latnode_iter_t; /* pay no attention to the man behind the curtain */
typedef struct ps_latlink_s ps_latlink_t;
typedef struct latlink_list_s ps_latlink_iter_t;
/* Forward declaration needed to avoid circular includes */
struct ps_decoder_s;
POCKETSPHINX_EXPORT
ps_lattice_t *ps_lattice_read(struct ps_decoder_s *ps,
char const *file);
POCKETSPHINX_EXPORT
ps_lattice_t *ps_lattice_retain(ps_lattice_t *dag);
POCKETSPHINX_EXPORT
int ps_lattice_free(ps_lattice_t *dag);
POCKETSPHINX_EXPORT
int ps_lattice_write(ps_lattice_t *dag, char const *filename);
POCKETSPHINX_EXPORT
int ps_lattice_write_htk(ps_lattice_t *dag, char const *filename);
POCKETSPHINX_EXPORT
logmath_t *ps_lattice_get_logmath(ps_lattice_t *dag);
POCKETSPHINX_EXPORT
ps_latnode_iter_t *ps_latnode_iter(ps_lattice_t *dag);
POCKETSPHINX_EXPORT
ps_latnode_iter_t *ps_latnode_iter_next(ps_latnode_iter_t *itor);
POCKETSPHINX_EXPORT
void ps_latnode_iter_free(ps_latnode_iter_t *itor);
POCKETSPHINX_EXPORT
ps_latnode_t *ps_latnode_iter_node(ps_latnode_iter_t *itor);
POCKETSPHINX_EXPORT
int ps_latnode_times(ps_latnode_t *node, int16 *out_fef, int16 *out_lef);
POCKETSPHINX_EXPORT
char const *ps_latnode_word(ps_lattice_t *dag, ps_latnode_t *node);
POCKETSPHINX_EXPORT
char const *ps_latnode_baseword(ps_lattice_t *dag, ps_latnode_t *node);
POCKETSPHINX_EXPORT
ps_latlink_iter_t *ps_latnode_exits(ps_latnode_t *node);
POCKETSPHINX_EXPORT
ps_latlink_iter_t *ps_latnode_entries(ps_latnode_t *node);
POCKETSPHINX_EXPORT
int32 ps_latnode_prob(ps_lattice_t *dag, ps_latnode_t *node,
ps_latlink_t **out_link);
POCKETSPHINX_EXPORT
ps_latlink_iter_t *ps_latlink_iter_next(ps_latlink_iter_t *itor);
POCKETSPHINX_EXPORT
void ps_latlink_iter_free(ps_latlink_iter_t *itor);
POCKETSPHINX_EXPORT
ps_latlink_t *ps_latlink_iter_link(ps_latlink_iter_t *itor);
POCKETSPHINX_EXPORT
int ps_latlink_times(ps_latlink_t *link, int16 *out_sf);
POCKETSPHINX_EXPORT
ps_latnode_t *ps_latlink_nodes(ps_latlink_t *link, ps_latnode_t **out_src);
POCKETSPHINX_EXPORT
char const *ps_latlink_word(ps_lattice_t *dag, ps_latlink_t *link);
POCKETSPHINX_EXPORT
char const *ps_latlink_baseword(ps_lattice_t *dag, ps_latlink_t *link);
POCKETSPHINX_EXPORT
ps_latlink_t *ps_latlink_pred(ps_latlink_t *link);
POCKETSPHINX_EXPORT
int32 ps_latlink_prob(ps_lattice_t *dag, ps_latlink_t *link, int32 *out_ascr);
POCKETSPHINX_EXPORT
void ps_lattice_link(ps_lattice_t *dag, ps_latnode_t *from, ps_latnode_t *to,
int32 score, int32 ef);
POCKETSPHINX_EXPORT
ps_latlink_t *ps_lattice_traverse_edges(ps_lattice_t *dag, ps_latnode_t *start, ps_latnode_t *end);
POCKETSPHINX_EXPORT
ps_latlink_t *ps_lattice_traverse_next(ps_lattice_t *dag, ps_latnode_t *end);
POCKETSPHINX_EXPORT
ps_latlink_t *ps_lattice_reverse_edges(ps_lattice_t *dag, ps_latnode_t *start, ps_latnode_t *end);
POCKETSPHINX_EXPORT
ps_latlink_t *ps_lattice_reverse_next(ps_lattice_t *dag, ps_latnode_t *start);
POCKETSPHINX_EXPORT
ps_latlink_t *ps_lattice_bestpath(ps_lattice_t *dag, ngram_model_t *lmset,
float32 lwf, float32 ascale);
POCKETSPHINX_EXPORT
int32 ps_lattice_posterior(ps_lattice_t *dag, ngram_model_t *lmset,
float32 ascale);
POCKETSPHINX_EXPORT
int32 ps_lattice_posterior_prune(ps_lattice_t *dag, int32 beam);
#ifdef NOT_IMPLEMENTED_YET
POCKETSPHINX_EXPORT
int32 ps_lattice_ngram_expand(ps_lattice_t *dag, ngram_model_t *lm);
#endif
POCKETSPHINX_EXPORT
int ps_lattice_n_frames(ps_lattice_t *dag);
#ifdef __cplusplus
}
#endif
#endif /* __PS_LATTICE_H__ */
ps_latlink_word
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
ps_latnode_baseword
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
ps_latnode_exits
POCKETSPHINX_EXPORT ps_latlink_iter_t * ps_latnode_exits(ps_latnode_t *node)
Iterate over exits from this node.
Definition: ps_lattice.c:749
ps_latnode_entries
POCKETSPHINX_EXPORT ps_latlink_iter_t * ps_latnode_entries(ps_latnode_t *node)
Iterate over entries to this node.
Definition: ps_lattice.c:755
ps_lattice_traverse_next
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
ps_lattice_read
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
ps_lattice_posterior_prune
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
ps_latlink_baseword
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
ps_lattice_write
POCKETSPHINX_EXPORT int ps_lattice_write(ps_lattice_t *dag, char const *filename)
Write a lattice to disk.
Definition: ps_lattice.c:210
ps_lattice_free
POCKETSPHINX_EXPORT int ps_lattice_free(ps_lattice_t *dag)
Free a lattice.
Definition: ps_lattice.c:665
ps_latnode_times
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
ps_lattice_n_frames
POCKETSPHINX_EXPORT int ps_lattice_n_frames(ps_lattice_t *dag)
Get the number of frames in the lattice.
Definition: ps_lattice.c:633
ps_latnode_iter_next
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
ps_lattice_link
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,...
Definition: ps_lattice.c:65
ps_latnode_word
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
ps_latnode_iter_node
POCKETSPHINX_EXPORT ps_latnode_t * ps_latnode_iter_node(ps_latnode_iter_t *itor)
Get node from iterator.
Definition: ps_lattice.c:706
ps_lattice_get_logmath
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
ps_latnode_prob
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
ps_latlink_nodes
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
ps_lattice_posterior
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
ps_latlink_pred
POCKETSPHINX_EXPORT ps_latlink_t * ps_latlink_pred(ps_latlink_t *link)
Get predecessor link in best path.
Definition: ps_lattice.c:816
ps_lattice_traverse_edges
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
ps_lattice_retain
POCKETSPHINX_EXPORT ps_lattice_t * ps_lattice_retain(ps_lattice_t *dag)
Retain a lattice.
Definition: ps_lattice.c:658
ps_latlink_iter_free
POCKETSPHINX_EXPORT void ps_latlink_iter_free(ps_latlink_iter_t *itor)
Stop iterating over links.
Definition: ps_lattice.c:767
ps_latlink_prob
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
ps_latnode_iter
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
ps_lattice_reverse_edges
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
ps_lattice_reverse_next
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
ps_latnode_iter_free
POCKETSPHINX_EXPORT void ps_latnode_iter_free(ps_latnode_iter_t *itor)
Stop iterating over nodes.
Definition: ps_lattice.c:700
ps_latlink_iter_link
POCKETSPHINX_EXPORT ps_latlink_t * ps_latlink_iter_link(ps_latlink_iter_t *itor)
Get link from iterator.
Definition: ps_lattice.c:773
ps_latlink_times
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
ps_lattice_write_htk
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
ps_lattice_bestpath
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
ps_latlink_iter_next
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
latlink_list_s
Linked list of DAG link pointers.
Definition: ps_lattice_internal.h:53
ps_decoder_s
Decoder object.
Definition: pocketsphinx_internal.h:201
ps_latlink_s
Links between DAG nodes.
Definition: ps_lattice_internal.h:96
ps_latnode_s
DAG nodes.
Definition: ps_lattice_internal.h:113
ps_lattice_s
Word graph structure used in bestpath/nbest search.
Definition: ps_lattice_internal.h:61