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為零,ValuenullThe 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.Speech 語意的技術。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. AGrammar物件可以指定要清楚得處理,藉由指定的片語,有兩個的語意子結構,一個用於選擇背景或前景 (由 「 背景 」 的文字表示),和另一個則用於選取的語意解譯(由文字"red") 的色彩。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.Speech 代表在樹狀目錄中的辨識作業的語意SemanticValue物件。System.Speech represents the semantics of a recognition operation in a tree of SemanticValue objects.

每個SemanticValue的執行個體包含下列:Each SemanticValue instance includes the following:

辨識引擎根據 System.Speech 提供有效的執行個體的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執行個體使用取得片語Semantics屬性上的RecognizedPhrase物件 (或從它繼承,這類的物件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.

SemanticValue 會實作IDictionary<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 的淺層複製。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.

Extension Methods

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

傳回DataTable,其中包含副本DataRow物件,指定輸入IEnumerable<T>物件其中泛型參數TDataRowReturns 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至指定的物件DataTable,根據輸入IEnumerable<T>物件其中泛型參數TDataRowCopies 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至指定的物件DataTable,根據輸入IEnumerable<T>物件其中泛型參數TDataRowCopies 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)

將轉換IEnumerableIQueryableConverts 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.

適用於

另請參閱