-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdescriptions.lisp
377 lines (299 loc) · 13.5 KB
/
descriptions.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
;---------------------------------------------
; DESCRIPTIONS: This file contains flavors, methods, and codelets for
; descriptions.
;---------------------------------------------
(in-package 'user)
;---------------------------------------------
(defflavor description
(object ; The object to which the description is attached.
string ; The string this description is in.
description-type ; The facet of the object that the description refers to,
; e.g., "letter-category", or "string-position-category".
descriptor ; The descriptor applying to the given facet, e.g., "A"
; or "leftmost".
description-number ; A unique number given to each description of an
; object.
)
(workspace-structure)
:gettable-instance-variables
:settable-instance-variables
:initable-instance-variables)
;---------------------------------------------
(defun make-description (object description-type descriptor &aux new-description)
; Returns a new description.
(setq new-description
(make-instance 'description
:object object
:string (send object :string)
:description-type description-type
:descriptor descriptor))
new-description)
;---------------------------------------------
(defmethod (description :print) ()
(format t "~a:~a; ~a: ~a "
(send object :pname) (send object :left-string-position)
(send description-type :pname) (send descriptor :pname))
(format t "~%"))
;---------------------------------------------
(defmethod (description :description-string) ()
(send descriptor :short-name))
;---------------------------------------------
(defmethod (description :relevant?) ()
; Returns t if the description-type being described is active (e.g., if
; "letter-category" is active, then letter-category descriptions, such as "A",
; are relevant).
(send description-type :active?))
;---------------------------------------------
(defmethod (description :conceptual-depth) ()
(send descriptor :conceptual-depth))
;----------------------------------------------
(defmethod (description :bond-description?) ()
; Returns t if the description (of a group) refers to the bonds making up
; the group, either the bond-category (e.g., "successor")
; or the bond-facet ("letter-category" or "length").
(or (eq description-type plato-bond-category)
(eq description-type plato-bond-facet)))
;---------------------------------------------
(defflavor extrinsic-description
; An extrinsic description is a description with respect to another object on
; the workspace. For example, "successor" of "letter-category" of <other-obj>.
; In "abc -> abd", the 'd' might get the description "successor of the 'c'".
(relation ; E.g., "successor".
description-type-related ; E.g., "letter-category".
other-obj ; The object this description refers to.
)
()
:gettable-instance-variables
:settable-instance-variables
:initable-instance-variables)
;---------------------------------------------
(defmethod (extrinsic-description :conceptual-depth) ()
(send relation :conceptual-depth))
;----------------------------------------------
(defun make-extrinsic-description (relation description-type-related other-obj)
; Returns a new extrinsic description.
(make-instance 'extrinsic-description
:relation relation
:description-type-related description-type-related
:other-obj other-obj))
;---------------------------------------------
(defmethod (extrinsic-description :print) ()
(format t "~a of ~a of " (send relation :pname)
(send description-type-related :pname))
(send other-obj :print))
;---------------------------------------------
(defmethod (description :apply-slippages) (object slippage-list
&aux new-description-type
new-descriptor)
; Returns a new description with the given slippages applied.
(setq new-description-type description-type)
(setq new-descriptor descriptor)
(loop for s in slippage-list
when (eq (send s :descriptor1) description-type)
do (setq new-description-type (send s :descriptor2))
when (eq (send s :descriptor1) descriptor)
do (setq new-descriptor (send s :descriptor2)))
(make-description object new-description-type new-descriptor))
;----------------------------------------------
(defun descriptions-equal? (d1 d2)
; Returns t if the two descriptions are the same.
(and (eq (send d1 :description-type) (send d2 :description-type))
(eq (send d1 :descriptor) (send d2 :descriptor))))
;----------------------------------------------
(defun description-member? (description list-of-descriptions)
; Returns t if the given description (or its equivalent) is a member of the
; given list of descriptions.
(loop for d in list-of-descriptions
when (descriptions-equal? description d)
return t
finally (return nil)))
;----------------------------------------------
(defun bottom-up-description-scout
(&aux chosen-object chosen-description chosen-descriptor
has-property-links choice-list chosen-property)
; Chooses an object probabilistically by total salience, and chooses a relevant
; description of the object probabilistically by activation. Sees if the
; descriptor has any "has property"
; links that are short enough. (E.g., "A" has a "has property" link to "
; first"). If so, chooses one
; of the properties probabilistically, based on degree of association and
; activation, proposes a description based on the property, and posts a
; description-strength-tester codelet with urgency a function of the
; activation of the property.
(block nil
(if* %verbose%
then (format t "~&In bottom-up-description-scout.~&"))
; Choose an object.
(setq chosen-object (send *workspace* :choose-object ':total-salience))
(if* %verbose%
then (format t "Chose object ")
(send chosen-object :print))
; Choose a relevant description of the object.
(setq chosen-description
(send chosen-object :choose-relevant-description-by-activation))
(if* (null chosen-description)
then (if* %verbose%
then (format t
"Couldn't choose a description. Fizzling.~&"))
(return))
(setq chosen-descriptor (send chosen-description :descriptor))
(if* %verbose% then (format t "Chose descriptor ~a~&"
(send chosen-descriptor :pname)))
; See if this descriptor has any "has property" links that are short
; enough (decided probabilistically).
(setq has-property-links
(send chosen-descriptor :similar-has-property-links))
(if* %verbose%
then (format t "Similar has-property-links:~&")
(send-method-to-list has-property-links :print))
(if* (null has-property-links)
then (if* %verbose%
then (format t "No short-enough has-property-links. Fizzling.~&"))
(return))
; Choose a property probabilistically, based on degree of association and
; activation.
(setq choice-list
(list-multiply
(send-method-to-list has-property-links :degree-of-association)
(send-method-to-list
(send-method-to-list has-property-links :to-node)
:activation)))
(setq chosen-property
(send (nth (select-list-position choice-list) has-property-links)
:to-node))
(if* %verbose%
then (format t
"Chosen-property: ~a~&" (send chosen-property :pname)))
(propose-description chosen-object (send chosen-property :category)
chosen-property)))
;---------------------------------------------
(defun top-down-description-scout (description-type
&aux chosen-object possible-descriptors
chosen-descriptor)
; Chooses an object probabilistically by total salience, and sees if this
; object fits any of the descriptions in this description-type's "has-instance"
; list. (E.g., if the description-type is "alphabetic-position-category", sees
; if the chosen object can be described as "first" or "last" in the alphabet.)
; If so, proposes a description based on the property, and posts a
; description-strength-tester codelet with urgency a function of the
; activation of the proposed descriptor..
(block nil
(if* %verbose%
then (format t "~%In top-down-description-scout with description-type ~a~&"
(send description-type :pname)))
; Choose an object.
(setq chosen-object (send *workspace* :choose-object ':total-salience))
(if* %verbose%
then (format t "Chose object ")
(send chosen-object :print))
; See if a description of this type can be made.
(setq possible-descriptors
(send description-type :get-possible-descriptors chosen-object))
(if* (null possible-descriptors)
then (if* %verbose%
then (format t
"Couldn't make description. Fizzling.~&"))
(return))
(setq chosen-descriptor
(select-list-item-by-method possible-descriptors ':activation))
(propose-description chosen-object description-type chosen-descriptor)))
;---------------------------------------------
(defun description-strength-tester (proposed-description
&aux proposed-description-strength
build-probability urgency)
; Calculates the proposed-description's strength, and probabilistically decides
; whether or not to post a description-builder codelet. If so, the urgency of
; the description-builder codelet is a function of the strength.
(block nil
; Activate the descriptor.
(send (send proposed-description :descriptor) :activate-from-workspace)
; Update the strength values for this description.
(send proposed-description :update-strength-values)
(setq proposed-description-strength
(send proposed-description :total-strength))
(if* %verbose%
then (format t "Proposed description: ")
(send proposed-description :print)
(format t "~% Strength: ~a~&" proposed-description-strength))
; Decide whether or not to post a description-builder codelet, based on the
; total strength of the proposed-description.
(setq build-probability
(get-temperature-adjusted-probability
(/ proposed-description-strength 100)))
(if* %verbose%
then (format t "Build-probability: ~a~&" build-probability))
(if* (eq (flip-coin build-probability) 'tails)
then (if* %verbose%
then (format t "Description not strong enough. Fizzling.~&"))
(return))
(setq urgency proposed-description-strength)
(if* %verbose%
then (format t "Posting a description-builder with urgency ~a.~&"
(get-urgency-bin urgency)))
; Post the description-builder codelet.
(send *coderack* :post
(make-codelet 'description-builder (list proposed-description)
(get-urgency-bin urgency)))))
;---------------------------------------------
(defun description-builder (proposed-description)
; Tries to build the proposed description, fizzling if the object no longer
; exists or if the description already exists.
(block nil
(if* %verbose%
then (format t "In description-builder with proposed-description ")
(send proposed-description :print)
(format t "~%"))
; If the object no longer exists, then fizzle.
(if* (null (memq (send proposed-description :object)
(send *workspace* :object-list)))
then (if* %verbose%
then (format t
"This object no longer exists. Fizzling.~&"))
(return))
; If this description already exists, then fizzle.
(if* (send (send proposed-description :object)
:description-present? proposed-description)
then (if* %verbose%
then (format t "This description already exists. Fizzling.~&"))
(send (send proposed-description :description-type) :activate-from-workspace)
(send (send proposed-description :descriptor) :activate-from-workspace)
(return))
(build-description proposed-description)))
;---------------------------------------------
(defun build-description (new-description)
; This function actually builds the new description.
(if* (send new-description :bond-description?)
then (send (send new-description :object)
:add-bond-description new-description)
else (send (send new-description :object)
:add-description new-description))
(send (send new-description :description-type) :activate-from-workspace)
(send (send new-description :descriptor) :activate-from-workspace)
(if* %workspace-graphics%
then (send (send new-description :object)
:init-description-graphics new-description))
; If the description describes the length of a group, then display the
; length.
(if* (and %workspace-graphics%
(eq (send new-description :description-type) plato-length))
then (send (send new-description :object) :init-length-graphics)
(send (send new-description :object) :draw-length))
; Keep length-description statistics.
(if* (eq (send new-description :description-type) plato-length)
then (incf *length-description-count*)))
;---------------------------------------------
(defun propose-description (object description-type descriptor
&aux proposed-description urgency)
; Creates a proposed description, and posts a description-strength-tester
; codelet with urgency a function of the activation of the description's
; descriptor.
(setq proposed-description (make-description object description-type descriptor))
(send (send proposed-description :descriptor) :activate-from-workspace)
(setq urgency (send description-type :activation))
(if* %verbose%
then (format t "Posting a description-strength-tester with urgency ~a~&"
(get-urgency-bin urgency)))
(send *coderack* :post
(make-codelet 'description-strength-tester (list proposed-description)
(get-urgency-bin urgency))))
;---------------------------------------------