#include "dictionary.h" #include "word.h" #include #include #include #include #include #include using std::string; using std::vector; Dictionary::Dictionary() {} bool Dictionary::contains(const string &word) const { int l = word.length(); Word w = Word(word); if (std::find(this->words[l].begin(), this->words[l].end(), w) != std::end(this->words[l])) { return true; } return false; } vector Dictionary::get_suggestions(const string &word) const { vector suggestions; // add_trigram_suggestions(suggestions, word); // rank_suggestions(suggestions, word); // trim_suggestions(suggestions); return suggestions; } int Dictionary::spit(path p) { std::ofstream file(p); if (!file.is_open()) { std::cerr << "Error opening file! " << std::endl; return 1; } for (int a = 0; a < MAXLEN; a++) { for (auto &word : words[a]) { file << word; file << std::endl; } } file.flush(); file.close(); return 0; } int Dictionary::slurp(path p) { std::ifstream file(p.string()); if (!file.is_open()) { std::cerr << "Error opening file! " << std::endl; return 1; } std::string line; while (std::getline(file, line)) { if (line.size() > MAXLEN) continue; words[line.size()].push_back(Word(line)); } file.close(); return 0; }