From 4a02cefc939c8b35353927fa0276b267996902d5 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 11 Sep 2016 02:47:25 -0400 Subject: Removed legacy malaprop code --- malaprop.cpp | 137 ----------------------------------------------------------- 1 file changed, 137 deletions(-) delete mode 100644 malaprop.cpp (limited to 'malaprop.cpp') diff --git a/malaprop.cpp b/malaprop.cpp deleted file mode 100644 index ff0cb5d..0000000 --- a/malaprop.cpp +++ /dev/null @@ -1,137 +0,0 @@ -#include "malaprop.h" -#include -#include -#include -#include - -bool removeIfM(char c) -{ - return !isalpha(c); -} - -char soundID(char l) -{ - switch (l) - { - case 'b': - case 'f': - case 'p': - case 'v': - return '1'; - - case 'c': - case 'g': - case 'j': - case 'k': - case 'q': - case 's': - case 'x': - case 'z': - return '2'; - - case 'd': - case 't': - return '3'; - - case 'l': - return '4'; - - case 'm': - case 'n': - return '5'; - - case 'r': - return '6'; - } - - return l; -} - -std::string canonizetwo(std::string f) -{ - std::string canonical(f); - std::transform(canonical.begin(), canonical.end(), canonical.begin(), ::tolower); - - std::string result; - std::remove_copy_if(canonical.begin(), canonical.end(), std::back_inserter(result), removeIfM); - - return result; -} - -malaprop::soundex malaprop::soundify(std::string f) -{ - std::string result(canonizetwo(f)); - - soundex ex; - ex.prefix = result[0]; - - std::string output; - - for (int i = 1; i >::iterator it = dict.begin(); it != dict.end(); it++) - { - printf("%c%03d (%d): ", it->first.prefix, it->first.code, it->second.size()); - - for (std::set::iterator jt = it->second.begin(); jt != it->second.end(); jt++) - { - std::cout << *jt << ", "; - } - - std::cout << std::endl; - } - - exit(0); -} - -std::string malaprop::alternate(std::string word) -{ - soundex ex = soundify(word); - std::set& opts = dict[ex]; - if (opts.size() == 0) - { - return word; - } - - int opt = rand() % opts.size(); - for (std::set::iterator it = opts.begin(); it != opts.end(); it++) - { - if (opt == 0) - { - return *it; - } - - opt--; - } - - return word; -} -- cgit 1.4.1