about summary refs log tree commit diff stats
path: root/gen.cpp
diff options
context:
space:
mode:
authorFeffernoose <fefferburbia@gmail.com>2013-10-06 19:51:45 -0400
committerFeffernoose <fefferburbia@gmail.com>2013-10-06 19:51:45 -0400
commit8d28a8e13dbe602783a505adb1df375b0d65efe0 (patch)
treec4ad30b6692fdacceb875d905a59b029f2e369f0 /gen.cpp
parent9f095cd071efa059449e4694f4fc3da22ca9e456 (diff)
downloadrawr-ebooks-8d28a8e13dbe602783a505adb1df375b0d65efe0.tar.gz
rawr-ebooks-8d28a8e13dbe602783a505adb1df375b0d65efe0.tar.bz2
rawr-ebooks-8d28a8e13dbe602783a505adb1df375b0d65efe0.zip
Split rawr-ebooks and rawr-gen
Also wrote README
Diffstat (limited to 'gen.cpp')
-rw-r--r--gen.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/gen.cpp b/gen.cpp new file mode 100644 index 0000000..dc73e0f --- /dev/null +++ b/gen.cpp
@@ -0,0 +1,48 @@
1#include <cstdio>
2#include <list>
3#include <map>
4#include "kgramstats.h"
5#include <ctime>
6#include <vector>
7#include <cstdlib>
8#include <fstream>
9#include <iostream>
10#include <unistd.h>
11#include <yaml-cpp/yaml.h>
12
13using namespace::std;
14
15int main(int argc, char** args)
16{
17 srand(time(NULL));
18
19 YAML::Node config = YAML::LoadFile("config.yml");
20
21 ifstream infile(config["corpus"].as<std::string>().c_str());
22 string corpus;
23 string line;
24 while (getline(infile, line))
25 {
26 corpus += " " + line;
27 }
28
29 cout << "Preprocessing corpus..." << endl;
30 kgramstats* stats = new kgramstats(corpus, 5);
31
32 cout << "Generating..." << endl;
33 for (;;)
34 {
35 vector<string> doc = stats->randomSentence(rand() % 35 + 15);
36 string hi;
37 for (vector<string>::iterator it = doc.begin(); it != doc.end(); ++it)
38 {
39 hi += *it + " ";
40 }
41
42 cout << hi << endl;
43
44 getc(stdin);
45 }
46
47 return 0;
48} \ No newline at end of file