次の方法で共有


SrgsRule コンストラクター

定義

SrgsRule クラスの新しいインスタンスを初期化します。

オーバーロード

SrgsRule(String)

SrgsRule クラスの新しいインスタンスを初期化して、規則の識別子を指定します。

SrgsRule(String, SrgsElement[])

SrgsElement オブジェクトの配列から SrgsRule クラスの新しいインスタンスを初期化します。

SrgsRule(String)

ソース:
SrgsRule.cs
ソース:
SrgsRule.cs
ソース:
SrgsRule.cs
ソース:
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

規則の識別子。

例外

idnullです。

id が空です。

id は適切な規則識別子ではありません。

次の例では、"ワールドカップで優勝した国" という語句の後に、ワールドカップで優勝した国の名前を認識する文法を作成します。 この例では、 という名前winnerRuleの オブジェクトをSrgsRule作成し、 としてString識別子WorldCupWinnerを渡します。 オブジェクトは 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 、次の状況で を FormatException スローします。

  • id は、 拡張マークアップ言語 (XML) 1.0 (第 5 版) で定義されている有効な XML 名ではありません。 この定義を言い換える場合、有効な XML 名は、文字、アンダースコア('_')、またはコロン (':') で始まる必要があり、その後に 0 個以上の NameChar 文字を付けることができます (XML 仕様でも定義されています)。

  • id が "NULL" または "VOID" または "GARBAGE" です。

  • id には、少なくとも 1 つの無効なルール ID 文字が含まれています。 これらの文字は、'?'、'*'、'+'、'|'、'('、')、'^'、'$'、'/'、';'、'=<>'、'['、']'、'{'、'}'、'\\'、'、'\t'、'\r'、'\n' です。

こちらもご覧ください

適用対象

SrgsRule(String, SrgsElement[])

ソース:
SrgsRule.cs
ソース:
SrgsRule.cs
ソース:
SrgsRule.cs
ソース:
SrgsRule.cs

SrgsElement オブジェクトの配列から SrgsRule クラスの新しいインスタンスを初期化します。

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 要素の配列。

例外

idnullです。

elementsnullです。

id が空です。

id は適切な規則識別子ではありません。

次の例では、"ワールドカップで優勝した国" という語句の後に、ワールドカップで優勝した国の名前を認識する文法を作成します。 この例では、 という名前 WorldCupWinnerのパブリック ルールを作成します。 次に、ruleEuropeルール識別子と ruleSAmericaオブジェクトを含むSrgsOneOf配列の をString渡す 2 つの SrgsRule オブジェクト と SrgsElement を作成します。 その後、この例では、規則 の との間で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 、次の状況で を FormatException スローします。

  • id は、 拡張マークアップ言語 (XML) 1.0 (第 5 版) で定義されている有効な XML 名ではありません。 この定義を言い換える場合、有効な XML 名は、文字、アンダースコア('_')、またはコロン (':') で始まる必要があり、その後に 0 個以上の NameChar 文字を付けることができます (XML 仕様でも定義されています)。

  • id が "NULL" または "VOID" または "GARBAGE" です。

  • id には、少なくとも 1 つの無効なルール ID 文字が含まれています。 これらの文字は、'?'、'*'、'+'、'|'、'('、')、'^'、'$'、'/'、';'、'=<>'、'['、']'、'{'、'}'、'\\'、'、'\t'、'\r'、'\n' です。

こちらもご覧ください

適用対象