Felix-ML commited on
Commit
ba9ab24
·
1 Parent(s): 13eea4d

added features: quotes(book_title, large_context(4*more characters than the normal context), characters(book_title)

Browse files
Files changed (1) hide show
  1. quoteli3.py +10 -5
quoteli3.py CHANGED
@@ -77,7 +77,9 @@ class QuoteLi3(datasets.GeneratorBasedBuilder):
77
  'answer_end': datasets.Value("int16"),
78
  'answer_in_context': datasets.Value("bool")},
79
  "question": datasets.Value("string"),
80
- "context": datasets.Value("string")
 
 
81
  }
82
  )
83
  else: #returns characters
@@ -87,7 +89,8 @@ class QuoteLi3(datasets.GeneratorBasedBuilder):
87
  "description": datasets.Value("string"),
88
  "gender": datasets.Value("string"),
89
  "id": datasets.Value("string"),
90
- "name": datasets.Value("string")
 
91
  }
92
  )
93
  return datasets.DatasetInfo(
@@ -133,6 +136,7 @@ class QuoteLi3(datasets.GeneratorBasedBuilder):
133
  quote_key = key + '_' + quote.attrib['id']
134
  mention, search_text = self.find_mention(quote, path)
135
  context = self.get_context(quote, path)
 
136
  answer_mention_start = context.find(search_text)
137
  answer_mention_end = answer_mention_start + len(mention)
138
  if mention != 'NO_MENTION' and answer_mention_start >= 0:
@@ -159,6 +163,8 @@ class QuoteLi3(datasets.GeneratorBasedBuilder):
159
  "answer_mention": answer_mention,
160
  "question": "Who says 'QUOTE'",
161
  "context": context,
 
 
162
  }
163
  else:
164
  character_list = base_tree.find('characters').findall('character')
@@ -170,6 +176,7 @@ class QuoteLi3(datasets.GeneratorBasedBuilder):
170
  "gender": character.attrib["gender"] if 'gender' in character.attrib else 'no_gender',
171
  "name": character.attrib["name"] if 'name' in character.attrib else 'no_name',
172
  "id": character.attrib["id"] if 'id' in character.attrib else 'no_id',
 
173
  }
174
 
175
 
@@ -222,10 +229,8 @@ class QuoteLi3(datasets.GeneratorBasedBuilder):
222
  return 'NO_MENTION', 'NO_MENTION'
223
  return mention_text, search_text
224
 
225
- def get_context(self, quote_element, filename):
226
  chapter_text = self.get_texts_by_file(filename)
227
- #maximum range for the context in characters
228
- max_range = 1000
229
  quote = self.get_quote_content(quote_element)
230
  start_index = chapter_text.find(quote)
231
 
 
77
  'answer_end': datasets.Value("int16"),
78
  'answer_in_context': datasets.Value("bool")},
79
  "question": datasets.Value("string"),
80
+ "context": datasets.Value("string"),
81
+ "large_context": datasets.Value("string"),
82
+ "book_title": datasets.Value("string")
83
  }
84
  )
85
  else: #returns characters
 
89
  "description": datasets.Value("string"),
90
  "gender": datasets.Value("string"),
91
  "id": datasets.Value("string"),
92
+ "name": datasets.Value("string"),
93
+ "book_title": datasets.Value("string")
94
  }
95
  )
96
  return datasets.DatasetInfo(
 
136
  quote_key = key + '_' + quote.attrib['id']
137
  mention, search_text = self.find_mention(quote, path)
138
  context = self.get_context(quote, path)
139
+ large_context = self.get_context(quote, path, 4000)
140
  answer_mention_start = context.find(search_text)
141
  answer_mention_end = answer_mention_start + len(mention)
142
  if mention != 'NO_MENTION' and answer_mention_start >= 0:
 
163
  "answer_mention": answer_mention,
164
  "question": "Who says 'QUOTE'",
165
  "context": context,
166
+ "large_context": large_context,
167
+ "book_title": key,
168
  }
169
  else:
170
  character_list = base_tree.find('characters').findall('character')
 
176
  "gender": character.attrib["gender"] if 'gender' in character.attrib else 'no_gender',
177
  "name": character.attrib["name"] if 'name' in character.attrib else 'no_name',
178
  "id": character.attrib["id"] if 'id' in character.attrib else 'no_id',
179
+ "book_title": key,
180
  }
181
 
182
 
 
229
  return 'NO_MENTION', 'NO_MENTION'
230
  return mention_text, search_text
231
 
232
+ def get_context(self, quote_element, filename, max_range=1000):
233
  chapter_text = self.get_texts_by_file(filename)
 
 
234
  quote = self.get_quote_content(quote_element)
235
  start_index = chapter_text.find(quote)
236