RecognizerContext.WordList Property

Gets or sets the WordList object that is used to improve the recognition results.

Namespace:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

Syntax

'Declaration
Public Property WordList As WordList
'Usage
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);
}
public function get WordList () : WordList 
public function set WordList (value : WordList)

Property Value

Type: Microsoft.Ink.WordList
The word list that is used to improve the recognition results. The returned object is an internal working copy of the underlying word list, not a direct reference.

Remarks

Before you can use this property, you must initialize it by instantiating a newWordList object, and assigning the freshly created object to the WordList property.

Setting the WordList property succeeds only if the Strokes property is nulla null reference (Nothing in Visual Basic). You must set the WordList property before you attach a Strokes collection to the Strokes property of the RecognizerContext, or you must set the Strokes property to nulla null reference (Nothing in Visual Basic) and then set the WordList property.

Note

If you use the latter method, you may need to reattach the Strokes collection to the Strokes property of the RecognizerContext object.

To remove the current word list and use the user dictionary, set the WordList property to nulla null reference (Nothing in Visual Basic). Any subsequent modification of the WordList object does not modify the recognition outcome.

Testing to see if this property has been set to nulla null reference (Nothing in Visual Basic) is not meaningful. The value returned by the get accessor is always non-null. The following sample illustrates this.

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");
}

Because the return value of this property is an internal working copy of the underlying word list, and not a direct reference, any word or phrase additions that you make are not available for use during recognition until the WordList property is re-assigned. Consider the following:

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);

In the previous example, the test word is added to the internal copy of the WordList property, and the copy is then re-assigned to the WordList property.

Alternately, you can add the test word to the WordList property itself. In this case, you are making changes to the internal working copy, and must still re-assign the WordList property before the newly added word is available for use during recognition.

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);

When you re-assign the WordList property with the copy obtained via the property's get accessor, the modified content does not replace the original WordList. Instead, it adds the delta to the original WordList. If you want to replace the original WordList, use one of the following techniques:

  1. Create a new RecognizerContext object and assign the modified WordList to it.

  2. Create a new WordList object and assign it to the existing RecognizerContext.

Use the Factoid property to limit the search to the word list that is associated with the context. You may also need to set the RecognitionFlags property to improve the results.

The WordList property cannot be set after a factoid is set. This prevents a factoid from referring to a possibly non existent wordlist. Attempting to do so will result in the following COM exception: "The method was called after Process has been called or Factoid has been set".

If a string is added to a word list, its capitalized versions are also implicitly added. For instance, adding "hello" implicitly adds "Hello" and "HELLO".

To clear the WordList, set it equal to an empty WordList object.

Examples

In this example, a RecognizerContext object is instantiated, and a new WordList object assigned to its WordList property. The IsStringSupported method is then used to determine if a specified string is supported. If not, the string is added to the 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;
}

Platforms

Windows 7, Windows Vista, Windows Server 2008 R2, Windows Server 2008

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Version Information

.NET Framework

Supported in: 3.0

See Also

Reference

RecognizerContext Class

RecognizerContext Members

Microsoft.Ink Namespace

RecognizerContext

WordList

RecognizerContext.Strokes

RecognizerContext.Factoid

RecognizerContext.RecognitionFlags