SemanticValue SemanticValue SemanticValue SemanticValue Class

定義

表示已辨識片語的語意組織。Represents the semantic organization of a recognized phrase.

public ref class SemanticValue sealed : System::Collections::Generic::ICollection<System::Collections::Generic::KeyValuePair<System::String ^, System::Speech::Recognition::SemanticValue ^>>, System::Collections::Generic::IDictionary<System::String ^, System::Speech::Recognition::SemanticValue ^>, System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<System::String ^, System::Speech::Recognition::SemanticValue ^>>
[System.Serializable]
public sealed class SemanticValue : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string,System.Speech.Recognition.SemanticValue>>, System.Collections.Generic.IDictionary<string,System.Speech.Recognition.SemanticValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string,System.Speech.Recognition.SemanticValue>>
type SemanticValue = class
    interface IDictionary<string, SemanticValue>
    interface ICollection<KeyValuePair<string, SemanticValue>>
    interface seq<KeyValuePair<string, SemanticValue>>
    interface IEnumerable
Public NotInheritable Class SemanticValue
Implements ICollection(Of KeyValuePair(Of String, SemanticValue)), IDictionary(Of String, SemanticValue), IEnumerable(Of KeyValuePair(Of String, SemanticValue))
繼承
SemanticValueSemanticValueSemanticValueSemanticValue
屬性
實作

範例

下列範例會顯示事件的處理常式SpeechRecognized , 其設計目的是要處理用來變更前景和背景色彩的命令。The following example shows a handler for a SpeechRecognized event designed to handle commands to change foreground and background color.

處理常式會藉由Count偵測的零Value和的null, 識別沒有基礎語義結構的已辨識片語。The handler identifies recognized phrases that have no underlying semantic structure by detecting a Count of zero and a Value of null. 此辨識輸出接著會藉由剖析原始文字來直接處理。This recognition output is then processed directly by parsing the raw text.

在其他情況下, 處理常式會使用索引鍵來取得色彩名稱的 RGB 元件, 以判斷命令是否會變更前景或背景, 或表示找不到有效的索引鍵。In other cases, the handler uses keys to obtain the RGB components of a color name, to determine whether the command will change the foreground or background, or to indicate that no valid key was found.


newGrammar.SpeechRecognized +=  
  delegate(object sender, SpeechRecognizedEventArgs eventArgs)   
  {  

    // Retrieve the value of the semantic property.  
    bool changeBackGround = true;  
    string errorString = "";  
    SemanticValue semantics = eventArgs.Result.Semantics;  

    Color newColor = Color.Empty;  

    try   
    {  
      if (semantics.Count == 0 && semantics.Value==null)  
      {  
        // Signifies recognition by a grammar with no semantics.  
        // Parse the string, assuming that the last word is color,  
        // and search for "background" or "foreground" in the input.  
        if (eventArgs.Result.Text.Contains("foreground"))   
        {  
          changeBackGround = false;  
        }  
        string cName = eventArgs.Result.Words[eventArgs.Result.Words.Count - 1].Text;  
        newColor = Color.FromName(cName);  

      }  
      else if (semantics.ContainsKey("colorStringList") ^ semantics.ContainsKey("colorRGBValueList"))   
      {  

        // Determine whether to change background or foreground.  
        if (semantics.ContainsKey("applyChgToBackground"))   
        {  
          changeBackGround = semantics["applyChgToBackground"].Value is bool;  
        }  

        // Get the RGB color value.  
        if (semantics.ContainsKey("colorStringList"))   
        {  
          newColor = Color.FromName((string)semantics["colorStringList"].Value);  
        }  
        if (semantics.ContainsKey("colorRGBValueList"))   
        {  
          newColor = System.Drawing.Color.FromArgb((int)semantics["colorRGBValueList"].Value);  
        }  
      }  
      else   
      {  

        // Throw an exception if the semantics do not contain the keys we  
        // support.  
        throw(new Exception("Unsupported semantics keys found."));  
      }  
    }  

    catch (Exception exp)   
    {  
      MessageBox.Show(String.Format("Unable to process color semantics.:\n{0}\n", exp.Message));  
      return;  
    }  

    // Change colors, either foreground or background.  
    if (changeBackGround)   
    {  
      BackColor = newColor;  
      float Bright = BackColor.GetBrightness();  
      float Hue = BackColor.GetHue();  
      float Sat = BackColor.GetSaturation();  

      // Make sure that text is readable regardless of the background.  
      if (BackColor.GetBrightness() <= .50)   
      {  
        ForeColor = Color.White;  
      }  
      else   
      {  
        ForeColor = Color.Black;  
      }  
    }  
    else   
    {  
      ForeColor = newColor;  
      float Bright = ForeColor.GetBrightness();  
      float Hue = ForeColor.GetHue();  
      float Sat = ForeColor.GetSaturation();  

      // Make sure that text is readable regardless of Foreground.  
      if (ForeColor.GetBrightness() <= .50)   
      {  
        BackColor = Color.White;  
      }  
      else   
      {  
        BackColor = Color.Black;  
      }  
    }  
    return;  
  };  

備註

SemanticValue是在 System.object 中執行語義技術的主要物件。SemanticValue is the primary object that implements the semantic technology in System.Speech. 語義轉譯可讓文法定義辨識引擎用來正確解讀音訊輸入的規則。Semantic interpretation allows grammars to define rules for use by a recognition engine to correctly interpret audio input. 語義轉譯也可以讓辨識引擎組織其結果, 以便更輕鬆地處理它們, 而不只是傳回已辨識的單字和單字的順序。Semantic interpretation also enables recognition engines to organize their results so that they can be more easily processed, rather than returning only recognized words and sequences of words.

例如, 辨識引擎輸出「將背景變更為紅色」, 必須先經過應用程式剖析和解讀, 然後才能處理。For example, the recognition engine output "Change background to red" would have to be parsed and interpreted by an application before it could be acted upon. Grammar物件可以指定語義轉譯, 藉由指定片語有兩個語義子結構, 一個用於選取背景或前景 (以文字 "background" 表示), 而另一個用於選取, 以讓處理變得更清楚。色彩 (以「紅色」文字表示)。A Grammar object can specify a semantic interpretation to make processing clearer by specifying that the phrase has two semantic substructures, one for selecting background or foreground (represented by the text "background"), and the other for selecting color (represented by the text "red").

[System.object] 代表SemanticValue物件樹狀結構中辨識作業的語義。System.Speech represents the semantics of a recognition operation in a tree of SemanticValue objects.

SemanticValue個實例都包含下列各項:Each SemanticValue instance includes the following:

以 system.string 為基礎的辨識引擎會針對辨識的SemanticValue所有輸出提供有效的實例, 即使是沒有明確語義結構的片語也一樣。Recognition engines based on System.Speech provide valid instances of SemanticValue for all output from recognition, even for phrases with no explicit semantic structure.

使用SemanticValue 物件RecognizedPhrase上的Semantics屬性 (或繼承自它的RecognitionResult物件, 例如), 即可取得片語的實例。The SemanticValue instance for a phrase is obtained using the Semantics property on the RecognizedPhrase object (or objects that inherit from it, such as RecognitionResult).

SemanticValue針對辨識的片語取得的物件若沒有語義結構, 其特性如下:SemanticValue objects obtained for recognized phrases without semantic structure are characterized by:

  • 缺少子系 (Count是 0)。The lack of children (Count is 0).

  • Value 屬性為 nullThe Value property is null.

  • 人工語義信賴等級為 1.0 (由Confidence傳回)。An artificial semantic confidence level of 1.0 (returned by Confidence).

通常, 應用程式SemanticValue會間接建立實例, 並Grammar使用SemanticResultValueSemanticResultKey實例將它們加入至物件, ChoicesGrammarBuilder結合和物件。Typically, applications create SemanticValue instances indirectly, adding them to Grammar objects by using SemanticResultValue and SemanticResultKey instances, in conjunction with Choices and GrammarBuilder objects.

SemanticValue實例的直接結構化在建立強型別文法期間很有用。Direct construction of a SemanticValue instance is useful during the creation of strongly-typed grammars.

SemanticValueIDictionary<TKey,TValue>執行、 ICollection<T>和介面。IEnumerable<T>SemanticValue implements the IDictionary<TKey,TValue>, ICollection<T>, and IEnumerable<T> interfaces.

建構函式

SemanticValue(Object) SemanticValue(Object) SemanticValue(Object) SemanticValue(Object)

初始化 SemanticValue 類別的新執行個體,並指定語意值。Initializes a new instance of the SemanticValue class and specifies a semantic value.

SemanticValue(String, Object, Single) SemanticValue(String, Object, Single) SemanticValue(String, Object, Single) SemanticValue(String, Object, Single)

初始化 SemanticValue 類別的新執行個體,並指定語意值、索引鍵名稱與信賴度。Initializes a new instance of the SemanticValue class and specifies a semantic value, a key name, and a confidence level.

屬性

Confidence Confidence Confidence Confidence

傳回確定性的相對量值,這是與傳回目前 SemanticValue 執行個體的語意剖析正確性有關。Returns a relative measure of the certainty as to the correctness of the semantic parsing that returned the current instance of SemanticValue.

Count Count Count Count

傳回目前的 SemanticValue 執行個體底下的子系 SemanticValue 物件數目。Returns the number of child SemanticValue objects under the current SemanticValue instance.

Item[String] Item[String] Item[String] Item[String]

傳回屬於目前 SemanticValue 的子系 SemanticValue 執行個體。Returns child SemanticValue instances that belong to the current SemanticValue.

Value Value Value Value

唯讀屬性,會傳回目前SemanticValue所包含的資訊。A read-only property that returns the information contained in the current SemanticValue.

方法

Contains(KeyValuePair<String,SemanticValue>) Contains(KeyValuePair<String,SemanticValue>) Contains(KeyValuePair<String,SemanticValue>) Contains(KeyValuePair<String,SemanticValue>)

指出目前 SemanticValue 執行個體集合是否包含以索引鍵/值組表示的特定索引鍵與特定 SemanticValue 執行個體。Indicates whether the current SemanticValue instance collection contains a specific key and a specific instance of SemanticValue expressed as a key/value pair.

ContainsKey(String) ContainsKey(String) ContainsKey(String) ContainsKey(String)

指出目前 SemanticValue 執行個體集合是否含有指定之索引鍵字串的子系 SemanticValue 執行個體。Indicates whether the current SemanticValue instance collection contains a child SemanticValue instance with a given key string.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否為 SemanticValue 的執行個體且等於 SemanticValue 目前的執行個體。Determines whether a specified object is an instance of SemanticValue and equal to the current instance of SemanticValue.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

提供 SemanticValue 物件的雜湊碼。Provides a hash code for a SemanticValue object.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

明確介面實作

ICollection<KeyValuePair<String,SemanticValue>>.Add(KeyValuePair<String,SemanticValue>) ICollection<KeyValuePair<String,SemanticValue>>.Add(KeyValuePair<String,SemanticValue>) ICollection<KeyValuePair<String,SemanticValue>>.Add(KeyValuePair<String,SemanticValue>) ICollection<KeyValuePair<String,SemanticValue>>.Add(KeyValuePair<String,SemanticValue>)

將指定的索引鍵和 SemanticValue 加入集合中。Adds the specified key and SemanticValue to the collection.

ICollection<KeyValuePair<String,SemanticValue>>.Clear() ICollection<KeyValuePair<String,SemanticValue>>.Clear() ICollection<KeyValuePair<String,SemanticValue>>.Clear() ICollection<KeyValuePair<String,SemanticValue>>.Clear()

從集合中移除所有索引鍵/值組。Removes all key/value pairs from the collection.

ICollection<KeyValuePair<String,SemanticValue>>.CopyTo(KeyValuePair<String,SemanticValue>[], Int32) ICollection<KeyValuePair<String,SemanticValue>>.CopyTo(KeyValuePair<String,SemanticValue>[], Int32) ICollection<KeyValuePair<String,SemanticValue>>.CopyTo(KeyValuePair<String,SemanticValue>[], Int32) ICollection<KeyValuePair<String,SemanticValue>>.CopyTo(KeyValuePair<String,SemanticValue>[], Int32)

將索引鍵/值組複製到目標陣列中的特定位置。Copies a key/value pair to a specific location in a targeted array.

ICollection<KeyValuePair<String,SemanticValue>>.IsReadOnly ICollection<KeyValuePair<String,SemanticValue>>.IsReadOnly ICollection<KeyValuePair<String,SemanticValue>>.IsReadOnly ICollection<KeyValuePair<String,SemanticValue>>.IsReadOnly

取得值,這個值表示集合是否為唯讀。Gets a value that indicates whether the collection is read-only.

ICollection<KeyValuePair<String,SemanticValue>>.Remove(KeyValuePair<String,SemanticValue>) ICollection<KeyValuePair<String,SemanticValue>>.Remove(KeyValuePair<String,SemanticValue>) ICollection<KeyValuePair<String,SemanticValue>>.Remove(KeyValuePair<String,SemanticValue>) ICollection<KeyValuePair<String,SemanticValue>>.Remove(KeyValuePair<String,SemanticValue>)

從集合移除指定的索引鍵和 SemanticValueRemoves the specified key and SemanticValue from the collection.

IDictionary<String,SemanticValue>.Add(String, SemanticValue) IDictionary<String,SemanticValue>.Add(String, SemanticValue) IDictionary<String,SemanticValue>.Add(String, SemanticValue) IDictionary<String,SemanticValue>.Add(String, SemanticValue)

將指定的索引鍵和 SemanticValue 加入字典中。Adds the specified key and SemanticValue to the dictionary.

IDictionary<String,SemanticValue>.Keys IDictionary<String,SemanticValue>.Keys IDictionary<String,SemanticValue>.Keys IDictionary<String,SemanticValue>.Keys

取得集合,其中包含索引鍵/值組的字典中的索引鍵。Gets a collection that contains the keys from a dictionary of key/value pairs.

IDictionary<String,SemanticValue>.Remove(String) IDictionary<String,SemanticValue>.Remove(String) IDictionary<String,SemanticValue>.Remove(String) IDictionary<String,SemanticValue>.Remove(String)

從字典中移除指定的索引鍵和 SemanticValueRemoves the specified key and SemanticValue from the dictionary.

IDictionary<String,SemanticValue>.TryGetValue(String, SemanticValue) IDictionary<String,SemanticValue>.TryGetValue(String, SemanticValue) IDictionary<String,SemanticValue>.TryGetValue(String, SemanticValue) IDictionary<String,SemanticValue>.TryGetValue(String, SemanticValue)

取得與指定索引鍵相關聯的 SemanticValueGets the SemanticValue associated with the specified key.

IDictionary<String,SemanticValue>.Values IDictionary<String,SemanticValue>.Values IDictionary<String,SemanticValue>.Values IDictionary<String,SemanticValue>.Values

取得集合,其中包含索引鍵/值組的字典中的值。Gets a collection that contains the values from a dictionary of key/value pairs.

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

傳回逐一查看集合的列舉值。Returns an enumerator that iterates through a collection.

IEnumerable<KeyValuePair<String,SemanticValue>>.GetEnumerator() IEnumerable<KeyValuePair<String,SemanticValue>>.GetEnumerator() IEnumerable<KeyValuePair<String,SemanticValue>>.GetEnumerator() IEnumerable<KeyValuePair<String,SemanticValue>>.GetEnumerator()

傳回逐一查看集合的列舉值。Returns an enumerator that iterates through a collection.

擴充方法

CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

根據輸入 DataTable 物件 (其中泛型參數 TDataRow) 傳回包含 IEnumerable<T> 物件複本的 DataRowReturns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

根據輸入 DataRow 物件 (其中泛型參數 TDataTable),將 IEnumerable<T> 物件複製到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

根據輸入 DataRow 物件 (其中泛型參數 TDataTable),將 IEnumerable<T> 物件複製到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>)

傳回包含來源集合中每個節點祖系的項目集合。Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName)

傳回包含來源集合中每個節點祖系的已篩選項目集合。Returns a filtered collection of elements that contains the ancestors of every node in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

傳回來源集合中每個文件和項目之子代節點的集合。Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>)

傳回包含來源集合中每個項目和文件之子代項目的項目集合。Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName)

傳回已篩選的項目集合,其中包含來源集合中每個項目和文件的子代項目。Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>)

傳回來源集合中每個項目和文件的子項目集合。Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName)

傳回來源集合中每個項目和文件的已篩選子項目集合。Returns a filtered collection of the child elements of every element and document in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>)

傳回包含來源集合中所有節點的節點集合,依據文件順序來排序。Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

傳回來源集合中每個文件和項目的子節點集合。Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

在來源集合中,從每一個節點的父節點移除這些節點。Removes every node in the source collection from its parent node.

適用於

另請參閱