Udostępnij za pośrednictwem


SemanticResultValue Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy SemanticResultValue.

Przeciążenia

SemanticResultValue(Object)

Inicjuje nowe wystąpienie SemanticResultValue klasy i określa wartość semantyczną.

SemanticResultValue(GrammarBuilder, Object)

Inicjuje nowe wystąpienie SemanticResultValue klasy i kojarzy wartość semantyczną z GrammarBuilder obiektem.

SemanticResultValue(String, Object)

Inicjuje nowe wystąpienie SemanticResultValue klasy i kojarzy wartość semantyczną z String obiektem.

Uwagi

SemanticResultValueKonstruktory obsługują Określanie Object wystąpienia z typem danych źródłowych bool , int , float , lub string .

Konstruktor może utworzyć SemanticResultValue wystąpienie w jednej z dwóch sytuacji:

  • SemanticResultValueWystąpienie musi być jawnie skojarzone z elementem gramatyki, gdy jest używany GrammarBuilder do konstruowania elementu Grammar .

  • SemanticResultValueJest już skojarzony z frazą wartości ciągu lub GrammarBuilder obiektem.

SemanticResultValue(Object)

Inicjuje nowe wystąpienie SemanticResultValue klasy i określa wartość semantyczną.

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)

Parametry

value
Object

Wartość zarządzana przez SemanticResultValue . Musi być typu bool , int ,, float lub string .

Przykłady

Poniższy przykład zwraca wartość Grammar , która rozpoznaje polecenie "Set/Change/ALTER pierwszego planu/tła... [Lista kolorów] ". SemanticResultValueSemanticResultKeywystąpienia (w połączeniu z Choices obiektami i GrammarBuilder ) są używane do definiowania semantyki, które mogą być analizowane podczas rozpoznawania. Przeanalizowana semantyka określi, który kolor został zażądany i czy ma być modyfikowany pierwszy plan lub tło.

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

Uwagi

SemanticResultValueZwracany przez ten konstruktor nie jest skojarzony z żadnym konkretnym elementem gramatyki. Skojarzenie musi być jawnie wykonane przy użyciu wystąpienia programu SemanticResultValue w połączeniu z GrammarBuilder .

Na przykład w poniższym fragmencie kodu, jeśli Grammar skonstruowany przy użyciu tego GrammarBuilder wystąpienia rozpoznaje wyraz "background", wartość true jest ustawiana w rozpoznanej semantyki frazy.

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

Dotyczy

SemanticResultValue(GrammarBuilder, Object)

Inicjuje nowe wystąpienie SemanticResultValue klasy i kojarzy wartość semantyczną z GrammarBuilder obiektem.

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)

Parametry

builder
GrammarBuilder

Składnik gramatyki, który ma być używany podczas rozpoznawania.

value
Object

Wartość zarządzana przez SemanticResultValue . Musi być typu bool , int ,, float lub string .

Przykłady

Poniższy przykład zwraca wartość Grammar , która rozpoznaje polecenie "Set/Change/ALTER pierwszego planu/tła... [Lista kolorów] ". SemanticResultValueSemanticResultKeywystąpienia (w połączeniu z Choices obiektami i GrammarBuilder ) są używane do definiowania semantyki, które mogą być analizowane podczas rozpoznawania. Przeanalizowana semantyka określi, który kolor został zażądany i czy ma być modyfikowany pierwszy plan lub tło.

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

Uwagi

Jeśli element gramatyki określony przez GrammarBuilder jest używany w logice rozpoznawania, value zostanie ustawiony w semantyki rozpoznanych danych wyjściowych.

W poniższym fragmencie kodu, jeśli logika rozpoznawania skonstruowana przy użyciu GrammarBuilder wystąpienia ( myGb ) używa Choices obiektu ( myChoice ) do identyfikowania danych wejściowych, wartość true jest dodawana do rozpoznanej semantyki.

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

Jako GrammarBuilder obsługuje niejawną konwersję dla Choices , SemanticResultValue , i SemanticResultKey , ten konstruktor może również używać tych obiektów.

Dotyczy

SemanticResultValue(String, Object)

Inicjuje nowe wystąpienie SemanticResultValue klasy i kojarzy wartość semantyczną z String obiektem.

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)

Parametry

phrase
String

Fraza, która ma być używana podczas rozpoznawania.

value
Object

Wartość zarządzana przez SemanticResultValue . Musi być typu bool , int ,, float lub string .

Przykłady

Poniższy przykład zwraca wartość Grammar , która rozpoznaje polecenie "Set/Change/ALTER pierwszego planu/tła... [Lista kolorów] ". SemanticResultValueSemanticResultKeywystąpienia (w połączeniu z Choices obiektami i GrammarBuilder ) są używane do definiowania semantyki, które mogą być analizowane podczas rozpoznawania. Przeanalizowana semantyka określi, który kolor został zażądany i czy ma być modyfikowany pierwszy plan lub tło.

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

Uwagi

Jeśli ciąg określony przez phrase jest używany w logice rozpoznawania, value zostanie ustawiony w semantyki rozpoznanych danych wyjściowych.

W poniższym fragmencie kodu, jeśli logika rozpoznawania skonstruowana przy użyciu GrammarBuilder wystąpienia ( myGb ) używa ciągu "My hipoteczn" do identyfikowania danych wejściowych, wartość true zostanie dodana do rozpoznanej semantyki.

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

Dotyczy