-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathExtraction.java
197 lines (165 loc) · 5.47 KB
/
Extraction.java
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
import java.util.Arrays;
/**
* The class that stores information pertaining to each extraction.
*
* Created by sebastian on 21/05/15.
*/
public class Extraction {
/**
* The id of the extraction in the format document ID slash sentence ID.
*/
private String id;
/**
* The emotion of the extraction.
*/
private String emotion;
/**
* The pattern that yielded the extraction.
*/
private String pattern;
/**
* The emotion holder.
*/
private String emotionHolder;
/**
* The NP cause. Can be empty.
*/
private String NPCause;
/**
* The subject of the S cause. Can be empty.
*/
private String subjSCause;
/**
* The predicate of the S cause. Can be empty.
*/
private String predSCause;
/**
* The direct object of the S cause. Can be empty.
*/
private String dobjSCause;
/**
* The prepositional objects of the S cause in the format [pobj1, pobj2, ...]. Can be empty.
*/
private String pobjsString;
/**
* The cause as a bag-of-words, tagged with parts-of-speech, in the format [word1, word2, ...].
*/
private String causeBoWString;
/**
* The prepositional objects of the S cause as an array. Can be empty.
*/
private String[] pobjs;
/**
* The bag-of-words of the cause as an array.
*/
private String[] causeBoW;
/**
* Creates an instance of an <code>Extraction</code>.
* @param id the id of the extraction
* @param emotion the emotion
* @param pattern the pattern
* @param emotionHolder the emotion holder
* @param NPCause the NP cause
* @param subjSCause the subject of the S cause
* @param predSCause the predicate of the S cause
* @param dobjSCause the direct object of the S cause
* @param pobjs the prepositional object string of the S cause
* @param causeBoW the bag-of-words string of the cause
*/
public Extraction(String id, String emotion, String pattern, String emotionHolder, String NPCause, String subjSCause,
String predSCause, String dobjSCause, String pobjs, String causeBoW) {
this.id = id;
this.emotion = emotion;
this.pattern = pattern;
this.emotionHolder = emotionHolder;
this.NPCause = NPCause;
this.subjSCause = subjSCause;
this.predSCause = predSCause;
this.dobjSCause = dobjSCause;
this.pobjsString = pobjs;
this.causeBoWString = causeBoW;
this.pobjs = pobjs.replaceAll("^\\[|\\]$", "").split(", ");
this.causeBoW = causeBoW.replaceAll("^\\[|\\]$", "").split(", ");
}
/**
* Transforms the extraction to its output format.
* @return the string representation of an extraction
*/
@Override
public String toString() {
return String.format("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", this.id, this.emotion, this.pattern,
this.emotionHolder, this.NPCause, this.subjSCause, this.predSCause, this.dobjSCause, this.pobjsString,
this.causeBoWString);
}
/**
* Compares to extractions with each other. They are only equal if all fields are equal except for the id.
* @param object the object against which the extraction should be compared
* @return 0 if the extractions are equal, else -1 or +1
*/
@Override
public boolean equals(Object object) {
if (object == null || object.getClass() != Extraction.class) {
return false;
}
Extraction other = (Extraction)object;
// ids can be different
return this.emotion.equals(other.emotion) && this.pattern.equals(other.pattern) &&
this.emotionHolder.equals(other.emotionHolder) && this.NPCause.equals(other.NPCause) &&
this.subjSCause.equals(other.subjSCause) && this.predSCause.equals(other.predSCause) &&
this.dobjSCause.equals(other.subjSCause) && this.pobjsString.equals(other.pobjsString) &&
this.causeBoWString.equals(other.causeBoWString);
}
/**
* Generate the hash code of an extraction.
* @return the hash code
*/
@Override
public int hashCode() {
int result = emotion.hashCode();
result = 31 * result + pattern.hashCode();
result = 31 * result + emotionHolder.hashCode();
result = 31 * result + NPCause.hashCode();
result = 31 * result + subjSCause.hashCode();
result = 31 * result + predSCause.hashCode();
result = 31 * result + dobjSCause.hashCode();
result = 31 * result + pobjsString.hashCode();
result = 31 * result + causeBoWString.hashCode();
return result;
}
public String getId() {
return id;
}
public String getEmotion() {
return emotion;
}
public String getPattern() {
return pattern;
}
public String getEmotionHolder() {
return emotionHolder;
}
public String getNPCause() {
return NPCause;
}
public String getSubjSCause() {
return subjSCause;
}
public String getPredSCause() {
return predSCause;
}
public String getDobjSCause() {
return dobjSCause;
}
public String getPobjsString() {
return pobjsString;
}
public String getCauseBoWString() {
return causeBoWString;
}
public String[] getPobjs() {
return pobjs;
}
public String[] getCauseBoW() {
return causeBoW;
}
}