PageRenderTime 29ms CodeModel.GetById 13ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 1ms

/extensions/spellcheck/hunspell/src/suggestmgr.hxx

http://github.com/zpao/v8monkey
C++ Header | 168 lines | 90 code | 21 blank | 57 comment | 0 complexity | 92df8bf140f172fc8062ecf4e978639e MD5 | raw file
  1/******* BEGIN LICENSE BLOCK *******
  2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3 * 
  4 * The contents of this file are subject to the Mozilla Public License Version
  5 * 1.1 (the "License"); you may not use this file except in compliance with
  6 * the License. You may obtain a copy of the License at
  7 * http://www.mozilla.org/MPL/
  8 * 
  9 * Software distributed under the License is distributed on an "AS IS" basis,
 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 11 * for the specific language governing rights and limitations under the
 12 * License.
 13 * 
 14 * The Initial Developers of the Original Code are Kevin Hendricks (MySpell)
 15 * and L�szl� N�meth (Hunspell). Portions created by the Initial Developers
 16 * are Copyright (C) 2002-2005 the Initial Developers. All Rights Reserved.
 17 * 
 18 * Contributor(s): Kevin Hendricks (kevin.hendricks@sympatico.ca)
 19 *                 David Einstein (deinst@world.std.com)
 20 *                 L�szl� N�meth (nemethl@gyorsposta.hu)
 21 *                 Caolan McNamara (caolanm@redhat.com)
 22 *                 Davide Prina
 23 *                 Giuseppe Modugno
 24 *                 Gianluca Turconi
 25 *                 Simon Brouwer
 26 *                 Noll Janos
 27 *                 Biro Arpad
 28 *                 Goldman Eleonora
 29 *                 Sarlos Tamas
 30 *                 Bencsath Boldizsar
 31 *                 Halacsy Peter
 32 *                 Dvornik Laszlo
 33 *                 Gefferth Andras
 34 *                 Nagy Viktor
 35 *                 Varga Daniel
 36 *                 Chris Halls
 37 *                 Rene Engelhard
 38 *                 Bram Moolenaar
 39 *                 Dafydd Jones
 40 *                 Harri Pitkanen
 41 *                 Andras Timar
 42 *                 Tor Lillqvist
 43 * 
 44 * Alternatively, the contents of this file may be used under the terms of
 45 * either the GNU General Public License Version 2 or later (the "GPL"), or
 46 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 47 * in which case the provisions of the GPL or the LGPL are applicable instead
 48 * of those above. If you wish to allow use of your version of this file only
 49 * under the terms of either the GPL or the LGPL, and not to allow others to
 50 * use your version of this file under the terms of the MPL, indicate your
 51 * decision by deleting the provisions above and replace them with the notice
 52 * and other provisions required by the GPL or the LGPL. If you do not delete
 53 * the provisions above, a recipient may use your version of this file under
 54 * the terms of any one of the MPL, the GPL or the LGPL.
 55 *
 56 ******* END LICENSE BLOCK *******/
 57
 58#ifndef _SUGGESTMGR_HXX_
 59#define _SUGGESTMGR_HXX_
 60
 61#define MAXSWL 100
 62#define MAXSWUTF8L (MAXSWL * 4)
 63#define MAX_ROOTS 100
 64#define MAX_WORDS 100
 65#define MAX_GUESS 200
 66#define MAXNGRAMSUGS 4
 67#define MAXPHONSUGS 2
 68#define MAXCOMPOUNDSUGS 3
 69
 70// timelimit: max ~1/4 sec (process time on Linux) for a time consuming function
 71#define TIMELIMIT (CLOCKS_PER_SEC >> 2)
 72#define MINTIMER 100
 73#define MAXPLUSTIMER 100
 74
 75#define NGRAM_LONGER_WORSE  (1 << 0)
 76#define NGRAM_ANY_MISMATCH  (1 << 1)
 77#define NGRAM_LOWERING      (1 << 2)
 78#define NGRAM_WEIGHTED      (1 << 3)
 79
 80#include "hunvisapi.h"
 81
 82#include "atypes.hxx"
 83#include "affixmgr.hxx"
 84#include "hashmgr.hxx"
 85#include "langnum.hxx"
 86#include <time.h>
 87
 88enum { LCS_UP, LCS_LEFT, LCS_UPLEFT };
 89
 90class LIBHUNSPELL_DLL_EXPORTED SuggestMgr
 91{
 92  char *          ckey;
 93  int             ckeyl;
 94  w_char *        ckey_utf;
 95
 96  char *          ctry;
 97  int             ctryl;
 98  w_char *        ctry_utf;
 99
100  AffixMgr*       pAMgr;
101  int             maxSug;
102  struct cs_info * csconv;
103  int             utf8;
104  int             langnum;
105  int             nosplitsugs;
106  int             maxngramsugs;
107  int             maxcpdsugs;
108  int             complexprefixes;
109
110
111public:
112  SuggestMgr(const char * tryme, int maxn, AffixMgr *aptr);
113  ~SuggestMgr();
114
115  int suggest(char*** slst, const char * word, int nsug, int * onlycmpdsug);
116  int ngsuggest(char ** wlst, char * word, int ns, HashMgr** pHMgr, int md);
117  int suggest_auto(char*** slst, const char * word, int nsug);
118  int suggest_stems(char*** slst, const char * word, int nsug);
119  int suggest_pos_stems(char*** slst, const char * word, int nsug);
120
121  char * suggest_morph(const char * word);
122  char * suggest_gen(char ** pl, int pln, char * pattern);
123  char * suggest_morph_for_spelling_error(const char * word);
124
125private:
126   int testsug(char** wlst, const char * candidate, int wl, int ns, int cpdsuggest,
127     int * timer, clock_t * timelimit);
128   int checkword(const char *, int, int, int *, clock_t *);
129   int check_forbidden(const char *, int);
130
131   int capchars(char **, const char *, int, int);
132   int replchars(char**, const char *, int, int);
133   int doubletwochars(char**, const char *, int, int);
134   int forgotchar(char **, const char *, int, int);
135   int swapchar(char **, const char *, int, int);
136   int longswapchar(char **, const char *, int, int);
137   int movechar(char **, const char *, int, int);
138   int extrachar(char **, const char *, int, int);
139   int badcharkey(char **, const char *, int, int);
140   int badchar(char **, const char *, int, int);
141   int twowords(char **, const char *, int, int);
142   int fixstems(char **, const char *, int);
143
144   int capchars_utf(char **, const w_char *, int wl, int, int);
145   int doubletwochars_utf(char**, const w_char *, int wl, int, int);
146   int forgotchar_utf(char**, const w_char *, int wl, int, int);
147   int extrachar_utf(char**, const w_char *, int wl, int, int);
148   int badcharkey_utf(char **, const w_char *, int wl, int, int);
149   int badchar_utf(char **, const w_char *, int wl, int, int);
150   int swapchar_utf(char **, const w_char *, int wl, int, int);
151   int longswapchar_utf(char **, const w_char *, int, int, int);
152   int movechar_utf(char **, const w_char *, int, int, int);
153
154   int mapchars(char**, const char *, int, int);
155   int map_related(const char *, char *, int, int, char ** wlst, int, int, const mapentry*, int, int *, clock_t *);
156   int ngram(int n, char * s1, const char * s2, int opt);
157   int mystrlen(const char * word);
158   int leftcommonsubstring(char * s1, const char * s2);
159   int commoncharacterpositions(char * s1, const char * s2, int * is_swap);
160   void bubblesort( char ** rwd, char ** rwd2, int * rsc, int n);
161   void lcs(const char * s, const char * s2, int * l1, int * l2, char ** result);
162   int lcslen(const char * s, const char* s2);
163   char * suggest_hentry_gen(hentry * rv, char * pattern);
164
165};
166
167#endif
168