Debian Codegraph @

backends/glass/glass_spelling.cc

raw symbols SCIP
1 /** @file
2 * @brief Spelling correction data for a glass database.
3 */
4 /* Copyright (C) 2004,2005,2006,2007,2008,2009,2010,2011,2015 Olly Betts
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <config.h>cxx . . $ `<file>/config.h`/
22
23 #include <xapian/error.h>cxx . . $ `<file>/include/xapian/error.h`/
24 #include <xapian/types.h>cxx . . $ `<file>/include/xapian/types.h`/
25
26 #include "expand/expandweight.h"cxx . . $ `<file>/expand/expandweight.h`/
27 #include "glass_spelling.h"cxx . . $ `<file>/backends/glass/glass_spelling.h`/
28 #include "omassert.h"cxx . . $ `<file>/common/omassert.h`/
29 #include "expand/ortermlist.h"cxx . . $ `<file>/expand/ortermlist.h`/
30 #include "pack.h"cxx . . $ `<file>/common/pack.h`/
31
32 #include "../prefix_compressed_strings.h"cxx . . $ `<file>/backends/prefix_compressed_strings.h`/
33
34 #include <algorithm>
35 #include <map>
36 #include <queue>
37 #include <vector>
38 #include <set>
39 #include <string>
40
41 using namespace Glass;
42 using namespace std;
43
44 void
45 GlassSpellingTablecxx . . $ GlassSpellingTable#::merge_changescxx . . $ GlassSpellingTable#merge_changes(49f6e7a06ebc5aa8).()
46 {
47 for (auto i : termlist_deltascxx . . $ GlassSpellingTable#termlist_deltas.) {
48 const stringcxx . . $ string#& key = i.firstcxx . . $ std/pair#first.;
49 const setcxx . . $ std/set#<stringcxx . . $ string#>& changes = i.secondcxx . . $ std/pair#second.;
50
51 auto d = changes.begincxx . . $ std/set#begin(3220b82c0db6d2a1).();
52 if (d ==cxx . . $ std/`operator==`(a84eb84a7a5e8237). changes.endcxx . . $ std/set#end(3220b82c0db6d2a1).()) continue;
53
54 stringcxx . . $ string# updatedcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).;
55 stringcxx . . $ string# currentcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).;
56 PrefixCompressedStringWritercxx . . $ PrefixCompressedStringWriter# outcxx . . $ PrefixCompressedStringWriter#PrefixCompressedStringWriter(80d0450aec2fd74).(updated);
57 if (get_exact_entrycxx . . $ GlassTable#get_exact_entry(6f76450b315e48b6).(key, current)) {
58 PrefixCompressedStringItorcxx . . $ PrefixCompressedStringItor# incxx . . $ PrefixCompressedStringItor#PrefixCompressedStringItor(9c546c94e5fcce4e).(current);
59 updated.reservecxx . . $ std/__cxx11/basic_string#reserve(9dac5f4bebd06212).(current.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).()); // FIXME plus some?
60 while (!in.at_endcxx . . $ PrefixCompressedStringItor#at_end(50ce9a9e25b4a850).() && d !=cxx . . $ std/`operator!=`(a84eb84a7a5e8237). changes.endcxx . . $ std/set#end(3220b82c0db6d2a1).()) {
61 const stringcxx . . $ string# & word = *cxx . . $ PrefixCompressedStringItor#`operator*`(f4fff0029955a25f).in;
62 Assertcxx . . $ `common/omassert.h:122:10`!(d != changes.end());
63 int cmp = word.comparecxx . . $ std/__cxx11/basic_string#compare(8f1500960b51eaf7).(*cxx . . $ std/_Rb_tree_const_iterator#`operator*`(2042464fc1fea03e).d);
64 if (cmp < 0) {
65 out.appendcxx . . $ PrefixCompressedStringWriter#append(9c546c94e5fcce4e).(word);
66 ++cxx . . $ PrefixCompressedStringItor#operator++(501cc6a9e6ec579b).in;
67 } else if (cmp > 0) {
68 out.appendcxx . . $ PrefixCompressedStringWriter#append(9c546c94e5fcce4e).(*cxx . . $ std/_Rb_tree_const_iterator#`operator*`(2042464fc1fea03e).d);
69 ++cxx . . $ std/_Rb_tree_const_iterator#operator++(9cb79ab07bb244bf).d;
70 } else {
71 // If an existing entry is in the changes list, that means
72 // we should remove it.
73 ++cxx . . $ PrefixCompressedStringItor#operator++(501cc6a9e6ec579b).in;
74 ++cxx . . $ std/_Rb_tree_const_iterator#operator++(9cb79ab07bb244bf).d;
75 }
76 }
77 if (!in.at_endcxx . . $ PrefixCompressedStringItor#at_end(50ce9a9e25b4a850).()) {
78 // FIXME : easy to optimise this to a fix-up and substring copy.
79 while (!in.at_endcxx . . $ PrefixCompressedStringItor#at_end(50ce9a9e25b4a850).()) {
80 out.appendcxx . . $ PrefixCompressedStringWriter#append(9c546c94e5fcce4e).(*cxx . . $ PrefixCompressedStringItor#`operator*`(f4fff0029955a25f).in++cxx . . $ PrefixCompressedStringItor#operator++(1f49990eb7d6da6a).);
81 }
82 }
83 }
84 while (d !=cxx . . $ std/`operator!=`(a84eb84a7a5e8237). changes.endcxx . . $ std/set#end(3220b82c0db6d2a1).()) {
85 out.appendcxx . . $ PrefixCompressedStringWriter#append(9c546c94e5fcce4e).(*cxx . . $ std/_Rb_tree_const_iterator#`operator*`(2042464fc1fea03e).d++cxx . . $ std/_Rb_tree_const_iterator#operator++(bc8647ccc78a993a).);
86 }
87 if (!updated.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) {
88 addcxx . . $ GlassTable#add(63deecd705778e94).(key, updated);
89 } else {
90 delcxx . . $ GlassTable#del(7c222eea44a24d43).(key);
91 }
92 }
93 termlist_deltascxx . . $ GlassSpellingTable#termlist_deltas..clearcxx . . $ std/map#clear(ced63f7c635d850d).();
94
95 mapcxx . . $ std/map#<string, Xapian::termcount>::const_iteratorcxx . . $ std/map#const_iterator# jcxx . . $ std/_Rb_tree_const_iterator#_Rb_tree_const_iterator(ced63f7c635d850d).;
96 for (j =cxx . . $ std/_Rb_tree_const_iterator#`operator=`(34333b2451d2a189). wordfreq_changescxx . . $ std/_Rb_tree_const_iterator#_Rb_tree_const_iterator(dc529b7882ffd73b)..begincxx . . $ std/map#begin(7e4de33083b6e738).(); j !=cxx . . $ std/`operator!=`(a84eb84a7a5e8237). wordfreq_changescxx . . $ std/_Rb_tree_const_iterator#_Rb_tree_const_iterator(dc529b7882ffd73b)..endcxx . . $ std/map#end(7e4de33083b6e738).(); ++cxx . . $ std/_Rb_tree_const_iterator#operator++(9cb79ab07bb244bf).j) {
97 stringcxx . . $ string# key = "W" +cxx . . $ std/operator+(42c652dfebe55ad7). j->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).firstcxx . . $ std/pair#first.;
98 Xapiancxx . . $ Xapian/::termcountcxx . . $ Xapian/termcount# wordfreq = j->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).secondcxx . . $ std/pair#second.;
99 if (wordfreq) {
100 stringcxx . . $ string# tagcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).;
101 pack_uint_lastcxx . . $ pack_uint_last(6c508de3dd6b8711).(tag, wordfreq);
102 addcxx . . $ GlassTable#add(63deecd705778e94).(key, tag);
103 if (wordfreq > wordfreq_upper_boundcxx . . $ GlassSpellingTable#wordfreq_upper_bound.)
104 wordfreq_upper_boundcxx . . $ GlassSpellingTable#wordfreq_upper_bound. = wordfreq;
105 } else {
106 delcxx . . $ GlassTable#del(7c222eea44a24d43).(key);
107 }
108 }
109 wordfreq_changescxx . . $ GlassSpellingTable#wordfreq_changes..clearcxx . . $ std/map#clear(ced63f7c635d850d).();
110 }
111
112 void
113 GlassSpellingTablecxx . . $ GlassSpellingTable#::toggle_fragmentcxx . . $ GlassSpellingTable#toggle_fragment(12206f91651e6267).(fragmentcxx . . $ Glass/fragment# frag, const stringcxx . . $ string# & word)
114 {
115 auto i = termlist_deltascxx . . $ GlassSpellingTable#termlist_deltas..findcxx . . $ std/map#find(36f8d56706583706).(frag);
116 if (i ==cxx . . $ std/`operator==`(be6a71a859368080). termlist_deltascxx . . $ GlassSpellingTable#termlist_deltas..endcxx . . $ std/map#end(7e4de33083b6e738).()) {
117 i =cxx . . $ std/_Rb_tree_iterator#`operator=`(3ed5e280ee84ce13). termlist_deltascxx . . $ GlassSpellingTable#termlist_deltas..insertcxx . . $ std/map#insert(92111883a3599ede).(make_paircxx . . $ std/make_pair(1d30b6e115203116).(frag, setcxx . . $ std/set#set(49f6e7a06ebc5aa8).<stringcxx . . $ string#>())).firstcxx . . $ std/pair#first.;
118 }
119 // The commonest case is that we're adding lots of words, so try insert
120 // first and if that reports that the word already exists, remove it.
121 auto res = i->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second..insertcxx . . $ std/set#insert(411a10a755068dfe).(word);
122 if (!res.secondcxx . . $ std/pair#second.) {
123 // word is already in the set, so remove it.
124 i->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second..erasecxx . . $ std/set#erase(36a7984e631cd3e9).(res.firstcxx . . $ std/pair#first.);
125 }
126 }
127
128 void
129 GlassSpellingTablecxx . . $ GlassSpellingTable#::add_wordcxx . . $ GlassSpellingTable#add_word(2a1b2e204ecf68f3).(const stringcxx . . $ string# & word, Xapiancxx . . $ Xapian/::termcountcxx . . $ Xapian/termcount# freqinc)
130 {
131 if (word.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() <= 1) return;
132
133 mapcxx . . $ std/map#<string, Xapian::termcount>::iteratorcxx . . $ std/map#iterator# i = wordfreq_changescxx . . $ GlassSpellingTable#wordfreq_changes..findcxx . . $ std/map#find(36f8d56706583706).(word);
134 if (i !=cxx . . $ std/`operator!=`(be6a71a859368080). wordfreq_changescxx . . $ GlassSpellingTable#wordfreq_changes..endcxx . . $ std/map#end(7e4de33083b6e738).()) {
135 // Word "word" already exists and has been modified.
136 if (i->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second.) {
137 i->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second. += freqinc;
138 return;
139 }
140 // If "word" is currently modified such that it no longer exists, so
141 // we need to execute the code below to re-add trigrams for it.
142 i->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second. = freqinc;
143 } else {
144 stringcxx . . $ string# key = "W" +cxx . . $ std/operator+(42c652dfebe55ad7). word;
145 stringcxx . . $ string# datacxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).;
146 if (get_exact_entrycxx . . $ GlassTable#get_exact_entry(6f76450b315e48b6).(key, data)) {
147 // Word "word" already exists, so increment its count.
148 Xapiancxx . . $ Xapian/::termcountcxx . . $ Xapian/termcount# freq;
149 const char * p = data.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).();
150 if (!unpack_uint_lastcxx . . $ unpack_uint_last(9620d6ecba0dad86).(&p, p + data.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).(), &freq) || freq == 0) {
151 throw Xapiancxx . . $ Xapian/::DatabaseCorruptErrorcxx . . $ Xapian/DatabaseCorruptError#("Bad spelling word freq"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
152 }
153 wordfreq_changescxx . . $ GlassSpellingTable#wordfreq_changes.[cxx . . $ std/map#`operator[]`(bbd415b616967878).word] = freq + freqinc;
154 return;
155 }
156 wordfreq_changescxx . . $ GlassSpellingTable#wordfreq_changes.[cxx . . $ std/map#`operator[]`(bbd415b616967878).word] = freqinc;
157 }
158
159 // Add trigrams for word.
160 toggle_wordcxx . . $ GlassSpellingTable#toggle_word(9c546c94e5fcce4e).(word);
161 }
162
163 void
164 GlassSpellingTablecxx . . $ GlassSpellingTable#::remove_wordcxx . . $ GlassSpellingTable#remove_word(2a1b2e204ecf68f3).(const stringcxx . . $ string# & word, Xapiancxx . . $ Xapian/::termcountcxx . . $ Xapian/termcount# freqdec)
165 {
166 if (word.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() <= 1) return;
167
168 mapcxx . . $ std/map#<string, Xapian::termcount>::iteratorcxx . . $ std/map#iterator# i = wordfreq_changescxx . . $ GlassSpellingTable#wordfreq_changes..findcxx . . $ std/map#find(36f8d56706583706).(word);
169 if (i !=cxx . . $ std/`operator!=`(be6a71a859368080). wordfreq_changescxx . . $ GlassSpellingTable#wordfreq_changes..endcxx . . $ std/map#end(7e4de33083b6e738).()) {
170 if (i->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second. == 0) {
171 // Word has already been deleted.
172 return;
173 }
174 // Word "word" exists and has been modified.
175 if (freqdec < i->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second.) {
176 i->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second. -= freqdec;
177 return;
178 }
179
180 // Mark word as deleted.
181 i->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second. = 0;
182 } else {
183 stringcxx . . $ string# key = "W" +cxx . . $ std/operator+(42c652dfebe55ad7). word;
184 stringcxx . . $ string# datacxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).;
185 if (!get_exact_entrycxx . . $ GlassTable#get_exact_entry(6f76450b315e48b6).(key, data)) {
186 // This word doesn't exist.
187 return;
188 }
189
190 Xapiancxx . . $ Xapian/::termcountcxx . . $ Xapian/termcount# freq;
191 const char *p = data.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).();
192 if (!unpack_uint_lastcxx . . $ unpack_uint_last(9620d6ecba0dad86).(&p, p + data.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).(), &freq)) {
193 throw Xapiancxx . . $ Xapian/::DatabaseCorruptErrorcxx . . $ Xapian/DatabaseCorruptError#("Bad spelling word freq"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
194 }
195 if (freqdec < freq) {
196 wordfreq_changescxx . . $ GlassSpellingTable#wordfreq_changes.[cxx . . $ std/map#`operator[]`(bbd415b616967878).word] = freq - freqdec;
197 return;
198 }
199 // Mark word as deleted.
200 wordfreq_changescxx . . $ GlassSpellingTable#wordfreq_changes.[cxx . . $ std/map#`operator[]`(bbd415b616967878).word] = 0;
201 }
202
203 // Remove trigrams for word.
204 toggle_wordcxx . . $ GlassSpellingTable#toggle_word(9c546c94e5fcce4e).(word);
205 }
206
207 void
208 GlassSpellingTablecxx . . $ GlassSpellingTable#::toggle_wordcxx . . $ GlassSpellingTable#toggle_word(9c546c94e5fcce4e).(const stringcxx . . $ string# & word)
209 {
210 fragmentcxx . . $ Glass/fragment# bufcxx . . $ Glass/fragment#fragment(49f6e7a06ebc5aa8).;
211 // Head:
212 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).0] = 'H';
213 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).1] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).0];
214 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).2] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).1];
215 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).3] = '\0';
216 toggle_fragmentcxx . . $ GlassSpellingTable#toggle_fragment(12206f91651e6267).(buf, word);
217
218 // Tail:
219 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).0] = 'T';
220 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).1] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).word.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() - 2];
221 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).2] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).word.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() - 1];
222 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).3] = '\0';
223 toggle_fragmentcxx . . $ GlassSpellingTable#toggle_fragment(12206f91651e6267).(buf, word);
224
225 if (word.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() <= 4) {
226 // We also generate 'bookends' for two, three, and four character
227 // terms so we can handle transposition of the middle two characters
228 // of a four character word, substitution or deletion of the middle
229 // character of a three character word, or insertion in the middle of a
230 // two character word.
231 // 'Bookends':
232 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).0] = 'B';
233 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).1] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).0];
234 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).3] = '\0';
235 toggle_fragmentcxx . . $ GlassSpellingTable#toggle_fragment(12206f91651e6267).(buf, word);
236 }
237 if (word.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() > 2) {
238 setcxx . . $ std/set#<fragmentcxx . . $ Glass/fragment#> donecxx . . $ std/set#set(49f6e7a06ebc5aa8).;
239 // Middles:
240 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).0] = 'M';
241 for (size_t start = 0; start <= word.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() - 3; ++start) {
242 memcpy(buf.datacxx . . $ Glass/fragment#data. + 1, word.datacxx . . $ std/__cxx11/basic_string#data(8e614c7de0b1573e).() + start, 3);
243 // Don't toggle the same fragment twice or it will cancel out.
244 // Bug fixed in 1.2.6.
245 if (done.insertcxx . . $ std/set#insert(411a10a755068dfe).(buf).secondcxx . . $ std/pair#second.)
246 toggle_fragmentcxx . . $ GlassSpellingTable#toggle_fragment(12206f91651e6267).(buf, word);
247 }
248 }
249 }
250
251 struct TermListGreaterApproxSizecxx . . $ TermListGreaterApproxSize# {
252 bool operatorcxx . . $ TermListGreaterApproxSize#`operator()`(9999d3620e4cfb97).()(const TermListcxx . . $ TermList# *a, const TermListcxx . . $ TermList# *b) const {
253 return a->get_approx_sizecxx . . $ Xapian/TermIterator#Internal#get_approx_size(ddd8539a2fcdd4ce).() > b->get_approx_sizecxx . . $ Xapian/TermIterator#Internal#get_approx_size(ddd8539a2fcdd4ce).();
254 }
255 };
256
257 TermListcxx . . $ TermList# *
258 GlassSpellingTablecxx . . $ GlassSpellingTable#::open_termlistcxx . . $ GlassSpellingTable#open_termlist(c2d075377a6ea65f).(const stringcxx . . $ string# & word)
259 {
260 // This should have been handled by Database::get_spelling_suggestion().
261 AssertRelcxx . . $ `common/omassert.h:123:10`!(word.size(),>,1);
262
263 // Merge any pending changes to disk, but don't call commit() so they
264 // won't be switched live.
265 if (!wordfreq_changescxx . . $ GlassSpellingTable#wordfreq_changes..emptycxx . . $ std/map#empty(3482b152b9333168).()) merge_changescxx . . $ GlassSpellingTable#merge_changes(49f6e7a06ebc5aa8).();
266
267 // Build a priority queue of TermList objects which returns those of
268 // greatest approximate size first.
269 priority_queuecxx . . $ std/priority_queue#<TermListcxx . . $ TermList#*, vectorcxx . . $ std/vector#<TermListcxx . . $ TermList#*>, TermListGreaterApproxSizecxx . . $ TermListGreaterApproxSize#> pqcxx . . $ std/priority_queue#priority_queue(49f6e7a06ebc5aa8).;
270 try {
271 stringcxx . . $ string# datacxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).;
272 fragmentcxx . . $ Glass/fragment# bufcxx . . $ Glass/fragment#fragment(49f6e7a06ebc5aa8).;
273
274 // Head:
275 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).0] = 'H';
276 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).1] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).0];
277 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).2] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).1];
278 if (get_exact_entrycxx . . $ GlassTable#get_exact_entry(6f76450b315e48b6).(stringcxx . . $ string#(buf), data))
279 pq.pushcxx . . $ std/priority_queue#push(bfe8a576267fe2ec).(new GlassSpellingTermListcxx . . $ GlassSpellingTermList#(data));
280
281 // Tail:
282 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).0] = 'T';
283 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).1] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).word.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() - 2];
284 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).2] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).word.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() - 1];
285 if (get_exact_entrycxx . . $ GlassTable#get_exact_entry(6f76450b315e48b6).(stringcxx . . $ string#(buf), data))
286 pq.pushcxx . . $ std/priority_queue#push(bfe8a576267fe2ec).(new GlassSpellingTermListcxx . . $ GlassSpellingTermList#(data));
287
288 if (word.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() <= 4) {
289 // We also generate 'bookends' for two, three, and four character
290 // terms so we can handle transposition of the middle two
291 // characters of a four character word, substitution or deletion of
292 // the middle character of a three character word, or insertion in
293 // the middle of a two character word.
294 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).0] = 'B';
295 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).1] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).0];
296 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).3] = '\0';
297 if (get_exact_entrycxx . . $ GlassTable#get_exact_entry(6f76450b315e48b6).(stringcxx . . $ string#(buf), data))
298 pq.pushcxx . . $ std/priority_queue#push(bfe8a576267fe2ec).(new GlassSpellingTermListcxx . . $ GlassSpellingTermList#(data));
299 }
300 if (word.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() > 2) {
301 // Middles:
302 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).0] = 'M';
303 for (size_t start = 0; start <= word.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() - 3; ++start) {
304 memcpy(buf.datacxx . . $ Glass/fragment#data. + 1, word.datacxx . . $ std/__cxx11/basic_string#data(8e614c7de0b1573e).() + start, 3);
305 if (get_exact_entrycxx . . $ GlassTable#get_exact_entry(6f76450b315e48b6).(stringcxx . . $ string#(buf), data))
306 pq.pushcxx . . $ std/priority_queue#push(bfe8a576267fe2ec).(new GlassSpellingTermListcxx . . $ GlassSpellingTermList#(data));
307 }
308
309 if (word.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() == 3) {
310 // For three letter words, we generate the two "single
311 // transposition" forms too, so that we can produce good
312 // spelling suggestions.
313 // ABC -> BAC
314 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).1] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).1];
315 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).2] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).0];
316 if (get_exact_entrycxx . . $ GlassTable#get_exact_entry(6f76450b315e48b6).(stringcxx . . $ string#(buf), data))
317 pq.pushcxx . . $ std/priority_queue#push(bfe8a576267fe2ec).(new GlassSpellingTermListcxx . . $ GlassSpellingTermList#(data));
318 // ABC -> ACB
319 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).1] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).0];
320 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).2] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).2];
321 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).3] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).1];
322 if (get_exact_entrycxx . . $ GlassTable#get_exact_entry(6f76450b315e48b6).(stringcxx . . $ string#(buf), data))
323 pq.pushcxx . . $ std/priority_queue#push(bfe8a576267fe2ec).(new GlassSpellingTermListcxx . . $ GlassSpellingTermList#(data));
324 }
325 } else {
326 Assertcxx . . $ `common/omassert.h:122:10`!(word.size() == 2);
327 // For two letter words, we generate H and T terms for the
328 // transposed form so that we can produce good spelling
329 // suggestions.
330 // AB -> BA
331 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).0] = 'H';
332 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).1] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).1];
333 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).2] = word[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).0];
334 if (get_exact_entrycxx . . $ GlassTable#get_exact_entry(6f76450b315e48b6).(stringcxx . . $ string#(buf), data))
335 pq.pushcxx . . $ std/priority_queue#push(bfe8a576267fe2ec).(new GlassSpellingTermListcxx . . $ GlassSpellingTermList#(data));
336 buf[cxx . . $ Glass/fragment#`operator[]`(584c111b47189dd).0] = 'T';
337 if (get_exact_entrycxx . . $ GlassTable#get_exact_entry(6f76450b315e48b6).(stringcxx . . $ string#(buf), data))
338 pq.pushcxx . . $ std/priority_queue#push(bfe8a576267fe2ec).(new GlassSpellingTermListcxx . . $ GlassSpellingTermList#(data));
339 }
340
341 if (pq.emptycxx . . $ std/priority_queue#empty(50ce9a9e25b4a850).()) return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
342
343 // Build up an OrTermList tree by combine leaves and/or branches in
344 // pairs. The tree is balanced by the approximated sizes of the leaf
345 // GlassSpellingTermList objects - the way the tree is built are very
346 // similar to how an optimal Huffman code is often constructed.
347 //
348 // Balancing the tree like this should tend to minimise the amount of
349 // work done.
350 while (pq.sizecxx . . $ std/priority_queue#size(71e6dd9020568ee8).() > 1) {
351 // Build the tree such that left is always >= right so that
352 // OrTermList can rely on this when trying to minimise work.
353 TermListcxx . . $ TermList# * termlist = pq.topcxx . . $ std/priority_queue#top(f3460657e6fa9e6a).();
354 pq.popcxx . . $ std/priority_queue#pop(49f6e7a06ebc5aa8).();
355
356 termlist = new OrTermListcxx . . $ OrTermList#(pq.topcxx . . $ std/priority_queue#top(f3460657e6fa9e6a).(), termlist);
357 pq.popcxx . . $ std/priority_queue#pop(49f6e7a06ebc5aa8).();
358 pq.pushcxx . . $ std/priority_queue#push(5cd2eaf705c8bad3).(termlist);
359 }
360
361 return pq.topcxx . . $ std/priority_queue#top(f3460657e6fa9e6a).();
362 } catch (...) {
363 // Make sure we delete all the TermList objects to avoid leaking
364 // memory.
365 while (!pq.emptycxx . . $ std/priority_queue#empty(50ce9a9e25b4a850).()) {
366 delete pq.topcxx . . $ std/priority_queue#top(f3460657e6fa9e6a).();
367 pq.popcxx . . $ std/priority_queue#pop(49f6e7a06ebc5aa8).();
368 }
369 throw;
370 }
371 }
372
373 Xapiancxx . . $ Xapian/::doccountcxx . . $ Xapian/doccount#
374 GlassSpellingTablecxx . . $ GlassSpellingTable#::get_word_frequencycxx . . $ GlassSpellingTable#get_word_frequency(f0a3e59d959dd0c2).(const stringcxx . . $ string# & word) const
375 {
376 mapcxx . . $ std/map#<string, Xapian::termcount>::const_iteratorcxx . . $ std/map#const_iterator# icxx . . $ std/_Rb_tree_const_iterator#_Rb_tree_const_iterator(ced63f7c635d850d).;
377 i =cxx . . $ std/_Rb_tree_const_iterator#`operator=`(34333b2451d2a189). wordfreq_changescxx . . $ GlassSpellingTable#wordfreq_changes..findcxx . . $ std/map#find(7b3585bb5da8f7d).(word);
378 if (i !=cxx . . $ std/`operator!=`(a84eb84a7a5e8237). wordfreq_changescxx . . $ GlassSpellingTable#wordfreq_changes..endcxx . . $ std/map#end(b953fec338ad1a3b).()) {
379 // Modified frequency for word:
380 return i->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).secondcxx . . $ std/pair#second.;
381 }
382
383 stringcxx . . $ string# key = "W" +cxx . . $ std/operator+(42c652dfebe55ad7). word;
384 stringcxx . . $ string# datacxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).;
385 if (get_exact_entrycxx . . $ GlassTable#get_exact_entry(6f76450b315e48b6).(key, data)) {
386 // Word "word" already exists.
387 Xapiancxx . . $ Xapian/::termcountcxx . . $ Xapian/termcount# freq;
388 const char *p = data.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).();
389 if (!unpack_uint_lastcxx . . $ unpack_uint_last(9620d6ecba0dad86).(&p, p + data.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).(), &freq)) {
390 throw Xapiancxx . . $ Xapian/::DatabaseCorruptErrorcxx . . $ Xapian/DatabaseCorruptError#("Bad spelling word freq"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
391 }
392 return freq;
393 }
394
395 return 0;
396 }
397
398 ///////////////////////////////////////////////////////////////////////////
399
400 Xapiancxx . . $ Xapian/::termcountcxx . . $ Xapian/termcount#
401 GlassSpellingTermListcxx . . $ GlassSpellingTermList#::get_approx_sizecxx . . $ GlassSpellingTermList#get_approx_size(ddd8539a2fcdd4ce).() const
402 {
403 // This is only used to decide how to build a OR-tree of TermList objects
404 // so we just need to return "sizes" which are ordered roughly correctly.
405 return datacxx . . $ GlassSpellingTermList#data..sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).();
406 }
407
408 stdcxx . . $ std/::stringcxx . . $ std/string#
409 GlassSpellingTermListcxx . . $ GlassSpellingTermList#::get_termnamecxx . . $ GlassSpellingTermList#get_termname(219584694fe2b248).() const
410 {
411 return current_termcxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).;
412 }
413
414 Xapiancxx . . $ Xapian/::termcountcxx . . $ Xapian/termcount#
415 GlassSpellingTermListcxx . . $ GlassSpellingTermList#::get_wdfcxx . . $ GlassSpellingTermList#get_wdf(ddd8539a2fcdd4ce).() const
416 {
417 return 1;
418 }
419
420 Xapiancxx . . $ Xapian/::doccountcxx . . $ Xapian/doccount#
421 GlassSpellingTermListcxx . . $ GlassSpellingTermList#::get_termfreqcxx . . $ GlassSpellingTermList#get_termfreq(ddd8539a2fcdd4ce).() const
422 {
423 return 1;
424 }
425
426 TermListcxx . . $ TermList# *
427 GlassSpellingTermListcxx . . $ GlassSpellingTermList#::nextcxx . . $ GlassSpellingTermList#next(cd86c745428e820f).()
428 {
429 if (pcxx . . $ GlassSpellingTermList#p. == datacxx . . $ GlassSpellingTermList#data..sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).()) {
430 pcxx . . $ GlassSpellingTermList#p. = 0;
431 datacxx . . $ GlassSpellingTermList#data..resizecxx . . $ std/__cxx11/basic_string#resize(9dac5f4bebd06212).(0);
432 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
433 }
434 if (!current_termcxx . . $ GlassSpellingTermList#current_term..emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) {
435 current_termcxx . . $ GlassSpellingTermList#current_term..resizecxx . . $ std/__cxx11/basic_string#resize(9dac5f4bebd06212).(uint8_tcxx . . $ uint8_t#(datacxx . . $ GlassSpellingTermList#data.[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).pcxx . . $ GlassSpellingTermList#p.++]) ^ MAGIC_XOR_VALUEcxx . . $ `backends/prefix_compressed_strings.h:34:9`!);
436 }
437 size_t add;
438 if (pcxx . . $ GlassSpellingTermList#p. == datacxx . . $ GlassSpellingTermList#data..sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() ||
439 (add = uint8_tcxx . . $ uint8_t#(datacxx . . $ GlassSpellingTermList#data.[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).pcxx . . $ GlassSpellingTermList#p.]) ^ MAGIC_XOR_VALUEcxx . . $ `backends/prefix_compressed_strings.h:34:9`!) >= datacxx . . $ GlassSpellingTermList#data..sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() - pcxx . . $ GlassSpellingTermList#p.)
440 throw Xapiancxx . . $ Xapian/::DatabaseCorruptErrorcxx . . $ Xapian/DatabaseCorruptError#("Bad spelling termlist"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
441 current_termcxx . . $ GlassSpellingTermList#current_term..appendcxx . . $ std/__cxx11/basic_string#append(4f422887dc0eafa2).(datacxx . . $ GlassSpellingTermList#data..datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).() + pcxx . . $ GlassSpellingTermList#p. + 1, add);
442 pcxx . . $ GlassSpellingTermList#p. += add + 1;
443 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
444 }
445
446 TermListcxx . . $ TermList# *
447 GlassSpellingTermListcxx . . $ GlassSpellingTermList#::skip_tocxx . . $ GlassSpellingTermList#skip_to(c2d075377a6ea65f).(const stringcxx . . $ string# & term)
448 {
449 while (!datacxx . . $ GlassSpellingTermList#data..emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).() && current_termcxx . . $ GlassSpellingTermList#current_term. <cxx . . $ std/`operator<`(5ea818b58063a774). term) {
450 (void)GlassSpellingTermListcxx . . $ GlassSpellingTermList#::nextcxx . . $ GlassSpellingTermList#next(cd86c745428e820f).();
451 }
452 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
453 }
454
455 bool
456 GlassSpellingTermListcxx . . $ GlassSpellingTermList#::at_endcxx . . $ GlassSpellingTermList#at_end(50ce9a9e25b4a850).() const
457 {
458 return datacxx . . $ GlassSpellingTermList#data..emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).();
459 }
460
461 Xapiancxx . . $ Xapian/::termcountcxx . . $ Xapian/termcount#
462 GlassSpellingTermListcxx . . $ GlassSpellingTermList#::positionlist_countcxx . . $ GlassSpellingTermList#positionlist_count(ddd8539a2fcdd4ce).() const
463 {
464 throw Xapiancxx . . $ Xapian/::UnimplementedErrorcxx . . $ Xapian/UnimplementedError#("GlassSpellingTermList::positionlist_count() not implemented"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
465 }
466
467 Xapiancxx . . $ Xapian/::PositionIteratorcxx . . $ Xapian/PositionIterator#
468 GlassSpellingTermListcxx . . $ GlassSpellingTermList#::positionlist_begincxx . . $ GlassSpellingTermList#positionlist_begin(1ab6e7e44dfdf8aa).() const
469 {
470 throw Xapiancxx . . $ Xapian/::UnimplementedErrorcxx . . $ Xapian/UnimplementedError#("GlassSpellingTermList::positionlist_begin() not implemented"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
471 }