diff options
| author | Feffernoose <fefferburbia@gmail.com> | 2013-10-07 23:32:37 -0400 |
|---|---|---|
| committer | Feffernoose <fefferburbia@gmail.com> | 2013-10-07 23:32:37 -0400 |
| commit | 40bf33c9df2d24219826147417ad07dd21e35d17 (patch) | |
| tree | 91a06d9c5aa4adbe927bddec5522e1b27c6756e5 /gen.cpp | |
| parent | d4b193e6e7fdefc66d9698337581b960c30844ea (diff) | |
| download | rawr-ebooks-40bf33c9df2d24219826147417ad07dd21e35d17.tar.gz rawr-ebooks-40bf33c9df2d24219826147417ad07dd21e35d17.tar.bz2 rawr-ebooks-40bf33c9df2d24219826147417ad07dd21e35d17.zip | |
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.
Diffstat (limited to 'gen.cpp')
| -rw-r--r-- | gen.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
| diff --git a/gen.cpp b/gen.cpp index e4a58e5..1d381c8 100644 --- a/gen.cpp +++ b/gen.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <cstdlib> | 7 | #include <cstdlib> |
| 8 | #include <fstream> | 8 | #include <fstream> |
| 9 | #include <iostream> | 9 | #include <iostream> |
| 10 | #include "freevars.h" | ||
| 10 | 11 | ||
| 11 | using namespace::std; | 12 | using namespace::std; |
| 12 | 13 | ||
| @@ -45,6 +46,11 @@ int main(int argc, char** args) | |||
| 45 | cout << "Preprocessing corpus..." << endl; | 46 | cout << "Preprocessing corpus..." << endl; |
| 46 | kgramstats* stats = new kgramstats(corpus, 5); | 47 | kgramstats* stats = new kgramstats(corpus, 5); |
| 47 | 48 | ||
| 49 | cout << "Preprocessing freevars..." << endl; | ||
| 50 | freevars* vars = new freevars(); | ||
| 51 | vars->addVar("name", "names.txt"); | ||
| 52 | vars->addVar("noun", "nouns.txt"); | ||
| 53 | |||
| 48 | cout << "Generating..." << endl; | 54 | cout << "Generating..." << endl; |
| 49 | for (;;) | 55 | for (;;) |
| 50 | { | 56 | { |
| @@ -52,7 +58,7 @@ int main(int argc, char** args) | |||
| 52 | string hi; | 58 | string hi; |
| 53 | for (vector<string>::iterator it = doc.begin(); it != doc.end(); ++it) | 59 | for (vector<string>::iterator it = doc.begin(); it != doc.end(); ++it) |
| 54 | { | 60 | { |
| 55 | hi += *it + " "; | 61 | hi += vars->parse(*it) + " "; |
| 56 | } | 62 | } |
| 57 | 63 | ||
| 58 | cout << hi << endl; | 64 | cout << hi << endl; |
