Choices Costruttori
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Inizializza una nuova istanza della classe Choices.
Overload
| Nome | Descrizione |
|---|---|
| Choices() |
Inizializza una nuova istanza della Choices classe che contiene un set vuoto di alternative. |
| Choices(GrammarBuilder[]) |
Inizializza una nuova istanza della Choices classe da una matrice contenente uno o più GrammarBuilder oggetti. |
| Choices(String[]) |
Inizializza una nuova istanza della Choices classe da una matrice contenente uno o più String oggetti. |
Esempio
Nell'esempio seguente vengono Choices utilizzati oggetti per creare due elenchi di alternative.
Il primo Choices oggetto viene costruito da una matrice di String oggetti. L'altro Choices oggetto viene costruito da una matrice di GrammarBuilder oggetti che sono stati convertiti in modo implicito da un cast.
Nell'esempio viene usato un GrammarBuilder oggetto per assemblare una frase, usando gli Choices oggetti e due stringhe aggiuntive, che possono essere usate per riconoscere l'input vocale sotto forma di "Call [contactlList] on [phoneType] phone", ad esempio "Call Jane on cell phone".
public GrammarBuilder ChoicesConstructor2 ()
{
GrammarBuilder gb = new GrammarBuilder ();
Choices phoneType = new Choices (new string[] {"cell", "home", "work"});
Choices contactList = new Choices (new GrammarBuilder[] {(GrammarBuilder) "Mark", (GrammarBuilder) "Jane", (GrammarBuilder) "Frank"});
gb.Append ("Call");
gb.Append (contactList);
gb.Append ("on");
gb.Append (phoneType);
gb.Append ("phone");
return gb;
}
Commenti
È possibile costruire un Choices oggetto usando un costruttore senza parametri (che restituisce un oggetto vuoto), da un gruppo di String oggetti o da un set di GrammarBuilder oggetti.
Poiché l'oggetto supporta la GrammarBuilder conversione implicita da SemanticResultValue e SemanticResultKey, un Choices oggetto può essere costruito da una matrice di questi oggetti usando un cast.
Choices()
- Origine:
- Choices.cs
- Origine:
- Choices.cs
- Origine:
- Choices.cs
- Origine:
- Choices.cs
Inizializza una nuova istanza della Choices classe che contiene un set vuoto di alternative.
public:
Choices();
public Choices();
Public Sub New ()
Esempio
Nell'esempio seguente vengono Choices usati oggetti e GrammarBuilder per creare una frase che può essere usata per riconoscere l'input vocale, ad esempio "Call Anne on her cell" e "Call James on his work phone". Nell'esempio vengono usati cast impliciti da Choices e String a GrammarBuilder.
public Grammar CreatePhonePhrase()
{
// Create alternatives for female names and add a phrase.
GrammarBuilder females = new Choices(new string[] { "Anne", "Mary" });
females.Append("on her");
// Create alternatives for male names and add a phrase.
GrammarBuilder males = new Choices(new string[] { "James", "Sam" });
males.Append("on his");
// Create a Choices object that contains an array of alternative
// GrammarBuilder objects.
Choices people = new Choices();
people.Add(new Choices(new GrammarBuilder[] {females, males}));
// Create a Choices object that contains a set of alternative phone types.
Choices phoneType = new Choices();
phoneType.Add(new string[] { "cell", "home", "work" });
// Construct the phrase.
GrammarBuilder gb = new GrammarBuilder();
gb.Append("call");
gb.Append(people);
gb.Append(phoneType);
gb.Append(new GrammarBuilder("phone"), 0, 1);
return new Grammar(gb);
}
Commenti
Questo costruttore restituisce un set di alternative valido e vuoto. È possibile aggiungere alternative usando uno dei Add metodi .
Vedi anche
Si applica a
Choices(GrammarBuilder[])
- Origine:
- Choices.cs
- Origine:
- Choices.cs
- Origine:
- Choices.cs
- Origine:
- Choices.cs
Inizializza una nuova istanza della Choices classe da una matrice contenente uno o più GrammarBuilder oggetti.
public:
Choices(... cli::array <System::Speech::Recognition::GrammarBuilder ^> ^ alternateChoices);
public Choices(params System.Speech.Recognition.GrammarBuilder[] alternateChoices);
new System.Speech.Recognition.Choices : System.Speech.Recognition.GrammarBuilder[] -> System.Speech.Recognition.Choices
Public Sub New (ParamArray alternateChoices As GrammarBuilder())
Parametri
- alternateChoices
- GrammarBuilder[]
Matrice contenente il set di alternative.
Esempio
Nell'esempio seguente vengono Choices usati oggetti e GrammarBuilder per creare un Grammar oggetto per frasi come "Chiama Anne sulla sua cella" e "Chiama James sul telefono di lavoro". Nell'esempio vengono usati cast impliciti da Choices e String a GrammarBuilder.
public Grammar CreatePhonePhrase()
{
// Create alternatives for female names and add a phrase.
GrammarBuilder females = new Choices(new string[] { "Anne", "Mary" });
females.Append("on her");
// Create alternatives for male names and add a phrase.
GrammarBuilder males = new Choices(new string[] { "James", "Sam" });
males.Append("on his");
// Create a Choices object that contains an array of alternative
// GrammarBuilder objects.
Choices people = new Choices();
people.Add(new Choices(new GrammarBuilder[] {females, males}));
// Create a Choices object that contains a set of alternative phone types.
Choices phoneType = new Choices();
phoneType.Add(new string[] { "cell", "home", "work" });
// Construct the phrase.
GrammarBuilder gb = new GrammarBuilder();
gb.Append("call");
gb.Append(people);
gb.Append(phoneType);
gb.Append(new GrammarBuilder("phone"), 0, 1);
return new Grammar(gb);
}
Commenti
Ognuno GrammarBuilder di essi alternateChoices definisce un'alternativa. Se alternateChoices è una matrice vuota, il costruttore restituisce un set vuoto di alternative. È possibile aggiungere alternative usando uno dei Add metodi .
Il costruttore genera un'eccezione ArgumentNullException quando alternateChoices è null o quando uno degli elementi della matrice è null.
Poiché la classe fornisce supporto per la GrammarBuilder conversione implicita di Choicesoggetti , SemanticResultValuee SemanticResultKey in GrammarBuilder istanze di , usando correttamente i cast, questo costruttore può essere usato anche per creare un Choices oggetto da un elenco di qualsiasi combinazione di questi oggetti.
Vedi anche
Si applica a
Choices(String[])
- Origine:
- Choices.cs
- Origine:
- Choices.cs
- Origine:
- Choices.cs
- Origine:
- Choices.cs
public:
Choices(... cli::array <System::String ^> ^ phrases);
public Choices(params string[] phrases);
new System.Speech.Recognition.Choices : string[] -> System.Speech.Recognition.Choices
Public Sub New (ParamArray phrases As String())
Parametri
- phrases
- String[]
Matrice contenente il set di alternative.
Esempio
Nell'esempio seguente vengono Choices usati oggetti e GrammarBuilder per creare un Grammar oggetto per le frasi, ad esempio "Chiamare Anne nella cella" e "Chiama James sul telefono di lavoro". Nell'esempio vengono usati cast impliciti da Choices e String a GrammarBuilder.
public Grammar CreatePhonePhrase()
{
// Create alternatives for female names and add a phrase.
GrammarBuilder females = new Choices(new string[] { "Anne", "Mary" });
females.Append("on her");
// Create alternatives for male names and add a phrase.
GrammarBuilder males = new Choices(new string[] { "James", "Sam" });
males.Append("on his");
// Create a Choices object that contains an array of alternative
// GrammarBuilder objects.
Choices people = new Choices();
people.Add(new Choices(new GrammarBuilder[] {females, males}));
// Create a Choices object that contains a set of alternative phone types.
Choices phoneType = new Choices();
phoneType.Add(new string[] { "cell", "home", "work" });
// Construct the phrase.
GrammarBuilder gb = new GrammarBuilder();
gb.Append("call");
gb.Append(people);
gb.Append(phoneType);
gb.Append(new GrammarBuilder("phone"), 0, 1);
return new Grammar(gb);
}
Commenti
Ognuno String di essi phrases definisce un'alternativa. Il motore di riconoscimento vocale può usare uno qualsiasi degli elementi nella matrice di stringhe per trovare una corrispondenza con l'input vocale. Se phrases è una matrice vuota, il costruttore restituisce un set vuoto di alternative. È possibile aggiungere alternative usando uno dei Add metodi .
Il costruttore genera un'eccezione ArgumentNullException quando phrases è null o uno degli elementi della matrice è null. Il costruttore genera un'eccezione ArgumentException se un elemento nella matrice è una stringa vuota ("").