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. --- gen.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'gen.cpp') diff --git a/gen.cpp b/gen.cpp index e4a58e5..1d381c8 100644 --- a/gen.cpp +++ b/gen.cpp @@ -7,6 +7,7 @@ #include #include #include +#include "freevars.h" using namespace::std; @@ -45,6 +46,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 (;;) { @@ -52,7 +58,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) + " "; } cout << hi << endl; -- cgit 1.4.1