#markov chain generator

4 messages · Page 1 of 1 (latest)

dire cairnBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

cloud hull
#
#include <iostream>
#include <unordered_map>
#include <vector>
#include <random>

std::unordered_map<std::string, std::vector<std::string>> corpus{
    {"the",{"mouse","cat"}},
    {"mouse",{"was","chased"}},
    {"was",{"chased"}},
    {"chased",{"by","the"}},
    {"by",{"the"}},
    {"cat",{"was","chased"}}
};

std::string mcg(std::unordered_map<std::string, std::vector<std::string>> in){
    std::string sentence{""};
    std::random_device r;
    std::mt19937_64 g(r());
    std::uniform_int_distribution<> d{0,1};
    for(auto x:in){
        if(x.second.size()<2){
            sentence+=(x.second[0]+" ");
            continue;
        }
        int word = d(g);
        sentence+=(x.second[word]+" ");
    }
    return sentence;
}

int main(){
    std::cout<<mcg(corpus);
}
#

!solved

dire cairnBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity