1 /**
2  * @file   vocabulary.h
3  *
4  * <JA>
5  * @brief  ñ�켭��ι�¤�����
6  *
7  * ���Υե������ǧ�����Ѥ�����ñ�켭���������ޤ���ñ�켭���ñ����ɤߡ�
8  * ����ʸ�����������¾�ˡ�ʸ�γ��ϡ���λñ���Ʃ��ñ�������ݻ����ޤ���
9  *
10  * N-gram�˽и�������äμ���� NGRAM_INFO �˳�Ǽ���졤����ǧ����ñ�켭��Ȥ�
11  * ���̤���뤳�Ȥ���դ��Ʋ�������ñ�켭����N-gram�θ��äؤΥޥåԥ���
12  * WORD_INFO ��� wton[] �ˤ�äƹԤʤ��ޤ����ޤ�DFA�ξ�硤wton ��
13  * ����ñ�줬°����DFA_INFO ��Υ��ƥ����ֹ��ޤߤޤ���
14  * </JA>
15  * <EN>
16  * @brief  Word dictionary for recognition
17  *
18  * This file defines data structure for word dictionary used in recognition.
19  * It stores word's string, output string, phoneme sequence, transparency.
20  * Beginning-of-sentence word and End-of-sentence word guessed from runtime
21  * environment is also stored here.
22  *
23  * Please note that the N-gram vocabulary is stored in NGRAM_INFO and it
24  * can differ from this word dictionary.  The reference from the word
25  * dictionary to a N-gram vocabulary is done by wton[] member in WORD_INFO.
26  * When used with DFA, the wton[] holds a category number to which each word
27  * belongs.
28  * </EN>
29  *
30  * @author Akinobu LEE
31  * @date   Sat Feb 12 12:38:13 2005
32  *
33  * $Revision: 1.5 $
34  *
35  */
36 /*
37  * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University
38  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
39  * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology
40  * All rights reserved
41  */
42 
43 #ifndef __SENT_VOCA_H__
44 #define __SENT_VOCA_H__
45 
46 #include <sent/stddefs.h>
47 #include <sent/htk_hmm.h>
48 
49 /// Memory allocation step in number of words when loading a word dictionary
50 #define	MAXWSTEP 4000
51 
52 /// Word dictionary structure to hold vocabulary
53 typedef struct {
54   WORD_ID	maxnum;		///< Allocated number of word space
55   WORD_ID	num;		///< Number of words
56   WORD_ID	errnum;		///< Number of error words that were skipped when reading dictionary
57   WORD_ID	linenum;	///< Current line number while loading
58   boolean	do_conv;	///< TRUE if needs conversion while loading
59   boolean	ok_flag;	///< FALSE if any error occur while loading
60 
61   unsigned char	*wlen;		///< Number of phonemes for each word [wid]
62 
63   char		**wname;	///< Word name string for each word [wid].  With DFA, it's category ID.  With N-gram, it's N-gram entry name.
64   char		**woutput;	///< Word output string that will be output as recognition result for each word [wid]
65   HMM_Logical   ***wseq;	///< Phone sequence of each word [wid][0..wlen[wid]-1]
66   WORD_ID	*wton;		///< Reference to N-gram/category ID of each word ID [wid]
67 #ifdef CLASS_NGRAM
68   LOGPROB	*cprob;		///< Class probability of each word [wid]
69   WORD_ID	cwnum;		///< Number of words whose class prob is specified (just for a statistic)
70 #endif
71   WORD_ID	head_silwid;	///< Word ID of beginning-of-sentence silence
72   WORD_ID	tail_silwid;	///< Word ID of end-of-sentence silence
73   short		maxwn;		///< Maximum number of %HMM states per word (statistic)
74   short         maxwlen;	///< Maximum number of phones in a word (statistic)
75   int		totalstatenum;  ///< Total number of HMM states
76   int		totalmodelnum;  ///< Total number of models (phonemes)
77   int		totaltransnum;  ///< Total number of state transitions
78   boolean	*is_transparent; ///< TRUE if the word can be treated as transparent [wid]
79   APATNODE	*errph_root; ///< Root node of index tree for gathering error %HMM name appeared when reading the dictionary
80   BMALLOC_BASE *mroot;		///< Pointer for block memory allocation
81 } WORD_INFO;
82 
83 WORD_INFO *word_info_new();
84 void word_info_free(WORD_INFO *winfo);
85 void winfo_init(WORD_INFO *winfo);
86 boolean winfo_expand(WORD_INFO *winfo);
87 boolean init_voca(WORD_INFO *winfo, char *filename, HTK_HMM_INFO *hmminfo, boolean, boolean);
88 boolean init_wordlist(WORD_INFO *winfo, char *filename, HTK_HMM_INFO *hmminfo, char *headphone, char *tailphone, char *contextphone, boolean force_dict);
89 void voca_set_stats(WORD_INFO *winfo);
90 void voca_load_start(WORD_INFO *winfo, HTK_HMM_INFO *hmminfo, boolean ignore_tri_conv);
91 boolean voca_load_line(char *buf, WORD_INFO *winfo, HTK_HMM_INFO *hmminfo);
92 boolean voca_load_end(WORD_INFO *winfo);
93 boolean voca_load_htkdict(FILE *, WORD_INFO *, HTK_HMM_INFO *, boolean);
94 boolean	voca_load_htkdict_fp(FILE *, WORD_INFO *, HTK_HMM_INFO *, boolean);
95 boolean voca_append_htkdict(char *entry, WORD_INFO *winfo, HTK_HMM_INFO *hmminfo, boolean ignore_tri_conv);
96 boolean voca_append(WORD_INFO *dstinfo, WORD_INFO *srcinfo, int coffset, int woffset);
97 boolean voca_load_htkdict_line(char *buf, WORD_ID *vnum, int linenum, WORD_INFO *winfo, HTK_HMM_INFO *hmminfo, boolean do_conv, boolean *ok_flag);
98 
99 boolean voca_load_word_line(char *buf, WORD_INFO *winfo, HTK_HMM_INFO *hmminfo, char *headphone, char *tailpohone, char *contextphone);
100 boolean voca_load_wordlist(FILE *fp, WORD_INFO *winfo, HTK_HMM_INFO *hmminfo, char *headphone, char *tailphone, char *contextphone);
101 boolean voca_load_wordlist_fp(FILE *fp, WORD_INFO *winfo, HTK_HMM_INFO *hmminfo, char *headphone, char *tailphone, char *contextphone);
102 boolean voca_load_wordlist_line(char *buf, WORD_ID *vnum, int linenum, WORD_INFO *winfo, HTK_HMM_INFO *hmminfo, boolean do_conv, boolean *ok_flag, char *headphone, char *tailphone, char *contextphone);
103 boolean voca_mono2tri(WORD_INFO *winfo, HTK_HMM_INFO *hmminfo);
104 WORD_ID voca_lookup_wid(char *, WORD_INFO *);
105 WORD_ID *new_str2wordseq(WORD_INFO *, char *, int *);
106 char *cycle_triphone(char *p);
107 char *cycle_triphone_flush();
108 void print_voca_info(FILE *fp, WORD_INFO *);
109 void put_voca(FILE *fp, WORD_INFO *winfo, WORD_ID wid);
110 
111 /* HMMList check */
112 boolean make_base_phone(HTK_HMM_INFO *hmminfo, WORD_INFO *winfo);
113 void print_phone_info(FILE *fp, HTK_HMM_INFO *hmminfo);
114 void print_all_basephone_detail(HMM_basephone *base);
115 void print_all_basephone_name(HMM_basephone *base);
116 void test_interword_triphone(HTK_HMM_INFO *hmminfo, WORD_INFO *winfo);
117 
118 #endif /* __SENT_VOCA_H__ */
119