1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * Copyright (C) 2002-2017 Németh László
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/
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
16 * Hunspell is based on MySpell which is Copyright (C) 2002 Kevin Hendricks.
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
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.
36 * ***** END LICENSE BLOCK ***** */
38 * Copyright 2002 Kevin B. Hendricks, Stratford, Ontario, Canada
39 * And Contributors. All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
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.
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.
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
70 #ifndef MYSPELLMGR_HXX_
71 #define MYSPELLMGR_HXX_
73 #include "hunvisapi.h"
79 #define SPELL_XML "<?xml?>"
81 #define MAXSUGGESTION 15
85 #define MAXWORDLEN 100
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)
98 class LIBHUNSPELL_DLL_EXPORTED Hunspell {
100 Hunspell(const Hunspell&);
101 Hunspell& operator=(const Hunspell&);
104 HunspellImpl* m_Impl;
107 /* Hunspell(aff, dic) - constructor of Hunspell class
108 * input: path of affix file and dictionary file
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()).
115 Hunspell(const char* affpath, const char* dpath, const char* key = NULL);
118 /* load extra dictionaries (only dic files) */
119 int add_dic(const char* dpath, const char* key = NULL);
121 /* spell(word) - spellcheck word
122 * output: false = bad word, true = good word
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)
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);
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.)
140 std::vector<std::string> suggest(const std::string& word);
141 H_DEPRECATED int suggest(char*** slst, const char* word);
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.)
151 std::vector<std::string> suffix_suggest(const std::string& root_word);
152 H_DEPRECATED int suffix_suggest(char*** slst, const char* root_word);
154 /* deallocate suggestion lists */
155 H_DEPRECATED void free_list(char*** slst, int n);
157 const std::string& get_dict_encoding() const;
158 char* get_dic_encoding();
160 /* morphological functions */
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);
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);
170 /* stem(analysis, n) - get stems from a morph. analysis
172 * char ** result, result2;
173 * int n1 = analyze(&result, "words");
174 * int n2 = stem(&result2, result, n1);
176 std::vector<std::string> stem(const std::vector<std::string>& morph);
177 H_DEPRECATED int stem(char*** slst, char** morph, int n);
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);
183 /* generate(result, word, desc, n) - generation by morph. description(s)
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]);
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);
193 /* functions for run-time modification of the dictionary */
195 /* add word to the run-time dictionary */
197 int add(const std::string& word);
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.
204 int add_with_affix(const std::string& word, const std::string& example);
206 /* remove word from the run-time dictionary */
208 int remove(const std::string& word);
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;
217 struct cs_info* get_csconv();
219 const char* get_version() const;
220 const std::string& get_version_cpp() const;
222 int get_langnum() const;
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);