SemanticValue.Count 속성

정의

현재 SemanticValue 인스턴스 아래의 자식 SemanticValue 개체 수를 반환합니다.

public:
 property int Count { int get(); };
public int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer

속성 값

현재 SemanticValue아래의 자식 SemanticValue 개체 수입니다.

구현

예제

다음 예제에서는 전경색 및 배경색을 변경 하는 명령을 처리 하도록 설계 된 이벤트에 대 한 처리기를 SpeechRecognized 보여 줍니다.

처리기는 0과 CountValue1을 검색하여 null 기본 의미 체계 구조가 없는 인식된 구를 식별합니다. 그런 다음 이 인식 출력은 원시 텍스트를 구문 분석하여 직접 처리됩니다.

다른 경우에 처리기는 키를 사용하여 색 이름의 RGB 구성 요소를 가져오거나, 명령이 포그라운드 또는 배경을 변경할지 여부를 확인하거나, 유효한 키를 찾을 수 없음을 나타냅니다.

newGrammar.SpeechRecognized +=
  delegate(object sender, SpeechRecognizedEventArgs eventArgs)
  {

    // Retrieve the value of the semantic property.
    bool changeBackGround = true;
    string errorString = "";
    SemanticValue semantics = eventArgs.Result.Semantics;

    Color newColor = Color.Empty;

    try
    {
      if (semantics.Count == 0 && semantics.Value==null)
      {
        // Signifies recognition by a grammar with no semantics.
        // Parse the string, assuming that the last word is color,
        //  searching for background or foreground in input.
        if (eventArgs.Result.Text.Contains("foreground"))
        {
          changeBackGround = false;
        }
        string cName = eventArgs.Result.Words[eventArgs.Result.Words.Count - 1].Text;
        newColor = Color.FromName(cName);

      }
      else if (semantics.ContainsKey("colorStringList") ^ semantics.ContainsKey("colorRGBValueList"))
      {

        // Determine whether to change background or foreground.
        if (semantics.ContainsKey("applyChgToBackground"))
        {
          changeBackGround = semantics["applyChgToBackground"].Value is bool;
        }

        // Get the RGB color value.
        if (semantics.ContainsKey("colorStringList"))
        {
          newColor = Color.FromName((string)semantics["colorStringList"].Value);
        }
        if (semantics.ContainsKey("colorRGBValueList"))
        {
          newColor = System.Drawing.Color.FromArgb((int)semantics["colorRGBValueList"].Value);
        }
      }
      else
      {

        // Throw an exception if the semantics do not contain the keys we
        // support.
        throw(new Exception("Unsupported semantics keys found."));
      }
    }

    catch (Exception exp)
    {
      MessageBox.Show(String.Format("Unable to process color semantics.:\n{0}\n", exp.Message));
      return;
    }

    // Change colors, either foreground or background.
    if (changeBackGround)
    {
      BackColor = newColor;
      float Bright = BackColor.GetBrightness();
      float Hue = BackColor.GetHue();
      float Sat = BackColor.GetSaturation();
      // Make sure that text is readable regardless of background.
      if (BackColor.GetBrightness() <= .50)
      {
        ForeColor = Color.White;
      }
      else
      {
        ForeColor = Color.Black;
      }
    }
    else
    {
      ForeColor = newColor;
      float Bright = ForeColor.GetBrightness();
      float Hue = ForeColor.GetHue();
      float Sat = ForeColor.GetSaturation();

      // Make sure that text is readable regardless of Foreground.
      if (ForeColor.GetBrightness() <= .50)
      {
        BackColor = Color.White;
      }
      else
      {
        BackColor = Color.Black;
      }
    }
    return;
  };

설명

의미 체계 구문 분석을 사용하지 않는 인식 결과에는 항상 값이 Count 0일 뿐만 Valuenull아니라

적용 대상