語言

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 該物件定義的規則。

範例

以下範例建立一個文法,該文法識別短語「A nation who had won the World Cup」後接一個贏得世界盃的國家/地區名稱。 範例中建立一個 SrgsDocument 物件,然後建立一個名為 winnerRule的公開規則。 在規則 中加入字串 winnerRule後,範例會產生兩條額外規則( 和ruleEuroperuleSAmerica),每個規則都包含國家/地區的列表。 使用該Add方法,範例將所有三條規則(、winnerRuleruleEurope 、 ruleSAmerica和 )加入 的性質Rules中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;
}

備註

你可以用屬性上SrgsRule的方法SrgsRulesCollection來新增Add物件Rules。 如果你初始化一個 SrgsDocument 物件並指定物件 SrgsRule 作為參數,該 SrgsRule 參數會自動加入 SrgsRulesCollectionSrgsDocument。

適用於

另請參閱