Share via


SrgsRule 생성자

정의

SrgsRule 클래스의 새 인스턴스를 초기화합니다.

오버로드

SrgsRule(String)

SrgsRule 클래스의 새 인스턴스를 초기화하고 규칙에 대한 식별자를 지정합니다.

SrgsRule(String, SrgsElement[])

SrgsRule 개체의 배열에서 SrgsElement 클래스의 새 인스턴스를 초기화합니다.

SrgsRule(String)

Source:
SrgsRule.cs
Source:
SrgsRule.cs
Source:
SrgsRule.cs

SrgsRule 클래스의 새 인스턴스를 초기화하고 규칙에 대한 식별자를 지정합니다.

public:
 SrgsRule(System::String ^ id);
public SrgsRule (string id);
new System.Speech.Recognition.SrgsGrammar.SrgsRule : string -> System.Speech.Recognition.SrgsGrammar.SrgsRule
Public Sub New (id As String)

매개 변수

id
String

규칙의 식별자입니다.

예외

id이(가) null인 경우

id가 비어 있는 경우

id은 적절한 규칙 식별자가 아닙니다.

예제

다음 예제에서는 라는 문구를 인식 하는 문법의 전 세계 월드컵 성공한에 국가 이름 뒤에 "가 전 세계 월드컵에 국가". 이 예제에서는 라는 winnerRule 개체를 SrgsRule 만들고 식별자에 WorldCupWinnerString를 전달합니다. 개체는 SrgsOneOf 규칙에서 인식할 대안을 포함하는 새 SrgsItem 개체의 배열로 구성됩니다.

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"), 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 생성자는 속성을 초기화합니다Id. 식별자는 지정된 문법 내에서 고유해야 합니다.

SrgsRule 생성자는 다음과 같은 상황에서 을 throw FormatException 합니다.

  • id 은 XML (Extensible Markup Language) 1.0(다섯 번째 버전)에 정의된 유효한 XML 이름이 아닙니다. 이 정의를 의역하려면 유효한 XML 이름은 문자, 밑줄 ('_') 또는 콜론(':')으로 시작해야 하며 0개 이상의 NameChar 문자(XML 사양에도 정의됨)가 뒤따를 수 있습니다.

  • id 은 "NULL" 또는 "VOID" 또는 "GARBAGE"입니다.

  • id 에는 하나 이상의 잘못된 규칙 ID 문자가 포함되어 있습니다. 이러한 문자는 '?', '*', '+', '|', '(', '), '^', '$', '/', ';', '.', '=', '<>', '[', ']', '{', '}', '\\', ', ', '\t', '\r', '\n'입니다.

추가 정보

적용 대상

SrgsRule(String, SrgsElement[])

Source:
SrgsRule.cs
Source:
SrgsRule.cs
Source:
SrgsRule.cs

SrgsRule 개체의 배열에서 SrgsElement 클래스의 새 인스턴스를 초기화합니다.

public:
 SrgsRule(System::String ^ id, ... cli::array <System::Speech::Recognition::SrgsGrammar::SrgsElement ^> ^ elements);
public SrgsRule (string id, params System.Speech.Recognition.SrgsGrammar.SrgsElement[] elements);
new System.Speech.Recognition.SrgsGrammar.SrgsRule : string * System.Speech.Recognition.SrgsGrammar.SrgsElement[] -> System.Speech.Recognition.SrgsGrammar.SrgsRule
Public Sub New (id As String, ParamArray elements As SrgsElement())

매개 변수

id
String

규칙의 식별자입니다.

elements
SrgsElement[]

SrgsElement 요소의 배열입니다.

예외

id이(가) null인 경우

elements이(가) null인 경우

id가 비어 있는 경우

id은 적절한 규칙 식별자가 아닙니다.

예제

다음 예제에서는 라는 문구를 인식 하는 문법의 전 세계 월드컵 성공한에 국가 이름 뒤에 "가 전 세계 월드컵에 국가". 이 예제에서는 라는 WorldCupWinner공용 규칙을 만듭니다. 그런 다음, ruleEurope 규칙 식별자에 대한 를 전달하고 ruleSAmerica개체를 포함하는 배열을 전달하는 String 두 개의 SrgsRule 개체와 SrgsElementSrgsOneOf 만듭니다. 그 후 이 예제에서는 규칙 에 규칙 참조를 ruleEuroperuleSAmerica 추가하고 규칙 WorldCupWinner에서 을 추가합니다.

public void WorldSoccerWinners ()
{
  // Create a grammar from an SRGSDocument, create a new rule
  // and set its scope to public.
  SrgsDocument srgsGrammar = 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 grammar and make winnerRule
  // the root rule of the grammar.
  document.Rules.Add(new SrgsRule[] {winnerRule, ruleEurope, ruleSAmerica});
  srgsGrammar.Root = winnerRule;
}

만든된 문법에 다음과 같은 형식입니다.

<grammar version="1.0" xml:lang="en-US" xmlns="http://www.w3.org/2001/06/grammar" root="WorldCupWinner">
    <rule id="WorldCupWinner" scope="public">
        <item> A nation that has won the world cup is </item>
        <one-of>
            <item>
                <ruleref uri="#EuropeanNations" />
            </item>
            <item>
                <ruleref uri="#SouthAmericanNations" />
            </item>
        </one-of>
    </rule>
    <rule id="EuropeanNations">
        <one-of>
            <item> England </item>
            <item> France </item>
            <item> Germany </item>
            <item> Italy </item>
        </one-of>
    </rule>
    <rule id="SouthAmericanNations">
        <one-of>
            <item> Argentina </item>
            <item> Brazil </item>
            <item> Uruguay </item>
        </one-of>
    </rule>
</grammar>

설명

SrgsRule 생성자는 속성을 초기화합니다Id. 식별자는 지정된 문법 내에서 고유해야 합니다.

SrgsRule 생성자는 다음과 같은 상황에서 을 throw FormatException 합니다.

  • id 은 XML (Extensible Markup Language) 1.0(다섯 번째 버전)에 정의된 유효한 XML 이름이 아닙니다. 이 정의를 의역하려면 유효한 XML 이름은 문자, 밑줄 ('_') 또는 콜론(':')으로 시작해야 하며 0개 이상의 NameChar 문자(XML 사양에도 정의됨)가 뒤따를 수 있습니다.

  • id 은 "NULL" 또는 "VOID" 또는 "GARBAGE"입니다.

  • id 에는 하나 이상의 잘못된 규칙 ID 문자가 포함되어 있습니다. 이러한 문자는 '?', '*', '+', '|', '(', '), '^', '$', '/', ';', '.', '=', '<>', '[', ']', '{', '}', '\\', ', ', '\t', '\r', '\n'입니다.

추가 정보

적용 대상