From 40bf33c9df2d24219826147417ad07dd21e35d17 Mon Sep 17 00:00:00 2001 From: Feffernoose Date: Mon, 7 Oct 2013 23:32:37 -0400 Subject: Implemented freevars Arbitrary variable tokens can now be defined (though at this point only in the code itself) as a pair of a variable name and a filename pointing to a plain text file containing a newline-delimited list of elements. When a token of the form $name$ (where name is the name of a variable) is encountered, the output will include a random element from the appropriate list. The variables $name$ and $noun$ are hard-coded at this point, but the program will not crash if names.txt and nouns.txt do not exist and will instead just silently ignore the variables. --- ebooks.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ebooks.cpp') diff --git a/ebooks.cpp b/ebooks.cpp index ed660a9..753ead6 100644 --- a/ebooks.cpp +++ b/ebooks.cpp @@ -10,6 +10,7 @@ #include #include #include +#include "freevars.h" using namespace::std; @@ -28,6 +29,11 @@ int main(int argc, char** args) cout << "Preprocessing corpus..." << endl; kgramstats* stats = new kgramstats(corpus, 5); + + cout << "Preprocessing freevars..." << endl; + freevars* vars = new freevars(); + vars->addVar("name", "names.txt"); + vars->addVar("noun", "nouns.txt"); cout << "Generating..." << endl; for (;;) @@ -36,7 +42,7 @@ int main(int argc, char** args) string hi; for (vector::iterator it = doc.begin(); it != doc.end(); ++it) { - hi += *it + " "; + hi += vars->parse(*it) + " "; } hi = hi.substr(0,140); -- cgit 1.4.1