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