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 对象定义的规则。

示例

以下示例创建一个语法,该语法识别短语“赢得世界杯的国家为”,后跟赢得世界杯的国家/地区的名称。 该示例创建一个 SrgsDocument 对象,然后创建一个名为 winnerRule的公共规则。 将字符串添加到规则 winnerRule后,本示例 (ruleEuroperuleSAmerica) 再创建两个规则,每个规则都包含一个国家/地区列表。 Add使用 方法,该示例将 (winnerRuleruleEuroperuleSAmerica) 的所有三个规则添加到 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;
}

注解

可以使用 属性上的 方法将 SrgsRulesCollectionAdd 对象添加到 。RulesSrgsRule 如果初始化 对象SrgsDocument并将对象指定SrgsRule为 参数,则 SrgsRule 会自动将 添加到 SrgsRulesCollection 的 。SrgsDocument

适用于

另请参阅