| 261 | } |
| 262 | |
| 263 | bool SymSpell::BuildDeletesWords(const std::string &key) { |
| 264 | //edits/suggestions are created only once, no matter how often word occurs |
| 265 | //edits/suggestions are created only as soon as the word occurs in the corpus, |
| 266 | //even if the same term existed before in the dictionary as an edit from another word |
| 267 | if (key.size() > _maxDictionaryWordLength) { |
| 268 | _maxDictionaryWordLength = key.size(); |
| 269 | } |
| 270 | //create deletes |
| 271 | auto edits = EditsPrefix(key); |
| 272 | for (auto it = edits.begin(); it != edits.end(); ++it) { |
| 273 | int deleteHash = GetStringHash(*it); |
| 274 | auto deletesFounded = _deletes.find(deleteHash); |
| 275 | if (deletesFounded != _deletes.end()) { |
| 276 | auto &suggestions = deletesFounded->second; |
| 277 | suggestions.emplace_back(key); |
| 278 | } else { |
| 279 | std::vector<std::string> suggestions = {key}; |
| 280 | |
| 281 | _deletes.insert({deleteHash, suggestions}); |
| 282 | } |
| 283 | } |
| 284 | return true; |
| 285 | } |
| 286 | |
| 287 | bool SymSpell::BuildAllDeletesWords() { |
| 288 | bool ret = true; |