hunspell.hxx (9141B)
1 /* ***** BEGIN LICENSE BLOCK ***** 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 3 * 4 * Copyright (C) 2002-2022 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 #ifndef MAXSUGGESTION 82 #define MAXSUGGESTION 15 83 #endif 84 85 #define MAXSHARPS 5 86 87 #ifndef MAXWORDLEN 88 #define MAXWORDLEN 100 89 #endif 90 91 #if defined __GNUC__ && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) 92 # define H_DEPRECATED __attribute__((__deprecated__)) 93 #elif defined(_MSC_VER) && (_MSC_VER >= 1300) 94 # define H_DEPRECATED __declspec(deprecated) 95 #else 96 # define H_DEPRECATED 97 #endif 98 99 class HunspellImpl; 100 101 class LIBHUNSPELL_DLL_EXPORTED Hunspell { 102 private: 103 Hunspell(const Hunspell&); 104 Hunspell& operator=(const Hunspell&); 105 106 private: 107 HunspellImpl* m_Impl; 108 109 public: 110 /* Hunspell(aff, dic) - constructor of Hunspell class 111 * input: path of affix file and dictionary file 112 * 113 * In WIN32 environment, use UTF-8 encoded paths started with the long path 114 * prefix \\\\?\\ to handle system-independent character encoding and very 115 * long path names (without the long path prefix Hunspell will use fopen() 116 * with system-dependent character encoding instead of _wfopen()). 117 */ 118 Hunspell(const char* affpath, const char* dpath, const char* key = NULL); 119 ~Hunspell(); 120 121 /* load extra dictionaries (only dic files) */ 122 int add_dic(const char* dpath, const char* key = NULL); 123 124 /* spell(word) - spellcheck word 125 * output: false = bad word, true = good word 126 * 127 * plus output: 128 * info: information bit array, fields: 129 * SPELL_COMPOUND = a compound word 130 * SPELL_FORBIDDEN = an explicit forbidden word 131 * root: root (stem), when input is a word with affix(es) 132 */ 133 bool spell(const std::string& word, int* info = NULL, std::string* root = NULL); 134 H_DEPRECATED int spell(const char* word, int* info = NULL, char** root = NULL); 135 136 /* suggest(suggestions, word) - search suggestions 137 * input: pointer to an array of strings pointer and the (bad) word 138 * array of strings pointer (here *slst) may not be initialized 139 * output: number of suggestions in string array, and suggestions in 140 * a newly allocated array of strings (*slts will be NULL when number 141 * of suggestion equals 0.) 142 */ 143 std::vector<std::string> suggest(const std::string& word); 144 H_DEPRECATED int suggest(char*** slst, const char* word); 145 146 /* Suggest words from suffix rules 147 * suffix_suggest(suggestions, root_word) 148 * input: pointer to an array of strings pointer and the word 149 * array of strings pointer (here *slst) may not be initialized 150 * output: number of suggestions in string array, and suggestions in 151 * a newly allocated array of strings (*slts will be NULL when number 152 * of suggestion equals 0.) 153 */ 154 std::vector<std::string> suffix_suggest(const std::string& root_word); 155 H_DEPRECATED int suffix_suggest(char*** slst, const char* root_word); 156 157 /* deallocate suggestion lists */ 158 H_DEPRECATED void free_list(char*** slst, int n); 159 160 const std::string& get_dict_encoding() const; 161 char* get_dic_encoding(); 162 163 /* morphological functions */ 164 165 /* analyze(result, word) - morphological analysis of the word */ 166 std::vector<std::string> analyze(const std::string& word); 167 H_DEPRECATED int analyze(char*** slst, const char* word); 168 169 /* stem(word) - stemmer function */ 170 std::vector<std::string> stem(const std::string& word); 171 H_DEPRECATED int stem(char*** slst, const char* word); 172 173 /* stem(analysis, n) - get stems from a morph. analysis 174 * example: 175 * char ** result, result2; 176 * int n1 = analyze(&result, "words"); 177 * int n2 = stem(&result2, result, n1); 178 */ 179 std::vector<std::string> stem(const std::vector<std::string>& morph); 180 H_DEPRECATED int stem(char*** slst, char** morph, int n); 181 182 /* generate(result, word, word2) - morphological generation by example(s) */ 183 std::vector<std::string> generate(const std::string& word, const std::string& word2); 184 H_DEPRECATED int generate(char*** slst, const char* word, const char* word2); 185 186 /* generate(result, word, desc, n) - generation by morph. description(s) 187 * example: 188 * char ** result; 189 * char * affix = "is:plural"; // description depends from dictionaries, too 190 * int n = generate(&result, "word", &affix, 1); 191 * for (int i = 0; i < n; i++) printf("%s\n", result[i]); 192 */ 193 std::vector<std::string> generate(const std::string& word, const std::vector<std::string>& pl); 194 H_DEPRECATED int generate(char*** slst, const char* word, char** desc, int n); 195 196 /* functions for run-time modification of the dictionary */ 197 198 /* add word to the run-time dictionary */ 199 200 int add(const std::string& word); 201 202 /* add word to the run-time dictionary with affix flags of 203 * the example (a dictionary word): Hunspell will recognize 204 * affixed forms of the new word, too. 205 */ 206 207 int add_with_affix(const std::string& word, const std::string& example); 208 209 /* remove word from the run-time dictionary */ 210 211 int remove(const std::string& word); 212 213 /* other */ 214 215 /* get extra word characters definied in affix file for tokenization */ 216 const char* get_wordchars() const; 217 const std::string& get_wordchars_cpp() const; 218 const std::vector<w_char>& get_wordchars_utf16() const; 219 220 struct cs_info* get_csconv(); 221 222 const char* get_version() const; 223 const std::string& get_version_cpp() const; 224 225 int get_langnum() const; 226 227 /* need for putdic */ 228 bool input_conv(const std::string& word, std::string& dest); 229 H_DEPRECATED int input_conv(const char* word, char* dest, size_t destsize); 230 }; 231 232 #endif