diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-01-04 23:16:17 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-01-04 23:16:17 -0500 |
commit | 9e89002477d1358de9be9cabdc1edba26bd32836 (patch) | |
tree | 9afb52740fe4f618105d014a816df26b36ed83f6 /malaprop.cpp | |
parent | 0a5c6bd740aff9be53e7ef117e9e926fde3c289e (diff) | |
download | rawr-ebooks-9e89002477d1358de9be9cabdc1edba26bd32836.tar.gz rawr-ebooks-9e89002477d1358de9be9cabdc1edba26bd32836.tar.bz2 rawr-ebooks-9e89002477d1358de9be9cabdc1edba26bd32836.zip |
Rewrote quite a bit of kgramstats
The algorithm still treats most tokens literally, but now groups together tokens that terminate a clause somehow (so, contain .?!,), without distinguishing between the different terminating characters. For each word that can terminate a sentence, the algorithm creates a histogram of the terminating characters and number of occurrences of those characters for that word (number of occurrences is to allow things like um???? and um,,,,, to still be folded down into um.). Then, when the terminating version of that token is invoked, a random terminating string is added to that token based on the histogram for that word (again, to allow things like the desu-ly use of multiple commas to end clauses). The algorithm now also has a slightly advanced kgram structure; a special "sentence wildcard" kgram value is set aside from normal strings of tokens that can match any terminating token. This kgram value is never printed (it is only ever present in the query kgrams and cannot actually be present in the histograms (it is of a different datatype)) and is used at the beginning of sentence generation to make sure that the first couple of words generated actually form the beginning of a sentence instead of picking up somewhere in the middle of a sentence. It is also used to reset sentence generation in the rare occasion that the end of the corpus is reached.
Diffstat (limited to 'malaprop.cpp')
-rw-r--r-- | malaprop.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/malaprop.cpp b/malaprop.cpp index 7fbdb6c..ccdd4c4 100644 --- a/malaprop.cpp +++ b/malaprop.cpp | |||
@@ -117,6 +117,11 @@ std::string malaprop::alternate(std::string word) | |||
117 | { | 117 | { |
118 | soundex ex = soundify(word); | 118 | soundex ex = soundify(word); |
119 | std::set<std::string>& opts = dict[ex]; | 119 | std::set<std::string>& opts = dict[ex]; |
120 | if (opts.size() == 0) | ||
121 | { | ||
122 | return word; | ||
123 | } | ||
124 | |||
120 | int opt = rand() % opts.size(); | 125 | int opt = rand() % opts.size(); |
121 | for (std::set<std::string>::iterator it = opts.begin(); it != opts.end(); it++) | 126 | for (std::set<std::string>::iterator it = opts.begin(); it != opts.end(); it++) |
122 | { | 127 | { |