digitalai commited on
Commit
77801a2
1 Parent(s): 61700c2

Upload 9 files

Browse files
config/config.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import config.long_responses as long
3
+ from config.valid_text import is_valid_input
4
+
5
+ def message_probability(
6
+ user_message, recognised_words,
7
+ single_response=False, required_words=None
8
+ ):
9
+ if required_words is None:
10
+ required_words = []
11
+ message_certainty = 0
12
+ has_required_words = True
13
+
14
+ # Counts how many words are present in each predefined message
15
+ for word in user_message:
16
+ if word in recognised_words:
17
+ message_certainty += 1
18
+
19
+ # Calculates the percent of recognised words in a user message
20
+ percentage = float(message_certainty) / float(len(recognised_words))
21
+
22
+ # Checks that the required words are in the string
23
+ for word in required_words:
24
+ if word not in user_message:
25
+ has_required_words = False
26
+ break
27
+
28
+ # Must either have the required words, or be a single response
29
+ if has_required_words or single_response:
30
+ return int(percentage * 100)
31
+ else:
32
+ return 0
33
+
34
+
35
+ def check_all_messages(message):
36
+ highest_prob_list = {}
37
+
38
+ # Simplifies response creation / adds it to the dict
39
+ def response(bot_response, list_of_words, single_response=False, required_words=[]):
40
+ nonlocal highest_prob_list
41
+ highest_prob_list[bot_response] = message_probability(message, list_of_words, single_response, required_words)
42
+
43
+ # Responses -------------------------------------------------------------------------------------------------------
44
+
45
+ response("بله", ["بله", "بلی", "بلخ", "یله", "پله", "gfi",
46
+ "آره", "آری", "آرخ", "yes", "ya",
47
+ "bale", "ari", "are", "fgi", "hvi",
48
+ "Hvd", "Hvd", "fgd", "hsj", "isj",
49
+ "nhvn", "هست", "است", "دارد",
50
+ "یس",], single_response=True)
51
+ response("خیر", [
52
+ "نه", "منفی", "odv", "kodv", "خیر", "no",
53
+ "ni", "نخیر", "نیست", "نبود", "نمیشود",
54
+ "نمی شود", "نمی\u200cشود", "نیست",
55
+ "ندیدم", "دخ", "nist", "nabod", "na",
56
+ "nah", "noch", "nuch", "nooch", "manfi",
57
+ ], single_response=True)
58
+
59
+
60
+ # Longer responses
61
+
62
+ response(long.R_L01, ["اختلالات", "حرکتی", "Movement", "disorders","حرکت"],
63
+ required_words=["حرکت"])
64
+ response(long.R_L02, ["تعمیم یافته", "صورت", "گردن", "اندامهای", "رقصاک", "فوقانی", "تحتانی", "تنه"],
65
+ required_words=["رقصاک"])
66
+ response(long.R_L03, ["چشمی", "عصبی", "حرکت"
67
+ ], required_words=["عصبی"])
68
+ response(long.R_L04, ["بیماری‌", "عصبی", "متا", "بولیکی", "نورومتابولیکی"
69
+ ], required_words=["عصبی"])
70
+ response(long.R_L05, ["روان‌پزشکی", "روانپریشی", "روان", "پزشکی", "روانپزشکی"
71
+ ], required_words=["روانپزشکی"])
72
+ response(long.R_L06, ["هیپرهموسیستئینمی", "hyperhomocysteinemia","ژنتیکی"
73
+ ], required_words=["ژنتیکی"])
74
+ response(long.R_L07, ["درگیری", "طناب", "نخاعی", "spinal", "cord", "نخاعی"
75
+ ], required_words=["نخاعی"])
76
+ response(long.R_L08, ["کوبالامین", "داخل", "سلولی", "intracellular", "cobalamin","سلولی"
77
+ ], required_words=["سلولی"])
78
+
79
+ response(long.R_L09, ["لیپاز", "اسید", "لیزوزومال", "LAL-D", "کمبود"
80
+ ], required_words=["کمبود"])
81
+ response(long.R_L10, ["هیدرولیپوآمید", "دهیدروژناز", "کمبود"
82
+ ], required_words=["کمبود"])
83
+ response(long.R_L11, ["فسفاتمی","هایپوفسفاتمی", "هیپوفسفاتمی", "hypophosphatemia", "HP", "ژنتیکی"
84
+ ], required_words=["ژنتیکی"])
85
+ response(long.R_L12, ["آنسفالوپاتی", "هیپرآمونمیک", "غیر", "کبدی", "جراحی", "چاقی", "Nonhepatic", "hyperammonemic", "encephalopathy", "bariatric", "surgery", "NHE-BS"
86
+ ], required_words=["کبدی"])
87
+ response(long.R_L13, ["لرزش", "میتو", "کندری", "میتوکندری", "ژنتیکی"
88
+ ], required_words=["ژنتیکی"])
89
+ response(long.R_L13, ["اندام", "لرزش", "ترمور", "Tremor", "TRM"
90
+ ], required_words=["عصبی"])
91
+
92
+
93
+ #
94
+ #
95
+ # "اختلالات حرکتی": "L01",
96
+ # " رقصاک تعمیم یافته در صورت ، گردن ، اندامهای فوقانی/تحتانی ، تنه ": "L02",
97
+ # "اختلالات حرکات چشم و علائم عصبی": "L03",
98
+ # "بیماریهای عصبی": "L04",
99
+ # "هوموستئینمی شدید": "L06",
100
+ # "تظاهرات روانی": "L05",
101
+ # "درگیری نخاع": "L07",
102
+ # "متابولیسم کبدی داخل سلولی": "L08",
103
+ # "کمبود لیپاز اسید لیزوزومی": "L09",
104
+ # "کمبود دی هیدرو ��یپوامید دی هیدروژناز": "L10",
105
+ #
106
+ #
107
+ # "فسفاتمی": "L11",
108
+ # "عوارض" ,"آنسفالوپاتی", "غیرکبدی" , "جراحی", "باریاتریک": "L12",
109
+ # "لرزش اندام فوقانی": "L13",
110
+ # "بیماریهای میتوکندری": "L14",
111
+ #
112
+ #
113
+ #
114
+ # "کمبود", "هیدرولیپوآمید", "دهیدروژناز"
115
+ # "هایپوفسفاتمی", "هیپوفسفاتمی", "hypophosphatemia", "HP"
116
+ # "آنسفالوپاتی", "هیپرآمونمیک", "غیر", "کبدی", "جراحی", "چاقی", "Nonhepatic", "hyperammonemic", "encephalopathy", "bariatric", "surgery", "NHE-BS
117
+ # "لرزش", "ترمور", "Tremor", "لرزش", "TRM"
118
+
119
+
120
+ best_match = max(highest_prob_list, key=highest_prob_list.get)
121
+ # print(highest_prob_list)
122
+ # print(f'Best match = {best_match} | Score: {highest_prob_list[best_match]}')
123
+
124
+ return long.unknown() if highest_prob_list[best_match] < 1 else best_match
125
+
126
+
127
+ # Used to get the response
128
+ def get_response(user_input):
129
+ split_message = re.split(r'\s+|[,;?!.-]\s*', user_input.lower())
130
+ response = check_all_messages(split_message)
131
+ return response
132
+
133
+
134
+ #
135
+ # # Testing the response system
136
+ # while True:
137
+ # print('Bot: ' + get_response(input('You: ')))
config/long_responses.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+
3
+ R_EATING = "I don't like eating anything because I'm a bot obviously!"
4
+ R_ADVICE = "If I were you, I would go to the internet and type exactly what you wrote there!"
5
+ R_L01 = "L01"
6
+ R_L02 = "L02"
7
+ R_L03 = "L03"
8
+ R_L04 = "L04"
9
+ R_L05 = "L05"
10
+ R_L06 = "L06"
11
+ R_L07 = "L07"
12
+ R_L08 = "L08"
13
+ R_L09 = "L09"
14
+ R_L10 = "L10"
15
+ R_L11 = "L11"
16
+ R_L12 = "L12"
17
+ R_L13 = "L13"
18
+ R_L14 = "L14"
19
+ def unknown():
20
+ response = ["Could you please re-phrase that? ",
21
+ "...",
22
+ "Sounds about right.",
23
+ "What does that mean?"][
24
+ random.randrange(4)]
25
+ return response
config/option.py CHANGED
@@ -13,7 +13,7 @@ class Option(Quiz):
13
  return [k for k in self.option_data[level]]
14
 
15
  def get_next_level(self, user_choice, level):
16
- print(self.option_data[level][user_choice]["next"])
17
  return self.option_data[level][user_choice]["next"]
18
 
19
  def get_feedback(self, user_choice, level):
 
13
  return [k for k in self.option_data[level]]
14
 
15
  def get_next_level(self, user_choice, level):
16
+ # print(self.option_data[level][user_choice]["next"])
17
  return self.option_data[level][user_choice]["next"]
18
 
19
  def get_feedback(self, user_choice, level):
config/print_data.py CHANGED
@@ -14,4 +14,4 @@ class ConversationProcessor:
14
  elif role == 'assistant':
15
  file.write("Assistant: " + content + "\n")
16
 
17
- print(f"مکالمات با موفقیت در فایل {output_file} ذخیره شدند.")
 
14
  elif role == 'assistant':
15
  file.write("Assistant: " + content + "\n")
16
 
17
+ # print(f"مکالمات با موفقیت در فایل {output_file} ذخیره شدند.")
config/quiz.py CHANGED
@@ -7,8 +7,8 @@ class Question(Quiz):
7
  super().__init__(question_file, datafile)
8
 
9
  def get_question_text(self, level):
10
- print(self.question_data)
11
  return self.question_data[level]
12
 
13
  def get_levels_id(self):
14
- return [k for k in self.question_data.keys()]
 
7
  super().__init__(question_file, datafile)
8
 
9
  def get_question_text(self, level):
10
+ # print(self.question_data)
11
  return self.question_data[level]
12
 
13
  def get_levels_id(self):
14
+ return [k for k in self.question_data.keys()]
config/valid_text.py CHANGED
@@ -1,24 +1,114 @@
1
  import re
2
 
 
3
  def is_valid_input(user_input):
4
  synonyms_dict = {
5
- "بله": ["بله",
6
- "بلی", "بلخ", "یله", "پله",
7
- "آره", "آری", "آرخ", "yes",
8
- "ya", "bale", "ari", "are",
9
- "fgi", "hvi", "Hvd", "Hvd",
10
- "fgd", "hsj", "isj", "nhvn",
11
- "هست", "است", "دارد", "یس",
 
 
 
 
12
  ],
13
- "خیر": ['نه', 'منفی', 'odv', 'kodv',
14
- "خیر", 'no', 'ni', 'نخیر',
15
- 'نیست', 'نبود', 'نمیشود',
16
- 'نمی شود','نمی\u200cشود',
17
- 'نیست', 'ندیدم','دخ', 'nist',
18
- 'nabod', 'na', 'nah', 'noch',
19
- 'nuch', 'nooch', 'manfi']
20
  }
21
- for k, v in synonyms_dict.items():
22
- if user_input in v:
23
- return k
24
- return "wrong value"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import re
2
 
3
+
4
  def is_valid_input(user_input):
5
  synonyms_dict = {
6
+ "بله": [
7
+ "بله", "بلی", "بلخ", "یله", "پله",
8
+ "آره", "آری", "آرخ", "yes", "ya", "bale", "ari",
9
+ "are", "fgi", "hvi", "Hvd", "Hvd", "fgd", "hsj",
10
+ "isj", "nhvn", "هست", "است", "دارد", "یس",
11
+ ],
12
+ "خیر": [
13
+ "نه", "منفی", "odv", "kodv", "خیر", "no", "ni", "نخیر",
14
+ "نیست", "نبود", "نمیشود", "نمی شود", "نمی\u200cشود", "نیست",
15
+ "ندیدم", "دخ", "nist", "nabod", "na", "nah", "noch", "nuch",
16
+ "nooch","manfi",
17
  ],
 
 
 
 
 
 
 
18
  }
19
+ input_list = user_input.split(" ")
20
+ for inp in input_list:
21
+ for k, v in synonyms_dict.items():
22
+ if inp in v:
23
+ return k
24
+ return user_input
25
+
26
+ def levels():
27
+ group_dict = {
28
+ "اختلالات حرکتی": "L01",
29
+ " رقصاک تعمیم یافته در صورت ، گردن ، اندامهای فوقانی/تحتانی ، تنه ": "L02",
30
+ "اختلالات حرکات چشم و علائم عصبی": "L03",
31
+ "بیماریهای عصبی": "L04",
32
+ "هوموستئینمی شدید": "L06",
33
+ "تظاهرات روانی": "L05",
34
+ "درگیری نخاع": "L07",
35
+ "متابولیسم کبدی داخل سلولی": "L08",
36
+ "کمبود لیپاز اسید لیزوزومی": "L09",
37
+ "کمبود دی هیدرو لیپوامید دی هیدروژناز": "L10",
38
+ "فسفاتمی": "L11",
39
+ "عوارض آنسفالوپاتی غیر کبدی به دنبال جراحی باریاتریک": "L12",
40
+ "لرزش اندام فوقانی": "L13",
41
+ "بیماریهای میتوکندری": "L14",
42
+ }
43
+ return list(group_dict.keys())
44
+
45
+
46
+ def user_choice_level(choice):
47
+ group_dict = {
48
+
49
+ "اختلالات حرکتی": "L01",
50
+ " رقصاک تعمیم یافته در صورت ، گردن ، اندامهای فوقانی/تحتانی ، تنه ": "L02",
51
+ "اختلالات حرکات چشم و علائم عصبی": "L03",
52
+ "بیماریهای عصبی": "L04",
53
+ "هوموستئینمی شدید": "L06",
54
+ "تظاهرات روانی": "L05",
55
+ "درگیری نخاع": "L07",
56
+ "متابولیسم کبدی داخل سلولی": "L08",
57
+ "کمبود لیپاز اسید لیزوزومی": "L09",
58
+ "کمبود دی هیدرو لیپوامید دی هیدروژناز": "L10",
59
+ "فسفاتمی": "L11",
60
+ "عوارض آنسفالوپاتی غیر کبدی به دنبال جراحی باریاتریک": "L12",
61
+ "لرزش اندام فوقانی": "L13",
62
+ "بیماریهای میتوکندری": "L14",
63
+ }
64
+ return group_dict[choice]
65
+ group_dict = {
66
+
67
+ "اختلالات حرکتی": "L01",
68
+ " رقصاک تعمیم یافته در صورت ، گردن ، اندامهای فوقانی/تحتانی ، تنه ": "L02",
69
+ "اختلالات حرکات چشم و علائم عصبی": "L03",
70
+ "بیماریهای عصبی": "L04",
71
+ "هوموستئینمی شدید": "L06",
72
+ "تظاهرات روانی": "L05",
73
+ "درگیری نخاع": "L07",
74
+ "متابولیسم کبدی داخل سلولی": "L08",
75
+ "کمبود لیپاز اسید لیزوزومی": "L09",
76
+ "کمبود دی هیدرو لیپوامید دی هیدروژناز": "L10",
77
+ "فسفاتمی": "L11",
78
+ "عوارض آنسفالوپاتی غیر کبدی به دنبال جراحی باریاتریک": "L12",
79
+ "لرزش اندام فوقانی": "L13",
80
+ "بیماریهای میتوکندری": "L14",
81
+ }
82
+ # print(type(user_choice_level("فسفاتمی")))
83
+ # for k in group_dict.keys():
84
+ # lst = k.split()
85
+ # print(lst)
86
+
87
+ #
88
+ # ['اختلالات', 'حرکتی']["اختلالات حرکتی","Movement" ,"disorders"]
89
+ # ['رقصاک', 'تعمیم', 'یافته', 'صورت', 'گردن', 'اندامهای', 'فوقانی/تحتانی', 'تنه']
90
+ # ['اختلالات', 'حرکات', '��شم', 'علائم', 'عصبی'][ 'حرکات', 'چشم', 'عصبی']
91
+ # ['بیماری', 'عصبی']["عصبی", "متابولیکی"]
92
+ # ['هوموستئینمی', 'شدید']["هیپرهموسیستئینمی" , "hyperhomocysteinemia"]
93
+ # ['تظاهرات', 'روانی',"روانشناسی"]["اختلالات","روانپزشکی","psychiatric","manifestations"]
94
+ # ['درگیری', 'نخاع']["درگیری","طناب", "نخاعی", "spinal", "cord"]
95
+ #
96
+ # ['متابولیسم', 'کبدی', 'داخل', 'سلولی']["کوبالامین" "داخل" "سلولی" "intracellular" "cobalamin"]
97
+ # ['کمبود', 'لیپاز', 'اسید', 'لیزوزومی']["لیپاز" "اسید" "لیزوزومال"]
98
+ # ['کمبود', 'دی', 'هیدرو', 'لیپوامید', 'دی', 'هیدروژناز']["کمبود" ,"دی هیدرولیپو","آمید", "دهیدروژناز"]
99
+ #
100
+ #
101
+ #
102
+ #
103
+ # ['فسفاتمی']["هایپوفسفاتمی"] ["hypophosphatemia","hp"]
104
+ # ['عوارض', 'آنسفالوپاتی', 'کبدی','دنبال', 'جراحی', 'باریاتریک']
105
+ # ["Nonhepatic", "hyperammonemic", "encephalopathy" ,"bariatric", "surgery", "آنسفالوپاتی"
106
+ # , "هیپرآمونمیک", "کبدی", "جراحی" ,"چاقی" ,"NHEBS"]
107
+ # ["لرزش","ترمور","Tremor"]
108
+ #
109
+ #
110
+ #
111
+ #
112
+ # ['لرزش', 'اندام', 'فوقانی']
113
+ # ['بیماریهای', 'میتوکندری']
114
+ # ["درگیری","طناب", "نخاعی", "spinal", "cord"]