SphinxBase  5prealpha
jsgf.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 2007 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 
38 #ifndef __JSGF_H__
39 #define __JSGF_H__
40 
48 #include <stdio.h>
49 
50 /* Win32/WinCE DLL gunk */
51 #include <sphinxbase/sphinxbase_export.h>
52 #include <sphinxbase/hash_table.h>
53 #include <sphinxbase/fsg_model.h>
54 #include <sphinxbase/logmath.h>
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 #if 0
60 /* Fool Emacs. */
61 }
62 #endif
63 
64 typedef struct jsgf_s jsgf_t;
65 typedef struct jsgf_rule_s jsgf_rule_t;
66 
73 SPHINXBASE_EXPORT
75 
83 SPHINXBASE_EXPORT
84 jsgf_t *jsgf_parse_file(const char *filename, jsgf_t *parent);
85 
93 SPHINXBASE_EXPORT
94 jsgf_t *jsgf_parse_string(const char *string, jsgf_t *parent);
95 
99 SPHINXBASE_EXPORT
100 char const *jsgf_grammar_name(jsgf_t *jsgf);
101 
105 SPHINXBASE_EXPORT
106 void jsgf_grammar_free(jsgf_t *jsgf);
107 
112 
116 SPHINXBASE_EXPORT
118 
122 #define jsgf_rule_iter_next(itor) hash_table_iter_next(itor)
123 
127 #define jsgf_rule_iter_rule(itor) ((jsgf_rule_t *)(itor)->ent->val)
128 
132 #define jsgf_rule_iter_free(itor) hash_table_iter_free(itor)
133 
137 SPHINXBASE_EXPORT
138 jsgf_rule_t *jsgf_get_rule(jsgf_t *grammar, const char *name);
139 
143 SPHINXBASE_EXPORT
145 
149 SPHINXBASE_EXPORT
150 char const *jsgf_rule_name(jsgf_rule_t *rule);
151 
155 SPHINXBASE_EXPORT
156 int jsgf_rule_public(jsgf_rule_t *rule);
157 
161 SPHINXBASE_EXPORT
163  logmath_t *lmath, float32 lw);
164 
173 SPHINXBASE_EXPORT
175  logmath_t *lmath, float32 lw);
176 
177 
183 SPHINXBASE_EXPORT
184 fsg_model_t *jsgf_read_file(const char *file, logmath_t * lmath, float32 lw);
185 
191 SPHINXBASE_EXPORT
192 fsg_model_t *jsgf_read_string(const char *string, logmath_t * lmath, float32 lw);
193 
194 
201 SPHINXBASE_EXPORT
202 int jsgf_write_fsg(jsgf_t *grammar, jsgf_rule_t *rule, FILE *outfh);
203 
204 #ifdef __cplusplus
205 }
206 #endif
207 
208 
209 #endif /* __JSGF_H__ */
SPHINXBASE_EXPORT jsgf_rule_t * jsgf_get_rule(jsgf_t *grammar, const char *name)
Get a rule by name from a grammar.
Definition: jsgf.c:469
SPHINXBASE_EXPORT jsgf_t * jsgf_parse_string(const char *string, jsgf_t *parent)
Parse a JSGF grammar from a string.
Definition: jsgf.c:937
SPHINXBASE_EXPORT jsgf_t * jsgf_parse_file(const char *filename, jsgf_t *parent)
Parse a JSGF grammar from a file.
Definition: jsgf.c:896
SPHINXBASE_EXPORT fsg_model_t * jsgf_build_fsg(jsgf_t *grammar, jsgf_rule_t *rule, logmath_t *lmath, float32 lw)
Build a Sphinx FSG object from a JSGF rule.
Definition: jsgf.c:585
SPHINXBASE_EXPORT char const * jsgf_rule_name(jsgf_rule_t *rule)
Get the rule name from a rule.
Definition: jsgf.c:513
SPHINXBASE_EXPORT jsgf_t * jsgf_grammar_new(jsgf_t *parent)
Create a new JSGF grammar.
Definition: jsgf.c:86
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.
Definition: jsgf.c:599
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.
Definition: jsgf.c:630
SPHINXBASE_EXPORT char const * jsgf_grammar_name(jsgf_t *jsgf)
Get the grammar name from the file.
Definition: jsgf.c:216
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.
Definition: jsgf.c:592
char * name
Rule name (NULL for an alternation/grouping)
SPHINXBASE_EXPORT int jsgf_rule_public(jsgf_rule_t *rule)
Test if a rule is public or not.
Definition: jsgf.c:519
Hash table implementation.
Word level FSG definition.
Definition: fsg_model.h:99
Fast integer logarithmic addition operations.
hash_iter_t jsgf_rule_iter_t
Iterator over rules in a grammar.
Definition: jsgf.h:111
SPHINXBASE_EXPORT void jsgf_grammar_free(jsgf_t *jsgf)
Free a JSGF grammar.
Definition: jsgf.c:108
SPHINXBASE_EXPORT jsgf_rule_t * jsgf_get_public_rule(jsgf_t *grammar)
Returns the first public rule of the grammar.
Definition: jsgf.c:484
SPHINXBASE_EXPORT int jsgf_write_fsg(jsgf_t *grammar, jsgf_rule_t *rule, FILE *outfh)
Convert a JSGF rule to Sphinx FSG text form.
Definition: jsgf.c:663
SPHINXBASE_EXPORT jsgf_rule_iter_t * jsgf_rule_iter(jsgf_t *grammar)
Get an iterator over all rules in a grammar.
Definition: jsgf.c:463