diff --git a/lab2/dictionary.cc b/lab2/dictionary.cc index dc97b04..feaf66d 100644 --- a/lab2/dictionary.cc +++ b/lab2/dictionary.cc @@ -25,8 +25,8 @@ bool Dictionary::contains(const string &word) const { std::vector Dictionary::get_suggestions(const string &word) const { vector suggestions; add_trigram_suggestions(suggestions, word); - rank_suggestions(suggestions, word); trim_suggestions(suggestions, word); + rank_suggestions(suggestions, word); return suggestions; } @@ -123,6 +123,8 @@ int Dictionary::slurp(path p) { std::string line; while (std::getline(file, line)) { + if (line.empty()) + continue; // Words larger than max gets placed in the topmost bucket words[std::min(line.size(), static_cast(MAXLEN) - 1)].push_back( Word(line)); diff --git a/lab2/word.cc b/lab2/word.cc index c1f73f6..d4e4b48 100644 --- a/lab2/word.cc +++ b/lab2/word.cc @@ -30,11 +30,9 @@ Word::Word(const std::string &w) : word(w) { std::sort(triagrams.begin(), triagrams.end()); } -string Word::get_word() const { return string(); } +string Word::get_word() const { return word; } -vector Word::get_triagrams() const { - return triagrams; -} +vector Word::get_triagrams() const { return triagrams; } unsigned int Word::get_matches(const vector &t) const { unsigned int matches = 0; diff --git a/lab2/word.h b/lab2/word.h index eb927a2..6c9a0df 100644 --- a/lab2/word.h +++ b/lab2/word.h @@ -18,7 +18,7 @@ class Word { std::string get_word() const; /** Returns triagrams */ - std::vector get_triagrams() const; + std::vector get_triagrams() const; /** Returns how many of the trigrams in t that are present in this word's trigram vector */