SemanticResultValue Construtores
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Inicializa uma nova instância da SemanticResultValue classe.
Sobrecargas
| Name | Description |
|---|---|
| SemanticResultValue(Object) |
Inicializa uma nova instância da SemanticResultValue classe e especifica um valor semântico. |
| SemanticResultValue(GrammarBuilder, Object) |
Inicializa uma nova instância da SemanticResultValue classe e associa um valor semântico a um GrammarBuilder objeto. |
| SemanticResultValue(String, Object) |
Inicializa uma nova instância da SemanticResultValue classe e associa um valor semântico a um String objeto. |
Observações
Os SemanticResultValue construtores suportam especificar uma Object instância com um tipo de dado subjacente de bool, int, float, ou string.
Um construtor pode criar uma SemanticResultValue instância em duas circunstâncias:
A
SemanticResultValueinstância deve estar explicitamente associada a um elemento gramatical ao usar a GrammarBuilder para construir um Grammar.O
SemanticResultValuejá está associado a uma frase de valor de cadeia ou a um GrammarBuilder objeto.
SemanticResultValue(Object)
- Origem:
- SemanticResultValue.cs
- Origem:
- SemanticResultValue.cs
- Origem:
- SemanticResultValue.cs
- Origem:
- SemanticResultValue.cs
Inicializa uma nova instância da SemanticResultValue classe e especifica um valor semântico.
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)
Parâmetros
- value
- Object
O valor gerido por SemanticResultValue. Deve ser do tipo bool, int, float, ou string.
Exemplos
O exemplo seguinte devolve um Grammar que reconhece o comando "Set/Change/Alter Foreground/Background ... [lista de cores]". SemanticResultValue e SemanticResultKey instâncias (em conjunto com Choices objetos e GrammarBuilder ) são usadas para definir semântica que pode ser analisada no reconhecimento. A semântica analisada determinará que cor foi solicitada e se o primeiro plano ou o fundo deve ser modificado.
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;
}
Observações
Um SemanticResultValue devolvido por este construtor não está associado a nenhum elemento gramatical em particular. A associação deve ser tornada explícita usando a instância de SemanticResultValue em conjunto com GrammarBuilder.
Por exemplo, no fragmento de código abaixo, se um Grammar construído usando esta GrammarBuilder instância reconhecer a palavra "background", um valor de true é definido na semântica da frase reconhecida.
GrammarBuilder backgroundGB=new GrammarBuilder("background");
backgroundGB.Append(new SemanticResultValue(true));
Aplica-se a
SemanticResultValue(GrammarBuilder, Object)
- Origem:
- SemanticResultValue.cs
- Origem:
- SemanticResultValue.cs
- Origem:
- SemanticResultValue.cs
- Origem:
- SemanticResultValue.cs
Inicializa uma nova instância da SemanticResultValue classe e associa um valor semântico a um GrammarBuilder objeto.
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)
Parâmetros
- builder
- GrammarBuilder
Um componente gramatical a ser usado no reconhecimento.
- value
- Object
O valor gerido por SemanticResultValue. Deve ser do tipo bool, int, float, ou string.
Exemplos
O exemplo seguinte devolve um Grammar que reconhece o comando "Set/Change/Alter Foreground/Background ... [lista de cores]". SemanticResultValue e SemanticResultKey instâncias (em conjunto com Choices objetos e GrammarBuilder ) são usadas para definir semântica que pode ser analisada no reconhecimento. A semântica analisada determinará que cor foi solicitada e se o primeiro plano ou o fundo deve ser modificado.
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;
}
Observações
Se o elemento gramatical especificado por GrammarBuilder for usado na lógica de reconhecimento, value será definido na semântica da saída reconhecida.
No fragmento de código abaixo, se a lógica de reconhecimento construída com a GrammarBuilder instância (myGb) usar o Choices objeto (myChoice) para identificar a entrada, o valor true é adicionado à semântica reconhecida.
myGb.Append(new SemanticResultValue(myChoice, true);
Como GrammarBuilder suporta conversão implícita para Choices, SemanticResultValue, e SemanticResultKey, este construtor pode também usar esses objetos.
Aplica-se a
SemanticResultValue(String, Object)
- Origem:
- SemanticResultValue.cs
- Origem:
- SemanticResultValue.cs
- Origem:
- SemanticResultValue.cs
- Origem:
- SemanticResultValue.cs
Inicializa uma nova instância da SemanticResultValue classe e associa um valor semântico a um String objeto.
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)
Parâmetros
- phrase
- String
Uma expressão a ser usada em reconhecimento.
- value
- Object
O valor gerido por SemanticResultValue. Deve ser do tipo bool, int, float, ou string.
Exemplos
O exemplo seguinte devolve um Grammar que reconhece o comando "Set/Change/Alter Foreground/Background ... [lista de cores]". SemanticResultValue e SemanticResultKey instâncias (em conjunto com Choices objetos e GrammarBuilder ) são usadas para definir semântica que pode ser analisada no reconhecimento. A semântica analisada determinará que cor foi solicitada e se o primeiro plano ou o fundo deve ser modificado.
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;
}
Observações
Se a cadeia especificada por phrase for usada na lógica de reconhecimento, value será definida na semântica da saída reconhecida.
No fragmento de código seguinte, se a lógica de reconhecimento construída com a GrammarBuilder instância (myGb) usar a cadeia "my mortgage" para identificar a entrada, o valor true será adicionado à semântica reconhecida.
myGb.Append(new SemanticResultValue("my mortgage", true);