SphinxBase  0.6
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 
89 SPHINXBASE_EXPORT
90 char const *jsgf_grammar_name(jsgf_t *jsgf);
91 
95 SPHINXBASE_EXPORT
96 void jsgf_grammar_free(jsgf_t *jsgf);
97 
102 
106 SPHINXBASE_EXPORT
108 
112 #define jsgf_rule_iter_next(itor) hash_table_iter_next(itor)
113 
117 #define jsgf_rule_iter_rule(itor) ((jsgf_rule_t *)(itor)->ent->val)
118 
122 #define jsgf_rule_iter_free(itor) hash_table_iter_free(itor)
123 
127 SPHINXBASE_EXPORT
128 jsgf_rule_t *jsgf_get_rule(jsgf_t *grammar, char const *name);
129 
133 SPHINXBASE_EXPORT
134 char const *jsgf_rule_name(jsgf_rule_t *rule);
135 
139 SPHINXBASE_EXPORT
140 int jsgf_rule_public(jsgf_rule_t *rule);
141 
145 SPHINXBASE_EXPORT
147  logmath_t *lmath, float32 lw);
148 
157 SPHINXBASE_EXPORT
159  logmath_t *lmath, float32 lw);
160 
161 
167 SPHINXBASE_EXPORT
168 fsg_model_t *jsgf_read_file(const char *file, logmath_t * lmath, float32 lw);
169 
176 SPHINXBASE_EXPORT
177 int jsgf_write_fsg(jsgf_t *grammar, jsgf_rule_t *rule, FILE *outfh);
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 
183 
184 #endif /* __JSGF_H__ */
SPHINXBASE_EXPORT jsgf_t * jsgf_parse_file(const char *filename, jsgf_t *parent)
Parse a JSGF grammar from a file.
Definition: jsgf.c:734
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:497
SPHINXBASE_EXPORT char const * jsgf_rule_name(jsgf_rule_t *rule)
Get the rule name from a rule.
Definition: jsgf.c:437
SPHINXBASE_EXPORT jsgf_t * jsgf_grammar_new(jsgf_t *parent)
Create a new JSGF grammar.
Definition: jsgf.c:79
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:511
SPHINXBASE_EXPORT char const * jsgf_grammar_name(jsgf_t *jsgf)
Get the grammar name from the file.
Definition: jsgf.c:233
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:504
char * name
Rule name (NULL for an alternation/grouping)
Definition: jsgf_internal.h:88
SPHINXBASE_EXPORT int jsgf_rule_public(jsgf_rule_t *rule)
Test if a rule is public or not.
Definition: jsgf.c:443
SPHINXBASE_EXPORT jsgf_rule_t * jsgf_get_rule(jsgf_t *grammar, char const *name)
Get a rule by name from a grammar.
Definition: jsgf.c:427
Hash table implementation.
Word level FSG definition.
Definition: fsg_model.h:91
Fast integer logarithmic addition operations.
hash_iter_t jsgf_rule_iter_t
Iterator over rules in a grammar.
Definition: jsgf.h:101
SPHINXBASE_EXPORT void jsgf_grammar_free(jsgf_t *jsgf)
Free a JSGF grammar.
Definition: jsgf.c:125
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:542
SPHINXBASE_EXPORT jsgf_rule_iter_t * jsgf_rule_iter(jsgf_t *grammar)
Get an iterator over all rules in a grammar.
Definition: jsgf.c:421