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.

134 lines
3.5 KiB

  1. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation. All rights reserved.
  4. //
  5. // Module:
  6. // volcano/dll/latticefl.c
  7. //
  8. // Description:
  9. // Functions to load various databases for the recognizer from
  10. // files.
  11. //
  12. // Author:
  13. // hrowley
  14. //
  15. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  16. #include "common.h"
  17. #include "volcanop.h"
  18. #include "brknet.h"
  19. BBOX_PROB_TABLE *g_pProbTable;
  20. UNIGRAM_INFO g_unigramInfo;
  21. BIGRAM_INFO g_bigramInfo;
  22. CLASS_BIGRAM_INFO g_classBigramInfo;
  23. TTUNE_INFO g_ttuneInfo;
  24. LOAD_INFO g_bboxProbInfo;
  25. wchar_t g_pLocale[16];
  26. wchar_t g_pLocaleDir[1024];
  27. wchar_t g_pRecogDir[1024];
  28. HINSTANCE g_hDLL;
  29. VOLCANO_PARAMS_INFO g_vtuneInfo;
  30. VOLCANO_CONFIG g_volcanoConfig;
  31. CENTIPEDE_INFO g_centipedeInfo;
  32. LOAD_INFO g_BrkNetInfo;
  33. LOAD_INFO g_SegmNetInfo;
  34. LOAD_INFO g_CharDetLoadInfo;
  35. BOOL LoadSegmNetFromFile(wchar_t *pwszRecogDir, LOAD_INFO *pLoadInfo);
  36. BOOL LoadCharDetFromFile(wchar_t *wszPath, LOAD_INFO *pLoadInfo);
  37. // Loads the following databases: unigrams, bigrams, class bigrams, tuning, centipede, free input
  38. BOOL LatticeConfigFile(wchar_t *pRecogDir)
  39. {
  40. LatticeConfigInit();
  41. if (!VTuneLoadFile(&g_vtuneInfo, pRecogDir))
  42. {
  43. ASSERT(("Error in VTuneLoadFile", FALSE));
  44. return FALSE;
  45. }
  46. if (!TTuneLoadFile(&g_ttuneInfo, pRecogDir)) {
  47. ASSERT(("Error in TTuneLoadFile", FALSE));
  48. return FALSE;
  49. }
  50. if (!UnigramLoadFile(&g_locRunInfo, &g_unigramInfo, pRecogDir)) {
  51. ASSERT(("Error in UnigramLoadFile", FALSE));
  52. return FALSE;
  53. }
  54. #if !defined(WINCE) && !defined(FAKE_WINCE)
  55. if (!BigramLoadFile(&g_locRunInfo, &g_bigramInfo, pRecogDir)) {
  56. ASSERT(("Error in BigramLoadFile", FALSE));
  57. return FALSE;
  58. }
  59. #endif
  60. if (!ClassBigramLoadFile(&g_locRunInfo, &g_classBigramInfo, pRecogDir)) {
  61. ASSERT(("Error in ClassBigramLoadFile", FALSE));
  62. return FALSE;
  63. }
  64. if (!CentipedeLoadFile(&g_centipedeInfo, pRecogDir, &g_locRunInfo)) {
  65. ASSERT(("Error in CentipedeLoadFile", FALSE));
  66. return FALSE;
  67. }
  68. // Failure here is not an error, it just means we don't support free input
  69. g_pProbTable = LoadBBoxProbTableFile(pRecogDir, &g_bboxProbInfo);
  70. #ifdef USE_IFELANG3
  71. LatticeConfigIFELang3();
  72. #endif
  73. // Don't bother trying to load other databases for free input if the basic
  74. // one is not present.
  75. if (g_pProbTable != NULL)
  76. {
  77. // load the brk net, this is optional
  78. if (LoadBrkNetFromFile (pRecogDir, &g_BrkNetInfo))
  79. {
  80. // load the segm nets, optional
  81. if (!LoadSegmNetFromFile (pRecogDir, &g_SegmNetInfo))
  82. {
  83. // ASSERT(("Error in LoadSegmNetFromFile", FALSE));
  84. // return FALSE;
  85. }
  86. // load the char detector, not optional
  87. if (!LoadCharDetFromFile(pRecogDir, &g_CharDetLoadInfo))
  88. {
  89. ASSERT(("Error in LoadCharDetFromFile", FALSE));
  90. return FALSE;
  91. }
  92. }
  93. }
  94. return TRUE;
  95. }
  96. BOOL LatticeUnconfigFile()
  97. {
  98. BOOL ok = TRUE;
  99. if (!UnigramUnloadFile(&g_unigramInfo)) ok = FALSE;
  100. #if !defined(WINCE) && !defined(FAKE_WINCE)
  101. if (!BigramUnloadFile(&g_bigramInfo)) ok = FALSE;
  102. #endif
  103. if (!ClassBigramUnloadFile(&g_classBigramInfo)) ok = FALSE;
  104. if (!TTuneUnloadFile(&g_ttuneInfo)) ok = FALSE;
  105. if (!CentipedeUnloadFile(&g_centipedeInfo)) ok = FALSE;
  106. if (g_pProbTable != NULL && !UnLoadBBoxProbTableFile(&g_bboxProbInfo)) ok = FALSE;
  107. if (!VTuneUnloadFile(&g_vtuneInfo))
  108. {
  109. ok = FALSE;
  110. }
  111. BrkNetUnloadfile (&g_BrkNetInfo);
  112. return ok;
  113. }