项目作者: victor-istomin

项目描述 :
Incremental search, spell checker and Optimal String Alignment distance implementation in C++
高级语言: C++
项目地址: git://github.com/victor-istomin/incrementalSpellCheck.git
创建时间: 2018-01-12T09:16:23Z
项目社区:https://github.com/victor-istomin/incrementalSpellCheck

开源协议:MIT License

下载


Incremental search and spell checker in C++

This is C++ header-only implementation of incremental search within a list of captions (menu, articles, etc) with misprint corrections support.

Demo

./test -i

Contents

Usage

  1. #include "incrementalSearch.hpp"
  2. void f()
  3. {
  4. std::vector<std::string> listOfTopics = {...};
  5. IncrementalSearch search { listOfTopics };
  6. const std::string& closestMatchedTopic = search.search('misprint');
  7. }
  8. // or:
  9. #include "spellCheck.hpp"
  10. void g()
  11. {
  12. const char* textCorpus[] = {"one two, three", "Four.Five", "verylongword"};
  13. SpellCheck speller { textCorpus };
  14. const size_t maxCount = 2;
  15. auto corrections = speller.getCorrections("tree", maxCount); // "three"
  16. auto incrementalCorrections = speller.getCorrections("_ery", maxCount, true); // "_ery" -> "very.*" -> "verylongword"
  17. }
  18. void h()
  19. {
  20. SpellCheck::getSmartDistance("abcde", "abc"); // == 2
  21. SpellCheck::getSmartDistance(CString("abcde"), std::string("abcd"));
  22. SpellCheck::getSmartDistance("abcde", "abc", true/*incremental*/); // == 0, "abc" -> "abc.*" -> "abcde"
  23. }

Supported compilers

C++ 14 with at least partial expression SFINAE is needed. Testsed on:

  • Visual Studio 2015 update 3
  • gcc 7.2

    See test.cpp for more detailed examples.