Language

SrgsRule コンストラクター

定義

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

オーバーロード

Name 説明
SrgsRule(String)

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

SrgsRule(String, SrgsElement[])

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

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

ルールの識別子。

例外

id は nullです。

id が空です。

id が適切なルール識別子ではありません。

例

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

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 が適切なルール識別子ではありません。

例

次の例では、"A nation that has the world Cup is" という語句を認識し、その後にワールドカップで優勝した国の名前を認識する文法を作成します。 この例では、 WorldCupWinnerという名前のパブリック ルールを作成します。 次に、SrgsRuleとruleEuropeの 2 つのruleSAmerica オブジェクトを作成し、ルール識別子のStringと、SrgsElement オブジェクトを含むSrgsOneOf配列を渡します。 その後、この例では、ルールの参照をruleEuropeに追加し、ルール ruleSAmericaから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'です。

関連項目

適用対象