diff --git a/lab2/dictionary.cc b/lab2/dictionary.cc index d4658e8..1ce7578 100644 --- a/lab2/dictionary.cc +++ b/lab2/dictionary.cc @@ -46,7 +46,7 @@ int Dictionary::spit(path p) { return 1; } - for (int a = 0; a < 25; a++) { + for (int a = 0; a < MAXLEN; a++) { for (auto &word : words[a]) { std::vector trias = get_trigrams(word.get_word()); file << word << " " << trias.size(); @@ -74,6 +74,8 @@ int Dictionary::slurp(path p) { std::string line; while (std::getline(file, line)) { + if (line.size() > MAXLEN) + continue; words[line.size()].push_back(Word(line, get_trigrams(line))); } diff --git a/lab2/dictionary.h b/lab2/dictionary.h index e543011..a9c5519 100644 --- a/lab2/dictionary.h +++ b/lab2/dictionary.h @@ -6,6 +6,8 @@ #include #include +#define MAXLEN 30 + using std::vector; using std::filesystem::path; @@ -18,7 +20,7 @@ class Dictionary { int spit(path p); private: - vector words[25]; + vector words[MAXLEN]; }; #endif diff --git a/lab2/spell.cc b/lab2/spell.cc index 04c3d39..1d00838 100644 --- a/lab2/spell.cc +++ b/lab2/spell.cc @@ -31,7 +31,7 @@ int main() { Dictionary dict; string word; dict.slurp(std::filesystem::path("/usr/share/dict/words")); - // dict.spit(std::filesystem::path("words.txt")); + dict.spit(std::filesystem::path("words.txt")); // while (cin >> word) { // transform(word.begin(), word.end(), word.begin(), ::tolower); diff --git a/lab2/word.h b/lab2/word.h index 7d07c8b..7c1fd5b 100644 --- a/lab2/word.h +++ b/lab2/word.h @@ -20,6 +20,6 @@ class Word { private: const std::string word; - const std::vector triagrams; + std::vector triagrams; friend std::ostream &operator<<(std::ostream &out, const Word &o); };