次の方法で共有


SmartTagBase.Recognize メソッド (2007 System)

更新 : 2007 年 11 月

認識された項目をテキストから検索します。

名前空間 :  Microsoft.Office.Tools
アセンブリ :  Microsoft.Office.Tools.Common.v9.0 (Microsoft.Office.Tools.Common.v9.0.dll 内)

構文

'宣言
Protected Overridable Sub Recognize ( _
    text As String, _
    site As ISmartTagRecognizerSite, _
    tokenList As ISmartTagTokenList _
)
'使用
Dim text As String
Dim site As ISmartTagRecognizerSite
Dim tokenList As ISmartTagTokenList

Me.Recognize(text, site, tokenList)
protected virtual void Recognize(
    string text,
    ISmartTagRecognizerSite site,
    ISmartTagTokenList tokenList
)

パラメータ

  • text
    型 : System.String

    認識された項目を検索するテキスト。

  • site
    型 : ISmartTagRecognizerSite

    ブックまたは文書内のテキストの位置。

  • tokenList
    型 : ISmartTagTokenList

    認識された項目を検索するテキストを、トークンのリストに分解したもの。

解説

認識された項目をテキストから検索するために、アイドル時間中に Visual Studio Tools for Office ランタイムによって呼び出されます。標準レコグナイザの他に独自の検索アルゴリズムも組み込んで実行するには、このメソッドを実装します。

Microsoft.Office.Tools.Excel.SmartTag から派生するクラス内で Recognize メソッドをオーバーライドする方法のコード例を次に示します。この例における Recognize の実装では、各スマート タグ項目と Microsoft Office Excel ワークシート内のセルの内容を比較します。このコードでは、セル内でスマート タグ項目が見つかると、カスタム スマート タグ プロパティを追加し、SmartTag.PersistTag(ISmartTagProperties) メソッドを呼び出してスマート タグを認識します。この例は、[参照の追加] ダイアログ ボックスの [COM] タブで、Microsoft Smart Tags 2.0 Type Library への参照が追加してあると仮定しています。次のコード例は、Microsoft.Office.Tools.Excel.SmartTag クラス用の、より大きなコード例の一部です。

この例は、ドキュメント レベルのカスタマイズ用に作成されています。

Protected Overrides Sub Recognize(ByVal text As String, _
    ByVal site As ISmartTagRecognizerSite, _
    ByVal tokenList As ISmartTagTokenList)

    ' Determine whether each smart tag term exists in 
    ' the document text.
    Dim Term As String
    For Each Term In Me.Terms

        ' Search the cell text for the first instance of 
        ' the current smart tag term.
        Dim index As Integer = Me.CellText.IndexOf(Term, 0)

        If (index >= 0) Then

            ' Create a smart tag token and a property bag for the 
            ' recognized term.
            Dim propertyBag As ISmartTagProperties = _
                site.GetNewPropertyBag()

            ' Write a new property value.
            Dim key As String = "Key1"
            propertyBag.Write(key, DateTime.Now)

            ' Attach the smart tag to the term in the document
            Me.PersistTag(propertyBag)

            ' This implementation only finds the first instance
            ' of a smart tag term in the cell. 
            Exit For
        End If
    Next
End Sub
protected override void Recognize(string text, 
    ISmartTagRecognizerSite site, ISmartTagTokenList tokenList)
{
    // Determine whether each smart tag term exists in 
    // the document text.
    foreach (string term in this.Terms)
    {
        // Search the cell text for the first instance of 
        // the current smart tag term.
        int index = this.CellText.IndexOf(term, 0);

        if (index >= 0)
        {
            // Create a smart tag token and a property bag for the 
            // recognized term.
            ISmartTagProperties propertyBag = 
                site.GetNewPropertyBag();

            // Write a new property value.                 
            string key = "Key1";
            propertyBag.Write(key, DateTime.Now.ToString());

            // Attach the smart tag to the term in the document
            this.PersistTag(propertyBag);

            // This implementation only finds the first instance
            // of a smart tag term in the cell. 
            break;
        }
    }
}

アクセス許可

  • 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

参照

SmartTagBase クラス

SmartTagBase メンバ

Microsoft.Office.Tools 名前空間