Frame matching
Frame matching is a variation on list matching. Frame patterns specify a set of conditions that need to be true of a concept for the pattern to match.
As with list patterns,
- a pattern has variables like
?x - the variable
?matches anything but does not produce a binding - the result of a match is a list of binding lists
The differences are that:
- a frame pattern is matched against a frame name, like CANARY
- the is-a hierarchy is taken into account, so CANARY matches the pattern ANIMAL
A frame pattern can be variable, frame name, or a frame list of the form
(pat-name pat-isas . pat-props)
where pat-name is either a variable or frame name, pat-isas is a list of frame names, and the remaining elements, pat-props, are role-filler pairs, where the fillers are a frame patterns.
The rules for matching are
| Pattern | Matches |
|---|---|
| frame name | any frame name that "is-a" the frame name |
| variable | matches any frame but every occurrence must match the same thing |
| frame list | matches any frame name that
|
Here are some examples of frame patterns and what they match, given the frames listed after the table.
| Pattern | Matches |
|---|---|
| animal | any animal, e.g., BIRD or TWEETY |
| (? (animal pet)) | any animal that is also a pet, like TWEETY but not WILLY |
| (? (animal) (can-fly yes)) | any animal that can fly, like TWEETY, CANARY, or FU-FU, but not WILLY |
| (? (animal) (color |
any animal with a color; ?x will bound to the color |
| (?x (animal) (color brown)) | any animal that is brown; ?x will bound to the animal name |
The examples in the table assume the frames below
(MAMMAL (ANIMAL)) (PET (ANIMAL)) (ANIMAL NIL (COLOR BROWN)) (BAT (MAMMAL)) (TWEETY (PET CANARY)) (WILLY (PENGUIN)) (FU-FU (BAT)) (BIRD (ANIMAL) (CAN-FLY YES)) (CANARY (BIRD) (COLOR YELLOW)) (PENGUIN (BIRD) (CAN-FLY NO) (COLOR BLACK-WHITE))
As an example of how to use the matcher,
if (get-frames) returns all the concept names above and
frame-match implements a frame matcher, then
(remove-if-not
(lambda (frame)
(frame-match '(? (animal) (color brown)) frame))
(get-frames))
would return all the brown animals
(MAMMAL PET ANIMAL BAT FU-FU BIRD)