Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

239 lines
5.8 KiB

  1. //////////////////////////////////////////////////////////////////////
  2. // PhoneContext.h: interface for the CPhoneContext class.
  3. //
  4. // Created by JOEM 04-2000
  5. // Copyright (C) 2000 Microsoft Corporation
  6. // All Rights Reserved
  7. //
  8. /////////////////////////////////////////////////////// JOEM 4-2000 //
  9. #if !defined(AFX_PHONECONTEXT_H__9E560692_45A6_4472_B0F9_31AD3F6157B8__INCLUDED_)
  10. #define AFX_PHONECONTEXT_H__9E560692_45A6_4472_B0F9_31AD3F6157B8__INCLUDED_
  11. #if _MSC_VER > 1000
  12. #pragma once
  13. #endif // _MSC_VER > 1000
  14. #include "common.h"
  15. #include "MSPromptEng.h"
  16. enum PHONE_CONTEXT_TAG_ID
  17. {
  18. START_TAG,
  19. END_TAG,
  20. RIGHT_TAG,
  21. LEFT_TAG
  22. };
  23. struct CONTEXT_PHONE_TAG
  24. {
  25. PHONE_CONTEXT_TAG_ID iPhoneTag;
  26. WCHAR* pszPhoneTag;
  27. };
  28. static const CONTEXT_PHONE_TAG g_Phone_Tags[] =
  29. {
  30. { START_TAG, L"START_PHONE" },
  31. { END_TAG, L"END_PHONE" },
  32. { RIGHT_TAG, L"RIGHT_CONTEXT" },
  33. { LEFT_TAG, L"LEFT_CONTEXT" }
  34. };
  35. struct Macro
  36. {
  37. WCHAR name[32];
  38. double value;
  39. };
  40. struct CPhoneClass
  41. {
  42. WCHAR* m_pszPhoneClassName;
  43. WCHAR** m_pppszPhones;
  44. USHORT m_unNPhones;
  45. double m_dWeight;
  46. };
  47. struct CContextRule
  48. {
  49. WCHAR* m_pszRuleName;
  50. USHORT m_unNPhoneClasses;
  51. CPhoneClass** m_pvPhoneClasses;
  52. };
  53. //--- START OF DEFAULT PHONE CONTEXT RULES -----------------------------
  54. // The following are used for default US English context rules.
  55. #define MAX_RULES 15
  56. static WCHAR* g_macros[] =
  57. {
  58. L"%NoMatchWeight 5.0",
  59. L"%BadMatchWeight 3.0",
  60. L"%GoodMatchWeight 1.0",
  61. L"%MatchWeight 0.0"
  62. };
  63. static const USHORT g_nMacros = sizeof(g_macros)/sizeof(g_macros[0]);
  64. enum RULE_CODES
  65. {
  66. main,
  67. phone,
  68. consonant,
  69. velar,
  70. alveolar,
  71. palatal,
  72. deltal,
  73. labial,
  74. labiodental
  75. };
  76. struct RULE
  77. {
  78. RULE_CODES code;
  79. WCHAR* name;
  80. WCHAR* rule[MAX_RULES];
  81. };
  82. static const RULE g_rules[] =
  83. {
  84. // main rule - these four classes are mandatory
  85. {
  86. main,
  87. L"main",
  88. {
  89. L"none {} %NoMatchWeight",
  90. L"all {} %MatchWeight",
  91. L"silence { sp sil } %MatchWeight",
  92. L"phone { uw uh oy ow iy ih ey eh ay ax aw ao ah ae aa zh \
  93. z y w v th t sh s r er p ng n m l k jh g \
  94. f dh d ch b h } %BadMatchWeight"
  95. }
  96. },
  97. // phone rule
  98. {
  99. phone,
  100. L"phone",
  101. {
  102. L"vowel { uw uh oy ow iy ih ey eh ay ax aw ao ah ae aa } %GoodMatchWeight",
  103. L"consonant { zh z y w v th t sh s r er p ng n m l k jh g f dh d ch b h } %BadMatchWeight"
  104. }
  105. },
  106. // consonant rule
  107. {
  108. consonant,
  109. L"consonant",
  110. {
  111. L"nasal { m ng n } %GoodMatchWeight",
  112. L"lateral { l } %GoodMatchWeight",
  113. L"retroflex { er r } %GoodMatchWeight",
  114. L"velar { k g } %BadMatchWeight",
  115. L"alveolar { z s t d } %BadMatchWeight",
  116. L"palatal { zh sh ch jh } %BadMatchWeight",
  117. L"dental { dh th } %BadMatchWeight",
  118. L"labial { b p } %BadMatchWeight",
  119. L"labiodental { v f } %BadMatchWeight",
  120. L"glide { w y } %GoodMatchWeight"
  121. L"glottal { h } %GoodMatchWeight"
  122. }
  123. },
  124. // velar rule
  125. {
  126. velar,
  127. L"velar",
  128. {
  129. L"voiced { g } %GoodMatchWeight",
  130. L"unvoiced { k } %GoodMatchWeight"
  131. }
  132. },
  133. // alveolar rule
  134. {
  135. alveolar,
  136. L"alveolar",
  137. {
  138. L"voiced { z d } %GoodMatchWeight",
  139. L"unvoiced { s t } %GoodMatchWeight"
  140. }
  141. },
  142. // palatal rule
  143. {
  144. palatal,
  145. L"palatal",
  146. {
  147. L"voiced { zh jh } %GoodMatchWeight",
  148. L"unvoiced { sh ch } %GoodMatchWeight"
  149. }
  150. },
  151. // deltal rule
  152. {
  153. deltal,
  154. L"deltal",
  155. {
  156. L"voiced { dh } %GoodMatchWeight",
  157. L"unvoiced { th } %GoodMatchWeight"
  158. }
  159. },
  160. // labial rule
  161. {
  162. labial,
  163. L"labial",
  164. {
  165. L"voiced { b } %GoodMatchWeight",
  166. L"unvoiced { p } %GoodMatchWeight"
  167. }
  168. },
  169. // labiodental rule
  170. {
  171. labiodental,
  172. L"labiodental",
  173. {
  174. L"voiced { v } %GoodMatchWeight",
  175. L"unvoiced { f } %GoodMatchWeight"
  176. }
  177. },
  178. };
  179. static const USHORT g_nRules = sizeof(g_rules) / sizeof(g_rules[0]);
  180. //--- END OF DEFAULT PHONE CONTEXT RULES -------------------------------
  181. class CPhoneContext
  182. {
  183. public:
  184. HRESULT LoadDefault();
  185. CPhoneContext();
  186. ~CPhoneContext();
  187. STDMETHOD(Load)(const WCHAR* pszPathName);
  188. STDMETHOD(Apply)(IPromptEntry* pPreviousEntry, IPromptEntry* pCurrentEntry, double* pdCost);
  189. void DebugContextClass();
  190. private:
  191. void DeleteContextRule(CContextRule* pRule);
  192. void DeletePhoneClass(CPhoneClass* pClass);
  193. STDMETHOD(ApplyRule)(const CContextRule* pRule, const WCHAR* pszPhone, WCHAR** ppszNextRule);
  194. STDMETHOD(GetWeight)(const CContextRule* pRule, const WCHAR* pszName, double* pdCost);
  195. STDMETHOD(ApplyPhoneticRule)(const WCHAR* pszPhone, const WCHAR* pszContext, double* pdCost);
  196. STDMETHOD(SearchPhoneTag)(IPromptEntry* DbEntry, const WCHAR** result, CONTEXT_PHONE_TAG phoneTag);
  197. STDMETHOD(AddPhoneToClass)(CPhoneClass* phClass, WCHAR *phone);
  198. STDMETHOD(CreatePhoneClass)(CPhoneClass*** pppClasses, USHORT* punClasses, const WCHAR *psz);
  199. STDMETHOD(ReadMacro)(const WCHAR* pszText, Macro** ppMacros, USHORT* punMacros);
  200. STDMETHOD(ParsePhoneClass)(const Macro *pMacros, const USHORT unMacros, CContextRule* pRule, WCHAR **ppszOrig);
  201. STDMETHOD(CreateRule)(const WCHAR* pszText);
  202. STDMETHOD(FindContextRule)(const WCHAR* pszName, CContextRule** ppRule);
  203. private:
  204. ULONG m_ulNRules;
  205. CContextRule** m_ppContextRules;
  206. };
  207. #endif // !defined(AFX_PHONECONTEXT_H__9E560692_45A6_4472_B0F9_31AD3F6157B8__INCLUDED_)