hunspell.hxx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #include "hunvisapi.h"
  2. #include "hashmgr.hxx"
  3. #include "affixmgr.hxx"
  4. #include "suggestmgr.hxx"
  5. #include "langnum.hxx"
  6. #define SPELL_XML "<?xml?>"
  7. #define MAXDIC 20
  8. #define MAXSUGGESTION 15
  9. #define MAXSHARPS 5
  10. #define HUNSPELL_OK (1 << 0)
  11. #define HUNSPELL_OK_WARN (1 << 1)
  12. #ifndef _MYSPELLMGR_HXX_
  13. #define _MYSPELLMGR_HXX_
  14. class LIBHUNSPELL_DLL_EXPORTED Hunspell
  15. {
  16. AffixMgr* pAMgr;
  17. HashMgr* pHMgr[MAXDIC];
  18. int maxdic;
  19. SuggestMgr* pSMgr;
  20. char * affixpath;
  21. char * encoding;
  22. struct cs_info * csconv;
  23. int langnum;
  24. int utf8;
  25. int complexprefixes;
  26. char** wordbreak;
  27. public:
  28. /* Hunspell(aff, dic) - constructor of Hunspell class
  29. * input: path of affix file and dictionary file
  30. */
  31. Hunspell(const char * affpath, const char * dpath, const char * key = NULL);
  32. ~Hunspell();
  33. /* load extra dictionaries (only dic files) */
  34. int add_dic(const char * dpath, const char * key = NULL);
  35. /* spell(word) - spellcheck word
  36. * output: 0 = bad word, not 0 = good word
  37. *
  38. * plus output:
  39. * info: information bit array, fields:
  40. * SPELL_COMPOUND = a compound word
  41. * SPELL_FORBIDDEN = an explicit forbidden word
  42. * root: root (stem), when input is a word with affix(es)
  43. */
  44. int spell(const char * word, int * info = NULL, char ** root = NULL);
  45. /* suggest(suggestions, word) - search suggestions
  46. * input: pointer to an array of strings pointer and the (bad) word
  47. * array of strings pointer (here *slst) may not be initialized
  48. * output: number of suggestions in string array, and suggestions in
  49. * a newly allocated array of strings (*slts will be NULL when number
  50. * of suggestion equals 0.)
  51. */
  52. int suggest(char*** slst, const char * word);
  53. /* deallocate suggestion lists */
  54. void free_list(char *** slst, int n);
  55. char * get_dic_encoding();
  56. /* morphological functions */
  57. /* analyze(result, word) - morphological analysis of the word */
  58. int analyze(char*** slst, const char * word);
  59. /* stem(result, word) - stemmer function */
  60. int stem(char*** slst, const char * word);
  61. /* stem(result, analysis, n) - get stems from a morph. analysis
  62. * example:
  63. * char ** result, result2;
  64. * int n1 = analyze(&result, "words");
  65. * int n2 = stem(&result2, result, n1);
  66. */
  67. int stem(char*** slst, char ** morph, int n);
  68. /* generate(result, word, word2) - morphological generation by example(s) */
  69. int generate(char*** slst, const char * word, const char * word2);
  70. /* generate(result, word, desc, n) - generation by morph. description(s)
  71. * example:
  72. * char ** result;
  73. * char * affix = "is:plural"; // description depends from dictionaries, too
  74. * int n = generate(&result, "word", &affix, 1);
  75. * for (int i = 0; i < n; i++) printf("%s\n", result[i]);
  76. */
  77. int generate(char*** slst, const char * word, char ** desc, int n);
  78. /* functions for run-time modification of the dictionary */
  79. /* add word to the run-time dictionary */
  80. int add(const char * word);
  81. /* add word to the run-time dictionary with affix flags of
  82. * the example (a dictionary word): Hunspell will recognize
  83. * affixed forms of the new word, too.
  84. */
  85. int add_with_affix(const char * word, const char * example);
  86. /* remove word from the run-time dictionary */
  87. int remove(const char * word);
  88. /* other */
  89. /* get extra word characters definied in affix file for tokenization */
  90. const char * get_wordchars();
  91. unsigned short * get_wordchars_utf16(int * len);
  92. struct cs_info * get_csconv();
  93. const char * get_version();
  94. int get_langnum() const;
  95. /* experimental and deprecated functions */
  96. #ifdef HUNSPELL_EXPERIMENTAL
  97. /* suffix is an affix flag string, similarly in dictionary files */
  98. int put_word_suffix(const char * word, const char * suffix);
  99. char * morph_with_correction(const char * word);
  100. /* spec. suggestions */
  101. int suggest_auto(char*** slst, const char * word);
  102. int suggest_pos_stems(char*** slst, const char * word);
  103. #endif
  104. private:
  105. int cleanword(char *, const char *, int * pcaptype, int * pabbrev);
  106. int cleanword2(char *, const char *, w_char *, int * w_len, int * pcaptype, int * pabbrev);
  107. void mkinitcap(char *);
  108. int mkinitcap2(char * p, w_char * u, int nc);
  109. int mkinitsmall2(char * p, w_char * u, int nc);
  110. void mkallcap(char *);
  111. int mkallcap2(char * p, w_char * u, int nc);
  112. void mkallsmall(char *);
  113. int mkallsmall2(char * p, w_char * u, int nc);
  114. struct hentry * checkword(const char *, int * info, char **root);
  115. char * sharps_u8_l1(char * dest, char * source);
  116. hentry * spellsharps(char * base, char *, int, int, char * tmp, int * info, char **root);
  117. int is_keepcase(const hentry * rv);
  118. int insert_sug(char ***slst, char * word, int ns);
  119. void cat_result(char * result, char * st);
  120. char * stem_description(const char * desc);
  121. int spellml(char*** slst, const char * word);
  122. int get_xml_par(char * dest, const char * par, int maxl);
  123. const char * get_xml_pos(const char * s, const char * attr);
  124. int get_xml_list(char ***slst, char * list, const char * tag);
  125. int check_xml_par(const char * q, const char * attr, const char * value);
  126. };
  127. #endif