通过


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

示例

以下示例创建一种语法,用于识别“赢得世界杯的国家”一词,后跟赢得世界杯的国家/地区的名称。 该示例创建一个对象,然后创建名为 <a0/> 的公共规则。 将字符串添加到规则 winnerRule后,该示例再创建两个规则(ruleEurope 以及 ruleSAmerica),每个规则都包含一个国家/地区列表。 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;
}

注解

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

适用于

另请参阅