RecognitionResult.GetAlternatesFromSelection 方法

RecognitionResult 对象的最佳结果字符串中的一个范围返回 RecognitionAlternates 集合,从而集合中的每个 RecognitionAlternate 对象只对应一个墨迹段。返回的集合被限制为 10 个元素。

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

语法

声明
Public Function GetAlternatesFromSelection As RecognitionAlternates
用法
Dim instance As RecognitionResult
Dim returnValue As RecognitionAlternates

returnValue = instance.GetAlternatesFromSelection()
public RecognitionAlternates GetAlternatesFromSelection()
public:
RecognitionAlternates^ GetAlternatesFromSelection()
public RecognitionAlternates GetAlternatesFromSelection()
public function GetAlternatesFromSelection() : RecognitionAlternates

返回值

类型:Microsoft.Ink.RecognitionAlternates
RecognitionResult 对象的最佳结果字符串中的选定部分返回 RecognitionAlternates 集合,从而集合中的每个 RecognitionAlternate 对象只对应一个墨迹段。

备注

识别器可能根据空白将“how are you”划分为三段,每个单词为一段。调用 GetAlternatesFromSelection 方法只返回此选定部分的一个段的备选项。

请注意 GetAlternatesFromSelection 方法与 RecognitionAlternate 对象的 AlternatesWithConstantPropertyValues 方法、LineAlternates 方法和 ConfidenceAlternates 方法之间的差异。尽管在 GetAlternatesFromSelection 方法返回的 RecognitionAlternates 集合中,每个 RecognitionAlternate 对象都只对应选定部分中的一个墨迹段,但在 AlternatesWithConstantPropertyValuesLineAlternatesConfidenceAlternates 方法返回的 RecognitionAlternates 集合中,RecognitionAlternate 对象对应选定部分的每个墨迹段。

示例

此示例处理同步识别以响应用户操作(如单击菜单项或按钮)。首先,从 InkOverlay 对象的关联 Strokes 集合分配 RecognizerContext 对象的 Strokes 集合,并检查笔画计数。如果 Strokes 集合包含至少一个 Stroke 对象,则调用 Recognize 方法开始识别过程。如果识别成功,则获取识别结果的第一个单词(如果在 TopString 属性找到多个单词)或整个识别结果的 RecognitionAlternates 集合。最后,通过将 RecognitionAlternates 添加至列表框中进行显示。

' 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());
        }
    }
}

平台

Windows Vista

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

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

RecognitionResult 类

RecognitionResult 成员

GetAlternatesFromSelection 重载

Microsoft.Ink 命名空间

GetAlternatesFromSelection

RecognitionAlternates