Leaked source code of windows server 2003
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.

190 lines
3.7 KiB

  1. #ifndef _LTS_CART_H
  2. #define _LTS_CART_H
  3. #include "CommonLx.h"
  4. #define INPUT 0
  5. #define OUTPUT 1
  6. #define _LEFT 2
  7. #define _RIGHT 3
  8. #define OUTPUT_QUES_OFFSET 20000
  9. #define RIGHT_QUES_OFFSET 10000
  10. #define QUESTION_CODE_RANGE 1000
  11. #define MAX_PRODUCTS 300
  12. #define CLR_BIT(array, n) ((array)[(n)/32] &= ~(1<<((n)%32)))
  13. #define SET_BIT(array, n) ((array)[(n)/32] |= (1<<((n)%32)))
  14. #define TST_BIT(array, n) ((array)[(n)/32] & (1<<((n)%32)))
  15. #define LONGEST_STR 1024
  16. #define NULL_SYMBOL_ID 0
  17. #define NO_SYMBOL -1
  18. typedef unsigned char SYMBOL;
  19. typedef struct
  20. {
  21. int n_symbols;
  22. UNALIGNED int *sym_idx;
  23. int n_bytes;
  24. char *storage;
  25. } LTS_SYMTAB;
  26. typedef struct
  27. {
  28. SYMBOL *pIn;
  29. SYMBOL *pOut;
  30. } LTS_SAMPLE;
  31. typedef struct
  32. {
  33. int n_feat;
  34. int dim;
  35. int **feature;
  36. } LTS_FEATURE;
  37. typedef struct t_node
  38. {
  39. float entropy_dec;
  40. int n_samples;
  41. int *count;
  42. char *prod;
  43. int index;
  44. struct t_node *yes_child;
  45. struct t_node *no_child;
  46. } T_NODE;
  47. #define NO_CHILD 0
  48. #define IS_LEAF_NODE(x) ((x)->yes == NO_CHILD)
  49. typedef struct
  50. {
  51. unsigned short yes; /* index to yes child, no child will always follow */
  52. int idx; /* index to prod (for internal) and dist (for leaf) */
  53. } LTS_NODE;
  54. typedef struct
  55. {
  56. short id;
  57. short cnt;
  58. } LTS_PAIR;
  59. typedef struct
  60. {
  61. int c_dists;
  62. LTS_PAIR p_pair;
  63. } LTS_DIST;
  64. typedef unsigned short LTS_PROD;
  65. #define PROD_NEG 0x8000
  66. #define MAX_PROD 0x8ffc
  67. #define PROD_TERM 0xfffe
  68. #define QUES_TERM 0xffff
  69. typedef struct
  70. {
  71. int n_nodes;
  72. LTS_NODE *nodes;
  73. LTS_DIST *p_dist;
  74. int size_dist;
  75. LTS_PROD *p_prod;
  76. int size_prod;
  77. } LTS_TREE;
  78. #define MAX_ALT_STRINGS 64
  79. #define INC_ALT_STRINGS 32
  80. #define MAX_OUTPUT_STRINGS 10
  81. #define MIN_OUT_PROB 0.01f
  82. #define DEFAULT_PRUNE 0.1f
  83. typedef struct
  84. {
  85. float prob;
  86. char pstr[SP_MAX_PRON_LENGTH];
  87. } LTS_OUT_PRON;
  88. typedef struct
  89. {
  90. int num_prons;
  91. char word[SP_MAX_WORD_LENGTH];
  92. LTS_OUT_PRON pron[MAX_OUTPUT_STRINGS];
  93. } LTS_OUTPUT;
  94. typedef struct
  95. {
  96. float prob;
  97. SYMBOL psym[SP_MAX_WORD_LENGTH];
  98. } LTS_OUT_STRING;
  99. typedef struct outresult
  100. {
  101. int num_strings;
  102. int num_allocated_strings;
  103. LTS_OUT_STRING **out_strings;
  104. } LTS_OUT_RESULT;
  105. typedef struct
  106. {
  107. LTS_SYMTAB *symbols;
  108. LTS_FEATURE *features;
  109. LTS_TREE **tree;
  110. LTS_OUTPUT out;
  111. const char *bogus_pron;
  112. const char **single_letter_pron;
  113. } LTS_FOREST;
  114. typedef struct simp_question
  115. {
  116. char questype;
  117. char context;
  118. char offset;
  119. short feature;
  120. } SIMPLE_QUESTION;
  121. #define QUES_DECODE(code, questype, context, offset, feature) \
  122. { \
  123. int c = code; \
  124. if (c > OUTPUT_QUES_OFFSET) { \
  125. questype = OUTPUT; \
  126. c -= OUTPUT_QUES_OFFSET; \
  127. } \
  128. else \
  129. questype = INPUT; \
  130. if (c > RIGHT_QUES_OFFSET) { \
  131. context = _RIGHT; \
  132. c -= RIGHT_QUES_OFFSET; \
  133. } \
  134. else \
  135. context = _LEFT; \
  136. offset = c / QUESTION_CODE_RANGE; \
  137. feature = c % QUESTION_CODE_RANGE; \
  138. }
  139. #define SAMPLE_GET_CONTEXT(sample, questype, context, offset, id) { \
  140. SYMBOL *ps, i; \
  141. if ((questype) == INPUT) \
  142. ps = (sample)->pIn; \
  143. else \
  144. ps = (sample)->pOut; \
  145. if ((context) == _LEFT) { \
  146. for (i = 0; i < (offset) && *ps != NULL_SYMBOL_ID; i++, ps--); \
  147. id = *ps; \
  148. } \
  149. else { \
  150. for (i = 0; i < (offset) && *ps != NULL_SYMBOL_ID; i++, ps++); \
  151. id = *ps; \
  152. } \
  153. }
  154. #ifdef __cplusplus
  155. extern "C" {
  156. #endif
  157. LTS_FOREST *LtscartReadData (LCID , PBYTE);
  158. void LtscartFreeData (LTS_FOREST *l_forest);
  159. HRESULT LtscartGetPron(LTS_FOREST *l_forest, char *word, LTS_OUTPUT **ppLtsOutput);
  160. #ifdef __cplusplus
  161. }
  162. #endif
  163. #endif