-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.cpp
117 lines (102 loc) · 3.2 KB
/
main.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "MiscUtils.h"
#include "RDSGraph.h"
#include "special.h"
#include "TimeFuncs.h"
#include <sstream>
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <fstream>
using std::vector;
using std::pair;
using std::string;
using std::stringstream;
using std::ifstream;
using std::ios;
using std::cout;
using std::endl;
vector<vector<string> > readSequencesFromFile(const string &filename)
{
vector<vector<string> > sequences;
vector<string> tokens;
string token;
ifstream in(filename.c_str(), ios::in);
if(!in.is_open())
{
cout << "Unable to open file: " << filename << endl;
exit(1);
}
while(!in.eof())
{
string line;
getline(in, line);
if(line.size() > 0)
{
stringstream ss(line);
while(!ss.eof())
{
ss >> token;
if(token == "*")
tokens.clear();
else if(token == "#")
{
sequences.push_back(tokens);
break;
}
else
tokens.push_back(token);
}
}
}
in.close();
return sequences;
}
int main(int argc, char *argv[])
{
if(argc < 6)
{
cout << "Usage:" << endl;
cout << "ModifiedADIOS <filename> <eta> <alpha> <context_size> <coverage> ---OPTIONAL--- <number_of_new_sequences>" << endl;
exit(1);
}
cout << "BEGIN CORPUS ----------" << endl;
vector<vector<string> > sequences = readSequencesFromFile(argv[1]);
for(unsigned int i = 0; i < sequences.size(); i++)
{
for(unsigned int j = 0; j < sequences[i].size(); j++)
cout << sequences[i][j] << " ";
cout << endl;
}
cout << "END CORPUS ----------" << endl << endl << endl;
RDSGraph testGraph(sequences);
cout << testGraph << endl;
double startTime = getTime();
testGraph.distill(ADIOSParams(atof(argv[2]), atof(argv[3]), atoi(argv[4]), atof(argv[5])));
double endTime = getTime();
cout << testGraph << endl << endl;
std::cout << endl << "Time elapsed: " << endTime - startTime << " seconds" << endl << endl << endl << endl;
testGraph.convert2PCFG(std::cout);
/*
startTime = getTime();
testGraph.distill(ADIOSParams(atof(argv[2]), atof(argv[3])*10, atoi(argv[4])-2, atof(argv[5])));
endTime = getTime();
cout << testGraph << endl << endl;
std::cout << endl << "Time elapsed: " << endTime - startTime << " seconds" << endl << endl << endl << endl;*/
/*
vector<string> testString(sequences[10].begin(), sequences[10].end());
for(unsigned int i = 0; i < testString.size() - 1; i++)
std::cout << testString[i] << " ";
std::cout << testString.back() << endl;
SearchPath newPath = testGraph.encode(testString);
std::cout << newPath << endl;
testGraph.predict(newPath);
if(argc > 6)
for(unsigned int i = 0; i < static_cast<unsigned int>(atoi(argv[6])); i++)
{
vector<string> sequence = testGraph.generate();
for(unsigned int j = 0; j < sequence.size(); j++)
std::cout << sequence[j] << " ";
std::cout << endl;
}*/
}