SrgsSemanticInterpretationTag 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表包含 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為該SrgsRuleRefcityRef物件所做SrgsRule的兩個參考分別指派一個語cities意鍵。 語意鍵將一個已認可的城市識別為航班的出發城市或抵達城市。 事件處理 SpeechRecognized 者會利用這些金鑰從識別結果中取得語意。
在程式碼範例中,「out」指的是包含 SrgsRule的規則變數。 「出去」這句話。「LeavingFrom」指的是規則變數在規則上LeavingFrom所命名bookFlight的屬性。
「rules.flightCities」這個表達式指的是規則上的規則變數,其 Id 為 flightCities,且是規則參考的目標。 在這個例子中,表達「out.leavevingFrom=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 語音 識別語意解釋(SISR)版本 1.0,其中包含腳本元素的格式 tag 為 semantics/1.0。 你必須指定使用此格式物件的 SrgsSemanticInterpretationTag 腳本。 在 的 semantics/1.0語法中:
- 包含規則元素的規則變數以「out」來識別。
- 能夠存取規則元素外規則變數的物件名稱,則以「rules」來識別。
- 最新引用規則與該語句相符的結果可用「rules.latest()」表示。
你也可以在文法中用物件,將語意值與文法中的片語關聯起來,而不必使用腳本 SrgsNameValueTag 。
建構函式
| 名稱 | Description |
|---|---|
| SrgsSemanticInterpretationTag() |
建立 SrgsSemanticInterpretationTag 類別的執行個體。 |
| SrgsSemanticInterpretationTag(String) |
建立類別的實例 SrgsSemanticInterpretationTag ,指定標籤的腳本內容。 |
屬性
| 名稱 | Description |
|---|---|
| Script |
取得或設定標籤的 ECMAScript 。 |
方法
| 名稱 | Description |
|---|---|
| CreateObjRef(Type) |
建立一個物件,包含產生代理伺服器所需的所有相關資訊,用於與遠端物件通訊。 (繼承來源 MarshalByRefObject) |
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetLifetimeService() |
已淘汰.
擷取控制這個實例存留期原則的目前存留期服務物件。 (繼承來源 MarshalByRefObject) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| InitializeLifetimeService() |
已淘汰.
取得存留期服務物件,以控制這個實例的存留期原則。 (繼承來源 MarshalByRefObject) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| MemberwiseClone(Boolean) |
建立目前 MarshalByRefObject 對象的淺層複本。 (繼承來源 MarshalByRefObject) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |