Aracılığıyla paylaş


Choices Oluşturucular

Tanım

Choices sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

Choices()

Boş bir alternatif kümesi içeren sınıfının yeni bir örneğini Choices başlatır.

Choices(GrammarBuilder[])

Bir veya daha fazla GrammarBuilder nesne içeren bir diziden sınıfının yeni bir örneğini Choices başlatır.

Choices(String[])

Bir veya daha fazla String nesne içeren bir diziden sınıfının yeni bir örneğini Choices başlatır.

Örnekler

Aşağıdaki örnek, iki alternatif listesi oluşturmak için nesneleri kullanır Choices .

İlk Choices nesne bir nesne dizisinden String oluşturulur. Diğer Choices nesne, örtük olarak bir atama tarafından dönüştürülen bir nesne dizisinden GrammarBuilder oluşturulur.

Örnek, nesneleri ve "[phoneType] telefonunda [contactlList] çağrısı" biçiminde konuşma girişini tanımak için kullanılabilecek iki ek dize kullanarak Choices bir tümceciği bir araya getirmek için bir nesne kullanırGrammarBuilder, örneğin "Cep telefonunda Jane'i ara".

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

Açıklamalar

Parametresiz bir oluşturucu kullanarak (boş bir nesne döndüren), bir nesne grubundan String veya nesne kümesinden GrammarBuilder bir nesne oluşturabilirsinizChoices.

nesnesi ve SemanticResultKeyöğesinden örtük dönüştürmeyi GrammarBuilder desteklediğindenSemanticResultValue, atama Choices kullanılarak bu nesnelerin dizisinden bir oluşturulabilir.

Choices()

Boş bir alternatif kümesi içeren sınıfının yeni bir örneğini Choices başlatır.

public:
 Choices();
public Choices ();
Public Sub New ()

Örnekler

Aşağıdaki örnek, "Cep telefonunda Anne'yi ara" ve "İş telefonunda James'i ara" gibi konuşma girişini tanımak için kullanılabilecek bir tümcecik oluşturmak için ve GrammarBuilder nesnelerini kullanırChoices. Örnek, ve'den Choices String öğesine GrammarBuilderörtük atamalar kullanır.

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

Açıklamalar

Bu oluşturucu geçerli, boş bir alternatif kümesi döndürür. Yöntemlerden herhangi birini Add kullanarak alternatifler ekleyebilirsiniz.

Ayrıca bkz.

Şunlara uygulanır

Choices(GrammarBuilder[])

Bir veya daha fazla GrammarBuilder nesne içeren bir diziden sınıfının yeni bir örneğini Choices başlatır.

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())

Parametreler

alternateChoices
GrammarBuilder[]

Alternatifler kümesini içeren bir dizi.

Örnekler

Aşağıdaki örnek, ve GrammarBuilder nesnelerini kullanarak Choices "Cep telefonunda Anne'yi Ara" ve "İş telefonunda James'i ara" gibi ifadeler Grammar oluşturur. Örnek, ve'den Choices String öğesine GrammarBuilderörtük atamalar kullanır.

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

Açıklamalar

içindeki alternateChoices her GrammarBuilder biri bir alternatif tanımlar. Boş bir diziyse alternateChoices , oluşturucu boş bir alternatif kümesi döndürür. Yöntemlerden herhangi birini Add kullanarak alternatifler ekleyebilirsiniz.

Oluşturucu, dizi öğelerinin nullherhangi biri olduğunda null alternateChoices veya olduğunda oluştururArgumentNullException.

GrammarBuilder sınıfı, , ve SemanticResultKey nesnelerinin örneklere örtük olarak dönüştürülmesi SemanticResultValueChoicesGrammarBuilder için destek sağladığından, atamaları düzgün bir şekilde kullanarak bu oluşturucu, bu nesnelerin herhangi bir Choices bileşiminin bir listesinden nesne oluşturmak için de kullanılabilir.

Ayrıca bkz.

Şunlara uygulanır

Choices(String[])

Bir veya daha fazla String nesne içeren bir diziden sınıfının yeni bir örneğini Choices başlatır.

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())

Parametreler

phrases
String[]

Alternatifler kümesini içeren bir dizi.

Örnekler

Aşağıdaki örnek, "Cep telefonunda Anne'yi ara" ve "İş telefonunda James'i ara" gibi ifadeler için bir Grammar oluşturmak üzere ve GrammarBuilder nesnelerini kullanırChoices. Örnek, ve'den Choices String öğesine GrammarBuilderörtük atamalar kullanır.

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

Açıklamalar

içindeki phrases her String biri bir alternatif tanımlar. Konuşma tanıma altyapısı, konuşma girişiyle eşleştirmek için dize dizisindeki öğelerden herhangi birini kullanabilir. Boş bir diziyse phrases , oluşturucu boş bir alternatif kümesi döndürür. Yöntemlerden herhangi birini Add kullanarak alternatifler ekleyebilirsiniz.

Oluşturucu, olduğunda veya dizi öğelerinin herhangi biri olduğunda phrases null nulloluşturur.ArgumentNullException Oluşturucu, dizideki herhangi bir öğe boş bir dizeyse ("") oluşturur ArgumentException .

Ayrıca bkz.

Şunlara uygulanır