共用方式為


RecognitionResult.GetAlternatesFromSelection 方法 (Int32, Int32)

RecognitionResult 物件的最佳結果字串中的範圍傳回 RecognitionAlternates 集合,讓集合中的每個 RecognitionAlternate 物件只對應於一個筆墨區段。傳回的集合受限於 10 個項目。

命名空間:  Microsoft.Ink
組件:  Microsoft.Ink (在 Microsoft.Ink.dll 中)

語法

'宣告
Public Function GetAlternatesFromSelection ( _
    selectionStart As Integer, _
    selectionLength As Integer _
) As RecognitionAlternates
'用途
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 RecognitionAlternates GetAlternatesFromSelection(
    int selectionStart,
    int selectionLength
)
public function GetAlternatesFromSelection(
    selectionStart : int, 
    selectionLength : int
) : RecognitionAlternates

參數

  • selectionLength
    型別:System.Int32
    文字選取範圍的長度,RecognitionAlternates 集合會從此範圍中傳回。預設值為 -1,表示文字從選取範圍的開頭至字串的結尾。

傳回值

型別:Microsoft.Ink.RecognitionAlternates
RecognitionResult 物件的最佳結果字串中的選取範圍傳回 RecognitionAlternates 集合,讓集合中的每個 RecognitionAlternate 物件只對應於一個筆墨區段。

備註

依據區段的間距,辨識器可能會將 "how are you" 區分為三個區段,每個單字為一個區段。呼叫 GetAlternatesFromSelection 方法,即可只針對這個選取範圍的一個區段傳回替代項目。

請注意 GetAlternatesFromSelection 方法與 RecognitionAlternate 物件的 AlternatesWithConstantPropertyValuesLineAlternatesConfidenceAlternates 方法之間的差異。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