RecognitionResult.GetAlternatesFromSelection Method (Int32, Int32)
Returns the RecognitionAlternates collection from a range within the best result string of the RecognitionResult object, so that each RecognitionAlternate object in the collection corresponds to only one segment of ink. The returned collection is limited to 10 elements.
Namespace: Microsoft.Ink
Assembly: Microsoft.Ink (in Microsoft.Ink.dll)
Syntax
'Declaration
Public Function GetAlternatesFromSelection ( _
selectionStart As Integer, _
selectionLength As Integer _
) As RecognitionAlternates
'Usage
Dim instance As RecognitionResult
Dim selectionStart As Integer
Dim selectionLength As Integer
Dim returnValue As RecognitionAlternates
returnValue = instance.GetAlternatesFromSelection(selectionStart, _
selectionLength)
public RecognitionAlternates GetAlternatesFromSelection(
int selectionStart,
int selectionLength
)
public:
RecognitionAlternates^ GetAlternatesFromSelection(
int selectionStart,
int selectionLength
)
public function GetAlternatesFromSelection(
selectionStart : int,
selectionLength : int
) : RecognitionAlternates
Parameters
selectionStart
Type: System.Int32The start of the text selection from which the RecognitionAlternates collection is returned. The default value is 0 (zero).
selectionLength
Type: System.Int32The length of the text selection from which the RecognitionAlternates collection is returned. The default value is –1, which specifies the text beginning from the start of the selection to the end of the string.
Return Value
Type: Microsoft.Ink.RecognitionAlternates
Returns the RecognitionAlternates collection from a selection within the best result string of the RecognitionResult object, so that each RecognitionAlternate object in the collection corresponds to only one segment of ink.
Remarks
A recognizer is likely to divide "how are you" into three segments—depending on the spacing between segments—one for each word. Call the GetAlternatesFromSelection method to return the alternates for only one segment of this selection.
Note the difference between the GetAlternatesFromSelection method and the AlternatesWithConstantPropertyValues, LineAlternates, and ConfidenceAlternates methods of the RecognitionAlternate object. Although the GetAlternatesFromSelection method returns a RecognitionAlternates collection in which each RecognitionAlternate object corresponds to only one segment of ink within a selection, the AlternatesWithConstantPropertyValues, LineAlternates, and ConfidenceAlternates methods return the RecognitionAlternates collection in which the RecognitionAlternate objects correspond to each segment of ink within a selection.
Examples
In this example, synchronous recognition is handled in response to a user action such as clicking on a menu item or a button. First, the Strokes collection of a RecognizerContext object is assigned from the Strokes collection associated with an InkOverlay object, and checked for stroke count. If the Strokes collection contains at least one Stroke object, the recognition process begins with a call to the Recognize method. If recognition is successful, a RecognitionAlternates collection is obtained for either the first word of the recognition result (if more than one word is found in the TopString property) or for the entire recognition result. Finally, the RecognitionAlternates are displayed by adding them to a list box.
' assign strokes collection from the collected strokes
Me.mRecognizerContext.Strokes = Me.mInkOverlay.Ink.Strokes
' check stroke count. Recognize() will throw exception if no strokes
If Me.mRecognizerContext.Strokes.Count > 0 Then
Dim status As RecognitionStatus
' perform the recognition
Dim rResult As RecognitionResult = Me.mRecognizerContext.Recognize(status)
' check status
If RecognitionStatus.NoError = status Then
Dim rAlts As RecognitionAlternates
' find the index of the first space in the top string
Dim idxOfSpace As Integer = rResult.TopString.IndexOf(" ")
If idxOfSpace <> -1 Then
' if we have a space (i.e. more than one word)
' get the alternates of the first segment (the first word)
rAlts = rResult.GetAlternatesFromSelection(0, idxOfSpace)
Else
' otherwise, get the alternates for the entire recognition result
rAlts = rResult.GetAlternatesFromSelection()
' Note: if (idxOfSpace <> -1) .. for illustrative purposes
' Could have uncondionally used:
' rAlts = rResult.GetAlternatesFromSelection(0, idxOfSpace)
' because:
' GetAlternatesFromSelection(0, -1)
' is the same as:
' GetAlternatesFromSelection()
End If
' display the alternates
For Each RA As RecognitionAlternate In rAlts
listBoxRecognitionResults.Items.Add(RA.ToString())
Next
End If
End If
// assign strokes collection from the collected strokes
this.mRecognizerContext.Strokes = this.mInkOverlay.Ink.Strokes;
// check stroke count. Recognize() will throw exception if no strokes
if (this.mRecognizerContext.Strokes.Count > 0)
{
RecognitionStatus status;
// perform the recognition
RecognitionResult rResult = this.mRecognizerContext.Recognize(out status);
// check status
if (RecognitionStatus.NoError == status)
{
RecognitionAlternates rAlts;
// find the index of the first space in the top string
int idxOfSpace = rResult.TopString.IndexOf(" ");
if (idxOfSpace != -1)
{
// if we have a space (i.e. more than one word)
// get the alternates of the first segment (the first word)
rAlts = rResult.GetAlternatesFromSelection(0, idxOfSpace);
}
else
{
// otherwise, get the alternates for the entire recognition result
rAlts = rResult.GetAlternatesFromSelection();
// Note: if (idxOfSpace != -1) .. for illustrative purposes
// Could have uncondionally used:
// rAlts = rResult.GetAlternatesFromSelection(0, idxOfSpace);
// because:
// GetAlternatesFromSelection(0, -1)
// is the same as:
// GetAlternatesFromSelection()
}
// display the alternates
foreach (RecognitionAlternate RA in rAlts)
{
listBoxRecognitionResults.Items.Add(RA.ToString());
}
}
}
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