File size: 3,020 Bytes
5d72d1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import random
from transformers import pipeline

class ToeicVocabularyApp:
    def __init__(self, data_path):
        self.data_path = data_path
        self.df = pd.read_csv(data_path)
        self.settings = {
            "num_questions": 10,
            "study_mode": ["Flashcard", "Trắc nghiệm", "Thử thách tốc độ", "Ôn tập theo chủ đề", "Kiểm tra"],
            "time_limit": 30,  # in seconds
            "selected_topics": []
        }
        self.classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
        self.topics = ["Kinh tế", "Du lịch", "Giao tiếp", "Công nghệ", "Giáo dục"]
    
    def update_settings(self, setting_name, value):
        if setting_name in self.settings:
            self.settings[setting_name] = value
    
    def add_vocabulary(self, word, meaning, topic=None):
        new_entry = {"Từ vựng": word, "Nghĩa": meaning, "Chủ đề": topic if topic else ""}
        self.df = self.df.append(new_entry, ignore_index=True)
        self.df.to_csv(self.data_path, index=False)
    
    def modify_vocabulary(self, index, word=None, meaning=None, topic=None):
        if word:
            self.df.at[index, "Từ vựng"] = word
        if meaning:
            self.df.at[index, "Nghĩa"] = meaning
        if topic:
            self.df.at[index, "Chủ đề"] = topic
        self.df.to_csv(self.data_path, index=False)
    
    def generate_question(self, mode):
        if mode == "Trắc nghiệm":
            questions = []
            for _ in range(self.settings["num_questions"]):
                correct_row = self.df.sample(1).iloc[0]
                wrong_answers = self.df[self.df["Từ vựng"] != correct_row["Từ vựng"]]["Nghĩa"].sample(3).tolist()
                options = [correct_row["Nghĩa"]] + wrong_answers
                random.shuffle(options)
                question = {
                    "question": correct_row["Từ vựng"],
                    "options": options,
                    "correct_answer": correct_row["Nghĩa"]
                }
                questions.append(question)
            return questions
        elif mode == "Ôn tập theo chủ đề":
            # Placeholder for topic-based review
            pass
        # Add other modes as needed
    
    def use_guide(self):
        return "Guide text will be added here."
    
    def run_mode(self, mode):
        if mode == "Hướng dẫn sử dụng":
            return self.use_guide()
        elif mode in ["Flashcard", "Trắc nghiệm", "Thử thách tốc độ", "Ôn tập theo chủ đề", "Kiểm tra"]:
            return self.generate_question(mode)
        else:
            return "Invalid mode selected."

# Example of usage
if __name__ == "__main__":
    app = ToeicVocabularyApp('toeic_vocabulary.csv')
    app.update_settings('num_questions', 5)
    print(app.run_mode('Trắc nghiệm'))