RecognizerContext.WordList 属性

获取或设置用于改进识别结果的 WordList 对象。

命名空间:  Microsoft.Ink
程序集:  Microsoft.Ink(在 Microsoft.Ink.dll 中)

语法

声明
Public Property WordList As WordList
用法
Dim instance As RecognizerContext
Dim value As WordList

value = instance.WordList

instance.WordList = value
public WordList WordList { get; set; }
public:
property WordList^ WordList {
    WordList^ get ();
    void set (WordList^ value);
}
/** @property */
public WordList get_WordList()
/** @property */
public  void set_WordList(WordList value)
public function get WordList () : WordList
public function set WordList (value : WordList)

属性值

类型:Microsoft.Ink.WordList
用于改进识别结果的单词列表。返回的对象是基础单词列表的内部工作副本,而不是直接引用。

备注

在使用此属性之前,必须初始化此属性,方法是实例化 newWordList 对象并将新创建的对象分配给 WordList 属性。

仅当 Strokes 属性为 nullnull 引用(在 Visual Basic 中为 Nothing) 时,才能成功设置 WordList 属性。必须先设置 WordList 属性,然后再将 Strokes 集合附加到 RecognizerContextStrokes 属性;或者必须先将 Strokes 属性设置为 nullnull 引用(在 Visual Basic 中为 Nothing),然后再设置 WordList 属性。

备注

如果使用后一种方法,可能需要将 Strokes 集合重新附加到 RecognizerContext 对象的 Strokes 属性。

若要移除当前单词列表并使用用户字典,请将 WordList 属性设置为 nullnull 引用(在 Visual Basic 中为 Nothing)。对 WordList 对象的任何后续修改都不会修改识别结果。

测试此属性是否已设置为 nullnull 引用(在 Visual Basic 中为 Nothing) 没有意义。get 访问器所返回的值始终是非 null 的值。下面的示例对此进行了说明。

Dim RC As RecognizerContext = New RecognizerContext()
RC.WordList = Nothing
If (Not RC.WordList Is Nothing) Then ' always true
    ' but this won't work, throws a null reference exception
    RC.WordList.Add("thunk")
End If
RecognizerContext RC = new RecognizerContext();
RC.WordList = null;
if (RC.WordList != null) // always true
{
    // but this won't work, throws a null reference exception
    RC.WordList.Add("thunk");
}

由于此属性的返回值是基础单词列表的内部工作副本,而不是直接引用,因此除非重新分配 WordList 属性,否则所添加的任何单词或短语都无法在识别期间使用。请看下面的示例:

Dim RC As RecognizerContext = New RecognizerContext()
RC.WordList = New WordList()
Dim testStr As String = "thunk"
' test if string is supported - false
Dim isTestStrSupported As Boolean = RC.IsStringSupported(testStr)
' get a copy of the WordList
Dim WL As WordList = RC.WordList
' add the string to the copy
WL.Add(testStr)
' test if string is supported - still false
isTestStrSupported = RC.IsStringSupported(testStr)
' assign copy back to the WordList property
RC.WordList = WL
' test if string is supported - now true
isTestStrSupported = RC.IsStringSupported(testStr)
RecognizerContext RC = new RecognizerContext();
RC.WordList = new WordList();
string testStr = "thunk";
// test if string is supported - false
bool isTestStrSupported = RC.IsStringSupported(testStr);
// get a copy of the WordList
WordList WL = RC.WordList;
// add the string to the copy
WL.Add(testStr);
// test if string is supported - still false
isTestStrSupported = RC.IsStringSupported(testStr);
// assign copy back to the WordList property
RC.WordList = WL;
// test if string is supported - now true
isTestStrSupported = RC.IsStringSupported(testStr);

上面的示例向 WordList 属性的内部副本添加测试单词,然后将该副本重新分配给 WordList 属性。

或者,也可以将测试单词添加到 WordList 属性本身。在这种情况下,您是对内部工作副本进行更改,因此仍须重新分配 WordList 属性,才能使新添加的单词在识别期间可用。

Dim RC As RecognizerContext = New RecognizerContext()
RC.WordList = New WordList()
Dim testStr As String = "thunk"
' test if string is supported - false
Dim isTestStrSupported As Boolean = RC.IsStringSupported(testStr)
' get a copy of the WordList
Dim WL As WordList = RC.WordList
' add the string to the WordList property itself
RC.WordList.Add(testStr)
' test if string is supported - still false
isTestStrSupported = RC.IsStringSupported(testStr)
' assign copy back to the WordList property
RC.WordList = WL
' test if string is supported - now true
isTestStrSupported = RC.IsStringSupported(testStr)
RecognizerContext RC = new RecognizerContext();
RC.WordList = new WordList();
string testStr = "thunk";
// test if string is supported - false
bool isTestStrSupported = RC.IsStringSupported(testStr);
// get a copy of the WordList
WordList WL = RC.WordList;
// add the string to the WordList property itself
RC.WordList.Add(testStr);
// test if string is supported - still false
isTestStrSupported = RC.IsStringSupported(testStr);
// assign copy back to the WordList property
RC.WordList = WL;
// test if string is supported - now true
isTestStrSupported = RC.IsStringSupported(testStr);

使用通过 WordList 属性的 get 访问器获取的副本为该属性重新赋值时,修改后的内容不会替换原始 WordList,而是将增量添加到原始 WordList。若要替换原始 WordList,请使用以下方式之一:

  1. 创建一个新的 RecognizerContext 对象,并将修改后的 WordList 分配给该对象。

  2. 创建一个新的 WordList 对象,并将该对象分配给现有 RecognizerContext

使用 Factoid 属性可将搜索范围限定为与上下文关联的单词列表。也可能需要设置 RecognitionFlags 属性以改进结果。

设置智能标记后,不能再设置 WordList 属性。这样做会使智能标记无法引用可能不存在的单词列表。尝试这么做将会导致以下 COM 异常:“在已调用进程或已设置智能标记后调用了该方法”[The method was called after Process has been called or Factoid has been set]。

如果将某个字符串添加到单词列表中,同时也会隐式添加该字符串的大写版本。例如,添加“hello”时将隐式添加“Hello”和“HELLO”。

若要清除 WordList,请将其设置为一个空 WordList 对象。

示例

此示例将实例化 RecognizerContext 对象,并向其 WordList 属性分配一个新的 WordList 对象。然后,使用 IsStringSupported 方法确定是否支持指定字符串。如果不支持,则将该字符串添加到 WordList 中。

Dim RC As RecognizerContext = New RecognizerContext()
RC.WordList = New WordList()
Dim testStr As String = "thunk"
If Not RC.IsStringSupported(testStr) Then
    Dim WL As WordList = RC.WordList
    WL.Add(testStr)
    ' testStr is not available for use in recognition
    ' until the WordList property is re-assigned
    RC.WordList = WL
End If
RecognizerContext RC = new RecognizerContext();
RC.WordList = new WordList();
string testStr = "thunk";
if (!RC.IsStringSupported(testStr))
{
    WordList WL = RC.WordList;
    WL.Add(testStr);
    // testStr is not available for use in recognition
    // until the WordList property is re-assigned
    RC.WordList = WL;
}

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

RecognizerContext 类

RecognizerContext 成员

Microsoft.Ink 命名空间

RecognizerContext

WordList

RecognizerContext.Strokes

RecognizerContext.Factoid

RecognizerContext.RecognitionFlags