about summary refs log tree commit diff stats
path: root/gen.cpp
blob: dc73e0fbfdc331f5f1239cb38bba0ee48b44a407 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <cstdio>
#include <list>
#include <map>
#include "kgramstats.h"
#include <ctime>
#include <vector>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <unistd.h>
#include <yaml-cpp/yaml.h>

using namespace::std;

int main(int argc, char** args)
{
	srand(time(NULL));
	
	YAML::Node config = YAML::LoadFile("config.yml");
	
	ifstream infile(config["corpus"].as<std::string>().c_str());
	string corpus;
	string line;
	while (getline(infile, line))
	{
		corpus += " " + line;
	}
	
    cout << "Preprocessing corpus..." << endl;
	kgramstats* stats = new kgramstats(corpus, 5);
    
    cout << "Generating..." << endl;
	for (;;)
	{
		vector<string> doc = stats->randomSentence(rand() % 35 + 15);
		string hi;
		for (vector<string>::iterator it = doc.begin(); it != doc.end(); ++it)
		{
			hi += *it + " ";
		}

		cout << hi << endl;
		
        getc(stdin);
	}
	
	return 0;
}