markly

Markov chain for text generation
git clone git://git.yotsev.xyz/markly.git
Log | Files | Refs | README | LICENSE

commit 1dfaedda180cd821bc9c00ee28cad817b1d950da
parent fe80ba0327d942e446ee95f66260a69a259c7b35
Author: Petar Yotsev <petar@yotsev.xyz>
Date:   Mon, 21 Feb 2022 18:03:49 +0000

Fix comments

Diffstat:
Mmain.cpp | 50++++++++++++++++++++++++++++++--------------------
1 file changed, 30 insertions(+), 20 deletions(-)

diff --git a/main.cpp b/main.cpp @@ -80,7 +80,9 @@ int main(int argc, char** argv) bool continuous = false; bool loud = false; + // // processing arguments + // string arg; for (int i = 1; i < argc; ++i) { arg = argv[i]; @@ -119,25 +121,11 @@ int main(int argc, char** argv) map<string, vector<char>> ngram; vector<string> beginnings; - // loads the chain if it exists - if (!generating) { - ifstream ifs(chain_filename, ios::binary); - if (ifs.is_open()) { - if (loud) - cerr << "Loading chain from " << chain_filename << endl; - boost::archive::binary_iarchive ia(ifs); - chain c; - ia >> c; - format = c.format; - order = c.order; - ngram = c.ngram; - if (format == 's') - beginnings = c.beginnings; - } else { - cerr << "Error: file " << chain_filename << " does not exist\n"; - return 1; - } - } else { // generates the chain + // + // gets the chain in one way or another + // + if (generating) { + // generates the chain if (loud) cerr << "Generating chain, this may take a while" << endl; string line; @@ -163,9 +151,28 @@ int main(int argc, char** argv) cerr << "Error: file " << filename << " does not exist\n"; return 1; } + } else { + // loads the chain if it exists + ifstream ifs(chain_filename, ios::binary); + if (ifs.is_open()) { + if (loud) + cerr << "Loading chain from " << chain_filename << endl; + boost::archive::binary_iarchive ia(ifs); + chain c; + ia >> c; + format = c.format; + order = c.order; + ngram = c.ngram; + if (format == 's') + beginnings = c.beginnings; + } else { + cerr << "Error: file " << chain_filename << " does not exist\n"; + return 1; + } } + + // saves the chain if (saving) { - // saves the chain chain_filename += ".o"; chain_filename += std::to_string(order); if (loud) @@ -181,6 +188,9 @@ int main(int argc, char** argv) oa << c; } + // + // generates text from the chain + // for (int i = 0; i < itterations || continuous; ++i) { string cgram; // get random starting gram