Bagikan melalui


SrgsRuleRef Konstruktor

Definisi

Menginisialisasi instans baru kelas SrgsRuleRef.

Overload

SrgsRuleRef(SrgsRule)

Menginisialisasi instans SrgsRuleRef baru kelas dan menentukan aturan untuk dirujuk.

SrgsRuleRef(Uri)

Menginisialisasi instans SrgsRuleRef baru kelas dan menentukan lokasi file tata bahasa eksternal ke referensi.

SrgsRuleRef(SrgsRule, String)

Menginisialisasi instans SrgsRuleRef baru kelas, menentukan aturan yang akan dirujuk dan string yang berisi kunci semantik.

SrgsRuleRef(Uri, String)

Menginisialisasi instans SrgsRuleRef baru kelas, menentukan lokasi file tata bahasa eksternal dan pengidentifikasi aturan yang akan dirujuk.

SrgsRuleRef(SrgsRule, String, String)

Menginisialisasi instans SrgsRuleRef baru kelas, menentukan aturan yang akan direferensikan, alias string kamus semantik, dan parameter inisialisasi.

SrgsRuleRef(Uri, String, String)

Menginisialisasi instans SrgsRuleRef baru kelas, menentukan lokasi file tata bahasa eksternal, pengidentifikasi aturan, dan alias string kamus semantik.

SrgsRuleRef(Uri, String, String, String)

Menginisialisasi instans SrgsRuleRef baru kelas, menentukan lokasi file tata bahasa eksternal, pengidentifikasi aturan, alias string kamus semantik, dan parameter inisialisasi.

SrgsRuleRef(SrgsRule)

Sumber:
SrgsRuleRef.cs
Sumber:
SrgsRuleRef.cs
Sumber:
SrgsRuleRef.cs

Menginisialisasi instans SrgsRuleRef baru kelas dan menentukan aturan untuk dirujuk.

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)

Parameter

rule
SrgsRule

Objek yang akan dirujuk.

Pengecualian

ruleadalah null.

Contoh

Contoh berikut membuat tata bahasa yang mengenali frasa "Bangsa yang telah memenangkan Piala Dunia adalah" diikuti dengan nama negara yang telah memenangkan Piala Dunia. Setelah membuat SrgsRule objek winnerRule dan memberinya pengidentifikasi WorldCupWinnerstring , contoh menambahkan string "Negara yang telah memenangkan Piala Dunia adalah" ke aturan. Menggunakan SrgsOneOf objek, contoh kemudian membangun daftar negara/wilayah Eropa dan daftar negara/wilayah Amerika Selatan, dan menambahkan setiap daftar ke aturan masing-masing, ruleEurope atau ruleSAmerica. Contoh kemudian membuat referensi aturan untuk ruleEurope dan ruleSAmerica dan menambahkannya ke WorldCupWinner aturan.

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

Tata bahasa yang dibuat memiliki formulir berikut.

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

Keterangan

Konstruktor ini membuat referensi aturan ke SrgsRule objek dalam tata bahasa yang berisi. Untuk membuat referensi aturan ke rule elemen dalam file tata bahasa eksternal, gunakan salah satu konstruktor berikut:

Lihat juga

Berlaku untuk

SrgsRuleRef(Uri)

Sumber:
SrgsRuleRef.cs
Sumber:
SrgsRuleRef.cs
Sumber:
SrgsRuleRef.cs

Menginisialisasi instans SrgsRuleRef baru kelas dan menentukan lokasi file tata bahasa eksternal ke referensi.

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)

Parameter

uri
Uri

Lokasi file tata bahasa di luar tata bahasa yang berisi.

Pengecualian

uriadalah null.

Contoh

Contoh berikut membuat tata bahasa untuk aplikasi yang mengembalikan informasi tentang layanan antar-jemput bus. Metode pertama, GrammarUrlForRoute, mengambil string yang menentukan rute dan menambahkannya ke string yang menentukan lokasi tata bahasa. Ini menentukan aturan tertentu dalam tata bahasa tersebut. Metode mengembalikan Uri untuk aturan tersebut.

Metode kedua, CreateGrammarForRoute, membuat elemen bernama SrgsDocumentgrammar dengan referensi aturan yang ditentukan oleh yang Uri diteruskan ke dalamnya oleh GrammarUrlForRoute. Perhatikan bahwa variabel bernama _route adalah anggota kelas penutup.

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

Catatan

Variabel bernama _route tidak dinyatakan dan tidak terdefinisi dalam sampel sebelumnya. Ini harus dinyatakan sebagai String dan berisi nomor rute untuk rute bus tertentu sebelum sampel sebelumnya dikompilasi dan dijalankan.

Keterangan

Konstruktor ini membuat referensi aturan ke file tata bahasa eksternal. URI juga dapat menyertakan pengidentifikasi aturan untuk dirujuk, misalnya http://www.contoso.com/ExternalGrammar.grxml#targetRule. uri Jika parameter tidak menentukan pengidentifikasi aturan, referensi aturan menunjuk ke aturan akar tata bahasa target. Untuk membuat referensi aturan ke SrgsRule objek dalam tata bahasa yang sama, gunakan salah satu konstruktor berikut:

Lihat juga

Berlaku untuk

SrgsRuleRef(SrgsRule, String)

Sumber:
SrgsRuleRef.cs
Sumber:
SrgsRuleRef.cs
Sumber:
SrgsRuleRef.cs

Menginisialisasi instans SrgsRuleRef baru kelas, menentukan aturan yang akan dirujuk dan string yang berisi kunci semantik.

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)

Parameter

rule
SrgsRule

Objek yang akan dirujuk.

semanticKey
String

Kunci semantik.

Contoh

Contoh berikut membuat tata bahasa untuk memilih kota untuk penerbangan. Contohnya membuat dua SrgsRuleRef instans, yang masing-masing menentukan kunci semantik. Kedua referensi aturan menargetkan objek yang sama SrgsRule , bernama cities, tetapi menandai hasil pengenalan dari referensi aturan dengan kunci semantik yang berbeda. Kunci semantik mengidentifikasi kota yang diakui sebagai kota keberangkatan atau kota kedatangan untuk penerbangan. Handler untuk SpeechRecognized peristiwa menggunakan kunci untuk mengambil nilai semantik yang dibuat menggunakan SrgsNameValueTag dari hasil pengenalan.

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

Keterangan

Konstruktor ini membuat referensi aturan ke SrgsRule objek dalam tata bahasa yang berisi. Untuk membuat referensi aturan ke rule elemen dalam file tata bahasa eksternal, gunakan salah satu konstruktor berikut:

Lihat juga

Berlaku untuk

SrgsRuleRef(Uri, String)

Sumber:
SrgsRuleRef.cs
Sumber:
SrgsRuleRef.cs
Sumber:
SrgsRuleRef.cs

Menginisialisasi instans SrgsRuleRef baru kelas, menentukan lokasi file tata bahasa eksternal dan pengidentifikasi aturan yang akan dirujuk.

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)

Parameter

uri
Uri

Lokasi file tata bahasa di luar tata bahasa yang berisi.

rule
String

Pengidentifikasi aturan untuk dirujuk.

Pengecualian

uriadalah null.

ruleadalah null.

Keterangan

Konstruktor ini membuat referensi aturan ke rule elemen dalam file tata bahasa eksternal. Untuk membuat referensi aturan ke SrgsRule objek dalam tata bahasa yang sama, gunakan salah satu konstruktor berikut:

Lihat juga

Berlaku untuk

SrgsRuleRef(SrgsRule, String, String)

Sumber:
SrgsRuleRef.cs
Sumber:
SrgsRuleRef.cs
Sumber:
SrgsRuleRef.cs

Menginisialisasi instans SrgsRuleRef baru kelas, menentukan aturan yang akan direferensikan, alias string kamus semantik, dan parameter inisialisasi.

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)

Parameter

rule
SrgsRule

Objek yang akan dirujuk.

semanticKey
String

Kunci semantik.

parameters
String

Parameter inisialisasi untuk SrgsRuleRef objek.

Keterangan

Konstruktor ini membuat referensi aturan ke SrgsRule objek dalam tata bahasa yang berisi. Untuk membuat referensi aturan ke rule elemen dalam file tata bahasa eksternal, gunakan salah satu konstruktor berikut:

Lihat juga

Berlaku untuk

SrgsRuleRef(Uri, String, String)

Sumber:
SrgsRuleRef.cs
Sumber:
SrgsRuleRef.cs
Sumber:
SrgsRuleRef.cs

Menginisialisasi instans SrgsRuleRef baru kelas, menentukan lokasi file tata bahasa eksternal, pengidentifikasi aturan, dan alias string kamus semantik.

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)

Parameter

uri
Uri

Lokasi file tata bahasa di luar tata bahasa yang berisi.

rule
String

Pengidentifikasi aturan untuk dirujuk.

semanticKey
String

String alias untuk kamus semantik.

Pengecualian

uriadalah null.

semanticKeyadalah null.

semanticKey kosong.

Keterangan

Konstruktor ini membuat referensi aturan ke rule elemen dalam file tata bahasa eksternal. Untuk membuat referensi aturan ke SrgsRule objek dalam tata bahasa yang sama, gunakan salah satu konstruktor berikut:

Lihat juga

Berlaku untuk

SrgsRuleRef(Uri, String, String, String)

Sumber:
SrgsRuleRef.cs
Sumber:
SrgsRuleRef.cs
Sumber:
SrgsRuleRef.cs

Menginisialisasi instans SrgsRuleRef baru kelas, menentukan lokasi file tata bahasa eksternal, pengidentifikasi aturan, alias string kamus semantik, dan parameter inisialisasi.

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)

Parameter

uri
Uri

Lokasi file tata bahasa di luar tata bahasa yang berisi.

rule
String

Pengidentifikasi aturan untuk dirujuk.

semanticKey
String

Kunci semantik.

parameters
String

Parameter inisialisasi untuk SrgsRuleRef objek.

Keterangan

Konstruktor ini membuat referensi aturan ke rule elemen dalam file tata bahasa eksternal. Untuk membuat referensi aturan ke SrgsRule objek dalam tata bahasa yang sama, gunakan salah satu konstruktor berikut:

Lihat juga

Berlaku untuk