SemanticValue.Item[String] 속성

정의

현재SemanticValue에 속하는 자식 SemanticValue 인스턴스를 반환합니다.

public:
 property System::Speech::Recognition::SemanticValue ^ default[System::String ^] { System::Speech::Recognition::SemanticValue ^ get(System::String ^ key); void set(System::String ^ key, System::Speech::Recognition::SemanticValue ^ value); };
public System.Speech.Recognition.SemanticValue this[string key] { get; set; }
member this.Item(string) : System.Speech.Recognition.SemanticValue with get, set
Default Public Property Item(key As String) As SemanticValue

매개 변수

key
String

현재 인스턴스에 KeyValuePair<String, SemanticValue> 포함된 키입니다 SemanticValue.

속성 값

키 값 쌍의 일부로 인덱싱할 수 있는 현재 SemanticValue 자식 값을 반환합니다 KeyValuePair<String,SemanticValue>.

구현

예외

현재 인스턴스 SemanticValue 의 자식 멤버에 매개 변수와 일치하는 key 키가 없습니다.

지정된 인덱스에서 SemanticValue 코드를 변경하려고 했습니다.

예제

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

의미 체계 구조가 없는 인식된 구를 처리한 후 처리기는 (ContainsKeyapplyChgToBackground또는colorRGBValueList) 속성을 사용하여 colorStringList)Item[] 적절한 키가 있는지 확인한 다음, 필요한 정보가 있는 노드를 가져옵니다.

사용 Item[] 은 아래에 강조 표시되어 있습니다.

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 semantic 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 the foreground.
      if (ForeColor.GetBrightness() <= .50)
      {
        BackColor = Color.White;
      }
      else
      {
        BackColor = Color.Black;
      }
    }
    return;
  };

설명

읽기 Item[] 전용이며 멤버가 수정된 경우 예외를 생성합니다.

예를 들어, 컴파일 타임이 아닌 런타임에 키 값으로만 데이터에 액세스할 수 있습니다 semantic["myKey"].Value. 존재하지 않는 키를 지정하면 예외가 생성됩니다.

지정된 키의 존재를 감지하려면 인스턴스에서 ContainsKeySemanticValue 속성을 사용합니다.

적용 대상