1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3 * Copyright (c) 2007 Carnegie Mellon University. All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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
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.
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.
34 * ====================================================================
42 * @file jsgf.h JSGF grammar compiler
44 * This file defines the data structures for parsing JSGF grammars
45 * into Sphinx finite-state grammars.
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>
64 typedef struct jsgf_s jsgf_t;
65 typedef struct jsgf_rule_s jsgf_rule_t;
68 * Create a new JSGF grammar.
70 * @param parent optional parent grammar for this one (NULL, usually).
71 * @return new JSGF grammar object, or NULL on failure.
74 jsgf_t *jsgf_grammar_new(jsgf_t *parent);
77 * Parse a JSGF grammar from a file.
79 * @param filename the name of the file to parse.
80 * @param parent optional parent grammar for this one (NULL, usually).
81 * @return new JSGF grammar object, or NULL on failure.
84 jsgf_t *jsgf_parse_file(const char *filename, jsgf_t *parent);
87 * Free a JSGF grammar.
90 void jsgf_grammar_free(jsgf_t *jsgf);
93 * Iterator over rules in a grammar.
95 typedef hash_iter_t jsgf_rule_iter_t;
98 * Get an iterator over all rules in a grammar.
101 jsgf_rule_iter_t *jsgf_rule_iter(jsgf_t *grammar);
104 * Advance an iterator to the next rule in the grammar.
106 #define jsgf_rule_iter_next(itor) hash_table_iter_next(itor)
109 * Get the current rule in a rule iterator.
111 #define jsgf_rule_iter_rule(itor) ((jsgf_rule_t *)(itor)->ent->val)
114 * Free a rule iterator (if the end hasn't been reached).
116 #define jsgf_rule_iter_free(itor) hash_table_iter_free(itor)
119 * Get a rule by name from a grammar.
122 jsgf_rule_t *jsgf_get_rule(jsgf_t *grammar, char const *name);
125 * Get the rule name from a rule.
128 char const *jsgf_rule_name(jsgf_rule_t *rule);
131 * Test if a rule is public or not.
134 int jsgf_rule_public(jsgf_rule_t *rule);
137 * Build a Sphinx FSG object from a JSGF rule.
140 fsg_model_t *jsgf_build_fsg(jsgf_t *grammar, jsgf_rule_t *rule,
141 logmath_t *lmath, float32 lw);
144 * Build a Sphinx FSG object from a JSGF rule.
146 * This differs from jsgf_build_fsg() in that it does not do closure
147 * on epsilon transitions or any other postprocessing. For the time
148 * being this is necessary in order to write it to a file - the FSG
149 * code will be fixed soon.
152 fsg_model_t *jsgf_build_fsg_raw(jsgf_t *grammar, jsgf_rule_t *rule,
153 logmath_t *lmath, float32 lw);
156 * Convert a JSGF rule to Sphinx FSG text form.
158 * This does a direct conversion without doing transitive closure on
159 * null transitions and so forth.
162 int jsgf_write_fsg(jsgf_t *grammar, jsgf_rule_t *rule, FILE *outfh);
169 #endif /* __JSGF_H__ */