diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-11-22 18:49:58 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-11-22 18:49:58 -0500 |
commit | 01746a0e03267b6c082b58436c1370567f7cb7c5 (patch) | |
tree | e3cfeadb97f93858f326f57958bff4675cd8f9ed /gen.cpp | |
parent | 294fe00911c6ee0dd9853df7612dcdbd63425c05 (diff) | |
download | rawr-ebooks-01746a0e03267b6c082b58436c1370567f7cb7c5.tar.gz rawr-ebooks-01746a0e03267b6c082b58436c1370567f7cb7c5.tar.bz2 rawr-ebooks-01746a0e03267b6c082b58436c1370567f7cb7c5.zip |
Added malapropisms
Diffstat (limited to 'gen.cpp')
-rw-r--r-- | gen.cpp | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/gen.cpp b/gen.cpp index 31ba4dc..3284ffa 100644 --- a/gen.cpp +++ b/gen.cpp | |||
@@ -9,65 +9,63 @@ | |||
9 | #include <iostream> | 9 | #include <iostream> |
10 | #include "freevars.h" | 10 | #include "freevars.h" |
11 | 11 | ||
12 | using namespace::std; | ||
13 | |||
14 | int main(int argc, char** args) | 12 | int main(int argc, char** args) |
15 | { | 13 | { |
16 | srand(time(NULL)); | 14 | srand(time(NULL)); |
17 | 15 | ||
18 | if (argc == 1) | 16 | if (argc == 1) |
19 | { | 17 | { |
20 | cout << "rawr-gen, version 1.0" << endl; | 18 | std::cout << "rawr-gen, version 1.0" << std::endl; |
21 | cout << "Usage: rawr-gen corpus-file" << endl; | 19 | std::cout << "Usage: rawr-gen corpus-file" << std::endl; |
22 | cout << " where 'corpus-file' is the path to your input" << endl; | 20 | std::cout << " where 'corpus-file' is the path to your input" << std::endl; |
23 | 21 | ||
24 | return 0; | 22 | return 0; |
25 | } | 23 | } |
26 | 24 | ||
27 | ifstream infile(args[1]); | 25 | std::ifstream infile(args[1]); |
28 | if (!infile) | 26 | if (!infile) |
29 | { | 27 | { |
30 | cout << "rawr-gen, version 1.0" << endl; | 28 | std::cout << "rawr-gen, version 1.0" << std::endl; |
31 | cout << "Usage: rawr-gen corpus-file" << endl; | 29 | std::cout << "Usage: rawr-gen corpus-file" << std::endl; |
32 | cout << " where 'corpus-file' is the path to your input" << endl; | 30 | std::cout << " where 'corpus-file' is the path to your input" << std::endl; |
33 | cout << endl; | 31 | std::cout << std::endl; |
34 | cout << "The file you specified does not exist." << endl; | 32 | std::cout << "The file you specified does not exist." << std::endl; |
35 | 33 | ||
36 | return 0; | 34 | return 0; |
37 | } | 35 | } |
38 | 36 | ||
39 | string corpus; | 37 | std::string corpus; |
40 | string line; | 38 | std::string line; |
41 | while (getline(infile, line)) | 39 | while (getline(infile, line)) |
42 | { | 40 | { |
43 | corpus += " " + line; | 41 | corpus += " " + line; |
44 | } | 42 | } |
45 | 43 | ||
46 | cout << "Preprocessing corpus..." << endl; | 44 | std::cout << "Preprocessing corpus..." << std::endl; |
47 | kgramstats* stats = new kgramstats(corpus, 3); | 45 | kgramstats* stats = new kgramstats(corpus, 3); |
48 | 46 | ||
49 | cout << "Preprocessing freevars..." << endl; | 47 | std::cout << "Preprocessing freevars..." << std::endl; |
50 | freevars* vars = new freevars(); | 48 | freevars* vars = new freevars(); |
51 | vars->addVar("name", "names.txt"); | 49 | vars->addVar("name", "names.txt"); |
52 | vars->addVar("noun", "nouns.txt"); | 50 | vars->addVar("noun", "nouns.txt"); |
53 | 51 | ||
54 | cout << "Generating..." << endl; | 52 | std::cout << "Generating..." << std::endl; |
55 | for (;;) | 53 | for (;;) |
56 | { | 54 | { |
57 | vector<string> doc = stats->randomSentence(rand() % 35 + 15); | 55 | std::vector<std::string> doc = stats->randomSentence(rand() % 35 + 15); |
58 | string hi; | 56 | std::string hi; |
59 | for (vector<string>::iterator it = doc.begin(); it != doc.end(); ++it) | 57 | for (std::vector<std::string>::iterator it = doc.begin(); it != doc.end(); ++it) |
60 | { | 58 | { |
61 | hi += vars->parse(*it) + " "; | 59 | hi += vars->parse(*it) + " "; |
62 | } | 60 | } |
63 | 61 | ||
64 | size_t lastperiod = hi.find_last_of("."); | 62 | size_t lastperiod = hi.find_last_of("."); |
65 | if ((lastperiod != string::npos) && (rand() % 3 > 0)) | 63 | if ((lastperiod != std::string::npos) && (rand() % 3 > 0)) |
66 | { | 64 | { |
67 | hi = hi.substr(0, lastperiod+1); | 65 | hi = hi.substr(0, lastperiod+1); |
68 | } | 66 | } |
69 | 67 | ||
70 | cout << hi << endl; | 68 | std::cout << hi << std::endl; |
71 | 69 | ||
72 | getc(stdin); | 70 | getc(stdin); |
73 | } | 71 | } |