-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract_answer.py
41 lines (37 loc) · 1.01 KB
/
extract_answer.py
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
import re
def extract_ans(response_str, language):
if language == 'ch':
pattern = [
r'答案:([A-D, ]+)',
r'正确选项:([A-D])',
r'正确选项:([A-D, ]+)',
r'正确选项:([A-D]).',
r'[A-D](?=[、。])',
r'([A-D])、?',
r'[A-D]',
r'^([A-D])\.',
r'[A-D](?=\.)',
]
elif language == 'en':
pattern = [
r"Answer: ([A-Za-z]+)",
r"Answer: (.*)",
r"Right Answer: (.*)",
r"Option (.*)",
r'[A-E](?=\.)',
r'([A-E])、?',
r'[A-E]',
r'^([A-E])\.',
r'[A-E](?=\.)',
]
ans_list = []
for p in pattern:
if len(ans_list) == 0:
ans_list = re.findall(p, response_str, flags=re.MULTILINE)
temp = []
for i in ans_list:
temp += i.split(',')
ans_list = temp
else:
break
return ans_list