Bagikan melalui


SrgsDocument.Rules Properti

Definisi

Mendapatkan kumpulan aturan yang saat ini ditentukan untuk SrgsDocument kelas .

public:
 property System::Speech::Recognition::SrgsGrammar::SrgsRulesCollection ^ Rules { System::Speech::Recognition::SrgsGrammar::SrgsRulesCollection ^ get(); };
public System.Speech.Recognition.SrgsGrammar.SrgsRulesCollection Rules { get; }
member this.Rules : System.Speech.Recognition.SrgsGrammar.SrgsRulesCollection
Public ReadOnly Property Rules As SrgsRulesCollection

Nilai Properti

Mengembalikan aturan yang ditentukan untuk SrgsDocument objek.

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. Contoh membuat SrgsDocument objek, lalu membuat aturan publik bernama winnerRule. Setelah menambahkan string ke aturan winnerRule, contoh membuat dua aturan lagi (ruleEurope dan ruleSAmerica), masing-masing berisi daftar negara/wilayah. Menggunakan metode , Add contoh menambahkan ketiga aturan (winnerRule, ruleEurope, dan ruleSAmerica) ke Rules properti .SrgsDocument

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

Keterangan

Anda dapat menambahkan SrgsRule objek ke SrgsRulesCollection dengan menggunakan Add metode pada Rules properti . Jika Anda menginisialisasi SrgsDocument objek dan menentukan SrgsRule objek sebagai argumen, SrgsRule secara otomatis ditambahkan ke SrgsRulesCollection untuk SrgsDocument.

Berlaku untuk

Lihat juga