다음을 통해 공유


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로부터 상속하고 인식될 수 있는 것을 지정하는 개체

예외

element이(가) null인 경우

예제

다음 예제에서는 라는 문구를 인식 하는 문법의 전 세계 월드컵 성공한에 국가 이름 뒤에 "가 전 세계 월드컵에 국가". 개체 winnerRuleSrgsRule 만들고 문자열 식별자를 WorldCupWinner지정한 후 예제에서는 메서드를 Add 사용하여 규칙에 "월드컵에서 우승한 국가는 입니다"라는 문자열을 추가합니다. 그런 다음, 이 예제에서는 및 ruleSAmerica두 개의 추가 규칙을 ruleEurope 만듭니다. 이 예제에서는 메서드를 Add 다시 사용하여 및 ruleSAmerica에 대한 규칙 참조를 WorldCupWinner 포함하는 규칙에 개체를 ruleEurope 추가 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 대한 일반적인 추가에는 스피커가 말할 수 있는 내용을 지정하는 , , 및 SrgsToken 개체가 포함SrgsItemSrgsOneOfSrgsRuleRef됩니다. 유효한 규칙 요소에는 하나 이상의 인식 가능한 텍스트 또는 하나의 규칙 참조가 포함되어야 합니다. 자세한 내용은 SrgsGrammar를 사용하여 문법 만들기 를 참조하세요.

또한 개체에는 SrgsRule 의미 체계 값과 SrgsSemanticInterpretationTag 의미 체계 키를 규칙에 추가하는 및 개체가 포함될 SrgsNameValueTag 수 있습니다. 음성 인식 엔진은 구를 인식할 때 인식된 구뿐만 아니라 의미 체계 정보를 반환합니다. 자세한 내용은 의미 체계 해석 태그 를 참조하세요.

적용 대상

추가 정보