示例#1
0
static fsg_model_t *
get_fsg(jsgf_t *grammar, const char *name)
{
    logmath_t *lmath;
    fsg_model_t *fsg;
    jsgf_rule_t *rule;

    /* Take the -toprule if specified. */
    if (name) {
        rule = jsgf_get_rule(grammar, name);
        if (rule == NULL) {
            E_ERROR("Start rule %s not found\n", name);
            return NULL;
        }
    } else {
        rule = jsgf_get_public_rule(grammar);
        if (rule == NULL) {
            E_ERROR("No public rules found in grammar %s\n", jsgf_grammar_name(grammar));
            return NULL;
        } else {
            E_INFO("No -toprule was given; grabbing the first public rule: "
                   "'%s' of the grammar '%s'.\n", 
                   jsgf_rule_name(rule), jsgf_grammar_name(grammar));
         }
    }

    lmath = logmath_init(1.0001, 0, 0);
    fsg = jsgf_build_fsg_raw(grammar, rule, lmath, 1.0);
    return fsg;
}
示例#2
0
int
jsgf_write_fsg(jsgf_t *grammar, jsgf_rule_t *rule, FILE *outfh)
{
    fsg_model_t *fsg;
    logmath_t *lmath = logmath_init(1.0001, 0, 0);

    if ((fsg = jsgf_build_fsg_raw(grammar, rule, lmath, 1.0)) == NULL)
        goto error_out;

    fsg_model_write(fsg, outfh);
    logmath_free(lmath);
    return 0;

error_out:
    logmath_free(lmath);
    return -1;
}
示例#3
0
fsg_model_t* ofxSphinxASR::get_fsg(jsgf_t *grammar, const char *name)
{
    jsgf_rule_iter_t *itor;
    logmath_t *lmath = logmath_init(1.0001, 0, 0);
    fsg_model_t *fsg = NULL;
    for (itor = jsgf_rule_iter(grammar); itor;
        itor = jsgf_rule_iter_next(itor)) {
            jsgf_rule_t *rule = jsgf_rule_iter_rule(itor);
            char const *rule_name = jsgf_rule_name(rule);
            if ((name == NULL && jsgf_rule_public(rule))
                || (name && strlen(rule_name)-2 == strlen(name) &&
                0 == strncmp(rule_name + 1, name, strlen(rule_name) - 2))) {
                    fsg = jsgf_build_fsg_raw(grammar,
                                             rule, logmath_retain(lmath), 1.0);
                    jsgf_rule_iter_free(itor);
                    break;
            }
    }
    logmath_free(lmath);
    return fsg;
}