Exemple #1
0
int 
ps_set_jsgf_string(ps_decoder_t *ps, const char *name, const char *jsgf_string)
{
  fsg_model_t *fsg;
  jsgf_rule_t *rule;
  char const *toprule;
  jsgf_t *jsgf = jsgf_parse_string(jsgf_string, NULL);
  float lw;
  int result;

  if (!jsgf)
      return -1;

  rule = NULL;
  /* Take the -toprule if specified. */
  if ((toprule = cmd_ln_str_r(ps->config, "-toprule"))) {
      rule = jsgf_get_rule(jsgf, toprule);
      if (rule == NULL) {
          E_ERROR("Start rule %s not found\n", toprule);
          return -1;
      }
  } else {
      rule = jsgf_get_public_rule(jsgf);
      if (rule == NULL) {
          E_ERROR("No public rules found in input string\n");
          return -1;
      }
  }

  lw = cmd_ln_float32_r(ps->config, "-lw");
  fsg = jsgf_build_fsg(jsgf, rule, ps->lmath, lw);
  result = ps_set_fsg(ps, name, fsg);
  fsg_model_free(fsg);
  return result;
}
Exemple #2
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;
}