diff --git a/lab2/dictionary.cc b/lab2/dictionary.cc index ac522ff..2e999c8 100644 --- a/lab2/dictionary.cc +++ b/lab2/dictionary.cc @@ -35,14 +35,14 @@ void Dictionary::add_trigram_suggestions(std::vector &suggestions, const std::string &word) const { // Get trigrams of the input word Word input_word(word); - const std::vector &input_trigrams = input_word.get_triagrams(); + const std::vector &input_trigrams = input_word.get_trigrams(); // Iterate through all words in the dictionary for (int i = 0; i < MAXLEN; ++i) { for (const Word &dict_word : words[i]) { // Get the trigrams of the dictionary word const std::vector &dict_word_trigrams = - dict_word.get_triagrams(); + dict_word.get_trigrams(); // Count how many trigrams match unsigned int match_count = dict_word.get_matches(input_trigrams); diff --git a/lab2/word.cc b/lab2/word.cc index d4e4b48..293f66e 100644 --- a/lab2/word.cc +++ b/lab2/word.cc @@ -7,8 +7,8 @@ using std::string; using std::vector; -Word::Word(const string &w, const vector &t) : word(w), triagrams(t) { - std::sort(triagrams.begin(), triagrams.end()); +Word::Word(const string &w, const vector &t) : word(w), trigrams(t) { + std::sort(trigrams.begin(), trigrams.end()); } std::vector get_trigrams(const std::string &text) { @@ -26,19 +26,19 @@ std::vector get_trigrams(const std::string &text) { } Word::Word(const std::string &w) : word(w) { - this->triagrams = get_trigrams(w); - std::sort(triagrams.begin(), triagrams.end()); + this->trigrams = ::get_trigrams(w); + std::sort(trigrams.begin(), trigrams.end()); } string Word::get_word() const { return word; } -vector Word::get_triagrams() const { return triagrams; } +vector Word::get_trigrams() const { return trigrams; } unsigned int Word::get_matches(const vector &t) const { unsigned int matches = 0; - for (const auto &triagram : t) { - if (std::binary_search(triagrams.begin(), triagrams.end(), triagram)) { + for (const auto &trigram : t) { + if (std::binary_search(trigrams.begin(), trigrams.end(), trigram)) { ++matches; } } @@ -49,15 +49,15 @@ std::ostream &operator<<(std::ostream &out, const Word &w) { auto space = string(" "); out << w.word; out << space; - out << w.triagrams.size(); - for (const auto &tria : w.triagrams) { - out << space << tria; + out << w.trigrams.size(); + for (const auto &tri : w.trigrams) { + out << space << tri; } return out; } bool operator==(const Word &lhs, const Word &rhs) { return lhs.word == rhs.word && - std::equal(lhs.triagrams.begin(), lhs.triagrams.end(), - rhs.triagrams.begin()); + std::equal(lhs.trigrams.begin(), lhs.trigrams.end(), + rhs.trigrams.begin()); } diff --git a/lab2/word.h b/lab2/word.h index 6c9a0df..27b92af 100644 --- a/lab2/word.h +++ b/lab2/word.h @@ -4,21 +4,21 @@ #include /* - * Contains a word and its triagrams + * Contains a word and its trigrams */ class Word { public: /** Creates a word w with the sorted trigrams t */ Word(const std::string &w, const std::vector &t); - /** Creates a word w and derives the triagrams internally */ + /** Creates a word w and derives the trigrams internally */ Word(const std::string &w); /** Returns the word */ std::string get_word() const; - /** Returns triagrams */ - std::vector get_triagrams() const; + /** Returns trigrams */ + std::vector get_trigrams() const; /** Returns how many of the trigrams in t that are present in this word's trigram vector */ @@ -26,7 +26,7 @@ class Word { private: const std::string word; - std::vector triagrams; + std::vector trigrams; friend std::ostream &operator<<(std::ostream &out, const Word &o); friend bool operator==(const Word &lhs, const Word &rhs); };