-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.cpp
123 lines (99 loc) · 3.07 KB
/
sample.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
118
119
120
121
122
#include <iostream>
#include <iomanip>
#include <string>
#include <list>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include "maxent.h"
using namespace std;
void split(string& str, vector<string>& tokens)
{
istringstream in(str);
char c;
while (in){
string token;
token = "";
while (in.get(c) && (c != '\t')) token.push_back(c);
tokens.push_back(token);
}
}
/* TODO: Repeating the usage string */
/* TODO: Incorporate the post-processing from BioNLP 2011? */
int main(int argc, char* argv[])
{
int ch, quiet;
/* Initialise arguments */
quiet = 0;
string progName = string(argv[0]);
/* Parse cmd-line arguments */
while((ch = getopt(argc, argv, "qh")) != -1) {
switch(ch) {
case 'q':
quiet = 1;
break;
case 'h':
cerr << "Usage: " << progName << " input output [path-to-ruby]" << endl;
exit(0);
case '?':
default:
cerr << "Usage: " << progName << " input output [path-to-ruby]" << endl;
exit(-1);
}
}
argc -= optind;
argv += optind;
if (argc < 2 || argc > 3) {
cerr << "Usage: " << progName << " input output [path-to-ruby]" << endl;
exit(-1);
}
ME_Model model;
string inFile = argv[0];
string outFile = argv[1];
//string modelFile = argv[2];
string modelFile = "model1-1.0";
string rubyCommand = (argc == 3) ? argv[2] : "ruby";
/* XXX: Should use temporary files if any! */
string eventFile = inFile + ".event";
string resultFile = inFile + ".result";
if (!quiet) {
cerr << "Extracting events.";
}
string extractionCommand =
rubyCommand + " EventExtracter.rb " + inFile + " " + eventFile;
system(extractionCommand.c_str());
if (!quiet) {
cerr << "roading model file." << endl;
}
model.load_from_file(modelFile.c_str());
//model.load_from_file("model" + setID + "-" + ineq);
//ifstream fileIn(string("/home/users/y-matsu/private/workspace/eclipse-workspace/GENIASS/" + setID + "/test.txt").c_str());
//ofstream fileOut(string("/home/users/y-matsu/private/workspace/eclipse-workspace/GENIASS/" + setID + "/test-" + ineq + ".prob").c_str());
ifstream fileIn(eventFile.c_str());
ofstream fileOut(resultFile.c_str());
string line, markedTxt;
getline(fileIn, markedTxt);
if (!quiet) {
cerr << "start classification." << endl;
}
while (getline(fileIn, line)){
vector<string> tokens;
split(line, tokens);
ME_Sample s;
for(vector<string>::const_iterator token = tokens.begin() + 1;
token != tokens.end(); ++token){
s.add_feature(*token);
}
(void) model.classify(s);
fileOut << s.label << endl;
}
fileOut.close();
fileIn.close();
remove(eventFile.c_str());
string splitCommand =
rubyCommand + " Classifying2Splitting.rb "
+ resultFile + " " + markedTxt + " " + outFile;
system(splitCommand.c_str());
return 0;
}