Share via


SemanticItem.Update Method (T, SemanticItemState)

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Updates the Value and the SemanticItemState of a semantic item.

Namespace: Microsoft.SpeechServer.Dialog
Assembly: Microsoft.SpeechServer (in microsoft.speechserver.dll)

Syntax

'Declaration
Public Sub Update ( _
    value As T, _
    state As SemanticItemState _
)
public void Update (
    T value,
    SemanticItemState state
)

Parameters

  • value
    The value of the semantic item.
  • state
    The state of the semantic item.

Example

The following example shows a collection of methods that are associated with getting and confirming a semantic item, _city. At a high level, a QuestionAnswerActivity named askCity prompts the user to say the name of a city in the array, _cityList. If the user's response is recognized with a confidence greater than the semantic item's ConfirmThreshold, the semantic item's State is updated to Confirmed. The user's response is then played to the user and the application exits.

If the user's response is recognized, but with a confidence less than or equal to the semantic item's ConfirmThreshold, the semantic item's State is updated to NeedsConfirmation, and a QuestionAnswerActivity named confirmCity is activated. If the user confirms the recognition result, the user's response is played to the user and the application exits.

If the user does not confirm the recognition result, the semantic item is denied and control returns to the initial QuestionAnswerActivity, askCity, restarting the recognition process. Each time the recognition process restarts, the city that was denied does not appear in the prompt to the user.

private SemanticItem<string> _city; 
// List of cities. Note that the cities in this list must be identical to those listed in Cities.grxml.
public string[] _cityList = new string[] { "Albany", "Butte", "Chicago", "Dover", "Eugene", "Ferndale", "Grand Rapids", "Helena" };

public Workflow1()
{
  InitializeComponent();
  _city = new SemanticItem<string>(this, "city");
  _city.Changed +=new EventHandler(_city_Changed);
  askCity.Answers.Add(_city);
  askCity.Confirms.Add(_city);
}

private void askCity_TurnStarting(object sender, TurnStartingEventArgs e)
{
  this.askCity.MainPrompt.SetText("Choose the name of a city from the following list ");
  this.askCity.MainPrompt.AppendBreak(TimeSpan.FromMilliseconds(200));
  // Iterate through the _cityList array, prompting for those cities not on the DeniedValues list.
  // There is no logic here for the case where all of the cities have been denied.
  for (int idx = 0; idx < _cityList.Length; idx++)
  {
    if (_city.DeniedValues.Count == 0 || !_city.DeniedValues.Contains(_cityList[idx]))
    {
      this.askCity.MainPrompt.AppendText(_cityList[idx]);
      this.askCity.MainPrompt.AppendBreak(TimeSpan.FromMilliseconds(150)); 
    }
  }
}

private void askCity_Closed(object sender, EventArgs e)
{
  if (askCity.RecognitionResult != null &&
      askCity.RecognitionResult.Semantics.ContainsKey("City"))
  {
    _city.Value = askCity.RecognitionResult.Semantics["City"].Value.ToString();
    if (askCity.RecognitionResult.Confidence <= _city.ConfirmThreshold)
    {
      _city.Update(_city.Value, SemanticItemState.NeedsConfirmation);
    }
    else
    {
      _city.Update(_city.Value, SemanticItemState.Confirmed);
    }
    _city.SpokenText = askCity.RecognitionResult.Text;
  }
}

private void confirmCity_TurnStarting(object sender, TurnStartingEventArgs e)
{
  this.confirmCity.MainPrompt.SetText(string.Format("You chose {0}", _city.Value));
  this.confirmCity.MainPrompt.AppendText("Is that correct?");
}

private void recoResultConfirmed(object sender, ConditionalEventArgs e)
{
  e.Result = (this._city.State == SemanticItemState.Confirmed);
}

private void cityConfirmed(object sender, ConditionalEventArgs e)
{
  e.Result = (this.confirmCity.RecognitionResult.Semantics.Value.ToString() == "Yes");
  if (e.Result == true)
  {
    _city.Accept();
  }
  else
  {
    _city.Deny();
  }
}

private void invalidateRecoResult(object sender, EventArgs e)
{
  _city.Invalidate();
}

private void sayByeBye_TurnStarting(object sender, TurnStartingEventArgs e)
{
  this.sayByeBye.MainPrompt.SetText("You chose {0}", this._city.Value);
  this.sayByeBye.MainPrompt.AppendBreak(TimeSpan.FromMilliseconds(150));
  this.sayByeBye.MainPrompt.AppendText("Goodbye");
}

private void _city_Changed(object sender, EventArgs e)
{
  System.Guid guid = _city.Identifier;
  string name = _city.Name;
  SemanticItemState state = _city.State;
  string value = _city.Value;
}

Thread Safety

All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.

Platforms

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition

Target Platforms

Windows Server 2003

See Also

Reference

SemanticItem Generic Class
SemanticItem Members
Microsoft.SpeechServer.Dialog Namespace
QuestionAnswerActivity Class
ConfirmThreshold
State
Confirmed
NeedsConfirmation