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