SrgsOneOf.Add(SrgsItem) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将 SrgsItem 包含单词或短语添加到替代项列表中。
public:
void Add(System::Speech::Recognition::SrgsGrammar::SrgsItem ^ item);
public void Add(System.Speech.Recognition.SrgsGrammar.SrgsItem item);
member this.Add : System.Speech.Recognition.SrgsGrammar.SrgsItem -> unit
Public Sub Add (item As SrgsItem)
参数
- item
- SrgsItem
要添加到替代项列表中的项。
例外
item 是 null。
示例
以下示例创建一种语法,用于识别“赢得世界杯的国家”一词,后跟赢得世界杯的国家/地区的名称。 该示例使用 SrgsOneOf 对象从对象数组 SrgsItem 生成可接受的国家/地区名称列表。
Add使用该方法,该示例将包含字符串“Italy”的字符串追加SrgsItem到SrgsOneOf对象oneOfEurope中。
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")});
oneOfEurope.Add(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;
}