SrgsRule.Add(SrgsElement) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將 SrgsElement 加入至 SrgsRule 物件。
public:
void Add(System::Speech::Recognition::SrgsGrammar::SrgsElement ^ element);
public void Add (System.Speech.Recognition.SrgsGrammar.SrgsElement element);
member this.Add : System.Speech.Recognition.SrgsGrammar.SrgsElement -> unit
Public Sub Add (element As SrgsElement)
參數
- element
- SrgsElement
繼承自SrgsElement 的物件,並會指定可辨識的項目。
例外狀況
element
為 null
。
範例
下列範例會建立一個文法,以辨識「已贏得世界盃的國家/地區」片語,後面接著已贏得 World Cup 的國家/地區名稱。 建立 SrgsRule 物件 winnerRule
並為其提供字串識別碼 WorldCupWinner
之後,此範例會使用 Add 方法,將「已贏得 World Cup 的一個國家」字串附加至規則。 然後,此範例會建立兩個額外的規則和 ruleEurope
ruleSAmerica
。 再次使用 Add 方法時,此範例會將 SrgsOneOf 物件附加至規則, WorldCupWinner
其中包含 和 ruleSAmerica
的規則參考 ruleEurope
。
// 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 專案包括 SrgsItem 、 SrgsOneOf 、 SrgsRuleRef 和 SrgsToken 物件,這些物件會指定說話者可以說什麼。 有效的規則專案必須至少包含一段可辨識的文字或一個規則參考。 如需詳細資訊,請參閱 使用 SrgsGrammar 建立文法 。
物件 SrgsRule 也可能包含 SrgsNameValueTag 和 SrgsSemanticInterpretationTag 物件,這些物件會將語意值和語意索引鍵新增至規則。 語音辨識引擎會在辨識片語時傳回語意資訊以及辨識的片語。 如需詳細資訊,請參閱 語意解譯標記 。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應