MCPcopy Create free account
hub / github.com/InternScience/SciReason / check_correctness

Function check_correctness

opencompass/datasets/MedCalc_Bench.py:14–70  ·  view source on GitHub ↗
(answer: str, ground_truth, calid, upper_limit,
                      lower_limit)

Source from the content-addressed store, hash-verified

12
13
14def check_correctness(answer: str, ground_truth, calid, upper_limit,
15 lower_limit):
16 """"""
17 calid = int(calid)
18
19 if calid in [13, 68]:
20 # Output Type: date
21
22 if datetime.strptime(
23 answer,
24 '%m/%d/%Y').strftime('%-m/%-d/%Y') == datetime.strptime(
25 ground_truth, '%m/%d/%Y').strftime('%-m/%-d/%Y'):
26 correctness = 1
27 else:
28 correctness = 0
29 elif calid in [69]:
30 # Output Type: integer (A, B)
31 match = re.search(
32 r"\(?[\"\']?(\d+)\s*(weeks?)?[\"\']?,?"
33 r"\s*[\"\']?(\d+)\s*(days?)?[\"\']?\s*\)?", ground_truth)
34 ground_truth = f'({match.group(1)}, {match.group(3)})'
35 match = re.search(
36 r"\(?[\"\']?(\d+)\s*(weeks?)?[\"\']?,?"
37 r"\s*[\"\']?(\d+)\s*(days?)?[\"\']?\s*\)?", answer)
38 if match:
39 weeks = match.group(1)
40 days = match.group(3)
41 answer = f'({weeks}, {days})'
42 if eval(answer) == eval(ground_truth):
43 correctness = 1
44 else:
45 correctness = 0
46 else:
47 correctness = 0
48 elif calid in [
49 4, 15, 16, 17, 18, 20, 21, 25, 27, 28, 29, 32, 33, 36, 43, 45, 48,
50 51, 69
51 ]:
52 # Output Type: integer A
53 answer = round(eval(answer))
54 if answer == eval(ground_truth):
55 correctness = 1
56 else:
57 correctness = 0
58 elif calid in [
59 2, 3, 5, 6, 7, 8, 9, 10, 11, 19, 22, 23, 24, 26, 30, 31, 38, 39,
60 40, 44, 46, 49, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67
61 ]:
62 # Output Type: decimal
63 answer = eval(answer)
64 if answer >= eval(lower_limit) and answer <= eval(upper_limit):
65 correctness = 1
66 else:
67 correctness = 0
68 else:
69 raise ValueError(f'Unknown calculator ID: {calid}')
70 return correctness
71

Callers 1

scoreMethod · 0.85

Calls 1

groupMethod · 0.80

Tested by

no test coverage detected