Classes | Macros | Typedefs | Functions
s3_cfg.h File Reference
#include <stdio.h>
#include <logmath.h>
#include "prim_type.h"
#include "hash_table.h"
#include "s3_arraylist.h"
#include "fsg.h"

Go to the source code of this file.

Classes

struct  s3_cfg_rule_s
 
struct  s3_cfg_item_t
 
struct  s3_cfg_entry_s
 
struct  s3_cfg_state_s
 
struct  s3_cfg_t
 

Macros

#define S3_CFG_MAX_RULE_STR_LEN   1023
 
#define S3_CFG_MAX_ITEM_STR_LEN   40
 
#define S3_CFG_MAX_ITEM_COUNT   20
 
#define S3_CFG_INITIAL_RULE_COUNT   1
 
#define S3_CFG_INITIAL_RULE_SET_COUNT   50
 
#define S3_CFG_INITIAL_PARSE_SET_COUNT   20
 
#define S3_CFG_PARSE_HASH_SIZE   251
 
#define S3_CFG_INITIAL_STATE_SET_COUNT   20
 
#define S3_CFG_INITIAL_TERM_COUNT   50
 
#define S3_CFG_NAME_HASH_SIZE   4091
 
#define S3_CFG_INVALID_SCORE   1.0f
 
#define S3_CFG_INITIAL_SCORE   0.0f
 
#define S3_CFG_NONTERM_PREFIX   '$'
 
#define S3_CFG_TERM_BIT   0x80000000
 
#define S3_CFG_INDEX_MASK   0x7FFFFFFF
 
#define S3_CFG_INVALID_ID   0x7FFFFFFF
 
#define S3_CFG_PSTART_ITEM   0x00000000
 
#define S3_CFG_PSTART_ITEM_STR   "$PSTART"
 
#define S3_CFG_START_ITEM   0x00000001
 
#define S3_CFG_START_ITEM_STR   "$START"
 
#define S3_CFG_EOR_ITEM   (0x00000002 | S3_CFG_TERM_BIT)
 
#define S3_CFG_EOR_ITEM_STR   "#EOR#"
 
#define S3_CFG_EOI_ITEM   (0x00000003 | S3_CFG_TERM_BIT)
 
#define S3_CFG_EOI_ITEM_STR   "#EOI#"
 
#define S3_CFG_NIL_ITEM   (0x00000004 | S3_CFG_TERM_BIT)
 
#define S3_CFG_NIL_ITEM_STR   "#NIL#"
 
#define S3_CFG_START_RULE   { S3_CFG_PSTART_ITEM, 0.0f, { S3_CFG_START_ITEM, S3_CFG_EOR_ITEM }, 1 }
 
#define S3_CFG_AUTO_PRUNE_SCORE   0x00000001
 
#define S3_CFG_AUTO_PRUNE_RANK   0x00000002
 
#define s3_cfg_is_null_parse(x)   (x->entries.count == 0)
 
#define s3_cfg_is_terminal(x)   (x & S3_CFG_TERM_BIT)
 
#define s3_cfg_id2index(x)   (x & S3_CFG_INDEX_MASK)
 

Typedefs

typedef uint32 s3_cfg_id_t
 
typedef struct s3_cfg_rule_s s3_cfg_rule_t
 
typedef struct s3_cfg_entry_s s3_cfg_entry_t
 
typedef struct s3_cfg_state_s s3_cfg_state_t
 

Functions

void s3_cfg_init (s3_cfg_t *_cfg)
 
void s3_cfg_close (s3_cfg_t *_cfg)
 
S3DECODER_EXPORT s3_cfg_ts3_cfg_read_simple (const char *_fn)
 
s3_cfg_ts3_cfg_read_srgs (const char *_fn)
 
void s3_cfg_write_simple (s3_cfg_t *_cfg, const char *_fn)
 
S3DECODER_EXPORT s2_fsg_ts3_cfg_convert_to_fsg (s3_cfg_t *_cfg, int _max_expansion)
 
void s3_cfg_rescore (s3_cfg_t *_cfg, logmath_t *logmath)
 
s3_cfg_item_ts3_cfg_get_term_info (s3_cfg_t *_cfg, s3_cfg_id_t _id)
 
s3_cfg_state_ts3_cfg_create_parse (s3_cfg_t *_cfg)
 
void s3_cfg_free_parse (s3_cfg_t *_cfg, s3_cfg_state_t *_parse)
 
void s3_cfg_free_parse_tree (s3_cfg_t *_cfg, s3_cfg_state_t *_parse)
 
s3_cfg_state_ts3_cfg_input_term (s3_cfg_t *_cfg, s3_cfg_state_t *_cur, s3_cfg_id_t _term)
 
s3_cfg_rule_ts3_cfg_add_rule (s3_cfg_t *_cfg, s3_cfg_id_t _src, float32 _fake_score, s3_cfg_id_t *_products)
 
S3DECODER_EXPORT void s3_cfg_compile_rules (s3_cfg_t *_cfg, logmath_t *logmath)
 
void s3_cfg_print_rule (s3_cfg_t *_cfg, s3_cfg_rule_t *_rule, FILE *_out)
 
void s3_cfg_print_entry (s3_cfg_t *_cfg, s3_cfg_entry_t *_entry, FILE *_out)
 
void s3_cfg_print_parse (s3_cfg_t *_cfg, s3_cfg_entry_t *_parse, FILE *_out)
 
s3_cfg_id_t s3_cfg_str2id (s3_cfg_t *_cfg, char *_item)
 
const char * s3_cfg_id2str (s3_cfg_t *_cfg, s3_cfg_id_t _id)
 

Macro Definition Documentation

◆ S3_CFG_AUTO_PRUNE_RANK

#define S3_CFG_AUTO_PRUNE_RANK   0x00000002

◆ S3_CFG_AUTO_PRUNE_SCORE

#define S3_CFG_AUTO_PRUNE_SCORE   0x00000001

◆ S3_CFG_EOI_ITEM

#define S3_CFG_EOI_ITEM   (0x00000003 | S3_CFG_TERM_BIT)

◆ S3_CFG_EOI_ITEM_STR

#define S3_CFG_EOI_ITEM_STR   "#EOI#"

◆ S3_CFG_EOR_ITEM

#define S3_CFG_EOR_ITEM   (0x00000002 | S3_CFG_TERM_BIT)

◆ S3_CFG_EOR_ITEM_STR

#define S3_CFG_EOR_ITEM_STR   "#EOR#"

◆ s3_cfg_id2index

#define s3_cfg_id2index (   x)    (x & S3_CFG_INDEX_MASK)

◆ S3_CFG_INDEX_MASK

#define S3_CFG_INDEX_MASK   0x7FFFFFFF

◆ S3_CFG_INITIAL_PARSE_SET_COUNT

#define S3_CFG_INITIAL_PARSE_SET_COUNT   20

◆ S3_CFG_INITIAL_RULE_COUNT

#define S3_CFG_INITIAL_RULE_COUNT   1

◆ S3_CFG_INITIAL_RULE_SET_COUNT

#define S3_CFG_INITIAL_RULE_SET_COUNT   50

◆ S3_CFG_INITIAL_SCORE

#define S3_CFG_INITIAL_SCORE   0.0f

◆ S3_CFG_INITIAL_STATE_SET_COUNT

#define S3_CFG_INITIAL_STATE_SET_COUNT   20

◆ S3_CFG_INITIAL_TERM_COUNT

#define S3_CFG_INITIAL_TERM_COUNT   50

◆ S3_CFG_INVALID_ID

#define S3_CFG_INVALID_ID   0x7FFFFFFF

◆ S3_CFG_INVALID_SCORE

#define S3_CFG_INVALID_SCORE   1.0f

◆ s3_cfg_is_null_parse

#define s3_cfg_is_null_parse (   x)    (x->entries.count == 0)

◆ s3_cfg_is_terminal

#define s3_cfg_is_terminal (   x)    (x & S3_CFG_TERM_BIT)

◆ S3_CFG_MAX_ITEM_COUNT

#define S3_CFG_MAX_ITEM_COUNT   20

◆ S3_CFG_MAX_ITEM_STR_LEN

#define S3_CFG_MAX_ITEM_STR_LEN   40

◆ S3_CFG_MAX_RULE_STR_LEN

#define S3_CFG_MAX_RULE_STR_LEN   1023

◆ S3_CFG_NAME_HASH_SIZE

#define S3_CFG_NAME_HASH_SIZE   4091

◆ S3_CFG_NIL_ITEM

#define S3_CFG_NIL_ITEM   (0x00000004 | S3_CFG_TERM_BIT)

◆ S3_CFG_NIL_ITEM_STR

#define S3_CFG_NIL_ITEM_STR   "#NIL#"

◆ S3_CFG_NONTERM_PREFIX

#define S3_CFG_NONTERM_PREFIX   '$'

◆ S3_CFG_PARSE_HASH_SIZE

#define S3_CFG_PARSE_HASH_SIZE   251

◆ S3_CFG_PSTART_ITEM

#define S3_CFG_PSTART_ITEM   0x00000000

◆ S3_CFG_PSTART_ITEM_STR

#define S3_CFG_PSTART_ITEM_STR   "$PSTART"

◆ S3_CFG_START_ITEM

#define S3_CFG_START_ITEM   0x00000001

◆ S3_CFG_START_ITEM_STR

#define S3_CFG_START_ITEM_STR   "$START"

◆ S3_CFG_START_RULE

#define S3_CFG_START_RULE   { S3_CFG_PSTART_ITEM, 0.0f, { S3_CFG_START_ITEM, S3_CFG_EOR_ITEM }, 1 }

◆ S3_CFG_TERM_BIT

#define S3_CFG_TERM_BIT   0x80000000

Typedef Documentation

◆ s3_cfg_entry_t

◆ s3_cfg_id_t

typedef uint32 s3_cfg_id_t

◆ s3_cfg_rule_t

typedef struct s3_cfg_rule_s s3_cfg_rule_t

◆ s3_cfg_state_t

Function Documentation

◆ s3_cfg_add_rule()

s3_cfg_rule_t* s3_cfg_add_rule ( s3_cfg_t _cfg,
s3_cfg_id_t  _src,
float32  _fake_score,
s3_cfg_id_t _products 
)

Add an expansion rule to the CFG parser.

Parameters
_cfgA CFG parser.
_srcThe source of the expansion. Must be a non-terminal.
_fake_scoreUn-normalized transition scores.
_productsAn array of expansion terms. Terminated by S3_CFG_EOR_ITEM.
Returns
A CFG expansion rule.

◆ s3_cfg_close()

void s3_cfg_close ( s3_cfg_t _cfg)

Close a CFG parser and free its contents. The parser structure is not freed (since it was not allocated by init).

Parameters
_cfgA (pre-allocated) CFG parser.

◆ s3_cfg_compile_rules()

S3DECODER_EXPORT void s3_cfg_compile_rules ( s3_cfg_t _cfg,
logmath_t *  logmath 
)

The consistency of the rule scores must be compiled before the parser can be used.

Parameters
_cfgA CFG parser.

◆ s3_cfg_convert_to_fsg()

S3DECODER_EXPORT s2_fsg_t* s3_cfg_convert_to_fsg ( s3_cfg_t _cfg,
int  _max_expansion 
)

Heuristically convert a CFG to a FSG by limiting non-terminal expansions.

Parameters
_cfgA CFG parser.
Returns
A FSG.

◆ s3_cfg_create_parse()

s3_cfg_state_t* s3_cfg_create_parse ( s3_cfg_t _cfg)

Start a CFG parse session.

Parameters
_cfgA CFG parser.
Returns
A parse session.

◆ s3_cfg_free_parse()

void s3_cfg_free_parse ( s3_cfg_t _cfg,
s3_cfg_state_t _parse 
)

Free a CFG parse session.

Parameters
_cfgA CFG parser.
_parseA parse session.

◆ s3_cfg_free_parse_tree()

void s3_cfg_free_parse_tree ( s3_cfg_t _cfg,
s3_cfg_state_t _parse 
)

◆ s3_cfg_get_term_info()

s3_cfg_item_t* s3_cfg_get_term_info ( s3_cfg_t _cfg,
s3_cfg_id_t  _id 
)

Fetch information on a term.

Parameters
_cfgA CFG parser.
_idA term id.
Returns
Term information.

◆ s3_cfg_id2str()

const char* s3_cfg_id2str ( s3_cfg_t _cfg,
s3_cfg_id_t  _id 
)

Convert a term id to its original string representation.

Parameters
_cfgA CFG parser.
_idA term id.
Returns
A string representation of the term.

◆ s3_cfg_init()

void s3_cfg_init ( s3_cfg_t _cfg)

Initialize a CFG parser. The parser structure must be allocated outside the function.

Parameters
_cfgA (pre-allocated) CFG parser.

◆ s3_cfg_input_term()

s3_cfg_state_t* s3_cfg_input_term ( s3_cfg_t _cfg,
s3_cfg_state_t _cur,
s3_cfg_id_t  _term 
)

Continue a parse session by feeding it an input term.

Parameters
_cfgA CFG parser.
_curA parse session.
_termAn input term. Must be a terminal.

◆ s3_cfg_print_entry()

void s3_cfg_print_entry ( s3_cfg_t _cfg,
s3_cfg_entry_t _entry,
FILE *  _out 
)

Print a CFG parse entry. It is a single stage of a single rule expansion. For reference, lookup chart parsers.

Parameters
_cfgA CFG parser.
_entryA CFG parse entry.
_outAn output stream.

◆ s3_cfg_print_parse()

void s3_cfg_print_parse ( s3_cfg_t _cfg,
s3_cfg_entry_t _parse,
FILE *  _out 
)

Print a parse session. This will print all active entries in the parse, including unfinished parses.

Parameters
_cfgA CFG parser.
_parseA parse session.
_outAn output stream.

◆ s3_cfg_print_rule()

void s3_cfg_print_rule ( s3_cfg_t _cfg,
s3_cfg_rule_t _rule,
FILE *  _out 
)

Print a CFG expansion rule.

Parameters
_cfgA CFG parser.
_ruleA CFG expansion rule.
_outAn output stream.

◆ s3_cfg_read_simple()

S3DECODER_EXPORT s3_cfg_t* s3_cfg_read_simple ( const char *  _fn)

Read a CFG from a plain-text file. The parser structure must be freed afterwards.

Parameters
_fnPlain-text file.
Returns
A CFG parser.

◆ s3_cfg_read_srgs()

s3_cfg_t* s3_cfg_read_srgs ( const char *  _fn)

Read a CFG from a XML-based SRGS file. The parser structure must be freed afterwards. For more information on SRGS, visit http://www.w3.org/TR/speech-grammar/.

Parameters
_fnXML-based SRGS file.
Returns
A CFG parser.

◆ s3_cfg_rescore()

void s3_cfg_rescore ( s3_cfg_t _cfg,
logmath_t *  logmath 
)

◆ s3_cfg_str2id()

s3_cfg_id_t s3_cfg_str2id ( s3_cfg_t _cfg,
char *  _item 
)

Convert a term string representation to a term id. If the term does not already exist, assign it a new id.

Parameters
_cfgA CFG parser.
_itemA term string representation.
Returns
A term id.

◆ s3_cfg_write_simple()

void s3_cfg_write_simple ( s3_cfg_t _cfg,
const char *  _fn 
)

Write the CFG to a plain-text file.

Parameters
_cfgA CFG parser.
_fnAn output filename.
Returns
0 for success. -1 for failure.