-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuserinfo.py
More file actions
226 lines (180 loc) · 6.92 KB
/
userinfo.py
File metadata and controls
226 lines (180 loc) · 6.92 KB
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
import json
class PersonalInfo:
def __init__(
self,
language,
name,
gender,
interests,
age,
personality,
mistakes,
past_conversation,
behaviours
):
self.language = language
self.name = name,
self.gender = gender,
self.interests = interests,
self.age = age,
self.personality = personality,
self.mistakes = mistakes,
self.past_conversation = past_conversation,
self.behaviours = behaviours
def get_language(self):
return str(self.language)
def get_name(self):
return str(self.name)
def get_gender(self):
return str(self.gender)
def get_interests(self):
return ', '.join(str(i) for i in self.interests)
def get_age(self):
return str(self.age)
def get_personality(self):
return str(self.personality)
def get_mistakes(self):
return str(self.mistakes)
def get_past_conversation(self):
return str(self.past_conversation)
def get_behaviours(self):
return str(self.behaviours)
def set_language(self, language):
self.language = str(language)
def set_name(self, name):
self.name = str(name)
def set_gender(self, gender):
self.gender = str(gender)
def set_interests(self, interests):
if isinstance(interests, list):
self.interests = interests
else:
self.interests = None
def set_age(self, age):
if isinstance(age, int):
self.age = age
else:
self.age = None
def set_personality(self, personality):
self.personality = str(personality)
def set_mistakes(self, mistakes):
self.mistakes = str(mistakes)
def set_past_conversation(self, past_conversation):
self.past_conversation = str(past_conversation)
def set_behaviours(self, behaviours):
self.behaviours = str(behaviours)
@staticmethod
def dump_to_json(json_file_path, interests, personality, mistakes, past_conversation, behaviours):
with open(json_file_path, 'r') as json_file:
data = json.load(json_file)
if not interests is None:
data["user_information"]["personal_information"]["interests"] = interests
if not personality is None:
data["user_information"]["personal_information"]["personality"] = personality
if not mistakes is None:
data["user_information"]["personal_information"]["mistakes"] = mistakes
if not past_conversation is None:
data["user_information"]["personal_information"]["past_conversation"] = past_conversation
if not behaviours is None:
data["user_information"]["personal_information"]["behaviours"] = behaviours
with open(json_file_path, 'w') as json_file:
json.dump(data, json_file, indent=4)
class LanguageProficiency:
def __init__(
self,
vocabulary,
grammar,
social_cultural_context,
comprehension,
conversation_skills
):
self.vocabulary = vocabulary
self.grammar = grammar
self.social_cultural_context = social_cultural_context
self.comprehension = comprehension
self.conversation_skills = conversation_skills
def get_vocabulary(self):
return self.vocabulary
def set_vocabulary(self, vocabulary):
if isinstance(vocabulary, int):
self.vocabulary = vocabulary
else:
self.vocabulary = None
def get_grammar(self):
return self.grammar
def set_grammar(self, grammar):
if isinstance(grammar, int):
self.grammar = grammar
else:
self.grammar = None
def get_social_cultural_context(self):
return self.social_cultural_context
def set_social_cultural_context(self, social_cultural_context):
if isinstance(social_cultural_context, int):
self.social_cultural_context = social_cultural_context
else:
self.social_cultural_context = None
def get_comprehension(self):
return self.comprehension
def set_comprehension(self, comprehension):
if isinstance(comprehension, int):
self.comprehension = comprehension
else:
self.comprehension = None
def get_conversation_skills(self):
return self.conversation_skills
def set_conversation_skills(self, conversation_skills):
if isinstance(conversation_skills, int):
self.conversation_skills = conversation_skills
else:
self.conversation_skills = None
def dump_to_json(self, json_file_path):
newdata = {
"vocabulary": self.vocabulary,
"grammar": self.grammar,
"social and cultural context": self.social_cultural_context,
"comprehension": self.comprehension,
"conversational skills": self.conversation_skills
}
with open(json_file_path, 'r') as json_file:
data = json.load(json_file)
data["user_information"]["language_proficiency"].update(newdata)
with open(json_file_path, 'w') as json_file:
json.dump(data, json_file, indent=4)
def get_user_personal_details(json_file_path):
with open(json_file_path, 'r') as json_file:
data = json.load(json_file)
personal_info = data["user_information"]["personal_information"]
language_choice = personal_info["language_choice"]
name = personal_info["name"]
gender = personal_info["gender"]
interests = personal_info["interests"]
age = personal_info["age"]
personality = personal_info["personality"]
behaviour = personal_info["behaviours"]
mistakes = personal_info["mistakes"]
past_conversation = personal_info["past_conversation"]
user_details = {
"language_choice": language_choice,
"name": name,
"gender": gender,
"interests": interests,
"age": age,
"personality": personality,
"behaviour": behaviour,
"mistakes": mistakes,
"past_conversation": past_conversation
}
return user_details
def get_user_language_proficiency(json_file_path):
with open(json_file_path, 'r') as json_file:
data = json.load(json_file)
language_proficiency = data["user_information"]["language_proficiency"]
user_language_proficiency = {
"vocabulary": language_proficiency["vocabulary"],
"grammar": language_proficiency["grammar"],
"social and cultural context": language_proficiency["social and cultural context"],
"comprehension": language_proficiency["comprehension"],
"conversational skills": language_proficiency["conversational skills"]
}
return user_language_proficiency