labs-edaf30/lab2/spell.cc
2024-11-20 17:46:21 +01:00

41 lines
1 KiB
C++

#include "dictionary.h"
#include <cctype>
#include <filesystem>
#include <iostream>
#include <string>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
void check_word(const string &word, const Dictionary &dict) {
if (dict.contains(word)) {
cout << "Correct." << endl;
} else {
vector<string> suggestions = dict.get_suggestions(word);
if (suggestions.empty()) {
cout << "Wrong, no suggestions." << endl;
} else {
cout << "Wrong. Suggestions:" << endl;
for (const auto &w : suggestions) {
cout << " " << w << endl;
}
}
}
}
int main() {
Dictionary dict;
string word;
dict.slurp(std::filesystem::path("/usr/share/dict/words"));
// dict.spit(std::filesystem::path("words.txt"));
// while (cin >> word) {
// transform(word.begin(), word.end(), word.begin(), ::tolower);
// check_word(word, dict);
// }
return 0;
}