Bagikan melalui


SrgsOneOf Konstruktor

Definisi

Membuat instans SrgsOneOf baru kelas.

Overload

SrgsOneOf()

Menginisialisasi instans baru kelas SrgsOneOf.

SrgsOneOf(SrgsItem[])

Menginisialisasi instans SrgsOneOf baru kelas dari array SrgsItem objek.

SrgsOneOf(String[])

Menginisialisasi instans SrgsOneOf baru kelas dari array String objek.

Keterangan

Anda dapat membuat instans SrgsOneOf kelas dari array String objek, dari array SrgsItem objek, atau sebagai daftar kosong. Menggunakan SrgsItem objek alih-alih String objek dalam daftar alternatif memungkinkan Anda menerapkan properti untuk SrgsItem setiap item dalam daftar, seperti MinRepeat, MaxRepeat, RepeatProbability, dan Weight.

SrgsOneOf()

Sumber:
SrgsOneOf.cs
Sumber:
SrgsOneOf.cs
Sumber:
SrgsOneOf.cs

Menginisialisasi instans baru kelas SrgsOneOf.

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

Contoh

Contoh berikut menggunakan SrgsOneOf elemen untuk membangun daftar SrgsItem elemen yang berisi nama negara/wilayah, salah satunya dapat digunakan untuk mengenali frasa yang berisi. Contohnya kemudian menambahkan salah satu objek yang SrgsOneOf dihasilkan ke aturan masing-masing untuk negara/wilayah Eropa dan Amerika Selatan. Selanjutnya, contoh menggunakan SrgsOneOf objek untuk mengelompokkan referensi aturan ke ruleEurope dan ruleSAmerica ke dalam daftar dua alternatif, salah satunya dapat digunakan untuk mengenali input lisan.

public void WorldSoccerWinners ()
{

  // Create an SrgsDocument, create a new rule
  // and set its scope to public.
  SrgsDocument document = new SrgsDocument();
  SrgsRule winnerRule = new SrgsRule("WorldCupWinner");
  winnerRule.Scope = SrgsRuleScope.Public;

  // Add the introduction.
  winnerRule.Elements.Add(new SrgsItem("A nation that has won the world cup is: "));

  // Create the rule for the European nations.
  SrgsOneOf oneOfEurope = new SrgsOneOf(new SrgsItem[] {new SrgsItem("England"),
    new SrgsItem("France"), new SrgsItem("Germany"), new SrgsItem("Italy")});
  SrgsRule ruleEurope = (new SrgsRule("EuropeanNations", new SrgsElement[] {oneOfEurope}));

  // Create the rule for the South American nations.
  SrgsOneOf oneOfSAmerica = new SrgsOneOf(new SrgsItem[] {new SrgsItem("Argentina"),
    new SrgsItem("Brazil"), new SrgsItem("Uruguay")});
  SrgsRule ruleSAmerica = (new SrgsRule("SouthAmericanNations", new SrgsElement[] {oneOfSAmerica}));

  // Add references to winnerRule for ruleEurope and ruleSAmerica.
  winnerRule.Elements.Add(new SrgsOneOf(new SrgsItem[] {(new SrgsItem
    (new SrgsRuleRef(ruleEurope))), new SrgsItem(new SrgsRuleRef(ruleSAmerica))}));

  // Add all the rules to the document and make winnerRule
  // the root rule of the document.
  document.Rules.Add(new SrgsRule[] {winnerRule, ruleEurope, ruleSAmerica});
  document.Root = winnerRule;
}

Lihat juga

Berlaku untuk

SrgsOneOf(SrgsItem[])

Sumber:
SrgsOneOf.cs
Sumber:
SrgsOneOf.cs
Sumber:
SrgsOneOf.cs

Menginisialisasi instans SrgsOneOf baru kelas dari array SrgsItem objek.

public:
 SrgsOneOf(... cli::array <System::Speech::Recognition::SrgsGrammar::SrgsItem ^> ^ items);
public SrgsOneOf (params System.Speech.Recognition.SrgsGrammar.SrgsItem[] items);
new System.Speech.Recognition.SrgsGrammar.SrgsOneOf : System.Speech.Recognition.SrgsGrammar.SrgsItem[] -> System.Speech.Recognition.SrgsGrammar.SrgsOneOf
Public Sub New (ParamArray items As SrgsItem())

Parameter

items
SrgsItem[]

Item alternatif untuk ditambahkan.

Pengecualian

itemsadalah null.

Elemen apa pun dalam items array adalah null.

Contoh

Contoh berikut membuat tata bahasa yang mengenali frasa "Bangsa yang telah memenangkan Piala Dunia adalah" diikuti dengan nama negara/wilayah yang telah memenangkan Piala Dunia. Ini membuat aturan publik bernama WorldCupWinner. Kemudian membuat dua SrgsRule objek menggunakan SrgsOneOf objek yang berisi array objek baru SrgsItem . Untuk melihat tata bahasa yang dihasilkan contoh ini, lihat SrgsRule.

 public void WorldSoccerWinners ()
{

  // Create an SrgsDocument, create a new rule
  // and set its scope to public.
  SrgsDocument document = new SrgsDocument();
  SrgsRule winnerRule = new SrgsRule("WorldCupWinner");
  winnerRule.Scope = SrgsRuleScope.Public;

  // Add the introduction.
  winnerRule.Elements.Add(new SrgsItem("A nation that has won the world cup is: "));

  // Create the rule for the European nations.
  SrgsOneOf oneOfEurope = new SrgsOneOf(new SrgsItem[] {new SrgsItem("England"), new SrgsItem("France"), new SrgsItem("Germany"), new SrgsItem("Italy")});
  SrgsRule ruleEurope = (new SrgsRule("EuropeanNations", new SrgsElement[] {oneOfEurope}));

  // Create the rule for the South American nations.
  SrgsOneOf oneOfSAmerica = new SrgsOneOf(new SrgsItem[] {new SrgsItem("Argentina"), new SrgsItem("Brazil"), new SrgsItem("Uruguay")});
  SrgsRule ruleSAmerica = (new SrgsRule("SouthAmericanNations", new SrgsElement[] {oneOfSAmerica}));

  // Add references to winnerRule for ruleEurope and ruleSAmerica.
  winnerRule.Elements.Add(new SrgsOneOf(new SrgsItem[] {(new SrgsItem
    (new SrgsRuleRef(ruleEurope))), new SrgsItem(new SrgsRuleRef(ruleSAmerica))}));

  // Add all the rules to the document and make winnerRule
  // the root rule of the document.
  document.Rules.Add(new SrgsRule[] {winnerRule, ruleEurope, ruleSAmerica});
  document.Root = winnerRule;
}

Lihat juga

Berlaku untuk

SrgsOneOf(String[])

Sumber:
SrgsOneOf.cs
Sumber:
SrgsOneOf.cs
Sumber:
SrgsOneOf.cs

Menginisialisasi instans SrgsOneOf baru kelas dari array String objek.

public:
 SrgsOneOf(... cli::array <System::String ^> ^ items);
public SrgsOneOf (params string[] items);
new System.Speech.Recognition.SrgsGrammar.SrgsOneOf : string[] -> System.Speech.Recognition.SrgsGrammar.SrgsOneOf
Public Sub New (ParamArray items As String())

Parameter

items
String[]

Item alternatif untuk ditambahkan.

Pengecualian

itemsadalah null.

Elemen apa pun dalam items array adalah null.

Contoh

Contoh berikut membuat tata bahasa yang mengenali frasa "Bangsa yang telah memenangkan Piala Dunia adalah" diikuti dengan nama negara/wilayah yang telah memenangkan Piala Dunia. Contohnya menggunakan SrgsOneOf elemen untuk membangun daftar nama negara/wilayah yang dapat diterima dari array String objek. Contohnya kemudian menambahkan salah satu objek yang SrgsOneOf dihasilkan ke aturan masing-masing untuk negara/wilayah Eropa dan Amerika Selatan.

public void WorldSoccerWinners ()
{
    // Create a grammar from an SRGSDocument, create a new rule
  // and set its scope to public.
  SrgsDocument srgsGrammar = new SrgsDocument ();
  SrgsRule winnerRule = new SrgsRule ("WorldCupWinner");
  winnerRule.Scope = SrgsRuleScope.Public;

  // Add the introduction.
  winnerRule.Elements.Add (new SrgsItem ("A nation that has won the world cup is"));

  // Create the rule for the European nations.
  SrgsOneOf oneOfEurope = new SrgsOneOf (new string[] {"England","France","Germany","Italy"});
  SrgsRule ruleEurope = (new SrgsRule("EuropeanNations", new SrgsElement[] {oneOfEurope}));

  // Create the rule for the South American nations.
  SrgsOneOf oneOfSAmerica = new SrgsOneOf (new string[] {"Argentina","Brazil","Uruguay"});
  SrgsRule ruleSAmerica = (new SrgsRule("SouthAmericanNations", new SrgsElement[] {oneOfSAmerica}));

  // Add references to winnerRule for ruleEurope and ruleSAmerica.
  winnerRule.Elements.Add(new SrgsOneOf(new SrgsItem[] {(new SrgsItem
    (new SrgsRuleRef(ruleEurope))), new SrgsItem(new SrgsRuleRef(ruleSAmerica))}));

  // Add all the rules to the grammar and make winnerRule
  // the root rule of the grammar.
  srgsGrammar.Rules.Add (new SrgsRule[] {winnerRule, ruleEurope, ruleSAmerica});
  srgsGrammar.Root = winnerRule;
}

Lihat juga

Berlaku untuk