1 | /* ***** BEGIN LICENSE BLOCK ***** |
2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
3 | * |
4 | * Copyright (C) 2002-2017 Németh László |
5 | * |
6 | * The contents of this file are subject to the Mozilla Public License Version |
7 | * 1.1 (the "License"); you may not use this file except in compliance with |
8 | * the License. You may obtain a copy of the License at |
9 | * http://www.mozilla.org/MPL/ |
10 | * |
11 | * Software distributed under the License is distributed on an "AS IS" basis, |
12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
13 | * for the specific language governing rights and limitations under the |
14 | * License. |
15 | * |
16 | * Hunspell is based on MySpell which is Copyright (C) 2002 Kevin Hendricks. |
17 | * |
18 | * Contributor(s): David Einstein, Davide Prina, Giuseppe Modugno, |
19 | * Gianluca Turconi, Simon Brouwer, Noll János, Bíró Árpád, |
20 | * Goldman Eleonóra, Sarlós Tamás, Bencsáth Boldizsár, Halácsy Péter, |
21 | * Dvornik László, Gefferth András, Nagy Viktor, Varga Dániel, Chris Halls, |
22 | * Rene Engelhard, Bram Moolenaar, Dafydd Jones, Harri Pitkänen |
23 | * |
24 | * Alternatively, the contents of this file may be used under the terms of |
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
27 | * in which case the provisions of the GPL or the LGPL are applicable instead |
28 | * of those above. If you wish to allow use of your version of this file only |
29 | * under the terms of either the GPL or the LGPL, and not to allow others to |
30 | * use your version of this file under the terms of the MPL, indicate your |
31 | * decision by deleting the provisions above and replace them with the notice |
32 | * and other provisions required by the GPL or the LGPL. If you do not delete |
33 | * the provisions above, a recipient may use your version of this file under |
34 | * the terms of any one of the MPL, the GPL or the LGPL. |
35 | * |
36 | * ***** END LICENSE BLOCK ***** */ |
37 | /* |
38 | * Copyright 2002 Kevin B. Hendricks, Stratford, Ontario, Canada |
39 | * And Contributors. All rights reserved. |
40 | * |
41 | * Redistribution and use in source and binary forms, with or without |
42 | * modification, are permitted provided that the following conditions |
43 | * are met: |
44 | * |
45 | * 1. Redistributions of source code must retain the above copyright |
46 | * notice, this list of conditions and the following disclaimer. |
47 | * |
48 | * 2. Redistributions in binary form must reproduce the above copyright |
49 | * notice, this list of conditions and the following disclaimer in the |
50 | * documentation and/or other materials provided with the distribution. |
51 | * |
52 | * 3. All modifications to the source code must be clearly marked as |
53 | * such. Binary redistributions based on modified source code |
54 | * must be clearly marked as modified versions in the documentation |
55 | * and/or other materials provided with the distribution. |
56 | * |
57 | * THIS SOFTWARE IS PROVIDED BY KEVIN B. HENDRICKS AND CONTRIBUTORS |
58 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
59 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
60 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
61 | * KEVIN B. HENDRICKS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
62 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
63 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
64 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
68 | * SUCH DAMAGE. |
69 | */ |
70 | #ifndef MYSPELLMGR_HXX_ |
71 | #define MYSPELLMGR_HXX_ |
72 | |
73 | #include "hunvisapi.h" |
74 | #include "w_char.hxx" |
75 | #include "atypes.hxx" |
76 | #include <string> |
77 | #include <vector> |
78 | |
79 | #define SPELL_XML "<?xml?>" |
80 | |
81 | #define MAXSUGGESTION 15 |
82 | #define MAXSHARPS 5 |
83 | |
84 | #ifndef MAXWORDLEN |
85 | #define MAXWORDLEN 100 |
86 | #endif |
87 | |
88 | #if defined __GNUC__ && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) |
89 | # define H_DEPRECATED __attribute__((__deprecated__)) |
90 | #elif defined(_MSC_VER) && (_MSC_VER >= 1300) |
91 | # define H_DEPRECATED __declspec(deprecated) |
92 | #else |
93 | # define H_DEPRECATED |
94 | #endif |
95 | |
96 | class HunspellImpl; |
97 | |
98 | class LIBHUNSPELL_DLL_EXPORTED Hunspell { |
99 | private: |
100 | Hunspell(const Hunspell&); |
101 | Hunspell& operator=(const Hunspell&); |
102 | |
103 | private: |
104 | HunspellImpl* m_Impl; |
105 | |
106 | public: |
107 | /* Hunspell(aff, dic) - constructor of Hunspell class |
108 | * input: path of affix file and dictionary file |
109 | * |
110 | * In WIN32 environment, use UTF-8 encoded paths started with the long path |
111 | * prefix \\\\?\\ to handle system-independent character encoding and very |
112 | * long path names (without the long path prefix Hunspell will use fopen() |
113 | * with system-dependent character encoding instead of _wfopen()). |
114 | */ |
115 | Hunspell(const char* affpath, const char* dpath, const char* key = NULL); |
116 | ~Hunspell(); |
117 | |
118 | /* load extra dictionaries (only dic files) */ |
119 | int add_dic(const char* dpath, const char* key = NULL); |
120 | |
121 | /* spell(word) - spellcheck word |
122 | * output: false = bad word, true = good word |
123 | * |
124 | * plus output: |
125 | * info: information bit array, fields: |
126 | * SPELL_COMPOUND = a compound word |
127 | * SPELL_FORBIDDEN = an explicit forbidden word |
128 | * root: root (stem), when input is a word with affix(es) |
129 | */ |
130 | bool spell(const std::string& word, int* info = NULL, std::string* root = NULL); |
131 | H_DEPRECATED int spell(const char* word, int* info = NULL, char** root = NULL); |
132 | |
133 | /* suggest(suggestions, word) - search suggestions |
134 | * input: pointer to an array of strings pointer and the (bad) word |
135 | * array of strings pointer (here *slst) may not be initialized |
136 | * output: number of suggestions in string array, and suggestions in |
137 | * a newly allocated array of strings (*slts will be NULL when number |
138 | * of suggestion equals 0.) |
139 | */ |
140 | std::vector<std::string> suggest(const std::string& word); |
141 | H_DEPRECATED int suggest(char*** slst, const char* word); |
142 | |
143 | /* Suggest words from suffix rules |
144 | * suffix_suggest(suggestions, root_word) |
145 | * input: pointer to an array of strings pointer and the word |
146 | * array of strings pointer (here *slst) may not be initialized |
147 | * output: number of suggestions in string array, and suggestions in |
148 | * a newly allocated array of strings (*slts will be NULL when number |
149 | * of suggestion equals 0.) |
150 | */ |
151 | std::vector<std::string> suffix_suggest(const std::string& root_word); |
152 | H_DEPRECATED int suffix_suggest(char*** slst, const char* root_word); |
153 | |
154 | /* deallocate suggestion lists */ |
155 | H_DEPRECATED void free_list(char*** slst, int n); |
156 | |
157 | const std::string& get_dict_encoding() const; |
158 | char* get_dic_encoding(); |
159 | |
160 | /* morphological functions */ |
161 | |
162 | /* analyze(result, word) - morphological analysis of the word */ |
163 | std::vector<std::string> analyze(const std::string& word); |
164 | H_DEPRECATED int analyze(char*** slst, const char* word); |
165 | |
166 | /* stem(word) - stemmer function */ |
167 | std::vector<std::string> stem(const std::string& word); |
168 | H_DEPRECATED int stem(char*** slst, const char* word); |
169 | |
170 | /* stem(analysis, n) - get stems from a morph. analysis |
171 | * example: |
172 | * char ** result, result2; |
173 | * int n1 = analyze(&result, "words"); |
174 | * int n2 = stem(&result2, result, n1); |
175 | */ |
176 | std::vector<std::string> stem(const std::vector<std::string>& morph); |
177 | H_DEPRECATED int stem(char*** slst, char** morph, int n); |
178 | |
179 | /* generate(result, word, word2) - morphological generation by example(s) */ |
180 | std::vector<std::string> generate(const std::string& word, const std::string& word2); |
181 | H_DEPRECATED int generate(char*** slst, const char* word, const char* word2); |
182 | |
183 | /* generate(result, word, desc, n) - generation by morph. description(s) |
184 | * example: |
185 | * char ** result; |
186 | * char * affix = "is:plural"; // description depends from dictionaries, too |
187 | * int n = generate(&result, "word", &affix, 1); |
188 | * for (int i = 0; i < n; i++) printf("%s\n", result[i]); |
189 | */ |
190 | std::vector<std::string> generate(const std::string& word, const std::vector<std::string>& pl); |
191 | H_DEPRECATED int generate(char*** slst, const char* word, char** desc, int n); |
192 | |
193 | /* functions for run-time modification of the dictionary */ |
194 | |
195 | /* add word to the run-time dictionary */ |
196 | |
197 | int add(const std::string& word); |
198 | |
199 | /* add word to the run-time dictionary with affix flags of |
200 | * the example (a dictionary word): Hunspell will recognize |
201 | * affixed forms of the new word, too. |
202 | */ |
203 | |
204 | int add_with_affix(const std::string& word, const std::string& example); |
205 | |
206 | /* remove word from the run-time dictionary */ |
207 | |
208 | int remove(const std::string& word); |
209 | |
210 | /* other */ |
211 | |
212 | /* get extra word characters definied in affix file for tokenization */ |
213 | const char* get_wordchars() const; |
214 | const std::string& get_wordchars_cpp() const; |
215 | const std::vector<w_char>& get_wordchars_utf16() const; |
216 | |
217 | struct cs_info* get_csconv(); |
218 | |
219 | const char* get_version() const; |
220 | const std::string& get_version_cpp() const; |
221 | |
222 | int get_langnum() const; |
223 | |
224 | /* need for putdic */ |
225 | bool input_conv(const std::string& word, std::string& dest); |
226 | H_DEPRECATED int input_conv(const char* word, char* dest, size_t destsize); |
227 | }; |
228 | |
229 | #endif |
230 | |