File size: 1,044 Bytes
256a159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 post_process_autoj(judgement: str):
    """Input a string like below:

    xxx[[5]]xxx, and extract the score
    """
    pattern = r'\[(\d+)\]'
    matched_result = re.findall(pattern, judgement)
    if matched_result:
        score = int(matched_result[0])
    else:
        return None
    return {'score': score}


def post_process_judgelm(judgement: str):
    """Input a string like below:

    5, reason:xxx and extract the score
    """
    if len(judgement) >= 2:
        first_two_chars = judgement[:2]
        if first_two_chars.isdigit() and first_two_chars == '10':
            score = 10
        else:
            first_char = judgement[0]
            if first_char.isdigit() and 0 <= int(first_char) <= 9:
                score = int(first_char)
            else:
                return None
    elif len(judgement) == 1:
        if judgement.isdigit() and 0 <= int(judgement) <= 9:
            score = int(judgement)
        else:
            return None
    else:
        return None
    return {'score': score}