mention_answer zu dict(answer, answer_start, answer_end)
Browse files- quoteli3.py +15 -13
quoteli3.py
CHANGED
@@ -53,7 +53,7 @@ _URLs = {
|
|
53 |
|
54 |
class QuoteLi3(datasets.GeneratorBasedBuilder):
|
55 |
|
56 |
-
VERSION = datasets.Version("
|
57 |
|
58 |
BUILDER_CONFIGS = [
|
59 |
datasets.BuilderConfig(name="quotes", version=VERSION, description="Returns Quotes"),
|
@@ -72,7 +72,7 @@ class QuoteLi3(datasets.GeneratorBasedBuilder):
|
|
72 |
"connection": datasets.Value("string"),
|
73 |
"id": datasets.Value("string"),
|
74 |
"answer": datasets.Value("string"),
|
75 |
-
"answer_mention":
|
76 |
"question": datasets.Value("string"),
|
77 |
"context": datasets.Value("string")
|
78 |
}
|
@@ -128,13 +128,15 @@ class QuoteLi3(datasets.GeneratorBasedBuilder):
|
|
128 |
if self.config.name == "quotes":
|
129 |
for quote in quote_list:
|
130 |
quote_key = key + '_' + quote.attrib['id']
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
138 |
yield quote_key, {
|
139 |
"mention": quote.attrib["mention"] if 'mention' in quote.attrib else 'no_mention',
|
140 |
"oid": quote.attrib["oid"] if 'oid' in quote.attrib else 'no_oid',
|
@@ -142,9 +144,9 @@ class QuoteLi3(datasets.GeneratorBasedBuilder):
|
|
142 |
"connection": quote.attrib["connection"] if 'connection' in quote.attrib else 'no_connection',
|
143 |
"id": quote.attrib["id"] if 'id' in quote.attrib else 'no_id',
|
144 |
"answer": "" if split == "test" else quote.attrib["speaker"],
|
145 |
-
"answer_mention":
|
146 |
"question": "Who says 'QUOTE'",
|
147 |
-
"context":
|
148 |
}
|
149 |
else:
|
150 |
character_list = base_tree.find('characters').findall('character')
|
@@ -205,8 +207,8 @@ class QuoteLi3(datasets.GeneratorBasedBuilder):
|
|
205 |
mention_tail = mention_tail[:25]
|
206 |
search_text = mention_text + mention_tail
|
207 |
if mention_tail == '':
|
208 |
-
return 'NO_MENTION'
|
209 |
-
return mention_text
|
210 |
|
211 |
def get_context(self, quote_element, filename):
|
212 |
chapter_text = self.get_texts_by_file(filename)
|
|
|
53 |
|
54 |
class QuoteLi3(datasets.GeneratorBasedBuilder):
|
55 |
|
56 |
+
VERSION = datasets.Version("0.1")
|
57 |
|
58 |
BUILDER_CONFIGS = [
|
59 |
datasets.BuilderConfig(name="quotes", version=VERSION, description="Returns Quotes"),
|
|
|
72 |
"connection": datasets.Value("string"),
|
73 |
"id": datasets.Value("string"),
|
74 |
"answer": datasets.Value("string"),
|
75 |
+
"answer_mention": dict,
|
76 |
"question": datasets.Value("string"),
|
77 |
"context": datasets.Value("string")
|
78 |
}
|
|
|
128 |
if self.config.name == "quotes":
|
129 |
for quote in quote_list:
|
130 |
quote_key = key + '_' + quote.attrib['id']
|
131 |
+
mention, search_text = self.find_mention(quote, path)
|
132 |
+
context = self.get_context(quote, path)
|
133 |
+
answer_mention_start = context.find(search_text)
|
134 |
+
answer_mention_end = answer_mention_start + len(mention)
|
135 |
+
answer_mention = {
|
136 |
+
'answer': mention,
|
137 |
+
'answer_start': answer_mention_start,
|
138 |
+
'answer_end': answer_mention_end
|
139 |
+
}
|
140 |
yield quote_key, {
|
141 |
"mention": quote.attrib["mention"] if 'mention' in quote.attrib else 'no_mention',
|
142 |
"oid": quote.attrib["oid"] if 'oid' in quote.attrib else 'no_oid',
|
|
|
144 |
"connection": quote.attrib["connection"] if 'connection' in quote.attrib else 'no_connection',
|
145 |
"id": quote.attrib["id"] if 'id' in quote.attrib else 'no_id',
|
146 |
"answer": "" if split == "test" else quote.attrib["speaker"],
|
147 |
+
"answer_mention": answer_mention,
|
148 |
"question": "Who says 'QUOTE'",
|
149 |
+
"context": context,
|
150 |
}
|
151 |
else:
|
152 |
character_list = base_tree.find('characters').findall('character')
|
|
|
207 |
mention_tail = mention_tail[:25]
|
208 |
search_text = mention_text + mention_tail
|
209 |
if mention_tail == '':
|
210 |
+
return 'NO_MENTION', 'NO_MENTION'
|
211 |
+
return mention_text, search_text
|
212 |
|
213 |
def get_context(self, quote_element, filename):
|
214 |
chapter_text = self.get_texts_by_file(filename)
|