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