-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExpertSystem.py
182 lines (166 loc) · 10.4 KB
/
ExpertSystem.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
import tkinter as tk
from tkinter import ttk
from aima.utils import expr
from aima.logic import FolKB, fol_fc_ask
from ttkthemes import ThemedTk
# Base de connaissances
kb = FolKB()
kb.tell(expr('Beach(x)'))
kb.tell(expr('Historical(x)'))
kb.tell(expr('Nature(x)'))
kb.tell(expr('City(x)'))
kb.tell(expr('Secluded(x)'))
kb.tell(expr('Crowded(x)'))
kb.tell(expr('Luxurious(x)'))
kb.tell(expr('Cheap(x)'))
kb.tell(expr('Beach(x) & Secluded(x) & Cheap(x) ==> TichyBeach(x)'))
kb.tell(expr('Beach(x) & Crowded(x) & Cheap(x) ==> AiguadesBeach(x)'))
kb.tell(expr('Beach(x) & Secluded(x) & Luxurious(x) ==> ThaisBeach(x)'))
kb.tell(expr('Beach(x) & Crowded(x) & Luxurious(x) ==> AtlantisBeach(x)'))
kb.tell(expr('Historical(x) & Secluded(x) & Cheap(x) ==> BourdjMoussaMuseum(x)'))
kb.tell(expr('Historical(x) & Secluded(x) & Luxurious(x) ==> EnchantedCave(x)'))
kb.tell(expr('Historical(x) & Crowded(x) & Cheap(x) ==> CasbahofBejaia(x)'))
kb.tell(expr('Historical(x) & Crowded(x) & Luxurious(x) ==> WaterMuseum(x)'))
kb.tell(expr('Nature(x) & Secluded(x) & Cheap(x) ==> KafridaWaterfalls(x)'))
kb.tell(expr('Nature(x) & Secluded(x) & Luxurious(x) ==> DarkLake(x)'))
kb.tell(expr('Nature(x) & Crowded(x) & Cheap(x) ==> CapCarbon(x)'))
kb.tell(expr('Nature(x) & Crowded(x) & Luxurious(x) ==> TiziNberbar(x)'))
kb.tell(expr('City(x) & Secluded(x) & Cheap(x) ==> Medina(x)'))
kb.tell(expr('City(x) & Secluded(x) & Luxurious(x) ==> TaosAmroucheCultureHouse(x)'))
kb.tell(expr('City(x) & Crowded(x) & Cheap(x) ==> PlaceGueydon(x)'))
kb.tell(expr('City(x) & Crowded(x) & Luxurious(x) ==> SoukElDjemaa(x)'))
# Initialisation de l'agenda
agenda = []
# Fonction de traitement du bouton
def button_func():
destinations = [var_1.get(), var_2.get(), var_3.get()]
user = expr('Bejaia')
agenda = [expr(destination + '(Bejaia)') for destination in destinations]
memory = {}
result = []
# Analyse de chaque destination
for p in agenda:
if fol_fc_ask(kb, expr(p)):
memory[p] = True
else:
memory[p] = False
# Recherche des destinations recommandées en fonction des préférences
if memory.get(expr('Beach(Bejaia)'), False) and memory.get(expr('Secluded(Bejaia)'), False) and memory.get(expr('Cheap(Bejaia)'), False):
result.append(expr('TichyBeach(Bejaia)'))
if memory.get(expr('Beach(Bejaia)'), False) and memory.get(expr('Crowded(Bejaia)'), False) and memory.get(expr('Cheap(Bejaia)'), False):
result.append(expr('AiguadesBeach(Bejaia)'))
if memory.get(expr('Beach(Bejaia)'), False) and memory.get(expr('Secluded(Bejaia)'), False) and memory.get(expr('Luxurious(Bejaia)'), False):
result.append(expr('ThaisBeach(Bejaia)'))
if memory.get(expr('Beach(Bejaia)'), False) and memory.get(expr('Crowded(Bejaia)'), False) and memory.get(expr('Luxurious(Bejaia)'), False):
result.append(expr('AtlantisBeach(Bejaia)'))
if memory.get(expr('Historical(Bejaia)'), False) and memory.get(expr('Secluded(Bejaia)'), False) and memory.get(expr('Cheap(Bejaia)'), False):
result.append(expr('BourdjMoussaMuseum(Bejaia)'))
if memory.get(expr('Historical(Bejaia)'), False) and memory.get(expr('Secluded(Bejaia)'), False) and memory.get(expr('Luxurious(Bejaia)'), False):
result.append(expr('EnchantedCave(Bejaia)'))
if memory.get(expr('Historical(Bejaia)'), False) and memory.get(expr('Crowded(Bejaia)'), False) and memory.get(expr('Cheap(Bejaia)'), False):
result.append(expr('CasbahofBejaia(Bejaia)'))
if memory.get(expr('Historical(Bejaia)'), False) and memory.get(expr('Crowded(Bejaia)'), False) and memory.get(expr('Luxurious(Bejaia)'), False):
result.append(expr('WaterMuseum(Bejaia)'))
if memory.get(expr('Nature(Bejaia)'), False) and memory.get(expr('Secluded(Bejaia)'), False) and memory.get(expr('Cheap(Bejaia)'), False):
result.append(expr('KafridaWaterfalls(Bejaia)'))
if memory.get(expr('Nature(Bejaia)'), False) and memory.get(expr('Secluded(Bejaia)'), False) and memory.get(expr('Luxurious(Bejaia)'), False):
result.append(expr('DarkLake(Bejaia)'))
if memory.get(expr('Nature(Bejaia)'), False) and memory.get(expr('Crowded(Bejaia)'), False) and memory.get(expr('Cheap(Bejaia)'), False):
result.append(expr('CapCarbon(Bejaia)'))
if memory.get(expr('Nature(Bejaia)'), False) and memory.get(expr('Crowded(Bejaia)'), False) and memory.get(expr('Luxurious(Bejaia)'), False):
result.append(expr('TiziNberbar(Bejaia)'))
if memory.get(expr('City(Bejaia)'), False) and memory.get(expr('Secluded(Bejaia)'), False) and memory.get(expr('Cheap(Bejaia)'), False):
result.append(expr('Medina(Bejaia)'))
if memory.get(expr('City(Bejaia)'), False) and memory.get(expr('Secluded(Bejaia)'), False) and memory.get(expr('Luxurious(Bejaia)'), False):
result.append(expr('TaosAmroucheCultureHouse(Bejaia)'))
if memory.get(expr('City(Bejaia)'), False) and memory.get(expr('Crowded(Bejaia)'), False) and memory.get(expr('Cheap(Bejaia)'), False):
result.append(expr('PlaceGueydon(Bejaia)'))
if memory.get(expr('City(Bejaia)'), False) and memory.get(expr('Crowded(Bejaia)'), False) and memory.get(expr('Luxurious(Bejaia)'), False):
result.append(expr('SoukElDjemaa(Bejaia)'))
# Effacer les labels de résultat existants
for label in window.winfo_children():
if isinstance(label, ttk.Label) and "Recommended destinations" in label.cget("text"):
label.pack_forget()
# Mise à jour du label de résultat avec les destinations recommandées
if result:
result_str = ', '.join(str(expr) for expr in result)
print(f"Destinations recommandées : {result_str}")
explanation = generate_explanation(result) # Générer l'explication
result_label = ttk.Label(window, text=f"Destinations recommandées : {result_str}\n{explanation}")
result_label.pack(pady=10)
else:
print("Aucune destination correspondante trouvée.")
result_label = ttk.Label(window, text="Aucune destination correspondante trouvée.")
result_label.pack(pady=10)
# Générer l'explication pour les destinations recommandées
def generate_explanation(destinations):
explanation = ""
for destination in destinations:
if destination == expr('TichyBeach(Bejaia)'):
explanation += "TichyBeach a été recommandé en raison de sa plage isolée et bon marché.\n"
elif destination == expr('AiguadesBeach(Bejaia)'):
explanation += "AiguadesBeach a été recommandé en raison de sa plage bondée et bon marché.\n"
elif destination == expr('ThaisBeach(Bejaia)'):
explanation += "ThaisBeach a été recommandé en raison de sa plage isolée et luxueuse.\n"
elif destination == expr('AtlantisBeach(Bejaia)'):
explanation += "AtlantisBeach a été recommandé en raison de sa plage bondée et luxueuse.\n"
elif destination == expr('BourdjMoussaMuseum(Bejaia)'):
explanation += "BourdjMoussaMuseum a été recommandé pour son caractère historique, sa tranquillité et son prix abordable.\n"
elif destination == expr('EnchantedCave(Bejaia)'):
explanation += "EnchantedCave a été recommandé pour son caractère historique, sa tranquillité et son luxe.\n"
elif destination == expr('CasbahofBejaia(Bejaia)'):
explanation += "CasbahofBejaia a été recommandé pour son caractère historique, sa foule et son prix abordable.\n"
elif destination == expr('WaterMuseum(Bejaia)'):
explanation += "WaterMuseum a été recommandé pour son caractère historique, sa foule et son luxe.\n"
elif destination == expr('KafridaWaterfalls(Bejaia)'):
explanation += "KafridaWaterfalls a été recommandé pour son aspect naturel, sa tranquillité et son prix abordable.\n"
elif destination == expr('DarkLake(Bejaia)'):
explanation += "DarkLake a été recommandé pour son aspect naturel, sa tranquillité et son luxe.\n"
elif destination == expr('CapCarbon(Bejaia)'):
explanation += "CapCarbon a été recommandé pour son aspect naturel, sa foule et son prix abordable.\n"
elif destination == expr('TiziNberbar(Bejaia)'):
explanation += "TiziNberbar a été recommandé pour son aspect naturel, sa foule et son luxe.\n"
elif destination == expr('Medina(Bejaia)'):
explanation += "Medina a été recommandé pour son aspect urbain, sa tranquillité et son prix abordable.\n"
elif destination == expr('TaosAmroucheCultureHouse(Bejaia)'):
explanation += "TaosAmroucheCultureHouse a été recommandé pour son aspect urbain, sa tranquillité et son luxe.\n"
elif destination == expr('PlaceGueydon(Bejaia)'):
explanation += "PlaceGueydon a été recommandé pour son aspect urbain, sa foule et son prix abordable.\n"
elif destination == expr('SoukElDjemaa(Bejaia)'):
explanation += "SoukElDjemaa a été recommandé pour son aspect urbain, sa foule et son luxe.\n"
# Ajouter d'autres explications pour les autres destinations ici
return explanation
# Créer la fenêtre ThemedTk
window = ThemedTk(theme="arc")
window.geometry('800x400')
window.title('Recommandateur de voyages')
# Créer les cadres et les widgets
frame_1 = ttk.Frame(window)
l_intro = ttk.Label(frame_1, text='Un recommandateur de voyages personnalisé. Répondez aux questions suivantes :')
frame_1.pack()
l_intro.pack()
var_1 = tk.StringVar(value='Beach')
frame_2 = ttk.Frame(window)
label_1 = ttk.Label(frame_2, text='Activité de loisir préférée :')
entry_1 = ttk.Combobox(frame_2, values=('Beach', 'Historical', 'Nature', 'City'), textvariable=var_1)
frame_2.pack(pady=10)
label_1.pack(side='left')
entry_1.pack(side='left')
var_2 = tk.StringVar(value='Secluded')
frame_3 = ttk.Frame(window)
label_2 = ttk.Label(frame_3, text='Préférence pour les foules :')
entry_2 = ttk.Combobox(frame_3, values=('Secluded', 'Crowded'), textvariable=var_2)
frame_3.pack(pady=10)
label_2.pack(side='left')
entry_2.pack(side='left')
var_3 = tk.StringVar(value='Cheap')
frame_4 = ttk.Frame(window)
label_3 = ttk.Label(frame_4, text='Préférence budgétaire :')
entry_3 = ttk.Combobox(frame_4, values=('Cheap', 'Luxurious'), textvariable=var_3)
frame_4.pack(pady=10)
label_3.pack(side='left')
entry_3.pack(side='left')
button = ttk.Button(window, text='Voir les résultats', command=button_func)
button.config(style='Accent.TButton')
button.pack(pady=10)
window.mainloop()