RecognizedWordUnit.Text 属性

定义

获取已识别单词的规划化文本。Gets the normalized text for a recognized word.

public:
 property System::String ^ Text { System::String ^ get(); };
public string Text { get; }
member this.Text : string
Public ReadOnly Property Text As String

属性值

String

包含给定输入单词的规范化文本输出的字符串。A string that contains the normalized text output for a given input word.

示例

下面的示例演示了一个实用工具例程,该例程使用以下三种格式之一来生成字符串:词法 (使用 LexicalForm) 、使用 Text) 的规范化 (和使用 (的拼音) PronunciationThe following example shows a utility routine that generates a string in one of three formats: lexical (using LexicalForm), normalized (using Text), and phonetic (using Pronunciation). 文本输出是从对象的对象获取的,该对象 ReadOnlyCollection<T> RecognizedWordUnit 是从 Words 对象上的属性获取的 RecognizedPhraseThe text output is obtained from a ReadOnlyCollection<T> of RecognizedWordUnit objects, which is obtained from the Words property on the RecognizedPhrase object.

internal enum WordType   
{  
  Text,  
  Normalized = Text,  
  Lexical,  
  Pronunciation  
}  
internal static string stringFromWordArray(  
          ReadOnlyCollection<RecognizedWordUnit> words,   
          WordType type)   
{  
  string text = "";  
  foreach (RecognizedWordUnit word in words)   
  {  
    string wordText = "";  
    if (type == WordType.Text || type == WordType.Normalized)   
    {  
      wordText = word.Text;  
    }   
    else if (type == WordType.Lexical)   
    {  
      wordText = word.LexicalForm;  
    }   
    else if (type == WordType.Pronunciation)   
    {  
      wordText = word.Pronunciation;  
    }   
    else   
    {  
      throw new InvalidEnumArgumentException(  
           String.Format("[0}: is not a valid input", type));  
    }  

    // Use display attribute  
    if ((word.DisplayAttributes & DisplayAttributes.OneTrailingSpace) != 0)   
    {  
      wordText += " ";  
    }  
    if ((word.DisplayAttributes & DisplayAttributes.TwoTrailingSpaces) != 0)   
    {  
      wordText += "  ";  
    }  
    if ((word.DisplayAttributes & DisplayAttributes.ConsumeLeadingSpaces) != 0)   
    {  
      wordText = wordText.TrimStart();  
    }  
    if ((word.DisplayAttributes & DisplayAttributes.ZeroTrailingSpaces) != 0)   
    {  
      wordText = wordText.TrimEnd();  
    }  

    text += wordText;  

  }  
  return text;  
}  

注解

在大多数情况下,由和返回的值 Text LexicalForm 都是相同的。In most cases the values returned by Text and LexicalForm will be identical. 不过,识别引擎可以使用语音规范化来返回更多用户友好的音频输入或 colloquial 的文本表示形式。However, recognition engines may use speech normalization to return more user-friendly or colloquial text representations of audio input.

语音规范化是在编写时使用特殊的构造或符号来表达语音。Speech normalization is the use of special constructs or symbols to express speech in writing. 例如,规范化可以在输出文本中将单词 "a 美元和十六美分" 替换为 "$1.16"。For example, normalization can replace the spoken words "a dollar and sixteen cents" with "$1.16" in output text.

适用于