Esempio n. 1
0
File: mdef.c Progetto: 10v/cmusphinx
static int32 parse_base_line (mdef_t *m, char *line, int32 lineno, s3pid_t p)
{
    int32 wlen, n;
    char *word;
    s3cipid_t ci;
    char tmp;

    /* Read base phone name */
    if ((wlen = nextword (line, delim, &word, &tmp)) < 0)	/* Empty line */
	E_FATAL("Line %d: Incomplete base phone line\n", lineno);

    /* Make sure it's not a duplicate */
    ci = mdef_ciphone_id (m, word);
    if (IS_CIPID(ci))
        E_FATAL("Line %d: Duplicate base phone: %s\n", lineno, word);

    /* Add ciphone to ciphone table with id p */
    ciphone_add (m, word, p);
    ci = p;

    /* Restore original delimiter to word */
    line = word+wlen;
    word[wlen] = tmp;

    /* Read and skip "-" for lc, rc, wpos */
    for (n = 0; n < 3; n++) {
        if ((wlen = nextword (line, delim, &word, &tmp)) < 0)
	    E_FATAL("Line %d: Incomplete base phone line\n", lineno);
	if ((wlen != 1) || (word[0] != '-'))
	    E_FATAL("Line %d: %s instead of '-' in base phone line\n", word, lineno);
	line = word+wlen;
	word[wlen] = tmp;
    }
    
    /* Read filler attribute, if present */
    if ((wlen = nextword (line, delim, &word, &tmp)) < 0)
	E_FATAL("Line %d: Incomplete base phone line\n", lineno);
    if (strcmp (word, "filler") == 0)
        m->ciphone[ci].filler = 1;
    else if (strcmp (word, "n/a") == 0)
        m->ciphone[ci].filler = 0;
    else
        E_FATAL("Line %d: Illegal attribute string: %s\n", lineno, word);
    line = word+wlen;
    word[wlen] = tmp;

    if (triphone_add (m, ci, BAD_CIPID, BAD_CIPID, WORD_POSN_UNDEFINED, p) < 0)
	E_FATAL("Line %d: Duplicate/Bad triphone\n", lineno);

    /* Parse remainder of line: transition matrix and state->senone mappings */
    parse_tmat_senmap (m, line, lineno, p);
    
    return 0;
}
Esempio n. 2
0
static void
parse_base_line(mdef_t * m, const char *line, s3pid_t p)
{
    int32 wlen, n;
    char word[1024];
    const char *lp;
    s3cipid_t ci;

    lp = line;

    /* Read base phone name */
    if (sscanf(lp, "%s%n", word, &wlen) != 1)
        E_FATAL("Missing base phone name: %s\n", line);
    lp += wlen;

    /* Make sure it's not a duplicate */
    ci = mdef_ciphone_id(m, word);
    if (IS_S3CIPID(ci))
        E_FATAL("Duplicate base phone: %s\n", line);

    /* Add ciphone to ciphone table with id p */
    ciphone_add(m, word, p);
    ci = (s3cipid_t) p;

    /* Read and skip "-" for lc, rc, wpos */
    for (n = 0; n < 3; n++) {
        if ((sscanf(lp, "%s%n", word, &wlen) != 1)
            || (strcmp(word, "-") != 0))
            E_FATAL("Bad context info for base phone: %s\n", line);
        lp += wlen;
    }

    /* Read filler attribute, if present */
    if (sscanf(lp, "%s%n", word, &wlen) != 1)
        E_FATAL("Missing filler atribute field: %s\n", line);
    lp += wlen;
    if (strcmp(word, "filler") == 0)
        m->ciphone[(int) ci].filler = 1;
    else if (strcmp(word, "n/a") == 0)
        m->ciphone[(int) ci].filler = 0;
    else
        E_FATAL("Bad filler attribute field: %s\n", line);

    triphone_add(m, ci, BAD_S3CIPID, BAD_S3CIPID, WORD_POSN_UNDEFINED, p);

    /* Parse remainder of line: transition matrix and state->senone mappings */
    parse_tmat_senmap(m, line, lp - line, p);
}
Esempio n. 3
0
static void
parse_tri_line(mdef_t * m, char *line, int p)
{
    int32 wlen;
    __BIGSTACKVARIABLE__ char word[1024], *lp;
    int ci, lc, rc;
    word_posn_t wpos = WORD_POSN_BEGIN;

    lp = line;

    /* Read base phone name */
    if (sscanf(lp, "%s%n", word, &wlen) != 1)
        E_FATAL("Missing base phone name: %s\n", line);
    lp += wlen;

    ci = mdef_ciphone_id(m, word);
    if (ci < 0)
        E_FATAL("Unknown base phone: %s\n", line);

    /* Read lc */
    if (sscanf(lp, "%s%n", word, &wlen) != 1)
        E_FATAL("Missing left context: %s\n", line);
    lp += wlen;
    lc = mdef_ciphone_id(m, word);
    if (lc < 0)
        E_FATAL("Unknown left context: %s\n", line);

    /* Read rc */
    if (sscanf(lp, "%s%n", word, &wlen) != 1)
        E_FATAL("Missing right context: %s\n", line);
    lp += wlen;
    rc = mdef_ciphone_id(m, word);
    if (rc < 0)
        E_FATAL("Unknown right  context: %s\n", line);

    /* Read tripone word-position within word */
    if ((sscanf(lp, "%s%n", word, &wlen) != 1) || (word[1] != '\0'))
        E_FATAL("Missing or bad word-position spec: %s\n", line);
    lp += wlen;
    switch (word[0]) {
    case 'b':
        wpos = WORD_POSN_BEGIN;
        break;
    case 'e':
        wpos = WORD_POSN_END;
        break;
    case 's':
        wpos = WORD_POSN_SINGLE;
        break;
    case 'i':
        wpos = WORD_POSN_INTERNAL;
        break;
    default:
        E_FATAL("Bad word-position spec: %s\n", line);
    }

    /* Read filler attribute, if present.  Must match base phone attribute */
    if (sscanf(lp, "%s%n", word, &wlen) != 1)
        E_FATAL("Missing filler attribute field: %s\n", line);
    lp += wlen;
    if (((strcmp(word, "filler") == 0) && (m->ciphone[(int) ci].filler)) ||
        ((strcmp(word, "n/a") == 0) && (!m->ciphone[(int) ci].filler))) {
        /* Everything is fine */
    }
    else
        E_FATAL("Bad filler attribute field: %s\n", line);

    triphone_add(m, ci, lc, rc, wpos, p);

    /* Parse remainder of line: transition matrix and state->senone mappings */
    parse_tmat_senmap(m, line, lp - line, p);
}
Esempio n. 4
0
File: mdef.c Progetto: 10v/cmusphinx
static int32 parse_tri_line (mdef_t *m, char *line, int32 lineno, s3pid_t p)
{
    int32 wlen;
    char *word;
    s3cipid_t ci, lc, rc;
    word_posn_t wpos;
    char tmp;

    /* Read base phone name */
    if ((wlen = nextword (line, delim, &word, &tmp)) < 0)	/* Empty line */
	E_FATAL("Line %d: Incomplete triphone line\n", lineno);
    ci = mdef_ciphone_id (m, word);
    if (NOT_CIPID(ci))
        E_FATAL("Line %d: Unknown base phone in triphone: %s\n", lineno, word);
    line = word+wlen;
    word[wlen] = tmp;

    /* Read lc */
    if ((wlen = nextword (line, delim, &word, &tmp)) < 0)
        E_FATAL("Line %d: Incomplete triphone line\n", lineno);
    lc = mdef_ciphone_id (m, word);
    if (NOT_CIPID(lc))
        E_FATAL("Line %d: Unknown left context in triphone: %s\n", lineno, word);
    line = word+wlen;
    word[wlen] = tmp;

    /* Read rc */
    if ((wlen = nextword (line, delim, &word, &tmp)) < 0)
        E_FATAL("Line %d: Incomplete triphone line\n", lineno);
    rc = mdef_ciphone_id (m, word);
    if (NOT_CIPID(rc))
        E_FATAL("Line %d: Unknown left context in triphone: %s\n", lineno, word);
    line = word+wlen;
    word[wlen] = tmp;
    
    /* Read tripone word-position within word */
    if (((wlen = nextword (line, delim, &word, &tmp)) < 0) ||
	(word[1] != '\0'))
        E_FATAL("Line %d: Missing or bad triphone word-position spec\n", lineno);
    switch (word[0]) {
    case 'b': wpos = WORD_POSN_BEGIN; break;
    case 'e': wpos = WORD_POSN_END; break;
    case 's': wpos = WORD_POSN_SINGLE; break;
    case 'i': wpos = WORD_POSN_INTERNAL; break;
    default: E_FATAL("Line %d: Bad word-position spec: %s\n", lineno, word);
    }
    line = word+wlen;
    word[wlen] = tmp;

    /* Read filler attribute, if present.  Must match base phone attribute */
    if ((wlen = nextword (line, delim, &word, &tmp)) < 0)
	E_FATAL("Line %d: Incomplete base phone line\n", lineno);
    if (((strcmp (word, "filler") == 0) && (m->ciphone[ci].filler)) ||
	((strcmp (word, "n/a") == 0) && (! m->ciphone[ci].filler))) {
    } else
        E_FATAL("Line %d: Bad attribute string: %s\n", lineno, word);
    line = word+wlen;
    word[wlen] = tmp;
    
    if (triphone_add (m, ci, lc, rc, wpos, p) < 0)
	E_FATAL("Line %d: Duplicate/Bad triphone\n", lineno);

    /* Parse remainder of line: transition matrix and state->senone mappings */
    parse_tmat_senmap (m, line, lineno, p);
    
    return 0;
}