RecognitionResult オブジェクトの最適な結果文字列から RecognitionAlternates コレクションを返します。コレクション内の RecognitionAlternate オブジェクトはそれぞれ、インクの 1 つのセグメントのみに対応します。返されるコレクションの要素数は、最大 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 オブジェクトはそれぞれ、インクの 1 つのセグメントのみに対応します。
解説
認識エンジンは、多くの場合 "how are you" をセグメント間の空きに従って 3 つのセグメントに分割します。つまり、1 単語につき 1 セグメントです。この選択範囲の 1 つのセグメントだけについて代替候補を返すには、GetAlternatesFromSelection メソッドを呼び出します。
GetAlternatesFromSelection メソッドと、RecognitionAlternate オブジェクトの AlternatesWithConstantPropertyValues メソッド、LineAlternates メソッド、および ConfidenceAlternates メソッドの間の相違点に注意してください。GetAlternatesFromSelection メソッドから返される RecognitionAlternates コレクションでは、各 RecognitionAlternate オブジェクトは選択範囲内のインクの 1 つのセグメントだけに対応しますが、AlternatesWithConstantPropertyValues メソッド、LineAlternates メソッド、および ConfidenceAlternates メソッドから返される、RecognitionAlternates コレクションには、選択範囲内のインクの各セグメントに対応する RecognitionAlternate オブジェクトが含まれています。
例
この例では、メニュー項目やボタンのクリックといったユーザーの操作に対応して同期認識が処理されます。まず、RecognizerContext オブジェクトの Strokes コレクションが、InkOverlay オブジェクトに関連付けられた Strokes コレクションから割り当てられ、ストロークの数がチェックされます。Strokes コレクションに少なくとも 1 つの 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