SmartTagBase.Recognize, méthode (System 2007)

Mise à jour : novembre 2007

Recherche le texte des termes reconnus.

Espace de noms :  Microsoft.Office.Tools
Assembly :  Microsoft.Office.Tools.Common.v9.0 (dans Microsoft.Office.Tools.Common.v9.0.dll)

Syntaxe

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
)

Paramètres

  • text
    Type : System.String

    Texte à rechercher pour les termes reconnus.

  • site
    Type : ISmartTagRecognizerSite

    Emplacement du texte dans le classeur ou le document.

  • tokenList
    Type : ISmartTagTokenList

    Texte à rechercher pour les termes reconnus, réparti dans une liste de jetons.

Notes

Appelée par le runtime de Visual Studio Tools pour Office pendant la durée d'inactivité destinée à la recherche des termes reconnus dans le texte. Implémentez cette méthode si vous souhaitez incorporer vos propres algorithmes de recherche à exécuter en plus des modules de reconnaissance standard.

Exemples

L'exemple de code suivant illustre la substitution de la méthode Recognize dans une classe qui dérive de Microsoft.Office.Tools.Excel.SmartTag. Cette implémentation de Recognize compare chaque terme de la balise active avec le contenu d'une cellule d'une feuille de calcul Microsoft Office Excel. Si un terme de la balise active est trouvé dans la cellule, le code ajoute une propriété de balise active personnalisée à la balise active, puis appelle la méthode SmartTag.PersistTag(ISmartTagProperties) pour reconnaître la balise active. Cet exemple suppose que vous avez ajouté une référence à Bibliothèque de types Microsoft Smart Tags 2.0 à partir de l'onglet COM de la boîte de dialogue Ajouter une référence. Cet exemple de code fait partie d'un exemple plus développé fourni pour la classe Microsoft.Office.Tools.Excel.SmartTag.

Cet exemple illustre une personnalisation au niveau du document.

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

Autorisations

Voir aussi

Référence

SmartTagBase, classe

Membres SmartTagBase

Microsoft.Office.Tools, espace de noms