SrgsRule.Add(SrgsElement) メソッド

定義

SrgsElementSrgsRule オブジェクトに追加します。

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 から継承し、認識できる内容を指定するオブジェクト。

例外

elementnullです。

次の例では、"ワールドカップで優勝した国" という語句の後に、ワールドカップで優勝した国の名前を認識する文法を作成します。 オブジェクトwinnerRuleSrgsRule作成し、文字列識別子 WorldCupWinnerを指定した後、この例では、 メソッドをAdd使用して、"A nation that has won the World Cup is" という文字列をルールに追加します。 次に、この例では、 と という 2 つの追加規則 ruleEuroperuleSAmerica作成します。 この例では、 メソッドをAdd使用して、 および へのルール参照をWorldCupWinner含むオブジェクトをルールにruleEurope追加SrgsOneOfしますruleSAmerica

// 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追加にはSrgsItemSrgsOneOfSrgsRuleRef、話者が言える内容を指定する 、および SrgsToken オブジェクトがあります。 有効なルール要素には、少なくとも 1 つの認識可能なテキストまたは 1 つのルール参照が含まれている必要があります。 詳細については、「 SrgsGrammar を使用して文法を作成 する」を参照してください。

SrgsRuleオブジェクトには、ルールにセマンティック値とSrgsSemanticInterpretationTagセマンティック キーを追加する オブジェクトと オブジェクトを含SrgsNameValueTagめることもできます。 音声認識エンジンは、その語句を認識すると、認識された語句と同様にセマンティック情報を返します。 詳細については、「 セマンティック解釈マークアップ 」を参照してください。

適用対象

こちらもご覧ください