SrgsSemanticInterpretationTag クラス

定義

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

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

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

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

式 "rules.flightCities" は、 が flightCitiesで、ルール参照のターゲットであるルールIdのルール変数を参照します。 この例では、式 "out.LeavingFrom=rules.flightCities;" はflightCities、 を持つIdルールの値を、 という名前のルールの Rule Variable という名前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)

適用対象