-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadPresDebateData.java
More file actions
207 lines (174 loc) · 4.42 KB
/
Copy pathReadPresDebateData.java
File metadata and controls
207 lines (174 loc) · 4.42 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package com.research.course.debate.preproc;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
public class ReadPresDebateData {
/**
* @param args
*/
public ReadPresDebateData()
{
}
public void readDebateFile ( String path ) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader (
new FileInputStream( path + "obama_romney_debate_1.txt") , "UTF8") );
Writer writer = new BufferedWriter( new OutputStreamWriter ( new FileOutputStream
( path + "debate_output_1.txt"), "UTF8") );
boolean romneyFlag = false ;
boolean obamaFlag = false ;
boolean modrtrFlag = false ;
String argument = null ;
String debateId = "1" ;
String speakerId = null ;
String htmlPageId = "1" ;
int speechSeqn = 0 ;
String polRef = null ;
String mention = "Y" ;
String vote = "Y" ;
while (true)
{
String line = reader.readLine();
if (line == null )
{
break;
}
if ( line.length() < 3)
{
continue ;
}
if(line.contains("to your own airplane and"))
{
System.out.println("here");
}
if (line.startsWith("ROMNEY") || line.startsWith("romney"))
{
speakerId = "500099" ;
polRef = "ROMNEY" ;
polRef = "R" ;
if ( null == argument )
{
//start
argument = line.substring(7,line.length());
}
else
{
//already in
if (obamaFlag)
{
writeTheArgument(writer, debateId, speakerId, htmlPageId, speechSeqn,
polRef, mention, vote, argument);
speechSeqn++ ;
argument = line.substring(7,line.length());
}
else if (modrtrFlag)
{
}
else if (romneyFlag)
{
//the last one is also a romney one
writeTheArgument(writer, debateId, speakerId, htmlPageId, speechSeqn, polRef,
mention, vote, argument);
speechSeqn++ ;
argument = line.substring(7,line.length());
}
}
romneyFlag = true ;
modrtrFlag = false ;
obamaFlag = false ;
}
else if (line.startsWith("OBAMA") || line.startsWith("obama"))
{
speakerId = "500100" ;
polRef = "OBAMA" ;
polRef = "D" ;
if ( null == argument )
{
//start
argument = line.substring(7,line.length());
}
else
{
//already in
if (romneyFlag)
{
writeTheArgument(writer, debateId, speakerId, htmlPageId, speechSeqn, polRef,
mention, vote, argument);
speechSeqn++ ;
argument = line.substring(7,line.length());
}
else if (modrtrFlag)
{
}
else if (obamaFlag)
{
//the last one is also a obama one
writeTheArgument(writer, debateId, speakerId, htmlPageId, speechSeqn, polRef,
mention, vote, argument);
speechSeqn++ ;
argument = line.substring(7,line.length());
}
}
obamaFlag = true ;
romneyFlag = false ;
modrtrFlag = false ;
}
else if (line.startsWith("LEHRER"))
{
if (null != argument)
{
writeTheArgument(writer, debateId, speakerId, htmlPageId, speechSeqn, polRef,
mention, vote, argument);
speechSeqn++ ;
}
modrtrFlag = true ;
obamaFlag = false ;
romneyFlag = false ;
//
argument = null ;
continue ;
}
else
{
if (romneyFlag)
{
//add on romney
argument = argument + " " + line ;
}
if ( obamaFlag)
{
//add on obama
argument = argument + " " + line ;
}
if (modrtrFlag)
{
continue ;
}
}
}
reader.close();
writer.close();
}
private void writeTheArgument(Writer writer, String debateId, String speakerId,
String htmlPageId, int speechSeqn, String polRef, String mention,
String vote, String speech ) throws IOException
{
// TODO Auto-generated method stub
speech = speech.trim();
writer.write(debateId + "\t" + speakerId + "\t" +
htmlPageId + "\t" + speechSeqn + "\t" + polRef + "\t" + mention + "\t" +
vote + "\t" + speech );
writer.write("\n");
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String path = "./data/presi_debates_2012/" ;
ReadPresDebateData readPresDebateObj = new ReadPresDebateData();
readPresDebateObj.readDebateFile(path) ;
}
}