utils.py 305 Bytes
Newer Older
haileyschoelkopf's avatar
haileyschoelkopf committed
1
2
3
import re


lintangsutawika's avatar
lintangsutawika committed
4
def doc_to_choice(doc):
haileyschoelkopf's avatar
haileyschoelkopf committed
5
6
7
8
9
10
11
12
    choices = [
        c[4:].rstrip(" ,")
        for c in re.findall(r"[abcd] \) .*?, |e \) .*?$", doc["options"])
    ]
    return choices


def doc_to_target(doc):
lintangsutawika's avatar
lintangsutawika committed
13
    choices = doc_to_choice(doc)
haileyschoelkopf's avatar
haileyschoelkopf committed
14
    return choices[["a", "b", "c", "d", "e"].index(doc["correct"])]