-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringify.py
47 lines (36 loc) · 1.38 KB
/
stringify.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
46
47
import numpy as np
def stringify(story, exist_answer=False, order=0): # exist_answer is dummy
lines = []
i = 0 # The number of descriptions processed
j = 0 # The number of lines output
count_order = 0
while True:
if isinstance(story[i], str):
line = story[i]
else:
line = story[i].render()
# Capitalize the line
line = line[0].upper() + line[1:]
# Prepend the line number
if line.split()[0] != 'Question:' and line.split()[0] != 'Choices:':
line = '%d %s' % (i + 1, line)
else: # Start with 'Choice'
if line.split()[0] == 'Choices:':
lines.append(line)
break
else: # Start with 'Question'
if count_order == order:
lines.append(line)
count_order += 1
i += 1
continue
lines.append(line)
# Increment counters
i += 1
# Append supporting lines indices if necessary
# if hasattr(story[i], 'idx_support') and story[i].idx_support:
# line += '\t%s' % ' '.join([str(x + 1)
# for x in story[i].idx_support])
if i >= len(story):
break
return lines