-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlowlevel.lisp
1142 lines (984 loc) · 33 KB
/
lowlevel.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
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; -*- Mode: LISP; Syntax: Common-lisp; Package: Meta-aqua; Base: 10 -*-
(in-package :metaaqua)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
;;;; The Meta-AQUA Introspective Multistrategy Learning System
;;;; Version 6
;;;;
;;;; Copyright (C) 1996 Michael T. Cox ([email protected])
;;;;
;;;;
;;;; File: lowlevel.lisp
;;;;
;;;;
;;;; *******************************************************
;;;
;;; This program is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by the Free
;;; Software Foundation; either version 1, or (at your option) any later
;;; version.
;;;
;;; This program is distributed in the hope that it will be useful, but WITHOUT
;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
;;; more details.
;;;
;;; You should have received a copy of the GNU General Public License along
;;; with this program; if not, write to the Free Software Foundation, Inc., 675
;;; Mass Ave, Cambridge, MA 02139, USA. In emacs type C-h C-w to view license.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; UTILITIES AND MISCELLANEOUS FUNCTIONS FOR META-AQUA
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; THE *Say-Way* PROPERTY
;;;
;;; The *Say-Way* property is used to attach the English equivalent
;;; descriptions of instantiations (tokens) to the frame representations of the
;;; instantiations. The following functions support this feature.
;;;
(defvar *say-way* 'say-way
"Text equivalent string for frame is placed on this property.")
(defun do-say (symbol)
(get symbol *say-way*)
)
(defun do-add-say (symbol descr)
(setf (get symbol *say-way*) descr)
)
(defun say-xp (xp)
(do-say (frame-type xp)))
;;;
;;; Function say-input is the first feedback the user receives for a new
;;; 'understands goal input into Meta-AQUA. It tells whether or not the goal
;;; originated outside the program or was a goal to understand the structure
;;; inferred by the script applier.
;;;
;;; ||||||Note that this needs to be fixed when the script applier starts to
;;; handle some of the hand-coded examples. Also, I am not sure what is
;;; happening with other modes (e.g., as with Meta-AQUA calls of ripsau) any
;;; longer. [cox 25feb95]
;;;
(defun say-input (new-input spinqua-input?)
;; Was there not a function to do the following?
;; Yes - say-xp, but it was for xps and did not have the additional bagage.
; (with-character-style (*Style*)
(format
*aqua-window*
(if
(and
spinqua-input? ; If the input from spinqua (Tale-Spin),
(not ; then the structure is inferred if the
(member new-input ; new input is not in the story concepts.
*Story-Concepts*
:test ; Cannot use this test if hand-coded input
#'(lambda (x y) ; since *story-concpets* does not have instantiated
(equal x (first y)) ; frame variable, but rather, has patterns with
)))) ; variable bindings.
"~%Inferred Structure: ~s"
"~%Input Structure: ~s"
)
new-input)
(format
*aqua-window*
"~% ~s~%"
(or (do-say new-input)
(do-say (frame-type new-input))))
; )
)
;;;
;;; Function say-sub-goal is used to display the current subgoal being
;;; processed by Meta-aqua at the beginning of a new cycle of reasoning.
;;;
(defun say-sub-goal (sub-goal)
; (with-character-style (*Style*)
(format
*aqua-window*
"~%Current Sub-Goal: ")
(format
*aqua-window*
"~%~a ~a~%"
(case (first (get-abstraction
(goal-object sub-goal)))
(id " Identify interesting concepts in")
(generate " Generate explanation for")
(test " Verify hypothesis")
(review/learn " Review reasoning trace")
(t "Other info "))
(if (and
(eq 'generate
(first (get-abstraction
(goal-object sub-goal))))
(isa-p 'relation (list (goal-state sub-goal))))
(str-concat
"why "
(string
(f.get (goal-state sub-goal)
*co-domain-slot*))
" decides to perform "
(string
(f.get (goal-state sub-goal)
*domain-slot*)))
(string (goal-state sub-goal))))
; )
)
;;;
;;; The following 4 calls of do-add-say used to be putprop calls on *say-way*
;;; in the rep_smuggle4.lisp file. The 5th was in file rep_planner.lisp. The
;;; sixth is Janis' new addition.
;;;
(do-add-say
'XP-HUNGRY-BARK
"Seals bark at objects when hungry.")
(do-add-say
'XP-DEFENSIVE-BARK
"Dogs bark at objects when threatened.")
(do-add-say
'XP-INJURY-HIT
"People hit animate-objects when they want to hurt them.")
(do-add-say
'XP-INSTRUMENTAL-SCENE->ACTOR
"Actor does action because it enables another more important action.")
(do-add-say
'XP-GOAL-OF-OUTCOME->ACTOR
"Actor does action because it achieves a goal the agent desires.")
(do-add-say
'XP-TYPICAL-ACTION-ANIMATES->ACTOR
"Actor does action because this kind of actor normally does this action.")
(do-add-say
'XP-DISABLE-ACT-PRECONDITION
"Actor does action because he knows that the plan which this action is an instrumental act for will lead to satisfying the goal of disenabling the undesired action.")
(do-add-say
'smoke-pipe
"Actor smokes a pipe.")
(do-add-say
'fill-pipe
"Actor fills the pipe.")
(do-add-say
'close-container
"The actor closes the container.")
(do-add-say
'open-container
"The actor opens the container.")
(do-add-say
'disembark-plane
"Actor disembarks from plane.")
;;;
;;; MISCELLANEOUS FUNCTIONS.
;;;
;;;
;;; Function print-goal-status simply prints the current value of the
;;; *Goal-Queue*, the goal to be processed next, and the state that the goal
;;; wishes to achieve.
;;;
;;; The function always returns true so that it will not effect the termination
;;; condition of the main body of function ripsau (the only place this function
;;; is used.
;;;
(defun print-goal-status (next-goal goal-queue &optional calling-function)
(if (goal-monitor-mode-p)
(let ((previous-window *aqua-window*))
(current-window *window3*)
(format-if
calling-function
*aqua-window*
"~%Called by function ~s."
calling-function)
(format
*aqua-window*
"~%~%Goal Queue --> ~s~%"
(list-queue goal-queue))
(format
*aqua-window*
"Next Goal --> ~s~%"
next-goal)
(f.pprint next-goal)
(format
*aqua-window*
"~%Goal-State --> ~s ~s ~s~%"
(goal-actor next-goal)
(first (get-abstraction
(goal-object next-goal)))
(goal-state next-goal
))
(current-window previous-window)))
t)
(defun print-cycle-division (&optional title-string)
(let ((previous-window *aqua-window*))
(current-window *window3*)
(format
*aqua-window*
(str-concat
"-----------------"
(or title-string
"new-cycle")
"-----------------"))
(current-window previous-window))
t)
;;;
;;; Predicate user-quits-p returns whether or not the system should stop
;;; processing. If the system is in automatic mode (automatic? = t), nil is
;;; returned. If it is in semi mode and the next goal to be processed is a
;;; understands goal (or if automatic is another value), then the user is
;;; prompted for this information.
;;;
;;; The function always has the side effect of displaying the upcoming goal for
;;; the user to see so he can make a decision if prompted.
;;;
(defun user-quits-p (automatic? next-goal)
(print-goal-status ; Print system goals.
next-goal *Goal-Queue*)
(if (or (goal-monitor-mode-p) ; If using the internal structures window
(memory-monitor-mode-p))
(print-cycle-division)) ; Mark a division between processing cycles on screen.
(not
(or
(eq automatic? t) ; Fully automatic or ..
(and (eq automatic? 'semi) ; Semi-automatic runs do not stop for
(isa-p ; understand goal or ..
'understands
(list
(f.get next-goal
'goal-object))))
(y-or-n-p ; Allow the user to quit.
"~%Continue ? ")))
)
;;;
;;; Function assert-truth assigns the given truth value to the given frame and
;;; all its subframes, unless there already exists a truth value for a
;;; particular frame. The optional parameter notify determines whether or not
;;; the user is notified of these pre-existing truth slots. The frame is
;;; returned by the function.
;;;
;;; Use of this function with frames that are already hooked into either the
;;; world or reasoning models should be limited. Truth values may be propagated
;;; further than desired.
;;;
(defun assert-truth (truth-value frame &optional notify)
(f.traverse-frame
frame
#'assert-as
truth-value
notify)
frame)
;;;
;;; Function assert-as is the actual helper function that does the work for
;;; function assert-truth.
;;;
(defun assert-as (current-frame parent role facet-name level truth-value notify)
(if (not (or (literal-p current-frame)
(attribute-value-p current-frame)))
(format-if
(and (not (f.put truth-value current-frame *truth-slot*))
notify)
*aqua-window*
"Frame ~s already has ~s as value of truth slot."
current-frame
(f.get current-frame *truth-slot*)))
)
;;;
;;; *INTERNAL-STRUCT-WINDOW* FLAG
;;;
;;; Data structure for flag to determine whether to use *window3* for
;;; displaying goal priority-queue or displaying memory. The first mode will be
;;; called goal-monitor-mode, whereas the second will be called memory-monitor
;;; mode.
;;;
(defvar *internal-struct-window* nil
"Determines whether the internal structures window shows behavior of goal queue or memory.")
(defconstant *shows-goals* 'show-goal-queue)
(defconstant *shows-memory* 'show-memory)
(defun init-struct-window-flag ()
(setf *internal-struct-window* *shows-goals*)
)
;;;
;;; Function toggle-structures-window is used by the system user to change the
;;; mode by which the Internal Structures Window works. The optional parameter
;;; active-window? can be used to disable the Internal Structures Window by
;;; passing it a nil value.
;;;
(defun toggle-structures-window (&optional (active-window? t))
(if active-window?
(let ((previous-window *aqua-window*))
(cond ((memory-monitor-mode-p)
(setf *internal-struct-window* *shows-goals*))
((goal-monitor-mode-p)
(setf *internal-struct-window* *shows-memory*))
(t ; otherwise we are re-enabling the window.
(setf *internal-struct-window* *shows-goals*)))
(current-window
*window3*
(str-concat
"Internal Structures Window "
(if (goal-monitor-mode-p)
"- Goal Priority-Queue"
"- Memory Monitor")))
(current-window previous-window))
(setf *internal-struct-window* nil))
)
(defun goal-monitor-mode-p ()
(eq *internal-struct-window* *shows-goals*)
)
(defun memory-monitor-mode-p ()
(eq *internal-struct-window*
*shows-memory*)
)
;;;
;;; WINDOW HANDLING FUNCTIONS
;;;
;;;
;;; Function screen-init is called by init-run at the start of each program
;;; run. It exposes the two display screens (LISP-Listeners) and clears any old
;;; output. If the mode is different than the previous mode, then the function
;;; calls prep to initialize the screen, as is done by init-aqua.
;;;
(defun screen-init (mode previous-mode)
(cond ((equal mode previous-mode)
(cond ((action-mode-p mode)
(current-window *window2*)
(cls)))
(current-window *window3*)
(cls)
(current-window *window1*)
(cls))
(t
(prep mode)))
)
;;;
;;; Make the global variable *aqua-window* (which points to the current output
;;; window) set to the window parameter. Bind terminal i/o and query i/o to the
;;; window. Optionally set the window label and make sure that when deexposed
;;; the screen does not grey out. Then finally expose the window for
;;; processing.
;;;
(defun current-window (window &optional window-label do-init)
nil
; (setf *aqua-window* window)
; Commented out the next 3 lines.[cox 6mar97]
; (if (not (null window-label))
; (send *aqua-window* :set-label window-label))
; (send *aqua-window* :expose)
; (if do-init
; (tv:set-screen-deexposed-gray nil))
;Commented out next6 2 [cox 6mar97]
; (setf *terminal-io* *aqua-window*)
; (setf *query-io* *aqua-window*)
)
;;;
;;; STATUS AND TRUTH SLOT HANDLING
;;;
;;;
;;; Predicate answers question:
;;; Is frame input from the story?
;;;
(defun story-instance-p (frame)
(equal (f.get frame *status-slot*) *story-instance*)
)
;;;
;;; Function add-story-status marks each non-attribute subframe of and
;;; including new-story-frame as being an input concept from a story.
;;;
(defun add-story-status (new-story-frame)
(f.traverse-frame
new-story-frame
#'(lambda (frame parent slot facet level)
(if (not (or (visited-p frame)
(attribute-value-p frame)))
(mark-as-story-instance frame))))
new-story-frame
)
;;; |||||
;;; In this simple version, all story-instances are naively believed,
;;; ie. truth slot marked as in, as in the original version of AQUA.
;;; However we eventually want to be able to override this or have suspicions
;;; about this assumption.
;;;
;;; BEWARE that this function does NOT check first to see whether the
;;; new-instance is an attribute or not.
;;;
(defun mark-as-story-instance (new-instance)
(when (and (frame-var-p new-instance)
(not (literal-p new-instance)))
(f.put *story-instance* new-instance *status-slot*)
(mark-in new-instance))
new-instance
)
;;;
;;; Function mark-as-believed recursively marks each subframe of
;;; frame (as well as frame itself) as being in the set of beliefs.
;;; Exceptions not marked are attribute values and fillers having a
;;; list as their value. ||||| This should be changed so that the
;;; function runs down the frmae lists recursively also. There is a
;;; possible conflict with the cycles when doing this however.
;;;
(defun mark-as-believed (frame)
(f.traverse-frame
frame
#'(lambda (frame parent slot facet level)
(if (not (or (visited-p frame)
(attribute-value-p frame)
(frame-list-p frame)))
(mark-in frame))))
frame)
;;;
;;; Function mark-in simply assign the *in* value to the *truth-slot*
;;; of the given frame.
;;;
(defun mark-in (frame)
(f.put *in* frame *truth-slot*)
)
;;;
;;; ANOMALY DETECTION
;;;
;;; The following routines support anomaly detection and indexing.
;;;
;;;
;;; Function declare-anomaly simply prints the discovery of an anomaly.
;;;
(defun declare-anomaly (concept anomaly-type path)
; (with-character-style (*Style*)
(format
*aqua-window*
(str-concat
"~%~%Anomaly detected: "
"Odd for a ~s~% to be in "
"path ~s of a ~s.")
anomaly-type path concept)
; )
)
;;;
;;; Function anomaly-check acts as a predicate to determine the presence of an
;;; anomaly. Currently, an anomaly exists if the actual filler in a frame is
;;; not of the same type as the proto-type declared in concept definitions for
;;; that filler by the Representation files (rep_*.lisp). If the prototype is
;;; an attribute value, then the two are checked for strict equivalence. If
;;; the two are literals, then their frame values are tested for equivalence
;;; using equal (this is so that two copies of the list '(literal) will
;;; equate). Otherwise the actual filler must be isa the prototype's type and
;;; the actual filler must not itself be anomalous. These kinds of anomalies
;;; generate the Incorporation Failure type when reading a story.
;;;
;;; The return value is a list of anomaly paths if the actual filler is
;;; anomalous, t if any of the other tests fail, nil otherwise. If the
;;; function returns t, then the anomaly is caused by the actual filler. If a
;;; list is returned, then the anomaly is deeper in the actual filler's frame
;;; structure.
;;;
;;; |||||| NOTE that the actual filler may be anomalous with respect to the
;;; definition of a frame it is contained in, *AND* the filler itself may be
;;; anomalous with respect to its own definition. In this case, the function
;;; will return the list, but will not signal the former anomaly. Need to fix
;;; this. [11apr94]
;;;
(defun anomaly-check (prototype-filler actual-filler check-list)
(let* ((anomalous-paths nil)
(exists-anomaly
(not
(if (attribute-value-p
prototype-filler)
(eq prototype-filler actual-filler)
(if (and (literal-p prototype-filler)
(literal-p actual-filler))
(or (equal (*FRAME* prototype-filler)
literal) ; Dummy literal
(equal (*FRAME* actual-filler)
literal) ; Dummy literal
(equal (*FRAME* prototype-filler)
(*FRAME* actual-filler)))
(and
(or
(isa-p
(frame-type prototype-filler)
(list actual-filler))
(isa-p
(frame-type actual-filler)
(list prototype-filler)))
(not (setf anomalous-paths
(is-anomalous
actual-filler check-list)))))))))
(or anomalous-paths
exists-anomaly))
)
;;;
;;; Predicate test-criteria-p returns true if it is OK to check for anomalies
;;; between the given filler and the proto-type, nil otherwise. This occurs if
;;; the filler is a non-list value filler and the prototype has a corresponding
;;; non-nil filler.
;;;
(defun test-criteria-p (facet filler prototype-filler)
(and
(equal *value-facet*
(facet->facet-name
facet))
(not (frame-list-p filler))
(not (null prototype-filler)))
)
;;;
;;; Function append-each-in-result-to appends the path prefix to each list in
;;; the list-of-suffixes. The resulting list is returned.
;;; For instance,
;;; (append-each-in-result-to
;;; '(actor domain)
;;; '((at-location co-domain) (object color)))
;;; --> '((actor domain at-location co-domain) (actor domain object color))
;;;
(defun append-each-in-result-to (path-prefix list-of-suffixes)
(let ((result nil))
(dolist (each-suffix list-of-suffixes)
(setf result
(cons (append
path-prefix
each-suffix)
result)))
result)
)
;;;
;;; Function recursive-check is called by is-anomalous in order to search for
;;; anomalies in sub-frames of the high-level concept passed to is-anomalous.
;;; It must be able to construct the paths to the anomalies returned by
;;; anomaly-check.
;;;
;;; The input prototype is an instantiated copy of the frame definition of the
;;; original concept being checked for anomalies. The path is a list of roles
;;; that traverse the path from the original concept, into its hierarchical
;;; structure to the current-concept being checked. Thus, the first time
;;; recursive-check is called (called by is-anomalous) the current-concept is
;;; the original concept, the prototype is the instantiation of the frame type
;;; of the original concept, and the path is nil.
;;;
;;; The function checks for anomalies by calling anomaly-check on each filler
;;; from the current-concept that passes the test criteria predicate against
;;; the corresponding proto-type-filler, and then recursively calling itself
;;; on each of these current-concept fillers with the path extended to point
;;; at the new current-concept.
;;;
;;;
(defun recursive-check (prototype path current-concept check-list)
(do-break recursive-check)
(let ((anomalies nil))
(dolist (each-slot (f.slot-list current-concept))
(let ((role (slot->role each-slot)))
(dolist (each-facet (slot->facets each-slot))
(let* ((filler (facet->filler each-facet))
(new-path (append path (list role)))
(prototype-filler
(apply #'f.chase-path
(cons prototype
new-path))))
(cond ((test-criteria-p
each-facet filler prototype-filler)
(let ((anomaly-check-result
(anomaly-check prototype-filler filler check-list)))
(cond (anomaly-check-result
(setf anomalies
(cond ((listp anomaly-check-result)
(append
(append-each-in-result-to
new-path
anomaly-check-result)
anomalies))
(t
(declare-anomaly
(frame-type prototype)
(frame-type filler)
new-path)
(cons
new-path
anomalies))))
)))
;; The if test also avoids infinite loops. There is no need to
;; check for anomalies within attribute values anyhow. [cox 1may94]
(if (not (attribute-value-p filler))
(let ((sub-roles (recursive-check
prototype
new-path
filler
check-list)))
(if sub-roles
(setf anomalies
(append
anomalies
sub-roles)))))))))))
anomalies))
;;;
;;; Function is-anomalous is the main anomaly detection function. It checks to
;;; see if the input concept is filled with normally expected values by
;;; calling function recursive-check, passing it an instantiated copy of the
;;; concept's frame definition (to act as prototype), nil (signaling a null
;;; path into the structure searched so far), and the concept to be checked
;;; for anomalies. It returns a list of paths into the input concept where
;;; anomalies occur, with duplicate paths removed. Note that literals are
;;; never considered anomalous.
;;;
;;; Is-anomalous acts as a predicate, returning nil if no anomalies exist
;;; within the concept, or returning the list of paths to the anomalies
;;; otherwise.
;;;
;;; The check-list is to avoid checking for anomalies repeatedly in the same
;;; concept. Recursive-check calls anomaly-check, which calls is-anomalous.
;;; If it comes back here with the same concept, return nil. This avoids
;;; infinite loops.
;;;
(defun is-anomalous (concept &optional check-list)
(do-break is-anomalous)
(if (or (literal-p concept)
(attribute-value-p concept)
(member concept check-list))
nil
(remove-duplicates
(recursive-check
(f.instantiate-frame
;; The concept's frame definition.
(frame-def concept))
nil
concept
(cons concept check-list))
:test #'equal))
)
;;;
;;; Function complain-missing-xp prints a message to the user that there exists
;;; an error in function index-anomaly because there is no explanation for the
;;; concept. The routine then executes a break. If show-bugs flag is nil then
;;; we do nothing.
;;;
(defun complain-missing-xp (concept show-bugs)
(when show-bugs
(format
*aqua-window*
(str-concat
"~%ERROR in index-anomaly:"
"No xps in concept ~s")
concept)
(break))
)
;;;
;;; Function index-anomaly places in memory any explanation (usually is the
;;; question) associated with the input concept so that it can be retrieved at
;;; a later time. If the concept is a relation, the anomaly is passed directly
;;; to the function do-index. However, if it is not a relation, then the actor
;;; relation of the concept is passed to do-index. Do-index requires a
;;; relation, and at this time, it indexes by actor relations of actions.
;;;
;;; |||||| Is this function redundant with the index-question function?
;;; [28nov93]
;;;
(defun index-anomaly (concept anomaly-list)
(let ((xps (f.get concept
*explanations-slot*)))
(do-break index-anomaly)
(if xps
(dolist (each-path anomaly-list)
(let ((anomaly
(apply
#'f.chase-path
(cons concept
each-path))))
(if (isa-p 'relation
(list anomaly))
(do-index xps
'question-type.0
anomaly)
(if (f.get anomaly
*actor-slot*)
(do-index xps
'question-type.0
(f.get-relation
anomaly
*actor-slot*))
))))
(complain-missing-xp concept
*Show-Bugs*)))
)
(defun index-anomaly2 (concept anomaly-list)
(let ((anomalous-frame (f.get concept *domain-slot*)))
(do-break index-anomaly2)
(if anomalous-frame
(dolist (each-path anomaly-list)
(let ((anomalous-node
(apply
#'f.chase-path
(cons anomalous-frame
(butlast each-path)))))
(if (isa-p 'relation
(list anomalous-node))
(do-index concept
'question-type.0
anomalous-node)
(if (f.get anomalous-node
*actor-slot*)
(do-index concept
'question-type.0
(f.get-relation
anomalous-node
*actor-slot*))
))))
(format *aqua-window*
"~%ERROR in index-anomaly2~%")))
)
;;;
;;; STORY COHERENCE
;;;
;;;
;;; The following code was an initial beginning to compute the coherence of the
;;; story. See comment on *Story-Tokens*.
;;;
(defvar *reference-counter* 0)
(defun story-references-in (frame)
"Count the number of input story concepts references within the frame."
(terpri *aqua-window*)
(setf *reference-counter* 0)
(f.traverse-frame
frame
#'sentences-touched)
(format
*aqua-window*
(str-concat
"~%~%~s story concept(s) "
"referenced within frame ~s.~%~%" )
*reference-counter*
frame)
)
(defun sentences-touched (current-frame parent role facet-name level)
(cond ((and
(not (visited-p current-frame *traverse-marker*))
(member current-frame
(get-model *Story-Tokens*)))
(setf *reference-counter*
(+ 1 *reference-counter*))
(format
*aqua-window*
"~%Sentence token: ~s"
current-frame))))
;;;
;;; Function return-path-to returns a path from the root frame to the target
;;; frame if it exists. This is really inefficient.
;;;
(defun return-path-to (target-frame root-frame)
(if (equal root-frame target-frame)
nil
(f.traverse-frame
root-frame
#'(lambda (current-frame
parent
role
facet-name
level)
(if (equal current-frame target-frame)
(print
(append
(return-path-to
parent root-frame)
(list (if (equal facet-name *value-facet*)
role
(list role facet-name)))))))))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; HIGH LEVEL PREDICATES
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Predicate action-mode-p returns true if Meta-AQUA is being run in
;;; problem-solving mode, false if story understanding mode.
;;;
(defun action-mode-p (mode)
(equal mode 'act-out-story)
)
;;;
;;; Predicate same-results-p returns true if the main-result of both nodes
;;; passed to it are of the same type, nil otherwise. The function returns as a
;;; second value: the common type if the types are the same, otherwise the
;;; second value returned is a list of the main-result type of the first node
;;; followed by the second.
;;;
(defun same-results-p (node1 node2)
(let ((first-type (get-abstraction
(f.get node1
'main-result
*value-facet*)))
(second-type (get-abstraction
(f.get node2
'main-result
*value-facet*))))
(if (and (not (or (null first-type)
(null second-type)))
(equal first-type second-type))
(values t first-type)
(values nil (list first-type second-type)))))
;;;
;;; The predicate siblings-p is a slight mis-nomer. Sibling are defined in
;;; this sense as nodes in which one is not the direct ancestor of the other
;;; not including entity, the root of the isa hierarchy.
;;;
;;; ||||| Look more closely at common-ancestor-p and lowest-common-ancestor-p
;;; for details since this explanation is off somewhat. they are in frame.lisp.
;;;
(defun siblings-p (node1 node2)
(let ((lca-type nil))
(if (and (not (f.common-ancestor-p node1 node2))
(not (equal '(entity)
(setf lca-type (f.lowest-common-ancestor node1 node2)))))
(values t lca-type)
(values nil lca-type))))
;;;
;;; Currently the function checks all slot's relation facets of the concept for
;;; an indexed question. If any of the co-domain slots of the relations has an
;;; actor slot, then it also checks the relation facet of these actor
;;; relations.
;;;
(Defun potential-answer-p (concept)
(do-break potential-answer-p)
(let ((question
(retrieve-memory
'question-type.0
concept))
(sub-questions
(mapcan
#'(lambda (each-slot)
(let*
((relation-filler
(slot->filler ; ||||||Turn this into a call of f.get-relation?
each-slot
*relation-facet*))
(return-val
(or
(and (not
(listp relation-filler))
(retrieve-memory
'question-type.0
relation-filler))
(let ((co-domain-filler ; This is really the value filler of the slot (each-slot)