次の方法で共有


SrgsRuleRef コンストラクター

定義

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

オーバーロード

SrgsRuleRef(SrgsRule)

SrgsRuleRef クラスの新しいインスタンスを初期化して、参照するルールを指定します。

SrgsRuleRef(Uri)

SrgsRuleRef クラスの新しいインスタンスを初期化し、参照する外部文法ファイルの場所を指定します。

SrgsRuleRef(SrgsRule, String)

SrgsRuleRef クラスの新しいインスタンスを初期化し、参照する規則およびセマンティクス キーを含む文字列を指定します。

SrgsRuleRef(Uri, String)

SrgsRuleRef クラスの新しいインスタンスを初期化し、参照する外部文法ファイルの場所および規則の識別子を指定します。

SrgsRuleRef(SrgsRule, String, String)

SrgsRuleRef クラスの新しいインスタンスを初期化し、参照する規則、セマンティクス ディクショナリの文字列エイリアス、および初期化パラメーターを指定します。

SrgsRuleRef(Uri, String, String)

SrgsRuleRef クラスの新しいインスタンスを初期化し、外部文法ファイルの場所、規則の識別子、およびセマンティクス ディクショナリの文字列エイリアスを指定します。

SrgsRuleRef(Uri, String, String, String)

SrgsRuleRef クラスの新しいインスタンスを初期化し、外部文法ファイルの場所、規則の識別子、セマンティクス ディクショナリの文字列エイリアス、および初期化パラメーターを指定します。

SrgsRuleRef(SrgsRule)

ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs

SrgsRuleRef クラスの新しいインスタンスを初期化して、参照するルールを指定します。

public:
 SrgsRuleRef(System::Speech::Recognition::SrgsGrammar::SrgsRule ^ rule);
public SrgsRuleRef (System.Speech.Recognition.SrgsGrammar.SrgsRule rule);
new System.Speech.Recognition.SrgsGrammar.SrgsRuleRef : System.Speech.Recognition.SrgsGrammar.SrgsRule -> System.Speech.Recognition.SrgsGrammar.SrgsRuleRef
Public Sub New (rule As SrgsRule)

パラメーター

rule
SrgsRule

参照するオブジェクト。

例外

rulenullです。

次の例では、"ワールドカップで優勝した国" という語句に続いて、ワールドカップで優勝した国の名前を認識する文法を作成します。 オブジェクトwinnerRuleSrgsRule作成し、文字列識別子WorldCupWinnerを指定した後、この例では、文字列 "A nation that has won the World Cup is" をルールに追加します。 オブジェクトを使用して SrgsOneOf 、ヨーロッパの国/地域の一覧と南アメリカの国/地域の一覧を作成し、それぞれのルール ruleEurope () ruleSAmericaに各リストを追加します。 次に、 と のルール参照をruleEuroperuleSAmerica作成し、ルールにWorldCupWinner追加します。

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;
}

作成された文法の形式は次のとおりです。

<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 ルール参照を作成します。 外部文法ファイル内の要素への rule ルール参照を作成するには、次のいずれかのコンストラクターを使用します。

こちらもご覧ください

適用対象

SrgsRuleRef(Uri)

ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs

SrgsRuleRef クラスの新しいインスタンスを初期化し、参照する外部文法ファイルの場所を指定します。

public:
 SrgsRuleRef(Uri ^ uri);
public SrgsRuleRef (Uri uri);
new System.Speech.Recognition.SrgsGrammar.SrgsRuleRef : Uri -> System.Speech.Recognition.SrgsGrammar.SrgsRuleRef
Public Sub New (uri As Uri)

パラメーター

uri
Uri

包含する文法の外部の文法ファイルの場所。

例外

urinullです。

次の例では、バス シャトル サービスに関する情報を返すアプリケーションの文法を作成します。 最初のメソッド である は、 GrammarUrlForRouteルートを指定する文字列を受け取り、文法の場所を指定する文字列に追加します。 これは、その文法の特定の規則を指定します。 メソッドは、そのルールの を Uri 返します。

2 番目のメソッド である は、 CreateGrammarForRouteによってGrammarUrlForRoute渡された によって指定されたルール参照を持つ という名前grammarUri要素を作成SrgsDocumentします。 _route という名前の変数は、外側のクラスのメンバーであることに注意してください。

private Uri GrammarUrlForRoute(string route)
{
  return new Uri("http://localhost/MyBus/MyBusLocations.grxml#LocationsForRoute" + route);
}

private SrgsDocument CreateGrammarForRoute()
{
  SrgsDocument grammar = new SrgsDocument();
  grammar.Mode = SrgsGrammarMode.Voice;
  SrgsRule rule = new SrgsRule("LocationsForRoute" + _route);
  SrgsRuleRef ruleref = new SrgsRuleRef(GrammarUrlForRoute(_route));

  SrgsSemanticInterpretationTag tag = new SrgsSemanticInterpretationTag ("$.Location = $$");

  rule.Elements.Add(ruleref);
  rule.Elements.Add(tag);
  grammar.Rules.Add(rule);
  grammar.Root = rule;
  return grammar;
}

注意

_route という名前の変数は宣言されておらず、前のサンプルでは未定義です。 前のサンプルをコンパイルして実行する前に、 として String 宣言し、特定のバス ルートのルート番号を含める必要があります。

注釈

このコンストラクターは、外部文法ファイルへのルール参照を作成します。 URI には、参照するルールの識別子 (例: http://www.contoso.com/ExternalGrammar.grxml#targetRule) を含めることもできます。 パラメーターで uri ルール識別子が指定されていない場合、ルール参照はターゲット文法のルート規則を指します。 同じ文法内でオブジェクトへのルール参照を SrgsRule 作成するには、次のいずれかのコンストラクターを使用します。

こちらもご覧ください

適用対象

SrgsRuleRef(SrgsRule, String)

ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs

SrgsRuleRef クラスの新しいインスタンスを初期化し、参照する規則およびセマンティクス キーを含む文字列を指定します。

public:
 SrgsRuleRef(System::Speech::Recognition::SrgsGrammar::SrgsRule ^ rule, System::String ^ semanticKey);
public SrgsRuleRef (System.Speech.Recognition.SrgsGrammar.SrgsRule rule, string semanticKey);
new System.Speech.Recognition.SrgsGrammar.SrgsRuleRef : System.Speech.Recognition.SrgsGrammar.SrgsRule * string -> System.Speech.Recognition.SrgsGrammar.SrgsRuleRef
Public Sub New (rule As SrgsRule, semanticKey As String)

パラメーター

rule
SrgsRule

参照するオブジェクト。

semanticKey
String

セマンティクス キー。

次の例では、フライトの都市を選択するための文法を作成します。 この例では、セマンティック キーを指定する 2 つの SrgsRuleRef インスタンスを構築します。 両方のルール参照は、 という名前citiesの同じSrgsRuleオブジェクトをターゲットにしますが、ルール参照からの認識結果に別のセマンティック キーでタグを付けます。 セマンティック キーは、フライトの出発都市または到着都市として認識された都市を識別します。 イベントのハンドラーは、 SpeechRecognized キーを使用して、認識結果から を使用して SrgsNameValueTag 作成されたセマンティクス値を取得します。

using System;
using System.Speech.Recognition;
using System.Speech.Recognition.SrgsGrammar;

namespace SampleRecognition
{
  class Program
  {
    static void Main(string[] args)

    // Initialize a SpeechRecognitionEngine object.
    {
      using (SpeechRecognitionEngine recognizer =
         new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")))
      {

        // Build a rule with a list of cities, assign a semantic value to each city.
        SrgsItem chi = new SrgsItem("Chicago");
        chi.Add(new SrgsNameValueTag("ORD"));
        SrgsItem bos = new SrgsItem("Boston");
        bos.Add(new SrgsNameValueTag("BOS"));
        SrgsItem mia = new SrgsItem("Miami");
        mia.Add(new SrgsNameValueTag("MIA"));
        SrgsItem dal = new SrgsItem("Dallas");
        dal.Add(new SrgsNameValueTag("DFW"));

        SrgsOneOf cities = new SrgsOneOf(new SrgsItem[] { chi, bos, mia, dal });
        SrgsRule citiesRule = new SrgsRule("flightCities");
        citiesRule.Add(cities);

        // Build the root rule, add rule references to the cities rule.
        SrgsRule flightBooker = new SrgsRule("bookFlight");
        flightBooker.Add(new SrgsItem("I want to fly from"));
        flightBooker.Add(new SrgsRuleRef(citiesRule, "departureCity"));
        flightBooker.Add(new SrgsItem("to"));
        flightBooker.Add(new SrgsRuleRef(citiesRule, "arrivalCity"));

        // Build an SrgsDocument object from the flightBooker rule and add the cities rule.
        SrgsDocument cityChooser = new SrgsDocument(flightBooker);
        cityChooser.Rules.Add(citiesRule);

        // Create a Grammar object from the SrgsDocument and load it to the recognizer.
        Grammar departArrive = new Grammar(cityChooser);
        departArrive.Name = ("Cities Grammar");
        recognizer.LoadGrammarAsync(departArrive);

        // Configure recognizer input.
        recognizer.SetInputToDefaultAudioDevice();

        // Attach a handler for the SpeechRecognized event.
        recognizer.SpeechRecognized +=
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);

        // Start asynchronous recognition.
        recognizer.RecognizeAsync();
        Console.WriteLine("Starting asynchronous recognition...");

        // Keep the console window open.
        Console.ReadLine();
      }
    }

    // Handle the SpeechRecognized event.
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
      Console.WriteLine("Speech recognized: " + e.Result.Text);
      Console.WriteLine();
      Console.WriteLine("Semantic results:");
      Console.WriteLine("  The departure city is: " + e.Result.Semantics["departureCity"].Value);
      Console.WriteLine("  The destination city is: " + e.Result.Semantics["arrivalCity"].Value);
    }
  }
}

注釈

このコンストラクターは、文法を含む オブジェクトへの SrgsRule ルール参照を作成します。 外部文法ファイル内の要素への rule ルール参照を作成するには、次のいずれかのコンストラクターを使用します。

こちらもご覧ください

適用対象

SrgsRuleRef(Uri, String)

ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs

SrgsRuleRef クラスの新しいインスタンスを初期化し、参照する外部文法ファイルの場所および規則の識別子を指定します。

public:
 SrgsRuleRef(Uri ^ uri, System::String ^ rule);
public SrgsRuleRef (Uri uri, string rule);
new System.Speech.Recognition.SrgsGrammar.SrgsRuleRef : Uri * string -> System.Speech.Recognition.SrgsGrammar.SrgsRuleRef
Public Sub New (uri As Uri, rule As String)

パラメーター

uri
Uri

包含する文法の外部の文法ファイルの場所。

rule
String

参照するルールの識別子。

例外

urinull です。

rulenullです。

rule が空です。

注釈

このコンストラクターは、外部文法ファイル内の rule 要素へのルール参照を作成します。 同じ文法内でオブジェクトへのルール参照を SrgsRule 作成するには、次のいずれかのコンストラクターを使用します。

こちらもご覧ください

適用対象

SrgsRuleRef(SrgsRule, String, String)

ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs

SrgsRuleRef クラスの新しいインスタンスを初期化し、参照する規則、セマンティクス ディクショナリの文字列エイリアス、および初期化パラメーターを指定します。

public:
 SrgsRuleRef(System::Speech::Recognition::SrgsGrammar::SrgsRule ^ rule, System::String ^ semanticKey, System::String ^ parameters);
public SrgsRuleRef (System.Speech.Recognition.SrgsGrammar.SrgsRule rule, string semanticKey, string parameters);
new System.Speech.Recognition.SrgsGrammar.SrgsRuleRef : System.Speech.Recognition.SrgsGrammar.SrgsRule * string * string -> System.Speech.Recognition.SrgsGrammar.SrgsRuleRef
Public Sub New (rule As SrgsRule, semanticKey As String, parameters As String)

パラメーター

rule
SrgsRule

参照するオブジェクト。

semanticKey
String

セマンティクス キー。

parameters
String

SrgsRuleRef オブジェクトの初期化パラメーター。

注釈

このコンストラクターは、文法を含む オブジェクトへの SrgsRule ルール参照を作成します。 外部文法ファイル内の要素への rule ルール参照を作成するには、次のいずれかのコンストラクターを使用します。

こちらもご覧ください

適用対象

SrgsRuleRef(Uri, String, String)

ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs

SrgsRuleRef クラスの新しいインスタンスを初期化し、外部文法ファイルの場所、規則の識別子、およびセマンティクス ディクショナリの文字列エイリアスを指定します。

public:
 SrgsRuleRef(Uri ^ uri, System::String ^ rule, System::String ^ semanticKey);
public SrgsRuleRef (Uri uri, string rule, string semanticKey);
new System.Speech.Recognition.SrgsGrammar.SrgsRuleRef : Uri * string * string -> System.Speech.Recognition.SrgsGrammar.SrgsRuleRef
Public Sub New (uri As Uri, rule As String, semanticKey As String)

パラメーター

uri
Uri

包含する文法の外部の文法ファイルの場所。

rule
String

参照するルールの識別子。

semanticKey
String

セマンティクス ディクショナリのエイリアスの文字列。

例外

urinull です。

semanticKeynullです。

semanticKey が空です。

注釈

このコンストラクターは、外部文法ファイル内の rule 要素へのルール参照を作成します。 同じ文法内でオブジェクトへのルール参照を SrgsRule 作成するには、次のいずれかのコンストラクターを使用します。

こちらもご覧ください

適用対象

SrgsRuleRef(Uri, String, String, String)

ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs
ソース:
SrgsRuleRef.cs

SrgsRuleRef クラスの新しいインスタンスを初期化し、外部文法ファイルの場所、規則の識別子、セマンティクス ディクショナリの文字列エイリアス、および初期化パラメーターを指定します。

public:
 SrgsRuleRef(Uri ^ uri, System::String ^ rule, System::String ^ semanticKey, System::String ^ parameters);
public SrgsRuleRef (Uri uri, string rule, string semanticKey, string parameters);
new System.Speech.Recognition.SrgsGrammar.SrgsRuleRef : Uri * string * string * string -> System.Speech.Recognition.SrgsGrammar.SrgsRuleRef
Public Sub New (uri As Uri, rule As String, semanticKey As String, parameters As String)

パラメーター

uri
Uri

包含する文法の外部の文法ファイルの場所。

rule
String

参照するルールの識別子。

semanticKey
String

セマンティクス キー。

parameters
String

SrgsRuleRef オブジェクトの初期化パラメーター。

注釈

このコンストラクターは、外部文法ファイル内の rule 要素へのルール参照を作成します。 同じ文法内でオブジェクトへのルール参照を SrgsRule 作成するには、次のいずれかのコンストラクターを使用します。

こちらもご覧ください

適用対象