semantic-net.lisp

来自「这是人工智能老师上课讲的课件 中文」· LISP 代码 · 共 39 行

LISP
39
字号

;;; These functions define a depth first inheritance search of a 
;;; semantic network.

(defun inherit-get (object property)
   (or (get object property)
       (get-from-parents (get object 'isa) property)))

(defun get-from-parents (parents property)
   (cond ((null parents) nil)
	 ((atom parents) (inherit-get parents property))
	 (t (or (get-from-parents (car parents) property)
	        (get-from-parents (cdr parents) property)))))

;;; These functions define a simple semantic network about animals.

(setf (get 'animal 'covering) 'skin)
(setf (get 'bird 'covering) 'feathers)
(setf (get 'bird 'travel) 'flies)
(setf (get 'bird 'isa) 'animal)
(setf (get 'fish 'isa) 'animal)
(setf (get 'fish 'travel) 'swim)
(setf (get 'ostrich 'isa) 'bird)
(setf (get 'ostrich 'travel) 'walk)
(setf (get 'penguin 'isa) 'bird)
(setf (get 'penguin 'travel) 'walk)
(setf (get 'penguin 'color) 'brown)
(setf (get 'opus 'isa) 'penguin)
(setf (get 'canary 'isa) 'bird)
(setf (get 'canary 'color) 'yellow)
(setf (get 'canary 'sound) 'sing)
(setf (get 'tweety 'isa) 'canary)
(setf (get 'tweety 'color) 'white)
(setf (get 'robin 'isa) 'bird)
(setf (get 'robin 'sound) 'sings)
(setf (get 'robin 'color) 'red)

;;;(inherit-get 'robin 'covering)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?