-
Notifications
You must be signed in to change notification settings - Fork 3
/
Task_prescribed_phrases.py
45 lines (35 loc) · 1.3 KB
/
Task_prescribed_phrases.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
42
43
44
45
from scorers.scorer import Scorer
import numpy as np
class Task_phrases_Scorer(Scorer):
def __init__(self):
super(Scorer,self).__init__()
def get_final_score(self, ans, histories, tasks):
'''
Input:
- ans (str): The answer to be scored.
- formats (list of dictionaries): Criteria for scoring the answer.
Output:
- final_score (float): The final score for the answer regarding *Task-prescribed Query*
Function:
Calculate the final score for the answer based on specified criteria.
'''
task_score = np.nan
if not isinstance(ans, str):
task_score = 0
else:
task_score = self.keywords_score(ans, tasks)
return task_score
def keywords_score(self, ans, criteria):
keywords = ''
for criterion in criteria:
if criterion['criterion'] in ["keywords"]:
keywords = criterion['limit']
break
elif criterion['criterion'] == 'NULL':
return np.nan
assert (keywords != '' and not isinstance(keywords, float) and len(keywords) != 0)
cnt = 0
for keyword in keywords:
if keyword in ans:
cnt += 1
return cnt / len(keywords)