int dict_write(dict_t *dict, char const *filename, char const *format) { FILE *fh; int i; if ((fh = fopen(filename, "w")) == NULL) { E_ERROR_SYSTEM("Failed to open %s", filename); return -1; } for (i = 0; i < dict->n_word; ++i) { char *phones; int j, phlen; if (!dict_real_word(dict, i)) continue; for (phlen = j = 0; j < dict_pronlen(dict, i); ++j) phlen += strlen(dict_ciphone_str(dict, i, j)) + 1; phones = ckd_calloc(1, phlen); for (j = 0; j < dict_pronlen(dict, i); ++j) { strcat(phones, dict_ciphone_str(dict, i, j)); if (j != dict_pronlen(dict, i) - 1) strcat(phones, " "); } fprintf(fh, "%-30s %s\n", dict_wordstr(dict, i), phones); ckd_free(phones); } fclose(fh); return 0; }
main (int32 argc, char *argv[]) { mdef_t *m; dict_t *d; char wd[1024]; s3wid_t wid; int32 p; if (argc < 3) E_FATAL("Usage: %s {mdeffile | NULL} dict [fillerdict]\n", argv[0]); m = (strcmp (argv[1], "NULL") != 0) ? mdef_init (argv[1]) : NULL; d = dict_init (m, argv[2], ((argc > 3) ? argv[3] : NULL), '_'); for (;;) { printf ("word> "); scanf ("%s", wd); wid = dict_wordid (d, wd); if (NOT_WID(wid)) E_ERROR("Unknown word\n"); else { for (wid = dict_basewid(d, wid); IS_WID(wid); wid = d->word[wid].alt) { printf ("%s\t", dict_wordstr(d, wid)); for (p = 0; p < d->word[wid].pronlen; p++) printf (" %s", dict_ciphone_str (d, wid, p)); printf ("\n"); } } } }
char * ps_lookup_word(ps_decoder_t *ps, const char *word) { s3wid_t wid; int32 phlen, j; char *phones; dict_t *dict = ps->dict; wid = dict_wordid(dict, word); if (wid == BAD_S3WID) return NULL; for (phlen = j = 0; j < dict_pronlen(dict, wid); ++j) phlen += strlen(dict_ciphone_str(dict, wid, j)) + 1; phones = ckd_calloc(1, phlen); for (j = 0; j < dict_pronlen(dict, wid); ++j) { strcat(phones, dict_ciphone_str(dict, wid, j)); if (j != dict_pronlen(dict, wid) - 1) strcat(phones, " "); } return phones; }
main (int32 argc, char *argv[]) { dict_t **d; int32 i, k, p, wid; char line[16384], *wp[1024]; if (argc < 2) { E_INFO("Usage: %s dictfile [dictfile ...] < vocabfile\n", argv[0]); exit(0); } d = (dict_t **) ckd_calloc (argc-1, sizeof(dict_t *)); for (i = 1; i < argc; i++) d[i-1] = dict_init (NULL, argv[i], NULL, 0); while (fgets (line, sizeof(line), stdin) != NULL) { if ((k = str2words (line, wp, 1024)) < 0) E_FATAL("Line too long: %s\n", line); if (k > 2) E_FATAL("Vocab entry contains too many words\n"); if (k == 0) continue; if (k == 1) wp[1] = wp[0]; /* Look up word in each dictionary until found */ k = 0; for (i = 0; (i < argc-1) && (k == 0); i++) { wid = dict_wordid (d[i], wp[1]); if (NOT_WID(wid)) continue; for (wid = dict_basewid(d[i], wid); IS_WID(wid); wid = dict_nextalt(d[i], wid)) { k++; if (k == 1) printf ("%s\t", wp[0]); else printf ("%s(%d)\t", wp[0], k); for (p = 0; p < dict_pronlen(d[i], wid); p++) printf (" %s", dict_ciphone_str (d[i], wid, p)); printf ("\n"); } } if (k == 0) E_ERROR("No pronunciation for: '%s'\n", wp[0]); } }