Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. void TextGen::readIn(const std::string &filename) {
  2.     std::ifstream file(filename);
  3.     std::string previous_word = "";
  4.     std::string current_word = "";
  5.     std::map<std::string, std::vector<std::string>>::iterator it;
  6.  
  7.     std::pair<std::string, std::vector<std::string>> first_word("^", {});
  8.     markov_chain.insert(first_word);
  9.  
  10.     while(file >> current_word) {
  11.         sanitize(current_word);
  12.  
  13.         if (isEndPunctuation(current_word[current_word.size() - 1])) {
  14.             std::string word = current_word.substr(0, current_word.size() - 1);
  15.             std::string punct(1, current_word[current_word.size() - 1]);
  16.             markov_chain[previous_word].push_back(word);
  17.             markov_chain[word].push_back(punct);
  18.             markov_chain[punct].push_back("$");
  19.  
  20.             previous_word = "";
  21.         } else {
  22.             if (previous_word == "") {
  23.                 markov_chain["^"].push_back(current_word);
  24.             } else {
  25.                 markov_chain[previous_word].push_back(current_word);
  26.             }
  27.  
  28.             previous_word = current_word;
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement