RecognizedWordUnit.LexicalForm 属性
定义
获取已识别的字符串的非正常化的文本。Gets the unnormalized text of a recognized word.
public:
property System::String ^ LexicalForm { System::String ^ get(); };
public string LexicalForm { get; }
member this.LexicalForm : string
Public ReadOnly Property LexicalForm As String
属性值
返回没有任何正常化的无法识别的单词的文本的 String。Returns a String containing the text of a recognized word, without any normalization.
示例
下面的示例演示一个实用工具例程,该例程使用以下三种格式之一生成文本:词法 (使用 LexicalForm) 、使用 Text) 的规范化 (和使用 (的拼音) Pronunciation 。The following example shows a utility routine that generates text in one of three formats: lexical (using LexicalForm), normalized (using Text), and phonetic (using Pronunciation). 文本输出是从对象的对象获取的,该对象 ReadOnlyCollection<T> RecognizedWordUnit 是从 Words 对象上的属性获取的 RecognizedPhrase 。The 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 are 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.