Tizen 2.1 base
[external/enchant.git] / src / myspell / hunspell.hxx
1 #include "hunvisapi.h"
2
3 #include "hashmgr.hxx"
4 #include "affixmgr.hxx"
5 #include "suggestmgr.hxx"
6 #include "langnum.hxx"
7
8 #define  SPELL_XML "<?xml?>"
9
10 #define MAXDIC 20
11 #define MAXSUGGESTION 15
12 #define MAXSHARPS 5
13
14 #define HUNSPELL_OK       (1 << 0)
15 #define HUNSPELL_OK_WARN  (1 << 1)
16
17 #ifndef _MYSPELLMGR_HXX_
18 #define _MYSPELLMGR_HXX_
19
20 class LIBHUNSPELL_DLL_EXPORTED Hunspell
21 {
22   AffixMgr*       pAMgr;
23   HashMgr*        pHMgr[MAXDIC];
24   int             maxdic;
25   SuggestMgr*     pSMgr;
26   char *          affixpath;
27   char *          encoding;
28   struct cs_info * csconv;
29   int             langnum;
30   int             utf8;
31   int             complexprefixes;
32   char**          wordbreak;
33
34 public:
35
36   /* Hunspell(aff, dic) - constructor of Hunspell class
37    * input: path of affix file and dictionary file
38    */
39
40   Hunspell(const char * affpath, const char * dpath, const char * key = NULL);
41   ~Hunspell();
42
43   /* load extra dictionaries (only dic files) */
44   int add_dic(const char * dpath, const char * key = NULL);
45
46   /* spell(word) - spellcheck word
47    * output: 0 = bad word, not 0 = good word
48    *   
49    * plus output:
50    *   info: information bit array, fields:
51    *     SPELL_COMPOUND  = a compound word 
52    *     SPELL_FORBIDDEN = an explicit forbidden word
53    *   root: root (stem), when input is a word with affix(es)
54    */
55    
56   int spell(const char * word, int * info = NULL, char ** root = NULL);
57
58   /* suggest(suggestions, word) - search suggestions
59    * input: pointer to an array of strings pointer and the (bad) word
60    *   array of strings pointer (here *slst) may not be initialized
61    * output: number of suggestions in string array, and suggestions in
62    *   a newly allocated array of strings (*slts will be NULL when number
63    *   of suggestion equals 0.)
64    */
65
66   int suggest(char*** slst, const char * word);
67
68   /* deallocate suggestion lists */
69
70   void free_list(char *** slst, int n);
71
72   char * get_dic_encoding();
73
74  /* morphological functions */
75
76  /* analyze(result, word) - morphological analysis of the word */
77  
78   int analyze(char*** slst, const char * word);
79
80  /* stem(result, word) - stemmer function */
81   
82   int stem(char*** slst, const char * word);
83   
84  /* stem(result, analysis, n) - get stems from a morph. analysis
85   * example:
86   * char ** result, result2;
87   * int n1 = analyze(&result, "words");
88   * int n2 = stem(&result2, result, n1);   
89   */
90  
91   int stem(char*** slst, char ** morph, int n);
92
93  /* generate(result, word, word2) - morphological generation by example(s) */
94
95   int generate(char*** slst, const char * word, const char * word2);
96
97  /* generate(result, word, desc, n) - generation by morph. description(s)
98   * example:
99   * char ** result;
100   * char * affix = "is:plural"; // description depends from dictionaries, too
101   * int n = generate(&result, "word", &affix, 1);
102   * for (int i = 0; i < n; i++) printf("%s\n", result[i]);
103   */
104
105   int generate(char*** slst, const char * word, char ** desc, int n);
106
107   /* functions for run-time modification of the dictionary */
108
109   /* add word to the run-time dictionary */
110   
111   int add(const char * word);
112
113   /* add word to the run-time dictionary with affix flags of
114    * the example (a dictionary word): Hunspell will recognize
115    * affixed forms of the new word, too.
116    */
117   
118   int add_with_affix(const char * word, const char * example);
119
120   /* remove word from the run-time dictionary */
121
122   int remove(const char * word);
123
124   /* other */
125
126   /* get extra word characters definied in affix file for tokenization */
127   const char * get_wordchars();
128   unsigned short * get_wordchars_utf16(int * len);
129
130   struct cs_info * get_csconv();
131   const char * get_version();
132
133   int get_langnum() const;
134   
135   /* experimental and deprecated functions */
136
137 #ifdef HUNSPELL_EXPERIMENTAL
138   /* suffix is an affix flag string, similarly in dictionary files */  
139   int put_word_suffix(const char * word, const char * suffix);
140   char * morph_with_correction(const char * word);
141
142   /* spec. suggestions */
143   int suggest_auto(char*** slst, const char * word);
144   int suggest_pos_stems(char*** slst, const char * word);
145 #endif
146
147 private:
148    int    cleanword(char *, const char *, int * pcaptype, int * pabbrev);
149    int    cleanword2(char *, const char *, w_char *, int * w_len, int * pcaptype, int * pabbrev);
150    void   mkinitcap(char *);
151    int    mkinitcap2(char * p, w_char * u, int nc);
152    int    mkinitsmall2(char * p, w_char * u, int nc);
153    void   mkallcap(char *);
154    int    mkallcap2(char * p, w_char * u, int nc);
155    void   mkallsmall(char *);
156    int    mkallsmall2(char * p, w_char * u, int nc);
157    struct hentry * checkword(const char *, int * info, char **root);
158    char * sharps_u8_l1(char * dest, char * source);
159    hentry * spellsharps(char * base, char *, int, int, char * tmp, int * info, char **root);
160    int    is_keepcase(const hentry * rv);
161    int    insert_sug(char ***slst, char * word, int ns);
162    void   cat_result(char * result, char * st);
163    char * stem_description(const char * desc);
164    int    spellml(char*** slst, const char * word);
165    int    get_xml_par(char * dest, const char * par, int maxl);
166    const char * get_xml_pos(const char * s, const char * attr);
167    int    get_xml_list(char ***slst, char * list, const char * tag);
168    int    check_xml_par(const char * q, const char * attr, const char * value);
169
170 };
171
172 #endif