/* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is Hunspell, based on MySpell. * * The Initial Developers of the Original Code are * Kevin Hendricks (MySpell) and Németh László (Hunspell). * Portions created by the Initial Developers are Copyright (C) 2002-2005 * the Initial Developers. All Rights Reserved. * * Contributor(s): David Einstein, Davide Prina, Giuseppe Modugno, * Gianluca Turconi, Simon Brouwer, Noll János, Bíró Árpád, * Goldman Eleonóra, Sarlós Tamás, Bencsáth Boldizsár, Halácsy Péter, * Dvornik László, Gefferth András, Nagy Viktor, Varga Dániel, Chris Halls, * Rene Engelhard, Bram Moolenaar, Dafydd Jones, Harri Pitkänen * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ /* * Copyright 2002 Kevin B. Hendricks, Stratford, Ontario, Canada * And Contributors. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * 3. All modifications to the source code must be clearly marked as * such. Binary redistributions based on modified source code * must be clearly marked as modified versions in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY KEVIN B. HENDRICKS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * KEVIN B. HENDRICKS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include <stdlib.h> #include <string.h> #include <stdio.h> #include <ctype.h> #include "suggestmgr.hxx" #include "htypes.hxx" #include "csutil.hxx" const w_char W_VLINE = …; #ifdef HUNSPELL_CHROME_CLIENT namespace { // A simple class which creates temporary hentry objects which are available // only in a scope. To conceal memory operations from SuggestMgr functions, // this object automatically deletes all hentry objects created through // CreateScopedHashEntry() calls in its destructor. So, the following snippet // raises a memory error. // // hentry* bad_copy = NULL; // { // ScopedHashEntryFactory factory; // hentry* scoped_copy = factory.CreateScopedHashEntry(0, source); // ... // bad_copy = scoped_copy; // } // if (bad_copy->word[0]) // memory for scoped_copy has been deleted! // // As listed in the above snippet, it is simple to use this class. // 1. Declare an instance of this ScopedHashEntryFactory, and; // 2. Call its CreateHashEntry() member instead of using 'new hentry' or // 'operator='. // class ScopedHashEntryFactory { … }; ScopedHashEntryFactory::ScopedHashEntryFactory() { … } ScopedHashEntryFactory::~ScopedHashEntryFactory() { … } hentry* ScopedHashEntryFactory::CreateScopedHashEntry(int index, const hentry* source) { … } } // namespace #endif #ifdef HUNSPELL_CHROME_CLIENT SuggestMgr::SuggestMgr(hunspell::BDictReader* reader, const char * tryme, int maxn, AffixMgr * aptr) { … } SuggestMgr::~SuggestMgr() { … } void SuggestMgr::testsug(std::vector<std::string>& wlst, const std::string& candidate, int cpdsuggest, int* timer, clock_t* timelimit) { … } // generate suggestions for a misspelled word // pass in address of array of char * pointers // onlycompoundsug: probably bad suggestions (need for ngram sugs, too) void SuggestMgr::suggest(std::vector<std::string>& slst, const char* w, int* onlycompoundsug) { … } // suggestions for an uppercase word (html -> HTML) void SuggestMgr::capchars_utf(std::vector<std::string>& wlst, const w_char* word, int wl, int cpdsuggest) { … } // suggestions for an uppercase word (html -> HTML) void SuggestMgr::capchars(std::vector<std::string>& wlst, const char* word, int cpdsuggest) { … } // suggestions for when chose the wrong char out of a related set int SuggestMgr::mapchars(std::vector<std::string>& wlst, const char* word, int cpdsuggest) { … } int SuggestMgr::map_related(const char* word, std::string& candidate, int wn, std::vector<std::string>& wlst, int cpdsuggest, const std::vector<mapentry>& maptable, int* timer, clock_t* timelimit) { … } // suggestions for a typical fault of spelling, that // differs with more, than 1 letter from the right form. int SuggestMgr::replchars(std::vector<std::string>& wlst, const char* word, int cpdsuggest) { … } // perhaps we doubled two characters (pattern aba -> ababa, for example vacation // -> vacacation) int SuggestMgr::doubletwochars(std::vector<std::string>& wlst, const char* word, int cpdsuggest) { … } // perhaps we doubled two characters (pattern aba -> ababa, for example vacation // -> vacacation) int SuggestMgr::doubletwochars_utf(std::vector<std::string>& wlst, const w_char* word, int wl, int cpdsuggest) { … } // error is wrong char in place of correct one (case and keyboard related // version) int SuggestMgr::badcharkey(std::vector<std::string>& wlst, const char* word, int cpdsuggest) { … } // error is wrong char in place of correct one (case and keyboard related // version) int SuggestMgr::badcharkey_utf(std::vector<std::string>& wlst, const w_char* word, int wl, int cpdsuggest) { … } // error is wrong char in place of correct one int SuggestMgr::badchar(std::vector<std::string>& wlst, const char* word, int cpdsuggest) { … } // error is wrong char in place of correct one int SuggestMgr::badchar_utf(std::vector<std::string>& wlst, const w_char* word, int wl, int cpdsuggest) { … } // error is word has an extra letter it does not need int SuggestMgr::extrachar_utf(std::vector<std::string>& wlst, const w_char* word, int wl, int cpdsuggest) { … } // error is word has an extra letter it does not need int SuggestMgr::extrachar(std::vector<std::string>& wlst, const char* word, int cpdsuggest) { … } // error is missing a letter it needs int SuggestMgr::forgotchar(std::vector<std::string>& wlst, const char* word, int cpdsuggest) { … } // error is missing a letter it needs int SuggestMgr::forgotchar_utf(std::vector<std::string>& wlst, const w_char* word, int wl, int cpdsuggest) { … } /* error is should have been two words */ int SuggestMgr::twowords(std::vector<std::string>& wlst, const char* word, int cpdsuggest) { … } // error is adjacent letter were swapped int SuggestMgr::swapchar(std::vector<std::string>& wlst, const char* word, int cpdsuggest) { … } // error is adjacent letter were swapped int SuggestMgr::swapchar_utf(std::vector<std::string>& wlst, const w_char* word, int wl, int cpdsuggest) { … } // error is not adjacent letter were swapped int SuggestMgr::longswapchar(std::vector<std::string>& wlst, const char* word, int cpdsuggest) { … } // error is adjacent letter were swapped int SuggestMgr::longswapchar_utf(std::vector<std::string>& wlst, const w_char* word, int wl, int cpdsuggest) { … } // error is a letter was moved int SuggestMgr::movechar(std::vector<std::string>& wlst, const char* word, int cpdsuggest) { … } // error is a letter was moved int SuggestMgr::movechar_utf(std::vector<std::string>& wlst, const w_char* word, int wl, int cpdsuggest) { … } // generate a set of suggestions for very poorly spelled words void SuggestMgr::ngsuggest(std::vector<std::string>& wlst, const char* w, const std::vector<HashMgr*>& rHMgr) { … } // see if a candidate suggestion is spelled correctly // needs to check both root words and words with affixes // obsolote MySpell-HU modifications: // return value 2 and 3 marks compounding with hyphen (-) // `3' marks roots without suffix int SuggestMgr::checkword(const std::string& word, int cpdsuggest, int* timer, clock_t* timelimit) { … } int SuggestMgr::check_forbidden(const char* word, int len) { … } std::string SuggestMgr::suggest_morph(const std::string& in_w) { … } static int get_sfxcount(const char* morph) { … } /* affixation */ std::string SuggestMgr::suggest_hentry_gen(hentry* rv, const char* pattern) { … } std::string SuggestMgr::suggest_gen(const std::vector<std::string>& desc, const std::string& in_pattern) { … } // generate an n-gram score comparing s1 and s2, UTF16 version int SuggestMgr::ngram(int n, const std::vector<w_char>& su1, const std::vector<w_char>& su2, int opt) { … } // generate an n-gram score comparing s1 and s2, non-UTF16 version int SuggestMgr::ngram(int n, const std::string& s1, const std::string& s2, int opt) { … } // length of the left common substring of s1 and (decapitalised) s2, UTF version int SuggestMgr::leftcommonsubstring( const std::vector<w_char>& su1, const std::vector<w_char>& su2) { … } // length of the left common substring of s1 and (decapitalised) s2, non-UTF int SuggestMgr::leftcommonsubstring( const char* s1, const char* s2) { … } int SuggestMgr::commoncharacterpositions(const char* s1, const char* s2, int* is_swap) { … } int SuggestMgr::mystrlen(const char* word) { … } // sort in decreasing order of score void SuggestMgr::bubblesort(char** rword, char** rword2, int* rsc, int n) { … } // longest common subsequence void SuggestMgr::lcs(const char* s, const char* s2, int* l1, int* l2, char** result) { … } int SuggestMgr::lcslen(const char* s, const char* s2) { … } int SuggestMgr::lcslen(const std::string& s, const std::string& s2) { … }