SemanticResultValue Costruttori

Definizione

Inizializza una nuova istanza della classe SemanticResultValue.

Overload

SemanticResultValue(Object)

Inizializza una nuova istanza della classe SemanticResultValue e specifica un valore semantico.

SemanticResultValue(GrammarBuilder, Object)

Inizializza una nuova istanza della classe SemanticResultValue e associa un valore semantico a un oggetto GrammarBuilder.

SemanticResultValue(String, Object)

Inizializza una nuova istanza della classe SemanticResultValue e associa un valore semantico a un oggetto String.

Commenti

I SemanticResultValue costruttori supportano la specifica Object di un'istanza con un tipo di dati sottostante bool ,, int float o string .

Un costruttore può creare un' SemanticResultValue istanza di in una delle due circostanze seguenti:

  • L' SemanticResultValue istanza deve essere associata in modo esplicito a un elemento di grammatica quando si usa un oggetto GrammarBuilder per costruire un oggetto Grammar .

  • SemanticResultValueÈ già associato a una frase di valore stringa o a un GrammarBuilder oggetto.

SemanticResultValue(Object)

Inizializza una nuova istanza della classe SemanticResultValue e specifica un valore semantico.

public:
 SemanticResultValue(System::Object ^ value);
public SemanticResultValue (object value);
new System.Speech.Recognition.SemanticResultValue : obj -> System.Speech.Recognition.SemanticResultValue
Public Sub New (value As Object)

Parametri

value
Object

Valore gestito da SemanticResultValue. Deve essere di tipo bool, int, float o string.

Esempio

Nell'esempio seguente viene restituito un oggetto Grammar che riconosce il comando "Set/Change/alter foreground/background... [elenco colori] ". SemanticResultValue le SemanticResultKey istanze e (insieme agli Choices GrammarBuilder oggetti e) vengono usate per definire la semantica che può essere analizzata al riconoscimento. La semantica analizzata determinerà quale colore è stato richiesto e se deve essere modificato il primo piano o lo sfondo.

private Grammar FgBgColorGrammar()   
{  
  Grammar grammar = null;  

  // Allow the command to begin with set, alter, change.  
  Choices introChoices = new Choices();  
  foreach (string introString in new string[] { "Change", "Set", "Alter" })   
  {  
    GrammarBuilder introGB = new GrammarBuilder(introString);  
    introChoices.Add(  
                  new SemanticResultValue(introGB,  
                  String.Format("Command: {0}", introString)));  
  }           

  GrammarBuilder cmdIntro = new GrammarBuilder(introChoices);  

  // Define the arguments for the command to select foreground or background   
  // and to change their color as semantic values.  
  Choices fgOrbgChoice = new Choices();  
  GrammarBuilder backgroundGB=new GrammarBuilder("background");  
  backgroundGB.Append(new SemanticResultValue(true));  
  fgOrbgChoice.Add(backgroundGB);  
  fgOrbgChoice.Add((GrammarBuilder)new SemanticResultValue("foreground", false));  
  SemanticResultKey fgOrbgChoiceKey = new SemanticResultKey("BgOrFgBool", fgOrbgChoice);  
  Choices colorChoice = new Choices();  
  foreach (string colorName in System.Enum.GetNames(typeof(KnownColor)))   
  {  

    // Use implicit conversion of SemanticResultValue to GrammarBuilder.      
    colorChoice.Add(  
                 (GrammarBuilder) (new SemanticResultValue(colorName, (Color.FromName(colorName)).Name)));  
  }  

  // Create a GrammarBuilder for CmdArgs to be appended to CmdIntro using  
  // semantic keys.  
  GrammarBuilder cmdArgs = new GrammarBuilder();  
  cmdArgs.Append(new SemanticResultKey("BgOrFgBool", fgOrbgChoice));  
  cmdArgs.AppendWildcard();  
  cmdArgs.Append(new SemanticResultKey("colorStringList", colorChoice));  

  GrammarBuilder cmds =   
      GrammarBuilder.Add(  
        cmdIntro,   
        new GrammarBuilder(new SemanticResultKey("Cmd Args", cmdArgs)));  
  grammar = new Grammar(cmds);  
  grammar.Name = "Tree [Set,change,alter] [foreground,background] * color";  
  return grammar;  
}  

Commenti

Un oggetto SemanticResultValue restituito da questo costruttore non è associato a un particolare elemento di grammatica. L'associazione deve essere resa esplicita utilizzando l'istanza di SemanticResultValue insieme a GrammarBuilder .

Nel frammento di codice seguente, ad esempio, se un Grammar costruito che usa questa GrammarBuilder istanza riconosce la parola "background", il valore di true viene impostato nella semantica di frase riconosciuta.

GrammarBuilder backgroundGB=new GrammarBuilder("background");  
backgroundGB.Append(new SemanticResultValue(true));  

Si applica a

SemanticResultValue(GrammarBuilder, Object)

Inizializza una nuova istanza della classe SemanticResultValue e associa un valore semantico a un oggetto GrammarBuilder.

public:
 SemanticResultValue(System::Speech::Recognition::GrammarBuilder ^ builder, System::Object ^ value);
public SemanticResultValue (System.Speech.Recognition.GrammarBuilder builder, object value);
new System.Speech.Recognition.SemanticResultValue : System.Speech.Recognition.GrammarBuilder * obj -> System.Speech.Recognition.SemanticResultValue
Public Sub New (builder As GrammarBuilder, value As Object)

Parametri

builder
GrammarBuilder

Componente di grammatica da utilizzare nel riconoscimento.

value
Object

Valore gestito da SemanticResultValue. Deve essere di tipo bool, int, float o string.

Esempio

Nell'esempio seguente viene restituito un oggetto Grammar che riconosce il comando "Set/Change/alter foreground/background... [elenco colori] ". SemanticResultValue le SemanticResultKey istanze e (insieme agli Choices GrammarBuilder oggetti e) vengono usate per definire la semantica che può essere analizzata al riconoscimento. La semantica analizzata determinerà quale colore è stato richiesto e se deve essere modificato il primo piano o lo sfondo.

private Grammar FgBgColorGrammar()   
{  
  Grammar grammar = null;  

  // Allow the command to begin with set, alter, change.  
  Choices introChoices = new Choices();  
  foreach (string introString in new string[] { "Change", "Set", "Alter" })   
  {  
    GrammarBuilder introGB = new GrammarBuilder(introString);  
    introChoices.Add(  
                  new SemanticResultValue(introGB,  
                  String.Format("Command: {0}", introString)));  
  }           
  GrammarBuilder cmdIntro = new GrammarBuilder(introChoices);  

  // Define the arguments for the command to select foreground or background   
  // and to change their color as semantic values.  
  Choices fgOrbgChoice = new Choices();  
  GrammarBuilder backgroundGB=new GrammarBuilder("background");  
  backgroundGB.Append(new SemanticResultValue(true));  
  fgOrbgChoice.Add(backgroundGB);  
  fgOrbgChoice.Add((GrammarBuilder)new SemanticResultValue("foreground", false));  
  SemanticResultKey fgOrbgChoiceKey = new SemanticResultKey("BgOrFgBool", fgOrbgChoice);  
  Choices colorChoice = new Choices();  
  foreach (string colorName in System.Enum.GetNames(typeof(KnownColor)))   
  {  

    // Use implicit conversion of SemanticResultValue to GrammarBuilder.      
    colorChoice.Add(  
              (GrammarBuilder) (new SemanticResultValue(colorName, (Color.FromName(colorName)).Name)));  
    }  

  // Create a GrammarBuilder for CmdArgs to be appended to CmdIntro using  
  // semantic keys.  
  GrammarBuilder cmdArgs = new GrammarBuilder();  
  cmdArgs.Append(new SemanticResultKey("BgOrFgBool", fgOrbgChoice));  
  cmdArgs.AppendWildcard();  
  cmdArgs.Append(new SemanticResultKey("colorStringList", colorChoice));  

  GrammarBuilder cmds =   
      GrammarBuilder.Add(  
                      cmdIntro,  
                      new GrammarBuilder(new SemanticResultKey("Cmd Args", cmdArgs)));  
  grammar = new Grammar(cmds);  
  grammar.Name = "Tree [Set,change,alter] [foreground,background] * color";  
  return grammar;  
}  

Commenti

Se l'elemento di grammatica specificato da GrammarBuilder viene utilizzato nella logica di riconoscimento, value verrà impostato nella semantica dell'output riconosciuto.

Nel frammento di codice seguente, se la logica di riconoscimento costruita con l' GrammarBuilder istanza ( myGb ) usa l' Choices oggetto ( myChoice ) per identificare l'input, il valore true viene aggiunto alla semantica riconosciuta.

myGb.Append(new SemanticResultValue(myChoice, true);  

Come GrammarBuilder supporta la conversione implicita per Choices , SemanticResultValue e SemanticResultKey , questo costruttore può utilizzare anche tali oggetti.

Si applica a

SemanticResultValue(String, Object)

Inizializza una nuova istanza della classe SemanticResultValue e associa un valore semantico a un oggetto String.

public:
 SemanticResultValue(System::String ^ phrase, System::Object ^ value);
public SemanticResultValue (string phrase, object value);
new System.Speech.Recognition.SemanticResultValue : string * obj -> System.Speech.Recognition.SemanticResultValue
Public Sub New (phrase As String, value As Object)

Parametri

phrase
String

Frase da utilizzare nel riconoscimento.

value
Object

Valore gestito da SemanticResultValue. Deve essere di tipo bool, int, float o string.

Esempio

Nell'esempio seguente viene restituito un oggetto Grammar che riconosce il comando "Set/Change/alter foreground/background... [elenco colori] ". SemanticResultValue le SemanticResultKey istanze e (insieme agli Choices GrammarBuilder oggetti e) vengono usate per definire la semantica che può essere analizzata al riconoscimento. La semantica analizzata determinerà quale colore è stato richiesto e se deve essere modificato il primo piano o lo sfondo.

private Grammar FgBgColorGrammar()   
{  
  Grammar grammar = null;  

  // Allow command to begin with set, alter, change.  
  Choices introChoices = new Choices();  
  foreach (string introString in new string[] { "Change", "Set", "Alter" })   
  {  
    GrammarBuilder introGB = new GrammarBuilder(introString);  
    introChoices.Add(  
                  new SemanticResultValue(introGB,  
                  String.Format("Command: {0}", introString)));  
  }  

  GrammarBuilder cmdIntro = new GrammarBuilder(introChoices);  

  // Define the arguments for the command to select foreground or background   
  // and to change their color as semantic values.  
  Choices fgOrbgChoice = new Choices();  
  GrammarBuilder backgroundGB=new GrammarBuilder("background");  
  backgroundGB.Append(new SemanticResultValue(true));  
  fgOrbgChoice.Add(backgroundGB);  
  fgOrbgChoice.Add((GrammarBuilder)new SemanticResultValue("foreground", false));  
  SemanticResultKey fgOrbgChoiceKey = new SemanticResultKey("BgOrFgBool", fgOrbgChoice);  
  Choices colorChoice = new Choices();  
  foreach (string colorName in System.Enum.GetNames(typeof(KnownColor)))   
  {  

    // Use implicit conversion of SemanticResultValue to GrammarBuilder.      
    colorChoice.Add(  
          (GrammarBuilder) (new SemanticResultValue(colorName, (Color.FromName(colorName)).Name)));  
  }  

  // Create a GrammarBuilder for CmdArgs to be appended to CmdIntro using  
  // semantic keys.  
  GrammarBuilder cmdArgs = new GrammarBuilder();  
  cmdArgs.Append(new SemanticResultKey("BgOrFgBool", fgOrbgChoice));  
  cmdArgs.AppendWildcard();  
  cmdArgs.Append(new SemanticResultKey("colorStringList", colorChoice));  

  GrammarBuilder cmds =   
      GrammarBuilder.Add(cmdIntro,  
                         new GrammarBuilder(new SemanticResultKey("Cmd Args", cmdArgs)));  
  grammar = new Grammar(cmds);  
  grammar.Name = "Tree [Set,change,alter] [foreground,background] * color";  
  return grammar;  
}  

Commenti

Se la stringa specificata da phrase viene utilizzata nella logica di riconoscimento, value verrà impostata nella semantica dell'output riconosciuto.

Nel frammento di codice seguente, se la logica di riconoscimento costruita con l' GrammarBuilder istanza ( myGb ) usa la stringa "My Mortgage" per identificare l'input, il valore true verrà aggiunto alla semantica riconosciuta.

myGb.Append(new SemanticResultValue("my mortgage", true);  

Si applica a