SemanticValue.Count SemanticValue.Count SemanticValue.Count SemanticValue.Count Property

Définition

Retourne le nombre d'objets SemanticValue enfants sous l'instance SemanticValue actuelle.Returns the number of child SemanticValue objects under the current SemanticValue instance.

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

Valeur de propriété

Nombre d'objets SemanticValue enfants sous la SemanticValue actuelle.The number of child SemanticValue objects under the current SemanticValue.

Implémente

Exemples

L’exemple suivant montre un gestionnaire pour un SpeechRecognized événement conçu pour gérer des commandes pour modifier la couleur de premier plan et d’arrière-plan.The following example shows a handler for a SpeechRecognized event designed to handle commands to change foreground and background color.

Le gestionnaire identifie les expressions reconnues qui n’ont pas de structure sémantique sous- Count jacente en détectant Value un nullde zéro et un de.The handler identifies recognized phrases that have no underlying semantic structure by detecting a Count of zero and a Value of null. Ce résultat de reconnaissance est ensuite traité directement en analysant le texte brut.This recognition output is then processed directly by parsing the raw text.

Dans d’autres cas, le gestionnaire utilise des clés pour obtenir les composants RGB d’un nom de couleur, pour déterminer si la commande doit modifier le premier plan ou l’arrière-plan, ou pour indiquer qu’aucune clé valide n’a été trouvée.In other cases, the handler uses keys to obtain the RGB components of a color name, to determine whether the command will change the foreground or background, or to indicate that no valid key was found.

  
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;  
  };  

Remarques

Les résultats de la reconnaissance qui ne font pas appel à l’analyse sémantique Count ont toujours une valeur égale à zéro, Value ainsi nullqu’un de.Recognition results that do not make use of semantic parsing always have a Count value of zero, as well as a Value of null.

S’applique à