From 1890eb5d4a496aea5e9114550081ca63bd280f3b Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 27 Feb 2019 21:52:59 -0500 Subject: Allow the sentence to end at the end of a corpus --- kgramstats.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kgramstats.cpp b/kgramstats.cpp index 7ece80f..b0a83dc 100644 --- a/kgramstats.cpp +++ b/kgramstats.cpp @@ -625,6 +625,13 @@ std::string rawr::randomSentence(int maxL) const // https://twitter.com/starla4444/status/684222271339237376 if (_stats.count(cur) == 0) { + // The end of a corpus should probably be treated like a terminator, so + // maybe we should just end here. + if ((result.length() > maxL) || (rand() % 4 == 0)) + { + break; + } + cur = kgram(1, wildcardQuery); } -- cgit 1.4.1