次の方法で共有


SrgsRule.Add(SrgsElement) メソッド

定義

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

例外

elementnullです。

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

// 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 つのルール参照が含まれている必要があります。

SrgsRule オブジェクトには、ルールにセマンティック値とセマンティック キーを追加するSrgsNameValueTagオブジェクトとSrgsSemanticInterpretationTag オブジェクトを含めることもできます。 音声認識エンジンは、語句を認識すると、認識された語句と同様にセマンティック情報を返します。

適用対象