beautypg.com

The signature and preconditions slots 18 – Apple Newton Programmer’s Newton 2.0 (for Newton 2.0) User Manual

Page 656

background image

C H A P T E R 1 8

Intelligent Assistant

18-10

About the Assistant

The Signature and PreConditions Slots

18

Your task template must define two slots, called

signature

and

preConditions

, which store arrays of templates and symbols, respectively.

The

signature

slot holds action templates and target templates that must be

matched to complete the primary action. The

preConditions

slot specifies the

names of slots that the Assistant creates in the task frame as templates in the

signature

slot are matched.

Each element of the

preConditions

array is related to the corresponding

element of the

signature

array. Specifically, an element of the

preConditions

array specifies the name of the slot that the Assistant creates in the task frame when
the template in the corresponding element of the

signature

array is matched.

For example, to send a fax the Assistant needs frames representing the action of
faxing, a fax number, the name of the person to whom the fax is sent, and the time
at which the fax is to be sent. The

signature

slot in the following code fragment

specifies by name the templates required to create these frames.

{...

// example: when fax_number is matched, Assistant creates

// a 'number slot in task frame & puts target frame in it

signature: [fax_action, fax_number, who_obj, when_obj],

preConditions: ['action, 'number, 'recipient, 'when],

...}

The corresponding elements of the

preConditions

slot specify the names of

slots that the Assistant creates in the task frame to hold the frames created as the
templates in the

signature

slot are matched. For example, the

preConditions

array in the previous code fragment specifies that the Assistant creates slots named

action

,

number

,

recipient

and

when

in the task frame as necessary.

Continuing with the example based on the previous code fragment, when the
Assistant parses the input phrase

"fax Bob"

, it matches the word

"fax"

to the

fax_action

template in the first element of the

signature

array and creates an

action frame from this template. The Assistant places this action frame in an

action

slot (named for the symbol in the first element of the

preConditions

array) that it creates in the task frame. Similarly, the Assistant creates a target
frame when the word

"Bob"

is matched to the

who_obj

template in the third

element of the

signature

array. The Assistant places this target frame in a

recipient

slot (named for the symbol in the third element of the

preConditions

array) that it creates in the task frame.

Words representing elements of the

signature

array do not necessarily need to

appear in the input string in order to be matched to a template; for example, your

PostParse

method might supply Bob’s fax number by finding it in the

Names soup.