Towhidul commited on
Commit
dc27637
·
1 Parent(s): a175381

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +119 -132
app.py CHANGED
@@ -90,6 +90,7 @@ from allennlp.predictors.predictor import Predictor
90
  import allennlp_models.tagging
91
  predictor = Predictor.from_path("structured-prediction-srl-bert.tar.gz")
92
 
 
93
  #---------------------------------------------------------------
94
  def claim(text):
95
  import re
@@ -148,163 +149,150 @@ def claim(text):
148
  #----------FOR COLUMN "WHO"------------#
149
  df['who'] = ''
150
  for j in range(len(df['modified'])):
151
- val_list = []
152
- val_string = ''
153
- for k,v in df['modified'][j].items():
154
- # print(type(v))
155
- val_list.append(v)
156
-
157
- who = []
158
- for indx in range(len(val_list)):
159
- val_string = val_list[indx]
160
- pos = val_string.find("who: ")
161
- substr = ''
162
-
163
- if pos != -1:
164
- for i in range(pos+5, len(val_string)):
165
- if val_string[i] == "]":
166
- break
 
 
 
 
 
167
  else:
168
- substr = substr + val_string[i]
169
- else:
170
- pass
171
- if len(substr)!= 0:
172
- who.append(substr)
173
- else:
174
- pass
175
- # who=list(set(who))
176
- df['who'][j] = "<sep>".join(who)
177
  # else:
178
  # continue
179
  #----------FOR COLUMN "WHAT"------------#
180
  df['what'] = ''
181
  for j in range(len(df['modified'])):
182
- val_list = []
183
- val_string = ''
184
- for k,v in df['modified'][j].items():
185
- # print(type(v))
186
- val_list.append(v)
187
-
188
- what = []
189
- for indx in range(len(val_list)):
190
- val_string = val_list[indx]
191
- pos = val_string.find("what: ")
192
- substr = ''
193
-
194
- if pos != -1:
195
- for i in range(pos+6, len(val_string)):
196
- if val_string[i] == "]":
197
- break
 
 
 
 
 
198
  else:
199
- substr = substr + val_string[i]
200
- else:
201
- pass
202
- if len(substr)!= 0:
203
- what.append(substr)
204
- else:
205
- pass
206
-
207
- df['what'][j] = "<sep>".join(what)
208
- # else:
209
- # continue
210
 
211
  #----------FOR COLUMN "WHY"------------#
212
  df['why'] = ''
213
  for j in range(len(df['modified'])):
214
- val_list = []
215
- val_string = ''
216
- for k,v in df['modified'][j].items():
217
- # print(type(v))
218
- val_list.append(v)
219
-
220
- why = []
221
- for indx in range(len(val_list)):
222
- val_string = val_list[indx]
223
- pos = val_string.find("why: ")
224
- substr = ''
225
-
226
- if pos != -1:
227
- for i in range(pos+5, len(val_string)):
228
- if val_string[i] == "]":
229
- break
 
 
 
 
 
230
  else:
231
- substr = substr + val_string[i]
232
- else:
233
- pass
234
- if len(substr)!= 0:
235
- why.append(substr)
236
- else:
237
- pass
238
- # why=list(set(why))
239
 
240
- df['why'][j] = "<sep>".join(why)
241
- # else:
242
- # continue
243
 
244
  #----------FOR COLUMN "WHEN"------------#
245
  df['when'] = ''
246
  for j in range(len(df['modified'])):
247
- val_list = []
248
- val_string = ''
249
- for k,v in df['modified'][j].items():
250
- # print(type(v))
251
- val_list.append(v)
252
-
253
- when = []
254
- for indx in range(len(val_list)):
255
- val_string = val_list[indx]
256
- pos = val_string.find("when: ")
257
- substr = ''
258
-
259
- if pos != -1:
260
- for i in range(pos+6, len(val_string)):
261
- if val_string[i] == "]":
262
- break
 
 
 
 
 
263
  else:
264
- substr = substr + val_string[i]
265
- else:
266
- pass
267
- if len(substr)!= 0:
268
- when.append(substr)
269
- else:
270
- pass
271
- # when=list(set(when))
272
 
273
- df['when'][j] = "<sep>".join(when)
274
- # else:
275
- # continue
276
 
277
 
278
  #----------FOR COLUMN "WHERE"------------#
279
  df['where'] = ''
280
  for j in range(len(df['modified'])):
281
- val_list = []
282
- val_string = ''
283
- for k,v in df['modified'][j].items():
284
- # print(type(v))
285
- val_list.append(v)
286
-
287
- where = []
288
- for indx in range(len(val_list)):
289
- val_string = val_list[indx]
290
- pos = val_string.find("where: ")
291
- substr = ''
292
-
293
- if pos != -1:
294
- for i in range(pos+7, len(val_string)):
295
- if val_string[i] == "]":
296
- break
 
 
 
 
 
297
  else:
298
- substr = substr + val_string[i]
299
- else:
300
- pass
301
- if len(substr)!= 0:
302
- where.append(substr)
303
- else:
304
- pass
305
- # where=list(set(where))
306
 
307
- df['where'][j] = "<sep>".join(where)
308
 
309
 
310
  data=df[["claim","who","what","why","when","where"]].copy()
@@ -626,7 +614,6 @@ def gen_qa_where(df):
626
  list_of_evidence_answer_where="No mention of 'where'in any related documents."
627
  rouge_l_scores="Not verifiable"
628
  return list_of_ques_where,list_of_ans_where,rouge_l_scores,list_of_evidence_answer_where
629
-
630
  #------------------------------------------------------
631
 
632
 
 
90
  import allennlp_models.tagging
91
  predictor = Predictor.from_path("structured-prediction-srl-bert.tar.gz")
92
 
93
+ #---------------------------------------------------------------
94
  #---------------------------------------------------------------
95
  def claim(text):
96
  import re
 
149
  #----------FOR COLUMN "WHO"------------#
150
  df['who'] = ''
151
  for j in range(len(df['modified'])):
152
+ val_list = []
153
+ val_string = ''
154
+ for k,v in df['modified'][j].items():
155
+ val_list.append(v)
156
+
157
+ who = set() # use set to remove duplicates
158
+ for indx in range(len(val_list)):
159
+ val_string = val_list[indx]
160
+ pos = val_string.find("who: ")
161
+ substr = ''
162
+
163
+ if pos != -1:
164
+ for i in range(pos+5, len(val_string)):
165
+ if val_string[i] == "]":
166
+ break
167
+ else:
168
+ substr = substr + val_string[i]
169
+ substr = substr.strip() # remove leading/trailing white space
170
+ pronouns = ['he', 'she', 'they', 'it', 'him', 'her', 'them', 'its', 'himself', 'herself', 'themselves']
171
+ if substr.lower() not in pronouns and not substr.lower().endswith("'s"): # remove pronouns and possessive pronouns
172
+ who.add(substr)
173
  else:
174
+ pass
175
+
176
+ df['who'][j] = "<sep>".join(who)
177
+
 
 
 
 
 
178
  # else:
179
  # continue
180
  #----------FOR COLUMN "WHAT"------------#
181
  df['what'] = ''
182
  for j in range(len(df['modified'])):
183
+ val_list = []
184
+ val_string = ''
185
+ for k,v in df['modified'][j].items():
186
+ val_list.append(v)
187
+
188
+ what = set() # use set to remove duplicates
189
+ for indx in range(len(val_list)):
190
+ val_string = val_list[indx]
191
+ pos = val_string.find("what: ")
192
+ substr = ''
193
+
194
+ if pos != -1:
195
+ for i in range(pos+5, len(val_string)):
196
+ if val_string[i] == "]":
197
+ break
198
+ else:
199
+ substr = substr + val_string[i]
200
+ substr = substr.strip() # remove leading/trailing white space
201
+ pronouns = ['he', 'she', 'they', 'it', 'him', 'her', 'them', 'its', 'himself', 'herself', 'themselves']
202
+ if substr.lower() not in pronouns and not substr.lower().endswith("'s"): # remove pronouns and possessive pronouns
203
+ what.add(substr)
204
  else:
205
+ pass
206
+
207
+ df['what'][j] = "<sep>".join(what)
 
 
 
 
 
 
 
 
208
 
209
  #----------FOR COLUMN "WHY"------------#
210
  df['why'] = ''
211
  for j in range(len(df['modified'])):
212
+ val_list = []
213
+ val_string = ''
214
+ for k,v in df['modified'][j].items():
215
+ val_list.append(v)
216
+
217
+ why = set() # use set to remove duplicates
218
+ for indx in range(len(val_list)):
219
+ val_string = val_list[indx]
220
+ pos = val_string.find("why: ")
221
+ substr = ''
222
+
223
+ if pos != -1:
224
+ for i in range(pos+5, len(val_string)):
225
+ if val_string[i] == "]":
226
+ break
227
+ else:
228
+ substr = substr + val_string[i]
229
+ substr = substr.strip() # remove leading/trailing white space
230
+ pronouns = ['he', 'she', 'they', 'it', 'him', 'her', 'them', 'its', 'himself', 'herself', 'themselves']
231
+ if substr.lower() not in pronouns and not substr.lower().endswith("'s"): # remove pronouns and possessive pronouns
232
+ why.add(substr)
233
  else:
234
+ pass
 
 
 
 
 
 
 
235
 
236
+ df['why'][j] = "<sep>".join(why)
 
 
237
 
238
  #----------FOR COLUMN "WHEN"------------#
239
  df['when'] = ''
240
  for j in range(len(df['modified'])):
241
+ val_list = []
242
+ val_string = ''
243
+ for k,v in df['modified'][j].items():
244
+ val_list.append(v)
245
+
246
+ when = set() # use set to remove duplicates
247
+ for indx in range(len(val_list)):
248
+ val_string = val_list[indx]
249
+ pos = val_string.find("when: ")
250
+ substr = ''
251
+
252
+ if pos != -1:
253
+ for i in range(pos+5, len(val_string)):
254
+ if val_string[i] == "]":
255
+ break
256
+ else:
257
+ substr = substr + val_string[i]
258
+ substr = substr.strip() # remove leading/trailing white space
259
+ pronouns = ['he', 'she', 'they', 'it', 'him', 'her', 'them', 'its', 'himself', 'herself', 'themselves']
260
+ if substr.lower() not in pronouns and not substr.lower().endswith("'s"): # remove pronouns and possessive pronouns
261
+ when.add(substr)
262
  else:
263
+ pass
 
 
 
 
 
 
 
264
 
265
+ df['when'][j] = "<sep>".join(when)
 
 
266
 
267
 
268
  #----------FOR COLUMN "WHERE"------------#
269
  df['where'] = ''
270
  for j in range(len(df['modified'])):
271
+ val_list = []
272
+ val_string = ''
273
+ for k,v in df['modified'][j].items():
274
+ val_list.append(v)
275
+
276
+ where = set() # use set to remove duplicates
277
+ for indx in range(len(val_list)):
278
+ val_string = val_list[indx]
279
+ pos = val_string.find("where: ")
280
+ substr = ''
281
+
282
+ if pos != -1:
283
+ for i in range(pos+5, len(val_string)):
284
+ if val_string[i] == "]":
285
+ break
286
+ else:
287
+ substr = substr + val_string[i]
288
+ substr = substr.strip() # remove leading/trailing white space
289
+ pronouns = ['he', 'she', 'they', 'it', 'him', 'her', 'them', 'its', 'himself', 'herself', 'themselves']
290
+ if substr.lower() not in pronouns and not substr.lower().endswith("'s"): # remove pronouns and possessive pronouns
291
+ where.add(substr)
292
  else:
293
+ pass
 
 
 
 
 
 
 
294
 
295
+ df['where'][j] = "<sep>".join(where)
296
 
297
 
298
  data=df[["claim","who","what","why","when","where"]].copy()
 
614
  list_of_evidence_answer_where="No mention of 'where'in any related documents."
615
  rouge_l_scores="Not verifiable"
616
  return list_of_ques_where,list_of_ans_where,rouge_l_scores,list_of_evidence_answer_where
 
617
  #------------------------------------------------------
618
 
619