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.

291 lines
6.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Thai WordBreak
  4. //
  5. // Thai WordBreak Interface Header File.
  6. //
  7. // History:
  8. // created 5/99 aarayas
  9. //
  10. // �1999 Microsoft Corporation
  11. //----------------------------------------------------------------------------
  12. #include "thwbint.h"
  13. #include "lexheader.h"
  14. #include "trie.h"
  15. #include "NLGlib.h"
  16. #include "ProofBase.h"
  17. #include "ctrie.hpp"
  18. #include "cthwb.hpp"
  19. #include "thwbdef.hpp"
  20. HINSTANCE g_hInst;
  21. static PTEC retcode(int mjr, int mnr) { return MAKELONG(mjr, mnr); }
  22. #define lidThai 0x41e
  23. // class trie.
  24. //CTrie trie;
  25. // class CThaiWordBreak
  26. CThaiWordBreak* thaiWordBreak = NULL;
  27. //+---------------------------------------------------------------------------
  28. //
  29. // Function: ThaiWordBreakInit
  30. //
  31. // Synopsis: Initialize Thai Word Break - initialize variables of Thai Word Break.
  32. //
  33. // Arguments: szFileName - contain the path of the word list lexicon.
  34. //
  35. // Modifies:
  36. //
  37. // History: created 6/99 aarayas
  38. //
  39. // Notes:
  40. //
  41. //----------------------------------------------------------------------------
  42. #if defined (NGRAM_ENABLE)
  43. PTEC WINAPI ThaiWordBreakInit(WCHAR* szFileName, WCHAR* szFileNameSentStruct, WCHAR* szFileNameTrigram)
  44. #else
  45. PTEC WINAPI ThaiWordBreakInit(WCHAR* szFileName, WCHAR* szFileNameTrigram)
  46. #endif
  47. {
  48. if (thaiWordBreak == NULL)
  49. {
  50. thaiWordBreak = new CThaiWordBreak;
  51. if (thaiWordBreak == NULL)
  52. return retcode(ptecIOErrorMainLex, ptecFileRead);
  53. }
  54. #if defined (NGRAM_ENABLE)
  55. return thaiWordBreak->Init(szFileName, szFileNameSentStruct, szFileNameTrigram);
  56. #else
  57. return thaiWordBreak->Init(szFileName, szFileNameTrigram);
  58. #endif
  59. }
  60. //+---------------------------------------------------------------------------
  61. //
  62. // Function: ThaiWordBreakInitResource
  63. //
  64. // Synopsis: Initialize Thai Word Break - initialize variables of Thai Word Break.
  65. //
  66. // Arguments:
  67. //
  68. // Modifies:
  69. //
  70. // History: created 6/2000 aarayas
  71. //
  72. // Notes:
  73. //
  74. //----------------------------------------------------------------------------
  75. PTEC WINAPI ThaiWordBreakInitResource(LPBYTE pThaiDic, LPBYTE pThaiTrigram)
  76. {
  77. if (thaiWordBreak == NULL)
  78. {
  79. thaiWordBreak = new CThaiWordBreak;
  80. if (thaiWordBreak == NULL)
  81. return retcode(ptecIOErrorMainLex, ptecFileRead);
  82. }
  83. return thaiWordBreak->InitRc(pThaiDic, pThaiTrigram);
  84. }
  85. //+---------------------------------------------------------------------------
  86. //
  87. // Function: ThaiWordBreakTerminate
  88. //
  89. // Synopsis: Terminate Thai Word Break - does the cleanup for Thai Word Break.
  90. //
  91. // Arguments:
  92. //
  93. // Modifies:
  94. //
  95. // History: created 6/99 aarayas
  96. //
  97. // Notes:
  98. //
  99. //----------------------------------------------------------------------------
  100. void WINAPI ThaiWordBreakTerminate()
  101. {
  102. if (thaiWordBreak)
  103. {
  104. thaiWordBreak->UnInit();
  105. delete thaiWordBreak;
  106. thaiWordBreak = NULL;
  107. }
  108. }
  109. //+---------------------------------------------------------------------------
  110. //
  111. // Function: ThaiWordBreakSearch
  112. //
  113. // Synopsis: Search to see if the word is in.
  114. //
  115. // Arguments: szWord - the word to search for
  116. //
  117. // Modifies:
  118. //
  119. // History: created 6/99 aarayas
  120. //
  121. // Notes:
  122. //
  123. //----------------------------------------------------------------------------
  124. BOOL WINAPI ThaiWordBreakSearch(WCHAR* szWord, DWORD* pdwPOS)
  125. {
  126. if (thaiWordBreak == NULL)
  127. return FALSE;
  128. return thaiWordBreak->Find(szWord, pdwPOS);
  129. }
  130. //+---------------------------------------------------------------------------
  131. //
  132. // Function: THWB_FindWordBreak
  133. //
  134. // Synopsis: Search to see if the word is in.
  135. //
  136. // Arguments: szWord - the word to search for
  137. //
  138. // Modifies:
  139. //
  140. // History: created 7/99 aarayas
  141. //
  142. // Notes:
  143. //
  144. //----------------------------------------------------------------------------
  145. int WINAPI THWB_FindWordBreak(WCHAR* wzString,unsigned int iStringLen, BYTE* pBreakPos,unsigned int iBreakLen, unsigned int mode)
  146. {
  147. if (thaiWordBreak == NULL)
  148. return 0;
  149. return thaiWordBreak->FindWordBreak(wzString,iStringLen, pBreakPos, iBreakLen, (BYTE) mode, true);
  150. }
  151. //+---------------------------------------------------------------------------
  152. //
  153. // Function: THWB_IndexWordBreak
  154. //
  155. // Synopsis: Search to see if the word is in.
  156. //
  157. // Arguments: szWord - the word to search for
  158. //
  159. // Modifies:
  160. //
  161. // History: created 3/00 aarayas
  162. //
  163. // Notes:
  164. //
  165. //----------------------------------------------------------------------------
  166. int WINAPI THWB_IndexWordBreak(WCHAR* wzString,unsigned int iStringLen, BYTE* pBreakPos,THWB_STRUCT* pThwb_Struct,unsigned int iBreakLen)
  167. {
  168. if (thaiWordBreak == NULL)
  169. return 0;
  170. return thaiWordBreak->IndexWordBreak(wzString,iStringLen, pBreakPos, pThwb_Struct, iBreakLen);
  171. }
  172. //+---------------------------------------------------------------------------
  173. //
  174. // Function: THWB_FindAltWord
  175. //
  176. // Synopsis:
  177. //
  178. // Arguments:
  179. // pBreakPos - array of 5 byte.
  180. //
  181. // Modifies:
  182. //
  183. // History: created 3/00 aarayas
  184. //
  185. // Notes:
  186. //
  187. //----------------------------------------------------------------------------
  188. int WINAPI THWB_FindAltWord(WCHAR* wzWord,unsigned int iWordLen, BYTE Alt, BYTE* pBreakPos)
  189. {
  190. if (thaiWordBreak == NULL)
  191. return 0;
  192. return thaiWordBreak->FindAltWord(wzWord,iWordLen,Alt,pBreakPos);
  193. }
  194. //+---------------------------------------------------------------------------
  195. //
  196. // Function: THWB_CreateThwbStruct
  197. //
  198. // Synopsis:
  199. //
  200. // Arguments:
  201. //
  202. // Modifies:
  203. //
  204. // History: created 3/00 aarayas
  205. //
  206. // Notes:
  207. //
  208. //----------------------------------------------------------------------------
  209. THWB_STRUCT* WINAPI THWB_CreateThwbStruct(unsigned int iNumStruct)
  210. {
  211. unsigned int i = 0;
  212. THWB_STRUCT* pThwb_Struct = NULL;
  213. pThwb_Struct = new THWB_STRUCT[iNumStruct];
  214. if (pThwb_Struct)
  215. {
  216. for(i=0;i < iNumStruct; i++)
  217. {
  218. pThwb_Struct[i].fThai = false;
  219. pThwb_Struct[i].alt = 0;
  220. }
  221. }
  222. return pThwb_Struct;
  223. }
  224. //+---------------------------------------------------------------------------
  225. //
  226. // Function: THWB_DeleteThwbStruct
  227. //
  228. // Synopsis:
  229. //
  230. // Arguments:
  231. //
  232. // Modifies:
  233. //
  234. // History: created 3/00 aarayas
  235. //
  236. // Notes:
  237. //
  238. //----------------------------------------------------------------------------
  239. void WINAPI THWB_DeleteThwbStruct(THWB_STRUCT* pThwb_Struct)
  240. {
  241. if (pThwb_Struct)
  242. delete pThwb_Struct;
  243. pThwb_Struct = NULL;
  244. }
  245. //+---------------------------------------------------------------------------
  246. //
  247. // Function: ThaiSoundEx
  248. //
  249. // Synopsis:
  250. //
  251. // Arguments:
  252. //
  253. // Modifies:
  254. //
  255. // History: created 8/99 aarayas
  256. //
  257. // Notes:
  258. //
  259. //----------------------------------------------------------------------------
  260. int WINAPI ThaiSoundEx(WCHAR* word)
  261. {
  262. // ::MessageBoxW(0,L"Soundex called",L"THWB",MB_OK);
  263. // return 0;
  264. if (thaiWordBreak == NULL)
  265. return 0;
  266. return thaiWordBreak->Soundex(word);
  267. }