-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathis_lesson_options.py
246 lines (226 loc) · 11.7 KB
/
is_lesson_options.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
48
49
50
51
52
53
54
55
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 18 14:24:28 2023
@author: Zoe
"""
import is_utility
from collections import namedtuple
import is_csvreader as csvr
import random as rd
#Part 1: General user options menus (ie not including vocabulary)--------------
menu_option = namedtuple('menu_option', ['key', 'description'])
async def options_menu(options, options_name, message="Select practice option"):
"""Display the specified options to the user and get chosen option from user.
* 'options' is just the 'options' object used by is_run_lesson.
* 'options_name' is one of the lists of named tuples below.
* 'message' is the message to be displayed to the user before the options
are presented."""
options_list = user_menu_options[options_name]
user_response = "0"
while user_response not in ["x"] + [str(n) for n in range(1,len(options_list)+1)]:
print()
print(message)
for index in range(len(options_list)):
print(str(index+1) + ": " + options_list[index].description)
print("X: Exit")
user_response = (await is_utility.user_input("Practice option: ")).lower().strip()
if user_response != "x":
options[options_name] = options_list[int(user_response)-1].key
else:
options[options_name] = "x"
parameter_prompts = {"gender_mode" : "Select practice option",
"comp_sup" : "Select practice option",
"chosen_tense" : "Select tense",
"verb_form" : "Practice which verb forms?",
"translate_words" : "Select translation direction",
"translate_numbers" : "Select translation direction",
"translate_generic" : "Select practice option",
"sentence" : "Select practice option",
"sentence_qa" : "Select practice option",
"prep_object" : "Use prepositions with pronouns or nouns?"}
user_menu_options = {"gender_mode" : [menu_option("adj", "Adjectives"),
menu_option("def_nom", "Definite articles (nom.)")#,
#menu_option("def_prep", "Definite articles (prep.)"),
#menu_option("def_poss", "Definite articles (poss.)"),
#menu_option("def_all", "Definite articles (All.)"),
],
"comp_sup" : [menu_option("comp", "Comparatives ('better', 'faster', etc)"),
menu_option("sup", "Superlatives ('best', 'fastest', etc)"),
menu_option("both", "Both")],
"chosen_tense" : [menu_option("present", "Present tense"),
menu_option("past", "Past tense"),
menu_option("future", "Future tense"),
menu_option("any", "All tenses")],
"verb_form" : [menu_option("p_s", "Positive statements only"),
menu_option("pn_s", "Positive and negative statements"),
menu_option("pn_sq", "Positive and negative statements and questions")],
"translate_words" : [menu_option("en_gd", "English to Gaelic"),
menu_option("gd_en", "Gaelic to English")],
"translate_numbers" : [menu_option("dig_gd", "Digits to Gaelic"),
menu_option("gd_dig", "Gaelic to digits")],
"translate_generic" : [menu_option("from_en", "English prompts"),
menu_option("from_gd", "Gaelic prompts")],
"sentence" : [menu_option("full", "Full sentence"),
menu_option("blank", "Fill in the blank")],
"sentence_qa" : [menu_option("full", "Full sentence"),
menu_option("blank", "Fill in the blank"),
menu_option("q_and_a", "Question and answer")],
"prep_object" : [menu_option("pronouns", "Prepositional pronouns"),
menu_option("nouns", "Prepositions with nouns (names, professions)")]
}
#Part 2: Vocabulary selection functions----------------------------------------
required_columns = {"give_get" : ("english", "nom_sing"),
"give_to" : ("english", "nom_sing"),
"get_from" : ("english", "nom_sing"),
"possession_aig" : ("english", "nom_sing"),
"gender" : ("english", "nom_sing", "gender"),
"numbers" : (),
"plurals" : ("english", "nom_sing", "nom_pl"),
"learn_nouns" : ("english", "nom_sing"),
"preferences" : ("english", "nom_sing"),
"verb_tenses" : ("english", "en_past", "en_vn", "root", "verbal_noun"),
"professions_annan" : (),
"emphasis_adjectives" : ("english", "adj_gd"),
"possession_mo" : ("english", "nom_sing", "nom_pl"),
"where_from" : ("english", "nom_sing", "gender"),
"where_in" : ("english", "nom_sing", "gender"),
"comparisons" : (),
"comparatives_superlatives": ("english", "nom_sing", "gender"),
"time" : (),
"which_season" : (),
"which_month" : (),
"going_to" : ("english", "place_gd")}
async def select_vocab(lesson, options):
"""Select vocabulary file to use in lesson"""
if len(required_columns[lesson.__name__]) == 0:
return None
#Cases where vocab file must be from selected list
elif lesson.__name__ == "possession_mo":
vocab_num = ""
while vocab_num not in ("x","1","2","3"):
print()
print("Select topic")
print("1: Body parts")
print("2: Clothes")
print("3: Family")
print("X: Exit")
vocab_num = (await is_utility.user_input("Practice mode: ")).lower().strip()
if vocab_num == "x":
return "x"
elif vocab_num == "1":
return csvr.read_csv('people_body')
elif vocab_num == "2":
return csvr.read_csv('people_clothes')
elif vocab_num == "3":
return csvr.read_csv('people_family')
elif lesson.__name__ in ("where_from", "going_to"):
vocab_num = ""
while vocab_num not in ("x","1","2"):
print()
print("Select geography")
print("1: Countries")
print("2: Places in Scotland")
print("X: Exit")
vocab_num = (await is_utility.user_input("Practice mode: ")).lower().strip()
if vocab_num == "x":
return "x"
elif vocab_num == "1":
return csvr.read_csv('places_world')
elif vocab_num == "2":
return csvr.read_csv('places_scotland')
elif lesson.__name__ == "where_in":
vocab_num = ""
while vocab_num not in ("x","1","2","3","4"):
print()
print("Select places")
print("1: Countries")
print("2: Places in Scotland")
print("3: Around town")
print("4: In the house")
print("X: Exit")
vocab_num = (await is_utility.user_input("Practice mode: ")).lower().strip()
if vocab_num == "x":
return "x"
elif vocab_num == "1":
places = csvr.read_csv('places_world')
csvr.rename_column(places, "place_gd", "nom_sing")
return places
elif vocab_num == "2":
places = csvr.read_csv('places_scotland')
csvr.rename_column(places, "place_gd", "nom_sing")
return places
elif vocab_num == "3":
return csvr.read_csv('places_town')
elif vocab_num == "4":
return csvr.read_csv('places_home')
#Case where any compatible vocab file can be used
else:
from os.path import exists
from os import listdir
#Get list of suitable vocab files, out of list of all files
allfiles = listdir("Vocabulary/")
vocab_suggestions = []
for filename in allfiles:
checkfile = csvr.read_csv(filename[:-4])
if check_vocab(lesson.__name__, checkfile, messages=False) == True:
vocab_suggestions.append(filename[:-4])
#Ask for user input
vocab_file = ""
print()
print("Name the vocabulary list to use in practice")
print("or type 'help' to list all possible vocabulary lists")
print("or X to exit")
while vocab_file not in vocab_suggestions + ["x"] + [str(n) for n in range(1,len(vocab_suggestions)+1)]:
print()
vocab_file = (await is_utility.user_input("Vocabulary list: ")).lower().strip()
#user escape
if vocab_file == "x":
return "x"
#user wants list of files
elif vocab_file == "help":
for index, file in enumerate(vocab_suggestions):
print(str(index+1) + ": " + vocab_suggestions[index])
elif vocab_file.isnumeric() and int(vocab_file) in range(1,len(vocab_suggestions)+1):
vocab_list = csvr.read_csv(f'{vocab_suggestions[int(vocab_file)]}')
elif exists(f"Vocabulary/{vocab_file}.csv")==False:
print()
print("File not found: Check vocabulary list is a CSV file in the Vocabulary folder")
elif vocab_file not in vocab_suggestions:
print()
check_vocab(lesson.__name__, checkfile, messages=True)
else:
vocab_list = csvr.read_csv(f'{vocab_file}')
return vocab_list
def check_vocab(lesson_name, vocab_sample, messages = True):
"""Check that the chosen vocab file has the right columns for the lesson"""
list_ok = True
if len(required_columns[lesson_name]) > 0:
for colname in required_columns[lesson_name]:
for entry in vocab_sample:
if colname not in entry:
list_ok = False
if messages == True:
print()
print(f"Error: Chosen vocabulary list must contain column {colname} (lower-case)")
if list_ok == False and messages == True:
print("Try another vocabulary list or add the required columns and try again")
return list_ok
async def vocab_sample_select(vocab_list, options):
user_size = ""
while user_size.isdigit()==False:
print()
print("How many words do you want to use from the list?")
user_size = await is_utility.user_input("(Max " + str(len(vocab_list)) + "): ")
user_size = max(1,min(int(user_size),len(vocab_list)))
if user_size == 1:
print()
print("Which word do you want to practice?")
wordlist = csvr.getcol(vocab_list, "english")
for index, word in enumerate(wordlist):
print(str(index+1) + ": " + word)
user_response = ""
while user_response not in [str(n) for n in range(1,len(wordlist)+1)]:
user_response = await is_utility.user_input("Number: ")
options["vocab_sample"] = csvr.filter_rows(vocab_list, [int(user_response)-1])
else:
options["vocab_sample"] = rd.sample(vocab_list, user_size)