Bagikan melalui


SrgsSemanticInterpretationTag Kelas

Definisi

Mewakili tag yang berisi ECMAScript yang dijalankan saat aturan dicocokkan.

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
Warisan
SrgsSemanticInterpretationTag
Atribut

Contoh

Contoh berikut membuat tata bahasa untuk memilih kota untuk penerbangan. Contohnya menggunakan SrgsSemanticInterpretationTag untuk menetapkan nilai semantik ke setiap kota, yang merupakan kode untuk bandara kota. Contoh ini juga menggunakan SrgsSemanticInterpretationTag untuk menetapkan kunci semantik terpisah untuk masing-masing dari dua referensi yang SrgsRuleRef dibuat oleh objek bernama cityRef ke SrgsRule objek bernama cities. Kunci semantik mengidentifikasi kota yang diakui sebagai kota keberangkatan atau kota kedatangan untuk penerbangan. Handler untuk SpeechRecognized peristiwa menggunakan kunci untuk mengambil semantik dari hasil pengenalan.

Dalam contoh kode, "out" mengacu pada Variabel Aturan yang berisi SrgsRule. Ekspresi "keluar. LeavingFrom" mengacu pada properti bernama LeavingFrom Variabel Aturan pada aturan bernama bookFlight.

Ekspresi "rules.flightCities" mengacu pada Variabel Aturan pada aturan yang Id merupakan flightCities, dan yang merupakan target referensi aturan. Dalam contoh, ekspresi "keluar. LeavingFrom=rules.flightCities;" menetapkan nilai dari aturan yang Id merupakan properti bernama LeavingFrom Variabel Aturan pada aturan bernama bookFlightflightCities . Lihat Konten Hasil Semantik, Referensi Nama Aturan Tata Bahasa, dan Referensi Aturan Tata Bahasa untuk informasi selengkapnya.

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

Berikut ini adalah bentuk XML tata bahasa yang dihasilkan oleh kode dalam contoh di atas.

<?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>  

Keterangan

Format semantik default untuk System.Speech sesuai dengan Interpretasi Semantik W3C untuk Pengenalan Ucapan (SISR) Versi 1.0, di mana format untuk tag elemen yang berisi skrip adalah semantics/1.0. Anda harus menentukan skrip untuk SrgsSemanticInterpretationTag objek menggunakan format ini. Dalam sintaks :semantics/1.0

  • Variabel Aturan dari elemen aturan yang berisi diidentifikasi oleh "out".

  • Nama objek yang memiliki akses ke Variabel Aturan elemen aturan di luar elemen aturan yang berisi diidentifikasi oleh "aturan".

  • Hasil dari aturan referensi terbaru yang cocok dengan ucapan dapat diwakili oleh "rules.latest()".

Anda juga dapat mengaitkan nilai semantik dengan frasa dalam tata bahasa tanpa menggunakan skrip, menggunakan SrgsNameValueTag objek .

Konstruktor

SrgsSemanticInterpretationTag()

Membuat instans SrgsSemanticInterpretationTag kelas .

SrgsSemanticInterpretationTag(String)

Membuat instans SrgsSemanticInterpretationTag kelas, menentukan konten skrip tag.

Properti

Script

Mendapatkan atau mengatur ECMAScript untuk tag.

Metode

CreateObjRef(Type)

Membuat objek yang berisi semua informasi relevan yang diperlukan untuk menghasilkan proksi yang digunakan untuk berkomunikasi dengan objek jarak jauh.

(Diperoleh dari MarshalByRefObject)
Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetLifetimeService()
Kedaluwarsa.

Mengambil objek layanan seumur hidup saat ini yang mengontrol kebijakan seumur hidup untuk instans ini.

(Diperoleh dari MarshalByRefObject)
GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
InitializeLifetimeService()
Kedaluwarsa.

Mendapatkan objek layanan seumur hidup untuk mengontrol kebijakan seumur hidup untuk instans ini.

(Diperoleh dari MarshalByRefObject)
MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
MemberwiseClone(Boolean)

Membuat salinan dangkal objek saat ini MarshalByRefObject .

(Diperoleh dari MarshalByRefObject)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Berlaku untuk