共用方式為


SrgsDocument.Rules 屬性

定義

取得目前針對 SrgsDocument 類別所定義之規則的集合。

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

屬性值

傳回 SrgsDocument 物件定義的規則。

範例

下列範例會建立一個文法,以辨識「已贏得世界盃的國家/地區」片語,後面接著已贏得 World Cup 的國家/地區名稱。 此範例會 SrgsDocument 建立 物件,然後建立名為 的 winnerRule 公用規則。 將字串新增至規則 winnerRule 之後,此範例會建立兩個其他規則 (ruleEuroperuleSAmerica) ,每個規則都包含國家/地區清單。 Add使用 方法時,此範例會將三個規則 (winnerRuleruleEuroperuleSAmerica) 新增至 RulesSrgsDocument 屬性。

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

備註

您可以使用 屬性上的 Rules 方法, Add 將 物件新增 SrgsRuleSrgsRulesCollection 。 如果您初始化 SrgsDocument 物件,並將 物件指定 SrgsRule 為 引數,則 SrgsRule 會自動將 新增至 SrgsRulesCollectionSrgsDocument

適用於

另請參閱