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,

The differences are that:

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

PatternMatches
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
  • matches the pat-name
  • "is-a" all the pat-isas
  • has or inherits properties that match all the pat-props

Here are some examples of frame patterns and what they match, given the frames listed after the table.

PatternMatches
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 ?x)) 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)