diff options
author | Kshitij Bansal <kshitij@cs.nyu.edu> | 2014-04-28 14:11:14 -0400 |
---|---|---|
committer | Kshitij Bansal <kshitij@cs.nyu.edu> | 2014-04-28 14:11:14 -0400 |
commit | c28d0a243dbfd4295f785a017890251bd2670ce8 (patch) | |
tree | 58b7c8ef04cc14563129017d9c2c8717f400825d /src/util/didyoumean.h | |
parent | 6f6703473ccc66b3d2bdefed688602f93d33cd8f (diff) | |
parent | ca423e291b1f7d67e1a325bb6d98663d6c0690c7 (diff) |
Merge pull request #25 from kbansal/sets
Sets
Diffstat (limited to 'src/util/didyoumean.h')
-rw-r--r-- | src/util/didyoumean.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/util/didyoumean.h b/src/util/didyoumean.h new file mode 100644 index 000000000..2907fcece --- /dev/null +++ b/src/util/didyoumean.h @@ -0,0 +1,49 @@ +/********************* */ +/*! \file didyoumean.h + ** \verbatim + ** Original author: Kshitij Bansal + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2014 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief did-you-mean style suggestions. + ** + ** ``What do you mean? I don't understand.'' An attempt to be more + ** helpful than that. Similar to one in git. + ** + ** There are no dependencies on CVC4, intentionally. + **/ + +#pragma once + +#include <vector> +#include <set> +#include <string> + +class DidYouMean { + typedef std::set<std::string> Words; + Words d_words; + +public: + DidYouMean() {} + ~DidYouMean() {} + + DidYouMean(Words words) : d_words(words) {} + + void addWord(std::string word) { + d_words.insert(word); + } + + std::vector<std::string> getMatch(std::string input); + + /** + * This is provided to make it easier to ensure consistency of + * output. Returned string is empty if there are no matches. + */ + std::string getMatchAsString(std::string input, int prefixNewLines = 2, int suffixNewLines = 0); +private: + int editDistance(const std::string& a, const std::string& b); +}; |