diff options
Diffstat (limited to 'gen.cpp')
-rw-r--r-- | gen.cpp | 48 |
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 | |||
13 | using namespace::std; | ||
14 | |||
15 | int 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 | ||