/src/aspell/modules/speller/default/affix.hpp
Line | Count | Source |
1 | | // This file is part of The New Aspell |
2 | | // Copyright (C) 2004 by Kevin Atkinson under the GNU LGPL |
3 | | // license version 2.0 or 2.1. You should have received a copy of the |
4 | | // LGPL license along with this library if you did not you can find it |
5 | | // at http://www.gnu.org/. |
6 | | // |
7 | | // Copyright 2002 Kevin B. Hendricks, Stratford, Ontario, Canada And |
8 | | // Contributors. All rights reserved. |
9 | | // |
10 | | |
11 | | #ifndef ASPELL_AFFIX__HPP |
12 | | #define ASPELL_AFFIX__HPP |
13 | | |
14 | | #include "posib_err.hpp" |
15 | | #include "wordinfo.hpp" |
16 | | #include "fstream.hpp" |
17 | | #include "parm_string.hpp" |
18 | | #include "simple_string.hpp" |
19 | | #include "char_vector.hpp" |
20 | | #include "objstack.hpp" |
21 | | |
22 | 3.14M | #define SETSIZE 256 |
23 | | #define MAXAFFIXES 256 |
24 | | #define MAXWORDLEN 255 |
25 | 77.5M | #define XPRODUCT (1 << 0) |
26 | | |
27 | | #define MAXLNLEN 1024 |
28 | | |
29 | 81.3k | #define TESTAFF( a , b) strchr(a, b) |
30 | | |
31 | | namespace acommon { |
32 | | class Config; |
33 | | struct CheckInfo; |
34 | | struct Conv; |
35 | | } |
36 | | |
37 | | namespace aspeller { |
38 | | |
39 | | using namespace acommon; |
40 | | |
41 | | class Language; |
42 | | |
43 | | class SpellerImpl; |
44 | | using acommon::CheckInfo; |
45 | | struct GuessInfo; |
46 | | |
47 | | struct LookupInfo; |
48 | | struct AffEntry; |
49 | | struct PfxEntry; |
50 | | struct SfxEntry; |
51 | | |
52 | | struct WordAff |
53 | | { |
54 | | SimpleString word; |
55 | | const unsigned char * aff; |
56 | | WordAff * next; |
57 | | }; |
58 | | |
59 | | enum CheckAffixRes {InvalidAffix, InapplicableAffix, ValidAffix}; |
60 | | |
61 | | class AffixMgr |
62 | | { |
63 | | const Language * lang; |
64 | | |
65 | | PfxEntry * pStart[SETSIZE]; |
66 | | SfxEntry * sStart[SETSIZE]; |
67 | | PfxEntry * pFlag[SETSIZE]; |
68 | | SfxEntry * sFlag[SETSIZE]; |
69 | | |
70 | | int max_strip_f[SETSIZE]; |
71 | | int max_strip_; |
72 | | |
73 | | const char * encoding; |
74 | | //const char * compound; |
75 | | //int cpdmin; |
76 | | |
77 | | ObjStack data_buf; |
78 | | |
79 | | const char * affix_file; |
80 | | |
81 | | public: |
82 | | |
83 | | AffixMgr(const Language * l); |
84 | | ~AffixMgr(); |
85 | | |
86 | 0 | unsigned int max_strip() const {return max_strip_;} |
87 | | |
88 | | PosibErr<void> setup(ParmString affpath, Conv &); |
89 | | |
90 | | bool affix_check(const LookupInfo &, ParmString, CheckInfo &, GuessInfo *) const; |
91 | | bool prefix_check(const LookupInfo &, ParmString, CheckInfo &, GuessInfo *, |
92 | | bool cross = true) const; |
93 | | bool suffix_check(const LookupInfo &, ParmString, CheckInfo &, GuessInfo *, |
94 | | int sfxopts, AffEntry* ppfx) const; |
95 | | |
96 | | void munch(ParmString word, GuessInfo *, bool cross = true) const; |
97 | | |
98 | | // None of the expand methods reset the objstack |
99 | | |
100 | | WordAff * expand(ParmString word, ParmString aff, |
101 | | ObjStack &, int limit = INT_MAX) const; |
102 | | |
103 | | CheckAffixRes check_affix(ParmString word, char aff) const; |
104 | | |
105 | | WordAff * expand_prefix(ParmString word, ParmString aff, |
106 | | ObjStack & buf) const |
107 | 0 | { |
108 | 0 | return expand(word,aff,buf,0); |
109 | 0 | } |
110 | | WordAff * expand_suffix(ParmString word, const unsigned char * aff, |
111 | | ObjStack &, int limit = INT_MAX, |
112 | | unsigned char * new_aff = 0, WordAff * * * l = 0, |
113 | | ParmString orig_word = 0) const; |
114 | | |
115 | | private: |
116 | | PosibErr<void> parse_file(const char * affpath, Conv &); |
117 | | |
118 | | PosibErr<void> build_pfxlist(PfxEntry* pfxptr); |
119 | | PosibErr<void> build_sfxlist(SfxEntry* sfxptr); |
120 | | PosibErr<void> process_pfx_order(); |
121 | | PosibErr<void> process_sfx_order(); |
122 | | }; |
123 | | |
124 | | PosibErr<AffixMgr *> new_affix_mgr(ParmString name, |
125 | | Conv &, |
126 | | const Language * lang); |
127 | | } |
128 | | |
129 | | #endif |
130 | | |