Share via


RecognitionResult.ModifyTopAlternate Method

Modifies the RecognitionResult object with a known RecognitionAlternate object.

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

Syntax

'Declaration
Public Sub ModifyTopAlternate ( _
    alternate As RecognitionAlternate _
)
'Usage
Dim instance As RecognitionResult 
Dim alternate As RecognitionAlternate

instance.ModifyTopAlternate(alternate)
public void ModifyTopAlternate(
    RecognitionAlternate alternate
)
public:
void ModifyTopAlternate(
    RecognitionAlternate^ alternate
)
public function ModifyTopAlternate(
    alternate : RecognitionAlternate
)

Parameters

Remarks

By default, the TopString property of the RecognitionResult object corresponds to the TopAlternate property; however, you can use this method to use alternates other than the top alternate in the result. When you choose an alternate other than the top alternate, you are essentially choosing a different path through the lattice of alternates that are associated with the results.

To retrieve the RecognitionAlternate objects that can be used to modify the RecognitionResult object, call the GetAlternatesFromSelection method.

The alternate used in this method can be a word alternate within an entire sentence. For example, calling the ModifyTopAlternate method on an alternate obtained by calling GetAlternatesFromSelection(0,5) for "Hello World" changes "Hello" and leaves "World" unaltered.

Note

A call to the ModifyTopAlternate method may modify the TopString and TopAlternate properties of the RecognitionResult object.

Examples

This C# example tracks the RecognitionResult object and its RecognitionAlternate objects. The example then saves the RecognitionResult objects with the Stroke objects that are recognized by using the SetResultOnStrokes method. Finally, the example modifies the TopAlternate property of the RecognitionResult object based on user input.

[C#]

// Declarations...
InkCollector theInkCollector;
Strokes theStrokes;
RecognizerContext theRecognizerContext;
RecognitionResult theRecognitionResult;

// Initialization...

// Initialize the recognizer's strokes
// and assign them to the context.
theStrokes = theInkCollector.Ink.Strokes;
theRecognizerContext = new RecognizerContext();
theRecognizerContext.Strokes = theStrokes;

// Install event handlers.
theRecognizerContext.RecognitionWithAlternates +=
    new RecognizerContextRecognitionWithAlternatesEventHandler(
        RecognitionWithAlternates_Event);

//...

// Recognition Event Handler
private void RecognitionWithAlternates_Event(
    object sender,
    RecognizerContextRecognitionWithAlternatesEventArgs e)
{
    // Save the RecognitionResult, and copy it to the strokes
    theRecognitionResult = e.Result;
    theRecognitionResult.SetResultOnStrokes();
}

// Modify the TopAlternate of the result
private void buttonAlt2_Click(object sender, System.EventArgs e)
{
    RecognitionAlternates theRecognitionAlternates =
        theRecognitionResult.GetAlternatesFromSelection(0, -1);
    theRecognitionResult.ModifyTopAlternate(theRecognitionAlternates[2]);
}

This Microsoft® Visual Basic® .NET example tracks the RecognitionResult object and its RecognitionAlternate objects. The example then saves the RecognitionResult objects with the Stroke objects that are recognized by using the SetResultOnStrokes method. Finally, the example modifies the TopAlternate property of the RecognitionResult object based on user input.

[Visual Basic]

'Declarations...
Dim theInkCollector As InkCollector
Dim theStrokes As Strokes
Dim theRecognizerContext As RecognizerContext
Dim theRecognitionResult As RecognitionResult

'Initialization...

'Initialize the recognizer's strokes
'and assign them to the context.
theStrokes = theInkCollector.Ink.Strokes
theRecognizerContext = new RecognizerContext()
theRecognizerContext.Strokes = theStrokes

'Install event handlers.
AddHandler theRecognizerContext.RecognitionWithAlternates, _
AddressOf RecognitionWithAlternates_Event

'...

'Recognition Event Handler
Private Sub RecognitionWithAlternates_Event( _
ByVal sender As Object, _
ByVal e As RecognizerContextRecognitionWithAlternatesEventArgs)
    'Save the RecognitionResult, and copy it to the strokes.
    theRecognitionResult = e.Result
    theRecognitionResult.SetResultOnStrokes()
End Sub

'Modify the TopAlternate of the result
Private Sub ButtonAlt2_Click(object sender, System.EventArgs e) _
Handles ButtonAlt2.Click
    RecognitionAlternates theRecognitionAlternates =
        theRecognitionResult.GetAlternatesFromSelection(0, -1)
    theRecognitionResult.ModifyTopAlternate(theRecognitionAlternates(2))
End Sub

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

RecognitionResult Class

RecognitionResult Members

Microsoft.Ink Namespace

RecognitionAlternate

RecognitionResult.GetAlternatesFromSelection

RecognitionResult.TopAlternate

RecognitionResult.TopString