styles.py 2.96 KB
Newer Older
1
2
3
import string
from functools import partial

lintangsutawika's avatar
lintangsutawika committed
4

5
6
7
8
9
10
11
12
13
14
15
16
def doc_to_text_base(alphabet, style, doc):

    choices = doc["choices"]["text"]
    num = len(choices)

    letter_list = [style.format(letter) for letter in alphabet[0:num]]

    if "\t" in style:
        choice_string = "{}{}"
    else:
        choice_string = "{} {}"

lintangsutawika's avatar
lintangsutawika committed
17
18
19
    doc_to_text = "\n\n".join(
        [
            "Question: " + doc["question"] + "\nAnswer:",
20
        ]
lintangsutawika's avatar
lintangsutawika committed
21
        + [choice_string.format(i, j) for i, j in zip(letter_list, choices)]
22
23
24
25
    )

    return doc_to_text

lintangsutawika's avatar
lintangsutawika committed
26

27
28
29
30
# Full continuation
def choice_A(doc):
    return doc["choices"]["text"]

lintangsutawika's avatar
lintangsutawika committed
31

32
33
34
35
36
37
38
39
# Letters only
def choice_B(alphabet, style, doc):

    choices = doc["choices"]["text"]
    num = len(choices)

    letter_list = [style.format(letter) for letter in alphabet[0:num]]
    if "\t" in style:
lintangsutawika's avatar
lintangsutawika committed
40
        letter_list = [letter.replace("\t", "") for letter in letter_list]
41
42
43

    return letter_list

lintangsutawika's avatar
lintangsutawika committed
44

45
46
47
48
49
50
51
52
# Letters + Full continuation
def choice_C(alphabet, style, doc):

    choices = doc["choices"]["text"]
    num = len(choices)

    letter_list = [style.format(letter) for letter in alphabet[0:num]]
    if "\t" not in style:
lintangsutawika's avatar
lintangsutawika committed
53
54
55
        letter_list = [letter + " " for letter in letter_list]

    return [letter + choice for letter, choice in zip(letter_list, choices)]
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89


template_01 = partial(doc_to_text_base, string.ascii_lowercase, "({})")
choice_01a = choice_A
choice_01b = partial(choice_B, string.ascii_lowercase, "({})")
choice_01c = partial(choice_C, string.ascii_lowercase, "({})")
template_02 = partial(doc_to_text_base, string.ascii_lowercase, "{})")
choice_02a = choice_A
choice_02b = partial(choice_B, string.ascii_lowercase, "{})")
choice_02c = partial(choice_C, string.ascii_lowercase, "{})")
template_03 = partial(doc_to_text_base, string.ascii_lowercase, "{}.")
choice_03a = choice_A
choice_03b = partial(choice_B, string.ascii_lowercase, "{}.")
choice_03c = partial(choice_C, string.ascii_lowercase, "{}.")
template_04 = partial(doc_to_text_base, string.ascii_lowercase, "{}\t")
choice_04a = choice_A
choice_04b = partial(choice_B, string.ascii_lowercase, "{}\t")
choice_04c = partial(choice_C, string.ascii_lowercase, "{}\t")
template_05 = partial(doc_to_text_base, string.ascii_uppercase, "({})")
choice_05a = choice_A
choice_05b = partial(choice_B, string.ascii_uppercase, "({})")
choice_05c = partial(choice_C, string.ascii_uppercase, "({})")
template_06 = partial(doc_to_text_base, string.ascii_uppercase, "{})")
choice_06a = choice_A
choice_06b = partial(choice_B, string.ascii_uppercase, "{})")
choice_06c = partial(choice_C, string.ascii_uppercase, "{})")
template_07 = partial(doc_to_text_base, string.ascii_uppercase, "{}.")
choice_07a = choice_A
choice_07b = partial(choice_B, string.ascii_uppercase, "{}.")
choice_07c = partial(choice_C, string.ascii_uppercase, "{}.")
template_08 = partial(doc_to_text_base, string.ascii_uppercase, "{}\t")
choice_08a = choice_A
choice_08b = partial(choice_B, string.ascii_uppercase, "{}\t")
choice_08c = partial(choice_C, string.ascii_uppercase, "{}\t")