SemanticResultValue Konstruktory

Definice

Inicializuje novou instanci SemanticResultValue třídy.

Přetížení

Name Description
SemanticResultValue(Object)

Inicializuje novou instanci SemanticResultValue třídy a určuje sémantickou hodnotu.

SemanticResultValue(GrammarBuilder, Object)

Inicializuje novou instanci SemanticResultValue třídy a přidruží sémantickou hodnotu k objektu GrammarBuilder .

SemanticResultValue(String, Object)

Inicializuje novou instanci SemanticResultValue třídy a přidruží sémantickou hodnotu k objektu String .

Poznámky

Konstruktory SemanticResultValue podporují určení Object instance s podkladovým datovým typem bool, int, floatnebo string.

Konstruktor může vytvořit SemanticResultValue instanci za některé ze dvou okolností:

  • Instance SemanticResultValue musí být explicitně přidružena k gramatickému prvku při použití GrammarBuilder konstruktoru Grammar.

  • Je SemanticResultValue již přidružen k řetězcové hodnotové frázi nebo objektu GrammarBuilder .

SemanticResultValue(Object)

Zdroj:
SemanticResultValue.cs
Zdroj:
SemanticResultValue.cs
Zdroj:
SemanticResultValue.cs
Zdroj:
SemanticResultValue.cs

Inicializuje novou instanci SemanticResultValue třídy a určuje sémantickou hodnotu.

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

Hodnota spravovaná uživatelem SemanticResultValue. Musí být typu bool, int, floatnebo string.

Příklady

Následující příklad vrátí příkaz Grammar Set/Change/Alter Foreground/Background ... [barevný seznam]". SemanticResultValue a SemanticResultKey instance (ve spojení s ChoicesGrammarBuilder objekty) slouží k definování sémantiky, které lze analyzovat při rozpoznávání. Analyzovaná sémantika určí, která barva byla požadována a zda má být změněna popředí nebo pozadí.

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

Poznámky

Vrácený SemanticResultValue tímto konstruktorem není přidružen k žádnému konkrétnímu gramatickému prvku. Přidružení musí být explicitní použitím instance SemanticResultValue ve spojení s GrammarBuilder.

Například v níže uvedeném fragmentu kódu, pokud Grammar vytvořený pomocí této GrammarBuilder instance rozpozná slovo "pozadí", je hodnota true nastavena v rozpoznané sémantice frází.

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

Platí pro

SemanticResultValue(GrammarBuilder, Object)

Zdroj:
SemanticResultValue.cs
Zdroj:
SemanticResultValue.cs
Zdroj:
SemanticResultValue.cs
Zdroj:
SemanticResultValue.cs

Inicializuje novou instanci SemanticResultValue třídy a přidruží sémantickou hodnotu k objektu 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)

Parametry

builder
GrammarBuilder

Gramatická komponenta, která se má použít při rozpoznávání.

value
Object

Hodnota spravovaná uživatelem SemanticResultValue. Musí být typu bool, int, floatnebo string.

Příklady

Následující příklad vrátí příkaz Grammar Set/Change/Alter Foreground/Background ... [barevný seznam]". SemanticResultValue a SemanticResultKey instance (ve spojení s ChoicesGrammarBuilder objekty) slouží k definování sémantiky, které lze analyzovat při rozpoznávání. Analyzovaná sémantika určí, která barva byla požadována a zda má být změněna popředí nebo pozadí.

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

Poznámky

Pokud je gramatický prvek určený GrammarBuilder v logice rozpoznávání, value bude nastaven v sémantice rozpoznaného výstupu.

Pokud logika rozpoznávání konstruovaná s GrammarBuilder instancí () používá Choices objekt (myGbmyChoice) k identifikaci vstupu v následujícím fragmentu kódu, přidá se hodnota true do rozpoznané sémantiky.

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

Jak GrammarBuilder podporuje implicitní převod pro Choices, SemanticResultValuea SemanticResultKey, tento konstruktor může také použít tyto objekty.

Platí pro

SemanticResultValue(String, Object)

Zdroj:
SemanticResultValue.cs
Zdroj:
SemanticResultValue.cs
Zdroj:
SemanticResultValue.cs
Zdroj:
SemanticResultValue.cs

Inicializuje novou instanci SemanticResultValue třídy a přidruží sémantickou hodnotu k objektu 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)

Parametry

phrase
String

Frázi, která se má použít při rozpoznávání.

value
Object

Hodnota spravovaná uživatelem SemanticResultValue. Musí být typu bool, int, floatnebo string.

Příklady

Následující příklad vrátí příkaz Grammar Set/Change/Alter Foreground/Background ... [barevný seznam]". SemanticResultValue a SemanticResultKey instance (ve spojení s ChoicesGrammarBuilder objekty) slouží k definování sémantiky, které lze analyzovat při rozpoznávání. Analyzovaná sémantika určí, která barva byla požadována a zda má být změněna popředí nebo pozadí.

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

Poznámky

Pokud se řetězec zadaný phrase v logice rozpoznávání použije, value nastaví se v sémantice rozpoznaného výstupu.

Pokud logika rozpoznávání konstruovaná s GrammarBuilder instancí (myGb) používá k identifikaci vstupu řetězec "moje hypotéka", přidá se hodnota true do rozpoznané sémantiky v následujícím fragmentu kódu.

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

Platí pro