Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void TextGen::readIn(const std::string &filename) {
- std::ifstream file(filename);
- std::string previous_word = "";
- std::string current_word = "";
- std::map<std::string, std::vector<std::string>>::iterator it;
- std::pair<std::string, std::vector<std::string>> first_word("^", {});
- markov_chain.insert(first_word);
- while(file >> current_word) {
- sanitize(current_word);
- if (isEndPunctuation(current_word[current_word.size() - 1])) {
- std::string word = current_word.substr(0, current_word.size() - 1);
- std::string punct(1, current_word[current_word.size() - 1]);
- markov_chain[previous_word].push_back(word);
- markov_chain[word].push_back(punct);
- markov_chain[punct].push_back("$");
- previous_word = "";
- } else {
- if (previous_word == "") {
- markov_chain["^"].push_back(current_word);
- } else {
- markov_chain[previous_word].push_back(current_word);
- }
- previous_word = current_word;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement