home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
aijournl
/
1986_12
/
expert.dec
< prev
next >
Wrap
Text File
|
1986-12-09
|
2KB
|
61 lines
Code Taken from
'Expert's Toolbox' column
written by Jonathan Amsterdam
for the Dec. 1986 issue of AI EXPERT
"Retrieval from a Frame Data Base"
Listing 1
(DEFUN FMATCH (PATTERN FRAME)
;; Returns the frame if it matches the pattern; else, returns NIL.
(DO ((SLOTS-AND-VALUES PATTERN (CDR SLOTS-AND-VALUES)))
((NULL SLOTS-AND-VALUES) FRAME)
(LET* ((SLOT (CAAR SLOTS-AND-VALUES))
(PATTERN-VALUE (CADAR SLOTS-AND-VALUES))
(FRAME-VALUE (FGET FRAME SLOT)))
(IF (NOT (MEMBER PATTERN-VALUE FRAME-VALUE))
(RETURN NIL)))))
Listing 2
(DEFUN FMATCH (PATTERN FRAME)
;; Returns the frame if it matches the pattern; else, returns NIL.
(DO ((SLOTS-AND-VALUES PATTERN (CDR SLOTS-AND-VALUES)))
((NULL SLOTS-AND-VALUES) FRAME)
(LET ((SLOT (CAAR SLOTS-AND-VALUES)))
(IF (NOT (FMATCH-SLOT
(CADAR SLOTS-AND-VALUES)
(IF (EQ SLOT 'AKO)
(COLLECT-FACET-WITH-INHERITANCE FRAME SLOT 'VALUE)
(FGET FRAME SLOT))))
(RETURN NIL)))))
(DEFUN FMATCH-SLOT (PATTERN-VALUE FRAME-VALUE)
;; Returns non-NIL iff the pattern-value and the frame-value match.
(COND
((FUNCTIONP PATTERN-VALUE)
(FUNCALL PATTERN-VALUE FRAME-VALUE))
((ATOM PATTERN-VALUE)
(MEMBER PATTERN-VALUE FRAME-VALUE))
((EQ (CAR PATTERN-VALUE) 'NOT)
(NOT (FMATCH-SLOT (CADR PATTERN-VALUE) FRAME-VALUE)))
((EQ (CAR PATTERN-VALUE) 'OR)
(DOLIST (OR-ITEM (CDR PATTERN-VALUE))
(IF (FMATCH-SLOT OR-ITEM FRAME-VALUE)
(RETURN T))))
((EQ (CAR PATTERN-VALUE) 'AND)
(NOT (DOLIST (AND-ITEM (CDR PATTERN-VALUE))
(IF (NOT (FMATCH-SLOT AND-ITEM FRAME-VALUE))
(RETURN T)))))
(T
(MEMBER PATTERN-VALUE FRAME-VALUE :TEST #'FMATCH))))