diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-05-20 23:14:06 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-05-20 23:15:10 -0400 |
commit | 8c3022e759191e90b5e12bcb6b0b5a6a48b37840 (patch) | |
tree | 0d9a8a12616d6ea335fdc687049b05f679e8ccc6 /gen.cpp | |
parent | a9c391efd5f0f73b5374dcfd807cdf59ed663e6b (diff) | |
download | rawr-ebooks-8c3022e759191e90b5e12bcb6b0b5a6a48b37840.tar.gz rawr-ebooks-8c3022e759191e90b5e12bcb6b0b5a6a48b37840.tar.bz2 rawr-ebooks-8c3022e759191e90b5e12bcb6b0b5a6a48b37840.zip |
Pulled the ebooks functionality out into a library
Diffstat (limited to 'gen.cpp')
-rw-r--r-- | gen.cpp | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/gen.cpp b/gen.cpp index 0319283..eba0277 100644 --- a/gen.cpp +++ b/gen.cpp | |||
@@ -44,18 +44,48 @@ int main(int argc, char** args) | |||
44 | 44 | ||
45 | corpus += line + "\n "; | 45 | corpus += line + "\n "; |
46 | } | 46 | } |
47 | |||
48 | // Replace old-style freevars while I can't be bothered to remake the corpus yet | ||
49 | std::vector<std::string> fv_names; | ||
50 | std::ifstream namefile("names.txt"); | ||
51 | if (namefile.is_open()) | ||
52 | { | ||
53 | while (!namefile.eof()) | ||
54 | { | ||
55 | std::string l; | ||
56 | getline(namefile, l); | ||
57 | if (l.back() == '\r') | ||
58 | { | ||
59 | l.pop_back(); | ||
60 | } | ||
61 | |||
62 | fv_names.push_back(l); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | namefile.close(); | ||
47 | 67 | ||
48 | std::cout << "Preprocessing corpus..." << std::endl; | 68 | std::cout << "Preprocessing corpus..." << std::endl; |
49 | kgramstats* stats = new kgramstats(corpus, 4); | 69 | rawr kgramstats; |
70 | kgramstats.addCorpus(corpus); | ||
71 | kgramstats.compile(4); | ||
72 | kgramstats.setTransformCallback([&] (std::string canonical, std::string) { | ||
73 | size_t pos = canonical.find("$name$"); | ||
74 | if (pos != std::string::npos) | ||
75 | { | ||
76 | canonical.replace(pos, 6, fv_names[rand() % fv_names.size()]); | ||
77 | } | ||
78 | |||
79 | return canonical; | ||
80 | }); | ||
50 | 81 | ||
51 | std::cout << "Generating..." << std::endl; | 82 | std::cout << "Generating..." << std::endl; |
52 | for (;;) | 83 | for (;;) |
53 | { | 84 | { |
54 | std::string doc = stats->randomSentence(140); | 85 | std::string doc = kgramstats.randomSentence(140); |
55 | std::string hi = doc; | 86 | doc.resize(140); |
56 | hi.resize(140); | ||
57 | 87 | ||
58 | std::cout << hi << std::endl; | 88 | std::cout << doc << std::endl; |
59 | 89 | ||
60 | getc(stdin); | 90 | getc(stdin); |
61 | } | 91 | } |