SrgsNameValueTag 构造函数

定义

初始化 SrgsNameValueTag 类的新实例。

重载

SrgsNameValueTag()

初始化 SrgsNameValueTag 类的新实例。

SrgsNameValueTag(Object)

在指定实例值的情况下,初始化 SrgsNameValueTag 类的新实例。

SrgsNameValueTag(String, Object)

初始化 SrgsNameValueTag 类的新实例,同时指定实例的名称和值。

SrgsNameValueTag()

Source:
SrgsNameValueTag.cs
Source:
SrgsNameValueTag.cs
Source:
SrgsNameValueTag.cs

初始化 SrgsNameValueTag 类的新实例。

public:
 SrgsNameValueTag();
public SrgsNameValueTag ();
Public Sub New ()

适用于

SrgsNameValueTag(Object)

Source:
SrgsNameValueTag.cs
Source:
SrgsNameValueTag.cs
Source:
SrgsNameValueTag.cs

在指定实例值的情况下,初始化 SrgsNameValueTag 类的新实例。

public:
 SrgsNameValueTag(System::Object ^ value);
public SrgsNameValueTag (object value);
new System.Speech.Recognition.SrgsGrammar.SrgsNameValueTag : obj -> System.Speech.Recognition.SrgsGrammar.SrgsNameValueTag
Public Sub New (value As Object)

参数

value
Object

用于设置此 Value 属性的值。

例外

valuenull

示例

以下示例创建一个语法,用于为外部测试版选择城市。 该示例使用 SrgsNameValueTag 将语义值分配给每个城市,即城市机场的代码。

该示例构造两 SrgsRuleRef 个实例,每个实例指定一个语义键。 这两个规则引用都针对同一 SrgsRule 个名为 cities的对象,但使用不同的语义键标记规则引用的识别结果。 语义键将已识别的城市标识为航班的出发城市或到达城市。 事件的处理程序 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);  
    }  
  }  
}  

适用于

SrgsNameValueTag(String, Object)

Source:
SrgsNameValueTag.cs
Source:
SrgsNameValueTag.cs
Source:
SrgsNameValueTag.cs

初始化 SrgsNameValueTag 类的新实例,同时指定实例的名称和值。

public:
 SrgsNameValueTag(System::String ^ name, System::Object ^ value);
public SrgsNameValueTag (string name, object value);
new System.Speech.Recognition.SrgsGrammar.SrgsNameValueTag : string * obj -> System.Speech.Recognition.SrgsGrammar.SrgsNameValueTag
Public Sub New (name As String, value As Object)

参数

name
String

Name对象上用于设置 SrgsNameValueTag 属性的字符串。

value
Object

Value对象上用于设置 SrgsNameValueTag 属性的对象。

例外

value 上声明的默认值为 null

name 上声明的默认值为 null

name 是一个空字符串。

适用于