-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTchaikovsky.lisp
611 lines (513 loc) · 27.5 KB
/
Tchaikovsky.lisp
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
(load "dataset.lisp")
; -------------------------------------------------------------------------------------------------
; FUNZIONI DI UTILITA'
; -------------------------------------------------------------------------------------------------
(defun random-elt (list)
(nth (random (length list)) list))
(defun getSetByAttribute (attribute)
(cond ((equal attribute '{Title}) Title_set)
((equal attribute '{Year}) Year_set)
((equal attribute '{Genre}) Genre_set)
((equal attribute '{Place}) Place_set)
((equal attribute '{Date}) Date_set)
((equal attribute '{Information}) Information_set)
)
)
(defun attrToCol (attribute)
(cond ((equal attribute '{Title}) 'Title)
((equal attribute '{Year}) 'Year)
((equal attribute '{Genre}) 'Genre)
((equal attribute '{Place}) 'Place)
((equal attribute '{Date}) 'Date)
((equal attribute '{Key}) 'Key)
((equal attribute '{Movements}) 'Movements)
((equal attribute '{Famous}) 'Famous)
((equal attribute '{Duration}) 'Duration)
)
)
(defun getValue (tuple attribute)
(cond ((equal attribute 'famous)
(cond ((equal (cadr (assoc attribute tuple :test 'equal)) '(yes) ) '(Yes it is))
((equal (cadr (assoc attribute tuple :test 'equal)) '(no) ) '(No it isn't))) )
(T (cadr (assoc attribute tuple :test 'equal)))
)
)
(defun findAllByValue (dataset attribute value)
(cond ((equal dataset ()) nil)
((equal (getValue (car dataset) attribute) value) (cons (car dataset) (findAllByValue (cdr dataset) attribute value)))
(T (findAllByValue (cdr dataset) attribute value)))
)
(defun isAttribute (a)
(or (equal a '{Title})
(equal a '{Genre})
(equal a '{Year})
(equal a '{Place})
(equal a '{Date})
(equal a '{Key})
(equal a '{Movements})
(equal a '{Duration})
(equal a '{Famous})
)
)
(defun missingValues (a)
(cond ((listp a)
(cond ((equal a ()) nil) (T (or (missingValues (car a)) (missingValues (cdr a))))))
((atom a)(cond ((equal a 'MISSING_VALUE) T)(T nil)))
(T T)
)
)
; -------------------------------------------------------------------------------------------------
; GESTIONE REGOLE
; -------------------------------------------------------------------------------------------------
; -------------------------------------------------------------------------------------------------
; Definizione delle regole
; -------------------------------------------------------------------------------------------------
(defvar _rules_ ())
(defvar _general_rules_ ())
(defvar _rule2tuple_ ())
(defvar _rule2head_ ())
(defvar _rule2tuples_ ())
(defparameter _rule_memory_ ()) ;regole per la gestione della memoria
(defvar _rules_template_ '(
((* x key * y {TITLE} * z) (x key ? it's {KEY}))
((* x like {Title} * y)
( x like {Title} y ? I do since it's {Genre} ) ( x like {Title} y ? I don't since it's {Genre} ) (Oh we are really similar! I'm a big fan of all {Genre} by Tchaikovsky) (I do not agree with you because I think {Genre} works of my master are the most boring to listen) (Mmm I don't know how to answer you because I only know the title of the work but I didn't have the chance to listen to it))
((* x listened to {Title} * y)
(x listened to {Title} ? Were you alive in {Year} ?) (Oh wow\, so you are really older than I thought! In {Year} I wasn't even in the mind of my creators))
(( * x {Title} * y {Genre})( Yes it is)
(yes\, if memory serves me correctly\, it should be part of the set of works that fall within the genre {Genre}))
(( * x {Title} * y Tchaikovsky * y)
(Yes it is)(After having scanned all the twists and turns in my memory\, I came to the conclusion that\: yes\, it is))
(( * x {Title} * y Tchaikovsky's * y)
(Yes it is)(After having scanned all the twists and turns in my memory\, I came to the conclusion that\: yes\, it is))
((* x listened to {Title} * y)
( x listened to {Title} ? Were you alive in {Year} ?)); => no => me neither
((* x about {TITLE} * y)
( x about {TITLE} ? It's a {GENRE} \, which was written in {YEAR} \. The key is {KEY} and The whole thing lasts {DURATION} minutes!)
( x about {TITLE} ? It's a {GENRE} \, which was written in {YEAR} \. The key is {KEY} and if you want to listen to it you'll need {DURATION} minutes of your time))
((* x about {TITLE} * y)
( x about {TITLE} ? It's a {GENRE} \, which was written in {YEAR} \. It's composed by {Movements} movements. If you want to listen to it you'll need {DURATION} minutes of your time))
((* x about {TITLE} * y)
( x about {TITLE} ? It's a {GENRE} \, which was written in {YEAR} \. It's composed by {Movements} movements. ))
((* x about {TITLE} * y)
( x about {TITLE} ? It's a {GENRE} \, which was written in {YEAR} \. The key is {KEY} and the whole thing lasts {DURATION} minutes!)
( x about {TITLE} ? It's a {GENRE} \, which was written in {YEAR} \. The key is {KEY} and if you want to listen to it you'll need {DURATION} minutes of your time))
((* x about {TITLE} * y)
( x about {TITLE} ? It's a {GENRE} \, which was written in {YEAR} \. The whole thing lasts {DURATION} minutes!)
( x about {TITLE} ? It's a {GENRE} \, which was written in {YEAR} \. If you want to listen to it you'll need {DURATION} minutes of your time))
((* x about {TITLE} * y)
( x about {TITLE} ? It was written in {YEAR} \. The whole thing lasts {DURATION} minutes!)
( x about {TITLE} ? It was written in {YEAR} \. If you want to listen to it you'll need {DURATION} minutes of your time))
((* x about {TITLE} * y)
( x about {TITLE} ? It was written in {YEAR} \. It's a {GENRE}))
((* x about {TITLE} * y)
( x about {TITLE} ? It's a {GENRE}))
((* x how long does * y {TITLE} last * z)
(It lasts for just about {DURATION} minutes. ))
((* x how long does * y {TITLE} last * z)
(I don't really know\, I never managed to listen to all of it. ))
((How many movements * X {Title})
({Title} consists of {Movements} movements))
((* x genre * y {TITLE} * z)(if i recall correctly\, it's a {GENRE}))
((* x when * y {TITLE} * z)(if i recall correctly\, it was z in {YEAR}))
((How many movements * X {Title}) (I have no information about it))
((* x {Title} * y {Year} * z) (yes\, it was written in {Year}))
(( * x {Title} a * x)( No it's not))
((* z where * x {Title} * y) ({Title} was y in {Place} \, on the {Date}))
((* x {Title} * y by Tchaikovsky * z )(Yes it was.))
(( * x {Title} * y a Tchaikovsky's work) (Yes it is))
((is {TITLE} * x well known ) ({Famous}) )
((is {TITLE} * x well known ) (It is well known\, like almost all of them\, of course))
((is {TITLE} * x famous ) ({Famous}))
((is {TITLE} * x famous ) (I think it is considered famous\, it's written by Tchaikovsky after all))
))
(defvar _general_rules_template_ '(
((* x favourite {GENRE} * y) (x favourite {GENRE} ? it's {PICK_RANDOM} \, obviously!))
((* x how many * y {Genre} * z) (There are {COUNT} works of that type that I know of. My favourite is {MOST_FAMOUS}) (I think there are {COUNT} works of that genre. ))
((* x how many * y {Year} * z) (There are {COUNT} works of that type that I know of. My favourite is {MOST_FAMOUS}))
((* x how many * y) (There are {COUNT} works that I know of. My favourite is {MOST_FAMOUS}))
))
(defvar _trivia_rules_template_ '(
((* x famous * y))
))
(defvar _rules_template_memory_ '(
((Title) (The title is {Title} ))
((Genre) (It is a {Genre} ))
((Date) (It was composed in {Date}))
((Place) (It was presented in {Place}))
((key) (It's written in {key} ))
((famous) ({Famous}))
((famous) (I think it is considered famous\, it's written by Tchaikovsky after all))
((Year) (It was written in {Year}) )
((Movements) (it's composed by {Movements} movements ))
((Duration) (it lasts about {DURATION} minutes))
))
; -------------------------------------------------------------------------------------------------
; Metodo per la generazione delle regole (su una sola tupla)
; -------------------------------------------------------------------------------------------------
; generate_rules:
; input : ds = a dataset
; rules_template = a set of template rules
; output: (not important - modifica _rules_)
;
; es:
; input ds = (((TITLE (SWAN LAKE))))
; rules_template = (((* X LIKE {TITLE} * Y) (X LIKE {TITLE} Y ? I DO TOO) (X LIKE {TITLE} Y ? I DON 'T)))
;
; in _rules_ (((* X LIKE SWAN LAKE * Y) (X LIKE SWAN LAKE Y ? I DO TOO) (X LIKE SWAN LAKE Y ? I DON 'T)))
(defun generate_rules (ds rules_template)
(dolist (curr_tuple ds)
(dolist (rule_template rules_template)
(progn (setq new_rule (generate_rule rule_template curr_tuple))
(cond ((missingValues new_rule) nil)
(T (progn (defparameter _rules_ (append _rules_ (list new_rule)))
(setq _rule2tuple_ (append _rule2tuple_ (list (list (car new_rule) curr_tuple))))
)
)
)
)
)
)
)
(defun concatenate-l (l)
(setf res ())
(dolist (el l)
(setf res (append res el))
(setf res (append res (list '\,)))
)
(reverse (cdr (reverse res)))
)
(defun generate_rule (rule_template curr_tuple)
(cond ((equal rule_template ()) ())
(T (cons (instantiate_rule (car rule_template) curr_tuple) (generate_rule (cdr rule_template) curr_tuple))))
)
(defun instantiate_rule (rule curr_tuple)
(cond ((equal rule ()) ())
((isAttribute (car rule))
(cond ((equal (getValue curr_tuple (attrToCol (car rule))) nil) '(MISSING_VALUE))
(T (append (getValue curr_tuple (attrToCol (car rule))) (instantiate_rule (cdr rule) curr_tuple)))))
(T (cons (car rule) (instantiate_rule (cdr rule) curr_tuple)))
)
)
; -------------------------------------------------------------------------------------------------
; Metodi per la gestione delle regole generali (su più tuple)
; -------------------------------------------------------------------------------------------------
(defun isAggregateFunction (a)
(or (equal a '{COUNT}) (equal a '{MOST_FAMOUS}) (equal a '{PICK_RANDOM}))
)
(defun computeAggregateFunction (a tuples)
(cond ((equal a '{COUNT}) (list (length tuples)))
((equal a '{MOST_FAMOUS}) (getvalue (car tuples) 'Title)) ; per ora car, ma da sistemare
((equal a '{PICK_RANDOM}) (getvalue (random-elt tuples) 'title))
(T nil))
)
(defun generate_general_rules (ds general_rules_template)
(setf _general_rules_ ())
(dolist ( rule_template general_rules_template); solo le teste in questo do list
(dolist (curr_tuple ds)
(progn (setq new_rule (generate_rule (list (car rule_template)) curr_tuple))
(cond ((missingValues new_rule) nil)
(T (progn
(cond
((not (member new_rule _general_rules_ :test 'equal))
(progn
(setf _rule2head_ (append _rule2head_ (list (list (car new_rule) (cdr rule_template)))))
(setf _rule2tuples_ (append _rule2tuples_ (list (list (car new_rule) curr_tuple))))
(defparameter _general_rules_ (append _general_rules_ (list new_rule)))
))
(T (progn
(setf prev_tuples (cdr (assoc (car new_rule) _rule2tuples_ :test 'equal)))
(setf (cdr (assoc (car new_rule) _rule2tuples_ :test 'equal)) (append prev_tuples (list curr_tuple)))
)
)
)
)
)
)
)
)
)
(dolist ( rule2head _rule2head_)
(dolist (rule_tail (cadr rule2head))
(progn
(setq built_rule_tail ())
(dolist (token rule_tail)
(cond ((isAggregateFunction token)
(setf built_rule_tail (append built_rule_tail (computeAggregateFunction token (cdr (assoc (car rule2head) _rule2tuples_ :test 'equal))))))
(T (cond ((isAttribute token) (setf built_rule_tail (append built_rule_tail (getvalue (cadr (assoc (car rule2head) _rule2tuples_ :test 'equal)) (attrToCol token)))))
(T (setf built_rule_tail (append built_rule_tail (list token))))))
)
)
(setf prev_tails (cdr (assoc (car rule2head) _general_rules_ :test 'equal)))
(setf (cdr (assoc (car rule2head) _general_rules_ :test 'equal)) (append prev_tails (list built_rule_tail)))
)
)
)
)
(defun generate_info_rules (ds)
(progn
(setf tuples_to_check ())
(dolist (curr_tuple ds)
(cond ((equal (cadr (assoc 'famous curr_tuple )) '(Yes))
(setf tuples_to_check (append tuples_to_check (list curr_tuple))))
(T nil)
)
)
(setf rule_tail ())
(cond ((> (length tuples_to_check) 1) (setf rule_tail '(the most famous works are )))
(T (setf rule_tail '(the most famous work is )))
)
(dolist (curr_tuple tuples_to_check)
( progn
(setf rule_tail (append rule_tail (getValue curr_tuple 'Title)))
(if (not (equal (getValue (car (findAllByValue dataset 'Title (getValue curr_tuple 'Title))) 'Genre) nil))
(progn
(setf rule_tail (append rule_tail '( \, which is)))
(setf rule_tail (append rule_tail (getValue (car (findAllByValue dataset 'Title (getValue curr_tuple 'Title))) 'Genre)))
(setf rule_tail (append rule_tail '( \, )))
)
)
)
)
rule_tail
)
)
; -------------------------------------------------------------------------------------------------
; Metodi per la gestione delle regole con memoria
; -------------------------------------------------------------------------------------------------
(defun generate_rules_memory (curr_tuple rules_template)
(setf _rule_memory_ ())
(dolist (rule_template rules_template)
(progn (setq new_rule (generate_rule rule_template curr_tuple))
(cond ((missingValues new_rule) nil)
(T (defparameter _rule_memory_ (append _rule_memory_ (list new_rule)))
)
)
)
)
)
(defparameter *prevTuple* nil)
;lista parole chiave nella domanda con memoria
(defparameter keyList (list '(year nil) '(information nil) '(like nil)
'(instrument nil) '(genre nil) '(movements nil) '(famous nil) '(Duration nil)))
(defun azzeraKey ()
;Azzera il vettore delle paroli chiavi
(dolist (k keyList) (setf (cadr k) nil))
)
;pre: input è una lista di atomi
(defun extractKey (in keylist)
(progn
;data la stringa in input
(dolist (k keylist)
(if (containsKey in (car k))
(setf (cadr k) T))
))
)
(defun containsKey (in key)
;return true if in cointains the word "key"
(member key in)
)
;funzione chiamata per ogni parola chiave trovata nella stringa di input
(defun getInfo (tupla key)
;data una chiave 'key' restituisce una stringa con l'informazione delle 'chiave'
;presa dalla tupla salvata
;nota: la tupla si riferisce alla domanda precedente
(block keyValue
(dolist (rule _rule_memory_)
(when (equal (caar rule) key)
(return-from keyValue (cadr rule) )))
)
)
; -------------------------------------------------------------------------------------------------
; MATCHING
; -------------------------------------------------------------------------------------------------
(defparameter _bindings_ ())
(defun match (pattern input)
(progn
(cond
((equal pattern ()) (equal input ()))
((equal (car pattern) '*)
(let* (
(new_input (wildcard (cddr pattern) input (list (cadr pattern))))
)
(match (cddr pattern) new_input)))
((equal (car pattern) (car input)) (match (cdr pattern) (cdr input)))
(T nil)
))
)
(defparameter _viewpoint_ '((I you) (you I) (me you) (am are) (my your)))
(defun wildcard (pattern input curr_binding)
(cond ((equal input ())
(cond ((OR (equal pattern ()) (equal (car pattern) '*)) (progn (setf _bindings_ (append _bindings_ (list curr_binding))) ()))
(T (progn (setf _bindings_ ()) ()))))
((equal (car input) (car pattern))
(cond ((equal (cadr input) (car pattern)) (wildcard pattern (cdr input) (append curr_binding (list (car input)))))
(T (progn (setf _bindings_ (append _bindings_ (list curr_binding)))) input)
)
)
((setq viewpoint (assoc (car input) _viewpoint_)) (wildcard pattern (cdr input) (append curr_binding (list (cadr viewpoint)))))
(T (wildcard pattern (cdr input) (append curr_binding (list (car input)))))
)
)
(defun subs (rule_tail)
(cond ((equal rule_tail ()) (progn (setf _bindings_ ()) ()))
((equal (car (assoc (car rule_tail) _bindings_)) (car rule_tail))
(append (cdr (assoc (car rule_tail) _bindings_)) (subs (cdr rule_tail))))
(T (cons (car rule_tail) (subs (cdr rule_tail))))
)
)
; -------------------------------------------------------------------------------------------------
; GENERATORE REGOLE
; -------------------------------------------------------------------------------------------------
(generate_rules dataset _rules_template_)
(generate_general_rules dataset _general_rules_template_)
(defparameter other_rules ())
(setf other_rules (append other_rules (list (list '(* x most famous * y) (generate_info_rules dataset)))))
(setf other_rules (append other_rules (list (list '(* x major * y) (generate_info_rules dataset)))))
(setf other_rules (append other_rules (list (list '(* x categories * y) (append '(the genres i know are) (concatenate-l Genre_set))))))
(setf other_rules (append other_rules (list (list '(* x types * y) (append '(the genres i know are) (concatenate-l Genre_set))))))
(setf other_rules (append other_rules (list (list '(* x genres * y) (append '(the genres i know are) (concatenate-l Genre_set))))))
(setf other_rules (append other_rules (list (list '(* x works * y) (append '(the works i know are) (concatenate-l Title_set))))))
(setf other_rules (append other_rules (list (list '(* x compositions * y) (append '(the works i know are) (concatenate-l Title_set))))))
(setf other_rules (append other_rules '(
((* x period * z) (He was a Russian composer in the Romantic period))
((* y last work * y) (it's Pathetique\, also known as Symphony no\. 6\.))
(( * x * y a Tchaikovsky's work) (No it is not))
((* x by Tchaikovsky * z )(No it wasn't.))
((yes)(are you sure?)(ok\, if you say so))
((no)(me neither))
((nice) (am i nice ?))
((why)(42)(everything has an explanation\, i think))
((* x hello * y) (hello. what do you wish to know about Tchaikovsky?))
((* x i hate * z Tchaikovsky * y) (Why? have you listened to Pathetique ?))
((who are you)(i am pyotr\.\.\. i cannot tell you anymore than that))
)))
; -------------------------------------------------------------------------------------------------
; ATOMIZZATORE
; -------------------------------------------------------------------------------------------------
; atomizzatore:
; input : stringa = input string
; lb = stringa left pointer (initially always 0)
; sp = stringa right pointer (initially always 0)
; output: (SPLITTED STRINGA)
;
; es:
; input stringa = (ciao, come stai?)
; lb = 0
; sp = 0
;
; output (CIAO COME STAI)
(defun atomizzazione(stringa)
(atomizzatore (concatenate 'string stringa "$") 0 0)
)
(defun atomizzatore(stringa lb sp)
(cond
((equal (char stringa lb) #\$)
'()
)
((equal (char stringa lb) #\Space ) (atomizzatore stringa (+ lb 1 ) (+ sp 1)))
((equal (char stringa lb) #\. ) (atomizzatore stringa (+ lb 1 ) (+ sp 1)))
((equal (char stringa lb) #\, ) (atomizzatore stringa (+ lb 1 ) (+ sp 1)))
((equal (char stringa lb) #\- ) (atomizzatore stringa (+ lb 1 ) (+ sp 1)))
((equal (char stringa lb) #\? ) (atomizzatore stringa (+ lb 1 ) (+ sp 1)))
((equal (char stringa sp) #\$)
(append (list (read-from-string(subseq stringa lb sp))) (atomizzatore stringa (+ lb (- sp lb)) (+ sp 1)))
)
((equal (char stringa sp) #\Space)
(append (list (read-from-string(subseq stringa lb sp))) (atomizzatore stringa (+ lb (+ (- sp lb) 1)) (+ sp 1)))
)
((equal (char stringa sp) #\,)
(append (list (read-from-string(subseq stringa lb sp))) (atomizzatore stringa (+ lb (+ (- sp lb) 1)) (+ sp 1)))
)
((equal (char stringa sp) #\.)
(append (list (read-from-string(subseq stringa lb sp))) (atomizzatore stringa (+ lb (+ (- sp lb) 1)) (+ sp 1)))
)
((equal (char stringa sp) #\-)
(append (list (read-from-string(subseq stringa lb sp))) (atomizzatore stringa (+ lb (+ (- sp lb) 1)) (+ sp 1)))
)
(T (atomizzatore stringa lb (+ sp 1))
)
)
)
; -------------------------------------------------------------------------------------------------
; MAIN DEL BOT
; -------------------------------------------------------------------------------------------------
(defun bot ()
(princ "(pyotr says) ")
(princ " hi, i am an expert on the works of cajkovskij / Tchaikovsky / and many other names. In short, I am a fan of the author of Swan Lake. Ask me something and let's see if I can be useful to you!")
(terpri)
(defvar *matching* nil)
(loop
(princ ">> ")
(let* (
(line (read-line))
(input (atomizzazione line)))
(when (string= line "bye") (return))
(setq _bindings_ nil)
(princ "(pyotr says) ")
(format t "~{~(~a ~)~}~%"
(block rule_management
(progn
; -------------------------------------------------------------------------------------------------
; LIVELLO REGOLE SU SINGOLA TUPLA
; -------------------------------------------------------------------------------------------------
(dolist (r _rules_)
(when (match (car r) input)
(progn
;dico che ho trovato una regola
(setf *matching* t); ho trovato una matching
(setf *prevTuple* (getValue _rule2tuple_ (car r))); ho trovato una risposta, ho dunque memorizzato tupla
(return-from rule_management (subs (random-elt (rest r))))
)
)
)
; -------------------------------------------------------------------------------------------------
; LIVELLO REGOLE SU PIU TUPLE
; -------------------------------------------------------------------------------------------------
(dolist (r _general_rules_)
(when (match (car r) input)
(progn
(setf *matching* nil)
(return-from rule_management (subs (random-elt (rest r))))
)
)
)
; -------------------------------------------------------------------------------------------------
; LIVELLO REGOLE ULTERIORI
; -------------------------------------------------------------------------------------------------
(dolist (r other_rules)
(when (match (car r) input)
(progn
(setf *matching* nil)
(return-from rule_management (subs (random-elt (rest r))))
)
)
)
; -------------------------------------------------------------------------------------------------
; LIVELLO REGOLE CON MEMORIA
; -------------------------------------------------------------------------------------------------
(if (and *matching* (not (equal *prevTuple* nil)))
(progn
(extractKey input keylist) ;estraggo parole chiave e le salvo
(defparameter rix ())
(generate_rules_memory *prevTuple* _rules_template_memory_)
(dolist (k keyList)
(if (cadr k)
(progn
(setf rix (append rix (getInfo *prevTuple* (car k))))
(setf rix (append rix (list '-)))
)
)
)
(setf rix (remove '- rix :count 1 :from-end t ))
(if (equal rix ()) (setf rix (append rix '(I'm sorry I can't answer you - but tell me more if you want) )) )
(azzeraKey)
(if (not (equal rix ()) ) (return-from rule_management rix))
)
)
(setf *matching* nil)
(progn (match '(* x) input) (subs (random-elt '((What do you mean by x ?)(I'm sorry I can't answer you - but tell me more if you want) ) )))
)
)
))))
(bot)