/* Decode the given mfc file and write result to matchfp and matchsegfp */
static void decode_utt (char *uttid, FILE *matchfp, FILE *matchsegfp)
{
    char dagfile[1024];
    hyp_t *h, *hyp;
    char *latdir, *latext;
    int32 nfrm, ascr, lscr;

    timing_reset (tm_utt);
    timing_start (tm_utt);
    
    latdir = (char *) cmd_ln_access ("-inlatdir");
    latext = (char *) cmd_ln_access ("-latext");
    if (latdir)
	sprintf (dagfile, "%s/%s.%s", latdir, uttid, latext);
    else
	sprintf (dagfile, "%s.%s", uttid, latext);
    
    if ((nfrm = dag_load (dagfile)) >= 0) {
	hyp = dag_search (uttid);

	if ( *((int32 *) cmd_ln_access("-backtrace")) )
	    log_hyp_detailed (stdout, hyp, uttid, "BP", "bp");
	
	/* Total scaled acoustic score and LM score */
	ascr = lscr = 0;
	for (h = hyp; h; h = h->next) {
	    ascr += h->ascr;
	    lscr += h->lscr;
	}
	
	printf ("BSTPTH: ");
	log_hypstr (stdout, hyp, uttid, ascr+lscr);

	printf ("BSTXCT: ");
	log_hypseg (uttid, stdout, hyp, nfrm);

	lm_cache_stats_dump ();
	lm_cache_reset ();
    } else {
	E_ERROR("DAG search (%s) failed\n", uttid);
	hyp = NULL;
    }
    
    /* Log recognition output to the standard match and matchseg files */
    if (matchfp)
	log_hypstr (matchfp, hyp, uttid, 0);
    if (matchsegfp)
	log_hypseg (uttid, matchsegfp, hyp, nfrm);
    
    dag_destroy ();

    timing_stop (tm_utt);
    
    printf ("%s: TMR: %5d Frm", uttid, nfrm);
    if (nfrm > 0) {
	printf (" %6.2f xEl", tm_utt->t_elapsed * 100.0 / nfrm);
	printf (" %6.2f xCPU", tm_utt->t_cpu * 100.0 / nfrm);
    }
    printf ("\n");
    fflush (stdout);

    tot_nfr += nfrm;
}
示例#2
0
文件: dpalign.c 项目: 10v/cmusphinx
static void process_reffile (char *reffile)
{
    FILE *rfp, *hfp;
    char line[16384], uttid[4096], file[4096], lc_uttid[4096];
    int32 i, k;
    dagnode_t ref[MAX_UTT_LEN];
    int32 nref, noov, nhyp;
    int32 tot_err, tot_ref, tot_corr, tot_oov, tot_hyp;
    dag_t *dag;
    dpnode_t retval;
    timing_t *tm;
    char *latdir, *hypfile;
    
    if ((rfp = fopen(reffile, "r")) == NULL)
	E_FATAL("fopen(%s,r) failed\n", reffile);

    latdir = (char *) cmd_ln_access ("-latdir");
    hypfile = (char *) cmd_ln_access ("-hyp");
    
    if ((! latdir) && (! hypfile))
	E_FATAL("Both -latdir and -hyp arguments missing\n");
    if (latdir && hypfile)
	E_FATAL("-latdir and -hyp arguments are mutually exclusive\n");

    hfp = NULL;
    if (hypfile) {
	if ((hfp = fopen(hypfile, "r")) == NULL)
	    E_FATAL("fopen(%s,r) failed\n", hypfile);
    }
    
    tot_err = 0;
    tot_ref = 0;
    tot_hyp = 0;
    tot_corr = 0;
    tot_oov = 0;
    
    tm = timing_new ("Utt");
    
    while (fgets(line, sizeof(line), rfp) != NULL) {
	timing_reset (tm);
	timing_start (tm);

	if ((nref = refline2wds (line, ref, &noov, uttid)) < 0)
	    E_FATAL("Bad line in file %s: %s\n", reffile, line);
	
	/* Read lattice or hypfile, whichever is specified */
	if (latdir) {
	    sprintf (file, "%s/%s.lat", latdir, uttid);
	    
	    dag = dag_load (file);
	    if (! dag) {
		/* Try lower casing uttid */
		strcpy (lc_uttid, uttid);
		lcase (lc_uttid);
		sprintf (file, "%s/%s.lat", latdir, lc_uttid);
		dag = dag_load (file);
	    }
	} else {
	    if (fgets(line, sizeof(line), hfp) == NULL)
		E_FATAL("Premature EOF(%s) at uttid %s\n", hypfile, uttid);

	    dag = hypline2dag (uttid, line);
	}
	
	if (dag) {
	    /* Append sentinel silwid node to end of DAG */
	    dag_append_sentinel (dag, silwid);
	    
	    /* Find best path (returns #errors/#correct and updates *nhyp) */
	    retval = dp (uttid, dict, oovbegin, ref, nref, dag, &nhyp, 0);
	    
	    dag_destroy (dag);
	} else {
	    retval.c = 0;
	    retval.e = nref-1;
	    nhyp = 0;
	}
	
	timing_stop (tm);
	
	tot_ref += nref-1;
	tot_hyp += nhyp;
	tot_err += retval.e;
	tot_corr += retval.c;
	tot_oov += noov;

	printf("(%s) << %d ref; %d %.1f%% oov; %d hyp; %d %.1f%% corr; %d %.1f%% err; %.1fs CPU >>\n",
	       uttid, nref-1,
	       noov, (nref > 1) ? (noov * 100.0) / (nref-1) : 0.0,
	       nhyp,
	       retval.c, (nref > 1) ? (retval.c * 100.0) / (nref-1) : 0.0,
	       retval.e, (nref > 1) ? (retval.e * 100.0) / (nref-1) : 0.0,
	       tm->t_cpu);

	printf("== %7d ref; %5d %5.1f%% oov; %7d hyp; %7d %5.1f%% corr; %6d %5.1f%% err; %5.1fs CPU; %s\n",
	       tot_ref,
	       tot_oov, (tot_ref > 0) ? (tot_oov * 100.0) / tot_ref : 0.0,
	       tot_hyp,
	       tot_corr, (tot_ref > 0) ? (tot_corr * 100.0) / tot_ref : 0.0,
	       tot_err, (tot_ref > 0) ? (tot_err * 100.0) / tot_ref : 0.0,
	       tm->t_tot_cpu,
	       uttid);

	fflush (stderr);
	fflush (stdout);
    }
    
    fclose (rfp);
    if (hfp)
	fclose (hfp);
    
    printf("SUMMARY: %d ref; %d %.3f%% oov; %d hyp; %d %.3f%% corr; %d %.3f%% err; %.1fs CPU\n",
	   tot_ref,
	   tot_oov, (tot_ref > 0) ? (tot_oov * 100.0) / tot_ref : 0.0,
	   tot_hyp,
	   tot_corr, (tot_ref > 0) ? (tot_corr * 100.0) / tot_ref : 0.0,
	   tot_err, (tot_ref > 0) ? (tot_err * 100.0) / tot_ref : 0.0,
	   tm->t_tot_cpu);
}
示例#3
0
/* Decode the given mfc file and write result to given directory */
static void
utt_astar(void *data, utt_res_t * ur, int32 sf, int32 ef, char *uttid)
{
    char dagfile[1024], nbestfile[1024];
    const char *latdir;
    const char *latext;
    const char *nbestext;
    dag_t *dag;
    int32 nfrm;

    if (ur->lmname)
        lmset_set_curlm_wname(lmset, ur->lmname);

    latdir = cmd_ln_str_r(config, "-inlatdir");
    latext = cmd_ln_str_r(config, "-latext");
    nbestext = cmd_ln_str_r(config, "-nbestext");
    if (latdir) {
        build_output_uttfile(dagfile, latdir, uttid, ur->uttfile);
        strcat(dagfile, ".");
        strcat(dagfile, latext);
    }
    else
        sprintf(dagfile, "%s.%s", uttid, latext);

    ptmr_reset(&tm_utt);
    ptmr_start(&tm_utt);

    nfrm = 0;
    if ((dag = dag_load(dagfile,
                        cmd_ln_int32_r(config, "-maxedge"),
                        cmd_ln_float32_r(config, "-logbase"),
                        cmd_ln_int32_r(config, "-dagfudge"), dict, fpen, config, logmath)) != NULL) {
        if (dict_filler_word(dict, dag->end->wid))
            dag->end->wid = dict->finishwid;

        dag_remove_unreachable(dag);
        if (dag_bypass_filler_nodes(dag, 1.0, dict, fpen) < 0) {
            E_ERROR("maxedge limit (%d) exceeded\n", dag->maxedge);
            goto search_done;
        }
        dag_compute_hscr(dag, dict, lmset->cur_lm, 1.0);
        dag_remove_bypass_links(dag);

        E_INFO("%5d frames, %6d nodes, %8d edges, %8d bypass\n",
               dag->nfrm, dag->nnode, dag->nlink, dag->nbypass);

        nfrm = dag->nfrm;
        build_output_uttfile(nbestfile, nbestdir, uttid, ur->uttfile);
        strcat(nbestfile, ".");
        strcat(nbestfile, nbestext);
        nbest_search(dag, nbestfile, uttid, 1.0, dict, lmset->cur_lm, fpen);

        lm_cache_stats_dump(lmset->cur_lm);
        lm_cache_reset(lmset->cur_lm);
    }
    else
        E_ERROR("Dag load (%s) failed\n", uttid);
search_done:
    dag_destroy(dag);

    ptmr_stop(&tm_utt);

    printf("%s: TMR: %5d Frm", uttid, nfrm);
    if (nfrm > 0) {
        printf(" %6.2f xEl", tm_utt.t_elapsed * 100.0 / nfrm);
        printf(" %6.2f xCPU", tm_utt.t_cpu * 100.0 / nfrm);
    }
    printf("\n");
    fflush(stdout);
}