Appendix C. Form Interpretation Algorithm

The Form Interpretation Algorithm (FIA) drives the interaction between the user and a VoiceXML form or menu.[1] A menu can be viewed as a form containing a single field whose grammar and the filled block are constructed from the choice elements.

[1] This appendix is taken verbatim from the VoiceXML 2.0 Specification and is meant to define VoiceXML's Form Interpretation Algorithm using pseudo-code. While Chapter 2, “VoiceXML essentials,” on page 24 should serve as the more thorough and readable guide to the Form Interpretation Algorithm, this pseudo-code representation should unambiguously define the behavior of a VoiceXML 2.0 compliant interpreter regarding the interpretation of forms.

The FIA must handle:

  • form initialization,

  • prompting, including management of prompt counters for prompt tapering,

  • grammar activation and deactivation at the form and form item levels,

  • entering the form with an utterance that matched one of the form's document-scoped grammars while the user was visiting a different form or menu,

  • leaving the form because the user matched another form, menu, or link's document-scoped grammar,

  • processing multiple field fills from one utterance, including the execution of the relevant filled actions,

  • selecting the next form item to visit, and then processing that form item,

  • choosing the correct catch element to handle any events thrown while processing a form item.

First, we define some terms and data structures used in the Form Interpretation Algorithm:

active grammar set

The set of grammars active during a VoiceXML interpreter context's input collection operation.

utterance

A summary of what the user said or keyed in, including the specific grammar matched and a semantic result consisting of an interpretation structure or, where there is no semantic interpretation, the raw text of the input (see The VoiceXML2.0 Specifications Document). An example utterance might be: “grammar 123 was matched, and the semantic interpretation is {drink: “coke” pizza: {number: “3” size: “large”}}.

execute

This refers to executing some executable content - either a block, a filled action, or a set of filled actions. If an event is thrown during execution, the execution of the executable content is aborted. The appropriate event handler is then executed, and this may cause control to resume in a form item, in the next iteration of the form's main loop, or outside of the form. If a goto is executed, the transfer takes place immediately, and the remaining executable content is not executed.

Here is the conceptual Form Interpretation Algorithm. The FIA can start with no initial utterance, or with an initial utterance passed in from another dialog as shown in Example c-1.

Example c-1. Psuedo-code description of the Form Interpretation Algorithm
//
// Initialization Phase
//

foreach ( <var> and form item variable, in document order )
  Declare the variable, initializing it to the value of
  the "expr" attribute, if any, or else to undefined.

foreach ( input item )
  Declare a prompt counter and set it to 1.

if ( there is an initial item )
  Declare a prompt counter and set it to 1.

if ( user entered form by matching its
     grammar while in a different form )
{
  Enter the main loop below, but start in
  the process phase, not the select phase:
  we already have a collection to process.
}

//
// Main Loop: select next form item and execute it.
//

while ( true )
{
  //
  // Select Phase: choose a form item to visit.
  //

  if ( the last main loop iteration ended
                   with a <goto nextitem> )
    Select the specified form item.

  else if ( there is a form item with an
             unsatisfied guard condition )
    Select the first such form item in document order.

  else
    Do an <exit/> - the form is full and no transition is specified.

  //
  // Collect Phase: execute the selected form item.
  //
  // Queue up prompts for the form item.

  unless ( the last loop iteration ended with
               a catch that had no <reprompt/> )
  {
    Select the appropriate prompts for the form item.

    Queue the selected prompts for play prior to
    the next collect operation.

    Increment the form item's prompt counter.
  }

  // Activate grammars for the form item.
 
  if ( the form item is modal )
    Set the active grammar set to the form item grammars,
    if any. (Note that some form items, e.g. <block>,
    cannot have any grammars.)
  else
    Set the active grammar set to the form item grammars 
    and any grammars scoped to the form, the current document, 
    the application root document, and the elements up 
    the <subdialog> call chain.

  // Execute the form item.
  
  if ( a <field> was selected )
    Collect an utterance or an event from the user.
  else if ( a <record> was chosen )
    Collect an utterance (with a name/value pair
    for the recorded bytes) or event from the user.
  else if ( an <object> was chosen )
    Execute the object, setting the <object>'s form item variable 
    to the returned ECMAScript value.
  else if ( a <subdialog> was chosen )
    Execute the subdialog, setting the <subdialog>'s form item
    variable to the returned ECMAScript value.
  else if ( a <transfer> was chosen )
    Do the transfer, and (if the wait attribute is set to true) 
    set the <transfer> form item variable to the returned result 
    status indicator.
  else if ( the <initial> was chosen )
    Collect an utterance or an event from the user.
  else if ( a <block> was chosen )
  {
    Set the block's form item variable to a defined value.

    Execute the block's executable context.
  }

  //
  // Process Phase: process the resulting utterance or event.
  //

  // Process an event.

  if ( the form item execution resulted in an event )
  {
    Find the appropriate catch for the event 
    starting in the scope of the current form item.
    Execute the catch (this may leave the FIA).

    continue
  }

  // Must have an utterance: process those from outside grammars.

  if ( the utterance matched a grammar from outside the form )
  {
    if ( the grammar belongs to a <link> element )
      Execute that link's goto or throw.

    if ( the grammar belongs to a menu's <choice> element )
      Execute the choice's goto or throw, leaving the FIA.

    // The grammar belongs to another form (or menu).

    Transition to that form (or menu), carrying the utterance
    to the other form's (or menu's) FIA.
  }

  // Process an utterance spoken to a grammar from this form.
  // First, copy the utterance result property values into
  // corresponding form item variables.

  Clear all "just_filled" flags.

  if ( the grammar is scoped to the field-level ) {
    // This grammar must be enclosed in an input item.  
    // The input item has an associated ECMAScript variable 
    // (referred to as the input item variable) and a slot name.

    if ( the result is not a structure )
      Copy the result into the input item variable.
    elseif ( a top-level property of the result matches the slot 
             name or the slot name is a dot-separated path 
             matching a subproperty of the result )
      Copy the value of that property into the input item variable.
    else
      Copy the entire result into the input item variable.

    Set this input item's "just_filled" flag.
  }
  else {
    foreach ( property in the user's utterance )
      {
        if ( the property matches an input item's slot name )
        {
          Copy the value of that property into the input item's 
          form item variable. 

          Set the input item's "just_filled" flag.}
        }
     }
  }

  // Set <initial> form item variable if any input items are filled.

  if ( any input item variable is set as a result of the user 
       utterance )
    Set the <initial> form item variable.

  // Next, execute any <filled> actions triggered by this utterance.

  foreach ( <filled> action in document order )
  {
    // Determine the input item variables the <filled> applies to.

    N = the <filled>'s "namelist" attribute.

    if ( N equals "" )
    {
      if ( the <filled> is a child of an input item )
        N = the input item's form item variable name.
      else if ( the <filled> is a child of a form )
        N = the form item variable names of all the input
            items in that form.
    }

    // Is the <filled> triggered?

    if ( any input item variable in the set N was "just_filled"
         AND  ( the <filled> mode is "all"
                AND all variables in N are filled
                OR the <filled> mode is "any"
                AND any variables in N are filled) )
      Execute the <filled> action.

      If an event is thrown during the execution of a <filled>, 
      event handler selection starts in the scope of the <filled>,
      which could be an input item or the form itself.
  }
  // If no input item is filled, just continue.
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.177.115