Share via


SmartTagBase.Recognize Method (2007 System)

Searches text for recognized terms.

Namespace:  Microsoft.Office.Tools
Assembly:  Microsoft.Office.Tools.Common.v9.0 (in Microsoft.Office.Tools.Common.v9.0.dll)

Syntax

'Declaration
Protected Overridable Sub Recognize ( _
    text As String, _
    site As ISmartTagRecognizerSite, _
    tokenList As ISmartTagTokenList _
)
'Usage
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
)
protected:
virtual void Recognize(
    String^ text, 
    ISmartTagRecognizerSite^ site, 
    ISmartTagTokenList^ tokenList
)
protected function Recognize(
    text : String, 
    site : ISmartTagRecognizerSite, 
    tokenList : ISmartTagTokenList
)

Parameters

  • text
    Type: System.String

    The text to search for recognized terms.

  • site
    Type: ISmartTagRecognizerSite

    The location of the text in the workbook or document.

  • tokenList
    Type: ISmartTagTokenList

    The text to search for recognized terms, broken down into a list of tokens.

Remarks

Called by the Visual Studio Tools for Office runtime during idle time to search text for recognized terms. Implement this method if you want to incorporate your own search algorithms to run in addition to the standard recognizers.

Examples

The following code example demonstrates how to override the Recognize method within a class that derives from Microsoft.Office.Tools.Excel.SmartTag. This implementation of Recognize compares each smart tag term to the contents of a cell in a Microsoft Office Excel worksheet. If a smart tag term is found in the cell, the code adds a custom smart tag property to the smart tag and then calls the SmartTag.PersistTag(ISmartTagProperties) method to recognize the smart tag. This example assumes that you have added a reference to Microsoft Smart Tags 2.0 Type Library from the COM tab of the Add Reference dialog box. This code example is part of a larger example provided for the Microsoft.Office.Tools.Excel.SmartTag class.

This example is for a document-level customization.

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;
        }
    }
}

.NET Framework Security

See Also

Reference

SmartTagBase Class

SmartTagBase Members

Microsoft.Office.Tools Namespace