-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
SemanticResultValue.xml
532 lines (436 loc) · 31.2 KB
/
SemanticResultValue.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
<Type Name="SemanticResultValue" FullName="System.Speech.Recognition.SemanticResultValue">
<TypeSignature Language="C#" Value="public class SemanticResultValue" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit SemanticResultValue extends System.Object" />
<TypeSignature Language="DocId" Value="T:System.Speech.Recognition.SemanticResultValue" />
<TypeSignature Language="VB.NET" Value="Public Class SemanticResultValue" />
<TypeSignature Language="F#" Value="type SemanticResultValue = class" />
<TypeSignature Language="C++ CLI" Value="public ref class SemanticResultValue" />
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute FrameworkAlternate="net-6.0;net-7.0;net-8.0;net-9.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1">
<AttributeName Language="C#">[System.Diagnostics.DebuggerDisplay("{_tag.DebugSummary}")]</AttributeName>
<AttributeName Language="F#">[<System.Diagnostics.DebuggerDisplay("{_tag.DebugSummary}")>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Represents a semantic value and optionally associates the value with a component of a speech recognition grammar.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Use of <xref:System.Speech.Recognition.SemanticResultValue> and <xref:System.Speech.Recognition.SemanticResultKey> objects, in conjunction with <xref:System.Speech.Recognition.GrammarBuilder> and <xref:System.Speech.Recognition.Choices>, is the easiest way to design a semantic structure for a <xref:System.Speech.Recognition.Grammar>. Semantic information for a phrase is accessed by obtaining an instance of <xref:System.Speech.Recognition.SemanticValue>, through the <xref:System.Speech.Recognition.RecognizedPhrase.Semantics%2A> property on <xref:System.Speech.Recognition.RecognizedPhrase>.
> [!NOTE]
> Values managed by <xref:System.Speech.Recognition.SemanticResultValue> objects are defined by <xref:System.Object> instances passed to their constructors. The underlying type of this <xref:System.Object> must be `bool`, `int`, `float`, or `string`. Any other type will prevent construction of a <xref:System.Speech.Recognition.Grammar> instance with the <xref:System.Speech.Recognition.SemanticResultValue>.
The typical use of a <xref:System.Speech.Recognition.SemanticResultValue> instance associates the instance with a recognizable component of a <xref:System.Speech.Recognition.Grammar>, such as a phrase, a rule, or a <xref:System.Speech.Recognition.Choices> object. If the associated component is used as part of a recognition operation, the <xref:System.Speech.Recognition.SemanticResultValue> is used to define a value in the semantics of the returned phrase.
There are two basic methods for associating a <xref:System.Speech.Recognition.SemanticResultValue> instance with a grammar element, depending on the constructor used to create the <xref:System.Speech.Recognition.SemanticResultValue>.
- If only the value (specified by an instance of <xref:System.Object>) is used to construct a <xref:System.Speech.Recognition.SemanticResultValue> object, the <xref:System.Speech.Recognition.SemanticResultValue> is associated with the grammar component that preceded it, in addition to a <xref:System.Speech.Recognition.GrammarBuilder> object.
For instance, in the code fragment below, if a <xref:System.Speech.Recognition.Grammar> constructed using this <xref:System.Speech.Recognition.GrammarBuilder> instance recognizes the word "background", a value of `true` is set in the recognized phrase semantics.
```csharp
GrammarBuilder backgroundGB=new GrammarBuilder("background");
backgroundGB.Append(new SemanticResultValue(true));
```
For more information, see the description of <xref:System.Speech.Recognition.SemanticResultValue.%23ctor%28System.Object%29>.
- If a string value phrase or specific <xref:System.Speech.Recognition.GrammarBuilder> instance is used, together with a <xref:System.Object> that specifies a <xref:System.Speech.Recognition.SemanticResultValue> value, that value is automatically associated with the string value phrase or the <xref:System.Speech.Recognition.GrammarBuilder> instance. If the phrase or <xref:System.Speech.Recognition.GrammarBuilder> object is used in the process of recognition, the value will be assigned to the semantics of the recognized phrase.
The following example illustrates this, and is functionally equivalent to the preceding example, which used explicit calls to <xref:System.Speech.Recognition.GrammarBuilder.Append%2A> and <xref:System.Speech.Recognition.SemanticResultValue.%23ctor%28System.Object%29>. If the recognition logic uses the word "background", the value `true` will be added to the recognized semantics.
```csharp
fgOrbgChoice.Add((GrammarBuilder)new SemanticResultValue("background", true));
```
For more information, see the description of <xref:System.Speech.Recognition.SemanticResultValue.%23ctor%28System.Speech.Recognition.GrammarBuilder%2CSystem.Object%29> and <xref:System.Speech.Recognition.SemanticResultValue.%23ctor%28System.String%2CSystem.Object%29>.
To be used by a <xref:System.Speech.Recognition.Grammar> in recognition, all <xref:System.Speech.Recognition.SemanticResultValue> instances must be associated with one of the <xref:System.Speech.Recognition.SemanticValue> objects used by that <xref:System.Speech.Recognition.Grammar>. This is done by associating a semantic key with the <xref:System.Speech.Recognition.SemanticResultValue>.
Semantic keys can be explicitly attached to a <xref:System.Speech.Recognition.SemanticResultValue>, using a <xref:System.Speech.Recognition.SemanticResultKey> object. <xref:System.Speech.Recognition.SemanticResultValue> instances not explicitly attached to a key are attached to the root key of the default <xref:System.Speech.Recognition.SemanticValue>.
After a <xref:System.Speech.Recognition.SemanticResultValue> has been used to set the <xref:System.Speech.Recognition.SemanticValue.Value%2A>, whether it is tagged with the default root key or by any particular <xref:System.Speech.Recognition.SemanticResultKey>, that value must not be modified or an exception will occur during recognition operations.
The following example will cause an exception because it sets and then modifies the root <xref:System.Speech.Recognition.SemanticValue.Value%2A> of a <xref:System.Speech.Recognition.Grammar>.
```csharp
GrammarBuilder gb=new GrammarBuilder();
gb.Append(new SemanticResultValue("One"));
gb.Append(new SemanticResultValue("Two"));
```
On the other hand, the code in the following example is permitted. Although it defines multiple instances of <xref:System.Speech.Recognition.SemanticResultValue>, they are included in a <xref:System.Speech.Recognition.Choices> object, and only one will ever be used to set the value of the key `bgOrfgText`.
```csharp
Choices fgOrbgChoice = new Choices();
fgOrbgChoice.Add((GrammarBuilder)new SemanticResultValue("background"));
fgOrbgChoice.Add((GrammarBuilder)new SemanticResultValue("foreground"));
SemanticResultKey fgOrbgChoiceKey = new SemanticResultKey("BgOrFgText", fgOrbgChoice);
```
## Examples
The following example returns a <xref:System.Speech.Recognition.Grammar> that recognizes the command "Set/Change/Alter Foreground/Background … [color list]". <xref:System.Speech.Recognition.SemanticResultValue> and <xref:System.Speech.Recognition.SemanticResultKey> instances (in conjunction with <xref:System.Speech.Recognition.Choices> and <xref:System.Speech.Recognition.GrammarBuilder> objects) are used to define semantics that can be parsed on recognition. The parsed semantics will determine which color was requested and whether the foreground or background is to be modified.
```
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;
}
```
]]></format>
</remarks>
<related type="Article" href="https://learn.microsoft.com/previous-versions/office/developer/speech-technologies/hh361587(v%3doffice.14)">Using a SemanticResultKey to Extract a SemanticResultValue</related>
</Docs>
<Members>
<MemberGroup MemberName=".ctor">
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Speech.Recognition.SemanticResultValue" /> class.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The `SemanticResultValue` constructors support specifying an <xref:System.Object> instance with an underlying data type of `bool`, `int`, `float`, or `string`.
A constructor can create a `SemanticResultValue` instance in either of two circumstances:
- The `SemanticResultValue` instance must be explicitly associated with a grammar element when using a <xref:System.Speech.Recognition.GrammarBuilder> to construct a <xref:System.Speech.Recognition.Grammar>.
- The `SemanticResultValue` is already associated with a string value phrase or a <xref:System.Speech.Recognition.GrammarBuilder> object.
]]></format>
</remarks>
</Docs>
</MemberGroup>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public SemanticResultValue (object value);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(object value) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Speech.Recognition.SemanticResultValue.#ctor(System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (value As Object)" />
<MemberSignature Language="F#" Value="new System.Speech.Recognition.SemanticResultValue : obj -> System.Speech.Recognition.SemanticResultValue" Usage="new System.Speech.Recognition.SemanticResultValue value" />
<MemberSignature Language="C++ CLI" Value="public:
 SemanticResultValue(System::Object ^ value);" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters>
<Parameter Name="value" Type="System.Object" />
</Parameters>
<Docs>
<param name="value">The value managed by <see cref="T:System.Speech.Recognition.SemanticResultValue" />. Must be of type <see langword="bool" />, <see langword="int" />, <see langword="float" />, or <see langword="string" />.</param>
<summary>Initializes a new instance of the <see cref="T:System.Speech.Recognition.SemanticResultValue" /> class and specifies a semantic value.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
A `SemanticResultValue` returned by this constructor is not associated with any particular grammar element. The association must be made explicit by using the instance of `SemanticResultValue` in conjunction with <xref:System.Speech.Recognition.GrammarBuilder>.
For instance, in the code fragment below, if a <xref:System.Speech.Recognition.Grammar> constructed using this <xref:System.Speech.Recognition.GrammarBuilder> instance recognizes the word "background", a value of `true` is set in the recognized phrase semantics.
```csharp
GrammarBuilder backgroundGB=new GrammarBuilder("background");
backgroundGB.Append(new SemanticResultValue(true));
```
## Examples
The following example returns a <xref:System.Speech.Recognition.Grammar> that recognizes the command "Set/Change/Alter Foreground/Background … [color list]". <xref:System.Speech.Recognition.SemanticResultValue> and <xref:System.Speech.Recognition.SemanticResultKey> instances (in conjunction with <xref:System.Speech.Recognition.Choices> and <xref:System.Speech.Recognition.GrammarBuilder> objects) are used to define semantics that can be parsed on recognition. The parsed semantics will determine which color was requested and whether the foreground or background is to be modified.
```csharp
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;
}
```
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public SemanticResultValue (System.Speech.Recognition.GrammarBuilder builder, object value);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(class System.Speech.Recognition.GrammarBuilder builder, object value) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Speech.Recognition.SemanticResultValue.#ctor(System.Speech.Recognition.GrammarBuilder,System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (builder As GrammarBuilder, value As Object)" />
<MemberSignature Language="F#" Value="new System.Speech.Recognition.SemanticResultValue : System.Speech.Recognition.GrammarBuilder * obj -> System.Speech.Recognition.SemanticResultValue" Usage="new System.Speech.Recognition.SemanticResultValue (builder, value)" />
<MemberSignature Language="C++ CLI" Value="public:
 SemanticResultValue(System::Speech::Recognition::GrammarBuilder ^ builder, System::Object ^ value);" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters>
<Parameter Name="builder" Type="System.Speech.Recognition.GrammarBuilder" />
<Parameter Name="value" Type="System.Object" />
</Parameters>
<Docs>
<param name="builder">A grammar component to be used in recognition.</param>
<param name="value">The value managed by <see cref="T:System.Speech.Recognition.SemanticResultValue" />. Must be of type <see langword="bool" />, <see langword="int" />, <see langword="float" />, or <see langword="string" />.</param>
<summary>Initializes a new instance of the <see cref="T:System.Speech.Recognition.SemanticResultValue" /> class and associates a semantic value with a <see cref="T:System.Speech.Recognition.GrammarBuilder" /> object.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If the grammar element specified by <xref:System.Speech.Recognition.GrammarBuilder> is used in the recognition logic, `value` will be set in the semantics of the recognized output.
In the code fragment below, if the recognition logic constructed with the <xref:System.Speech.Recognition.GrammarBuilder> instance (`myGb`) uses the <xref:System.Speech.Recognition.Choices> object (`myChoice`) to identify input, the value `true` is added to the recognized semantics.
```csharp
myGb.Append(new SemanticResultValue(myChoice, true);
```
As <xref:System.Speech.Recognition.GrammarBuilder> supports implicit conversion for <xref:System.Speech.Recognition.Choices>, `SemanticResultValue`, and <xref:System.Speech.Recognition.SemanticResultKey>, this constructor can use those objects as well.
## Examples
The following example returns a <xref:System.Speech.Recognition.Grammar> that recognizes the command "Set/Change/Alter Foreground/Background … [color list]". <xref:System.Speech.Recognition.SemanticResultValue> and <xref:System.Speech.Recognition.SemanticResultKey> instances (in conjunction with <xref:System.Speech.Recognition.Choices> and <xref:System.Speech.Recognition.GrammarBuilder> objects) are used to define semantics that can be parsed on recognition. The parsed semantics will determine which color was requested and whether the foreground or background is to be modified.
```csharp
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;
}
```
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public SemanticResultValue (string phrase, object value);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string phrase, object value) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Speech.Recognition.SemanticResultValue.#ctor(System.String,System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (phrase As String, value As Object)" />
<MemberSignature Language="F#" Value="new System.Speech.Recognition.SemanticResultValue : string * obj -> System.Speech.Recognition.SemanticResultValue" Usage="new System.Speech.Recognition.SemanticResultValue (phrase, value)" />
<MemberSignature Language="C++ CLI" Value="public:
 SemanticResultValue(System::String ^ phrase, System::Object ^ value);" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters>
<Parameter Name="phrase" Type="System.String" />
<Parameter Name="value" Type="System.Object" />
</Parameters>
<Docs>
<param name="phrase">A phrase to be used in recognition.</param>
<param name="value">The value managed by <see cref="T:System.Speech.Recognition.SemanticResultValue" />. Must be of type <see langword="bool" />, <see langword="int" />, <see langword="float" />, or <see langword="string" />.</param>
<summary>Initializes a new instance of the <see cref="T:System.Speech.Recognition.SemanticResultValue" /> class and associates a semantic value with a <see cref="T:System.String" /> object.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If the string specified by `phrase` is used in the recognition logic, `value` will be set in the semantics of the recognized output.
In the following code fragment, if the recognition logic constructed with the <xref:System.Speech.Recognition.GrammarBuilder> instance (`myGb`) uses the string "my mortgage" to identify input, the value `true` will be added to the recognized semantics.
```csharp
myGb.Append(new SemanticResultValue("my mortgage", true);
```
## Examples
The following example returns a <xref:System.Speech.Recognition.Grammar> that recognizes the command "Set/Change/Alter Foreground/Background … [color list]". <xref:System.Speech.Recognition.SemanticResultValue> and <xref:System.Speech.Recognition.SemanticResultKey> instances (in conjunction with <xref:System.Speech.Recognition.Choices> and <xref:System.Speech.Recognition.GrammarBuilder> objects) are used to define semantics that can be parsed on recognition. The parsed semantics will determine which color was requested and whether the foreground or background is to be modified.
```
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;
}
```
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="ToGrammarBuilder">
<MemberSignature Language="C#" Value="public System.Speech.Recognition.GrammarBuilder ToGrammarBuilder ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance class System.Speech.Recognition.GrammarBuilder ToGrammarBuilder() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Speech.Recognition.SemanticResultValue.ToGrammarBuilder" />
<MemberSignature Language="VB.NET" Value="Public Function ToGrammarBuilder () As GrammarBuilder" />
<MemberSignature Language="F#" Value="member this.ToGrammarBuilder : unit -> System.Speech.Recognition.GrammarBuilder" Usage="semanticResultValue.ToGrammarBuilder " />
<MemberSignature Language="C++ CLI" Value="public:
 System::Speech::Recognition::GrammarBuilder ^ ToGrammarBuilder();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Speech.Recognition.GrammarBuilder</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns an instance of <see cref="T:System.Speech.Recognition.GrammarBuilder" /> constructed from the current <see cref="T:System.Speech.Recognition.SemanticResultValue" /> instance.</summary>
<returns>Returns an instance of <see cref="T:System.Speech.Recognition.GrammarBuilder" /> constructed from the current <see cref="T:System.Speech.Recognition.SemanticResultValue" /> instance.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The use of <xref:System.Speech.Recognition.SemanticResultValue.ToGrammarBuilder%2A> is equivalent to using the <xref:System.Speech.Recognition.GrammarBuilder> constructor that takes a <xref:System.Speech.Recognition.SemanticResultValue> as an argument (<xref:System.Speech.Recognition.GrammarBuilder.%23ctor%28System.Speech.Recognition.SemanticResultValue%29>).
## Examples
The following example creates <xref:System.Speech.Recognition.Grammar> objects that support commands to change the background color.
A <xref:System.Speech.Recognition.Choices> object (`colorChoice`) containing the list of options for background colors is filled using the <xref:System.Speech.Recognition.Choices.Add%28System.Speech.Recognition.GrammarBuilder%5B%5D%29> method with <xref:System.Speech.Recognition.GrammarBuilder> instances that are obtained from the <xref:System.Speech.Recognition.SemanticResultKey.ToGrammarBuilder> method on the `SemanticResultValue` objects created from color strings.
A <xref:System.Speech.Recognition.GrammarBuilder> is then obtained by calling <xref:System.Speech.Recognition.SemanticResultKey.ToGrammarBuilder> on a <xref:System.Speech.Recognition.SemanticResultKey> instance, which will be used to key the semantic choices in the `colorChoice` instance.
```csharp
private Grammar CreateGrammarBuilderRGBSemantics()
{
// Create a set of choices, each a lookup from a color name to RBG.
// Choices constructors do not take a SemanticResultValue parameter, so
// cast SemanticResultValue to GrammarBuilder.
Choices colorChoice = new Choices();
foreach (string colorName in System.Enum.GetNames(typeof(KnownColor)))
{
// Use implicit conversion of SemanticResultValue to GrammarBuilder.
SemanticResultValue colorValue =
new SemanticResultValue(colorName, Color.FromName(colorName).ToArgb());
colorChoice.Add(colorValue.ToGrammarBuilder());
}
SemanticResultKey choiceKey = new SemanticResultKey("rgb", colorChoice);
GrammarBuilder choiceBuilder = choiceKey.ToGrammarBuilder();
// Create two intermediate grammars with an introductory phrase and the
// color choice.
GrammarBuilder makeBackgroundBuilder = "Make background";
makeBackgroundBuilder.Append(choiceBuilder);
GrammarBuilder configureBackgroundBuilder = new GrammarBuilder("Configure background as");
configureBackgroundBuilder.Append((new SemanticResultKey("rgb", colorChoice)).ToGrammarBuilder());
// Create the final grammar, which recognizes either intermediate grammar.
Grammar grammar = new Grammar(new Choices(new GrammarBuilder[] { makeBackgroundBuilder, configureBackgroundBuilder }));
grammar.Name = "Set Background Color";
return grammar;
}
```
]]></format>
</remarks>
</Docs>
</Member>
</Members>
</Type>