SrgsSemanticInterpretationTag クラス

定義

ルールが一致したときに実行される ECMAScript を含むタグを表します。

public ref class SrgsSemanticInterpretationTag : System::Speech::Recognition::SrgsGrammar::SrgsElement
public class SrgsSemanticInterpretationTag : System.Speech.Recognition.SrgsGrammar.SrgsElement
[System.Serializable]
public class SrgsSemanticInterpretationTag : System.Speech.Recognition.SrgsGrammar.SrgsElement
type SrgsSemanticInterpretationTag = class
    inherit SrgsElement
[<System.Serializable>]
type SrgsSemanticInterpretationTag = class
    inherit SrgsElement
Public Class SrgsSemanticInterpretationTag
Inherits SrgsElement
継承
SrgsSemanticInterpretationTag
属性

次の例では、フライトの都市を選択するための文法を作成します。 この例では、 SrgsSemanticInterpretationTag を使用して、都市の空港のコードである各都市にセマンティック値を割り当てます。 この例では、SrgsSemanticInterpretationTagを使用して、SrgsRuleRefという名前のcityRef オブジェクトによって作成された 2 つの参照のそれぞれに対して、SrgsRuleという名前のcities オブジェクトに個別のセマンティック キーを割り当てます。 セマンティック キーは、フライトの出発都市または到着都市として認識された都市を識別します。 SpeechRecognized イベントのハンドラーは、キーを使用して認識結果からセマンティクスを取得します。

コード例では、"out" は、含まれる SrgsRuleのルール変数を参照します。 式 "out.LeavingFrom" は、LeavingFromという名前のルールのルール変数のbookFlightという名前のプロパティを参照します。

式 "rules.flightCities" は、 IdflightCitiesであり、ルール参照のターゲットであるルールのルール変数を参照します。 この例では、式 "out.LeavingFrom=rules.flightCities;" は、IdflightCitiesされたルールの値を、LeavingFromという名前のルールのルール変数のbookFlightという名前のプロパティに割り当てます。 詳細については、「 セマンティック結果のコンテンツ」、「 文法規則の名前の参照」、「 文法規則参照の参照」 を参照してください。

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")))
      {

        // Create a rule for the cities, assign a semantic value to each city.
        SrgsRule cities = new SrgsRule("flightCities");
        SrgsItem chi = new SrgsItem("Chicago");
        chi.Add(new SrgsSemanticInterpretationTag("out = \"ORD\";"));
        SrgsItem bos = new SrgsItem("Boston");
        bos.Add(new SrgsSemanticInterpretationTag("out = \"BOS\";"));
        SrgsItem mia = new SrgsItem("Miami");
        mia.Add(new SrgsSemanticInterpretationTag("out = \"MIA\";"));
        SrgsItem dal = new SrgsItem("Dallas");
        dal.Add(new SrgsSemanticInterpretationTag("out = \"DFW\";"));

        SrgsOneOf airports = new SrgsOneOf(chi, bos, mia, dal);
        cities.Add(airports);
        cities.Scope = SrgsRuleScope.Private;

        // Create a rule reference to the rule for cities.
        SrgsRuleRef cityRef = new SrgsRuleRef(cities);

        // Create the root rule for the grammar.
        SrgsRule bookFlight = new SrgsRule("flightBooker");
        bookFlight.Add(new SrgsItem("I want to fly from"));
        bookFlight.Add(cityRef);
        bookFlight.Add(new SrgsSemanticInterpretationTag("out.LeavingFrom=rules.flightCities;"));
        bookFlight.Add(new SrgsItem("to"));
        bookFlight.Add(cityRef);
        bookFlight.Add(new SrgsSemanticInterpretationTag("out.GoingTo=rules.flightCities;"));
        bookFlight.Scope = SrgsRuleScope.Public;

        // Initialize the SrgsDocument, set the root rule, add rules to the collection.
        SrgsDocument itinerary = new SrgsDocument(bookFlight);
        itinerary.Rules.Add(cities);

        // Create a Grammar object and load it to the recognizer.
        Grammar g = new Grammar(itinerary);
        g.Name = ("City Chooser");
        recognizer.LoadGrammarAsync(g);

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

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

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

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

    // Write to the console the text and the semantics from the recognition result.
    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["LeavingFrom"].Value);
      Console.WriteLine("  The arrival city is: " + e.Result.Semantics["GoingTo"].Value);
    }
  }
}

上記の例のコードによって生成される文法の XML 形式を次に示します。

<?xml version="1.0" encoding="utf-8"?>
<grammar xml:lang="en-US" root="flightBooker" tag-format="semantics/1.0"
version="1.0" xmlns="http://www.w3.org/2001/06/grammar">

  <rule id="flightBooker" scope="public">
    <item> I want to fly from </item>
    <ruleref uri="#flightCities" />
    <tag> out.LeavingFrom=rules.flightCities; </tag>
    <item> to </item>
    <ruleref uri="#flightCities" />
    <tag> out.GoingTo=rules.flightCities; </tag>
  </rule>

  <rule id="flightCities" scope="private">
    <one-of>
      <item> Chicago <tag> out="ORD"; </tag></item>
      <item> Boston <tag> out="BOS"; </tag></item>
      <item> Miami <tag> out="MIA"; </tag></item>
      <item> Dallas <tag> out="DFW"; </tag></item>
    </one-of>
  </rule>

</grammar>

注釈

System.Speech の既定のセマンティック形式は、W3C Semantic Interpretation for Speech Recognition (SISR) バージョン 1.0 に準拠しています。ここで、スクリプトを含む tag 要素の形式は semantics/1.0。 この形式を使用して、 SrgsSemanticInterpretationTag オブジェクトのスクリプトを指定する必要があります。 semantics/1.0の構文:

  • 含まれているルール要素の Rule 変数は、"out" で識別されます。
  • 含まれるルール要素の外部にあるルール要素の Rule 変数にアクセスできるオブジェクトの名前は、"rules" によって識別されます。
  • 発話に一致する最新の参照先ルールの結果は、"rules.latest()" で表すことができます。

また、 SrgsNameValueTag オブジェクトを使用して、スクリプトを使用せずに文法内の語句にセマンティック値を関連付けることもできます。

コンストラクター

名前 説明
SrgsSemanticInterpretationTag()

SrgsSemanticInterpretationTag クラスのインスタンスを作成します。

SrgsSemanticInterpretationTag(String)

タグのスクリプトの内容を指定して、 SrgsSemanticInterpretationTag クラスのインスタンスを作成します。

プロパティ

名前 説明
Script

タグの ECMAScript を取得または設定します。

メソッド

名前 説明
CreateObjRef(Type)

リモート オブジェクトとの通信に使用されるプロキシの生成に必要なすべての関連情報を含むオブジェクトを作成します。

(継承元 MarshalByRefObject)
Equals(Object)

指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetLifetimeService()
古い.

このインスタンスの有効期間ポリシーを制御する現在の有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
InitializeLifetimeService()
古い.

このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
MemberwiseClone(Boolean)

現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。

(継承元 MarshalByRefObject)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象