SphinxBase  5prealpha
jsgf.h File Reference

JSGF grammar compiler. More...

#include <stdio.h>
#include <sphinxbase/sphinxbase_export.h>
#include <sphinxbase/hash_table.h>
#include <sphinxbase/fsg_model.h>
#include <sphinxbase/logmath.h>

Go to the source code of this file.

Macros

#define jsgf_rule_iter_next(itor)   hash_table_iter_next(itor)
 Advance an iterator to the next rule in the grammar.
 
#define jsgf_rule_iter_rule(itor)   ((jsgf_rule_t *)(itor)->ent->val)
 Get the current rule in a rule iterator.
 
#define jsgf_rule_iter_free(itor)   hash_table_iter_free(itor)
 Free a rule iterator (if the end hasn't been reached).
 

Typedefs

typedef struct jsgf_s jsgf_t
 
typedef struct jsgf_rule_s jsgf_rule_t
 
typedef hash_iter_t jsgf_rule_iter_t
 Iterator over rules in a grammar.
 

Functions

SPHINXBASE_EXPORT jsgf_tjsgf_grammar_new (jsgf_t *parent)
 Create a new JSGF grammar. More...
 
SPHINXBASE_EXPORT jsgf_tjsgf_parse_file (const char *filename, jsgf_t *parent)
 Parse a JSGF grammar from a file. More...
 
SPHINXBASE_EXPORT jsgf_tjsgf_parse_string (const char *string, jsgf_t *parent)
 Parse a JSGF grammar from a string. More...
 
SPHINXBASE_EXPORT char const * jsgf_grammar_name (jsgf_t *jsgf)
 Get the grammar name from the file.
 
SPHINXBASE_EXPORT void jsgf_grammar_free (jsgf_t *jsgf)
 Free a JSGF grammar.
 
SPHINXBASE_EXPORT
jsgf_rule_iter_t
jsgf_rule_iter (jsgf_t *grammar)
 Get an iterator over all rules in a grammar.
 
SPHINXBASE_EXPORT jsgf_rule_tjsgf_get_rule (jsgf_t *grammar, const char *name)
 Get a rule by name from a grammar. More...
 
SPHINXBASE_EXPORT jsgf_rule_tjsgf_get_public_rule (jsgf_t *grammar)
 Returns the first public rule of the grammar.
 
SPHINXBASE_EXPORT char const * jsgf_rule_name (jsgf_rule_t *rule)
 Get the rule name from a rule.
 
SPHINXBASE_EXPORT int jsgf_rule_public (jsgf_rule_t *rule)
 Test if a rule is public or not.
 
SPHINXBASE_EXPORT fsg_model_tjsgf_build_fsg (jsgf_t *grammar, jsgf_rule_t *rule, logmath_t *lmath, float32 lw)
 Build a Sphinx FSG object from a JSGF rule.
 
SPHINXBASE_EXPORT fsg_model_tjsgf_build_fsg_raw (jsgf_t *grammar, jsgf_rule_t *rule, logmath_t *lmath, float32 lw)
 Build a Sphinx FSG object from a JSGF rule. More...
 
SPHINXBASE_EXPORT fsg_model_tjsgf_read_file (const char *file, logmath_t *lmath, float32 lw)
 Read JSGF from file and return FSG object from it. More...
 
SPHINXBASE_EXPORT fsg_model_tjsgf_read_string (const char *string, logmath_t *lmath, float32 lw)
 Read JSGF from string and return FSG object from it. More...
 
SPHINXBASE_EXPORT int jsgf_write_fsg (jsgf_t *grammar, jsgf_rule_t *rule, FILE *outfh)
 Convert a JSGF rule to Sphinx FSG text form. More...
 

Detailed Description

JSGF grammar compiler.

This file defines the data structures for parsing JSGF grammars into Sphinx finite-state grammars.

Definition in file jsgf.h.

Function Documentation

SPHINXBASE_EXPORT fsg_model_t* jsgf_build_fsg_raw ( jsgf_t grammar,
jsgf_rule_t rule,
logmath_t lmath,
float32  lw 
)

Build a Sphinx FSG object from a JSGF rule.

This differs from jsgf_build_fsg() in that it does not do closure on epsilon transitions or any other postprocessing. For the time being this is necessary in order to write it to a file - the FSG code will be fixed soon.

Definition at line 592 of file jsgf.c.

Referenced by jsgf_write_fsg().

SPHINXBASE_EXPORT jsgf_rule_t* jsgf_get_rule ( jsgf_t grammar,
const char *  name 
)

Get a rule by name from a grammar.

Name should not contain brackets.

Definition at line 469 of file jsgf.c.

References ckd_free(), hash_table_lookup(), jsgf_s::rules, and string_join().

SPHINXBASE_EXPORT jsgf_t* jsgf_grammar_new ( jsgf_t parent)

Create a new JSGF grammar.

Parameters
parentoptional parent grammar for this one (NULL, usually).
Returns
new JSGF grammar object, or NULL on failure.

Definition at line 86 of file jsgf.c.

References ckd_calloc, hash_table_new(), jsgf_s::imports, jsgf_s::parent, jsgf_s::rules, and jsgf_s::searchpath.

Referenced by jsgf_parse_file(), and jsgf_parse_string().

SPHINXBASE_EXPORT jsgf_t* jsgf_parse_file ( const char *  filename,
jsgf_t parent 
)

Parse a JSGF grammar from a file.

Parameters
filenamethe name of the file to parse.
parentoptional parent grammar for this one (NULL, usually).
Returns
new JSGF grammar object, or NULL on failure.

Definition at line 896 of file jsgf.c.

References E_ERROR, E_ERROR_SYSTEM, jsgf_grammar_free(), and jsgf_grammar_new().

Referenced by jsgf_read_file().

SPHINXBASE_EXPORT jsgf_t* jsgf_parse_string ( const char *  string,
jsgf_t parent 
)

Parse a JSGF grammar from a string.

Parameters
0-terminatedstring with grammar.
parentoptional parent grammar for this one (NULL, usually).
Returns
new JSGF grammar object, or NULL on failure.

Definition at line 937 of file jsgf.c.

References E_ERROR, jsgf_grammar_free(), and jsgf_grammar_new().

Referenced by jsgf_read_string().

SPHINXBASE_EXPORT fsg_model_t* jsgf_read_file ( const char *  file,
logmath_t lmath,
float32  lw 
)

Read JSGF from file and return FSG object from it.

This function looks for a first public rule in jsgf and constructs JSGF from it.

Definition at line 599 of file jsgf.c.

References E_ERROR, jsgf_build_fsg(), jsgf_grammar_free(), jsgf_parse_file(), jsgf_rule_iter(), jsgf_rule_iter_free, jsgf_rule_iter_next, jsgf_rule_iter_rule, and jsgf_rule_public().

SPHINXBASE_EXPORT fsg_model_t* jsgf_read_string ( const char *  string,
logmath_t lmath,
float32  lw 
)

Read JSGF from string and return FSG object from it.

This function looks for a first public rule in jsgf and constructs JSGF from it.

Definition at line 630 of file jsgf.c.

References E_ERROR, jsgf_build_fsg(), jsgf_grammar_free(), jsgf_parse_string(), jsgf_rule_iter(), jsgf_rule_iter_free, jsgf_rule_iter_next, jsgf_rule_iter_rule, and jsgf_rule_public().

SPHINXBASE_EXPORT int jsgf_write_fsg ( jsgf_t grammar,
jsgf_rule_t rule,
FILE *  outfh 
)

Convert a JSGF rule to Sphinx FSG text form.

This does a direct conversion without doing transitive closure on null transitions and so forth.

Definition at line 663 of file jsgf.c.

References jsgf_build_fsg_raw(), logmath_free(), and logmath_init().