ISmartTagExtension.Recognize, méthode
Recherche les termes reconnus dans le texte du document.
Espace de noms : Microsoft.Office.Tools.Word
Assembly : Microsoft.Office.Tools.Word (dans Microsoft.Office.Tools.Word.dll)
Syntaxe
'Déclaration
Sub Recognize ( _
text As String, _
site As ISmartTagRecognizerSite, _
tokenList As ISmartTagTokenList, _
context As SmartTagRecognizeContext _
)
void Recognize(
string text,
ISmartTagRecognizerSite site,
ISmartTagTokenList tokenList,
SmartTagRecognizeContext context
)
Paramètres
- text
Type : System.String
Texte à rechercher pour les termes reconnus.
- site
Type : Microsoft.Office.Interop.SmartTag.ISmartTagRecognizerSite
Emplacement du texte dans le classeur ou le document.
- tokenList
Type : Microsoft.Office.Interop.SmartTag.ISmartTagTokenList
Texte à rechercher pour les termes reconnus, réparti dans une liste de jetons.
- context
Type : Microsoft.Office.Tools.Word.SmartTagRecognizeContext
Objet qui fournit le texte du paragraphe envoyé au module de reconnaissance et une méthode pouvant être appelée pour indiquer que la balise active a été trouvée.
Notes
Cette méthode est appelée par Visual Studio Tools pour Office Runtime pour rechercher le texte correspondant aux termes reconnus. 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 montre comment implémenter la méthode Recognize. Cette implémentation compare chaque terme de balise active au contenu du paragraphe. Pour chaque terme de la balise active trouvé dans le paragraphe, le code ajoute une propriété de balise active personnalisée et utilise la méthode PersistTag pour reconnaître la balise active. Cet exemple suppose que vous avez ajouté une référence à Microsoft.Office.Interop.SmartTag à partir de l'onglet .NET de la boîte de dialogue Ajouter une référence. Cet exemple de code fait partie d'un exemple plus complet fourni pour l'interface ISmartTagExtension.
Private Sub Recognize(ByVal text As String,
ByVal site As ISmartTagRecognizerSite,
ByVal tokenList As ISmartTagTokenList,
ByVal context As SmartTagRecognizeContext) Implements ISmartTagExtension.Recognize
For Each term As String In smartTagDemo.Terms
' Search the text for the current smart tag term.
Dim index As Integer = text.IndexOf(term, 0)
While (index >= 0)
' 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.ToString())
' Attach the smart tag to the term in the document
context.PersistTag(index, term.Length, propertyBag)
' Increment the index and then find the next instance of the smart tag term.
index += term.Length
index = text.IndexOf(term, index)
End While
Next
End Sub
void ISmartTagExtension.Recognize(string text, ISmartTagRecognizerSite site, ISmartTagTokenList tokenList,
SmartTagRecognizeContext context)
{
foreach (string term in smartTagDemo.Terms)
{
// Search the text for the current smart tag term.
int index = text.IndexOf(term, 0);
while (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
context.PersistTag(index, term.Length, propertyBag);
// Increment the index and then find the next instance of the smart tag term.
index += term.Length;
index = text.IndexOf(term, index);
}
}
}
Sécurité .NET Framework
- Confiance totale accordée à l'appelant immédiat. Ce membre ne peut pas être utilisé par du code d'un niveau de confiance partiel. Pour plus d'informations, consultez Utilisation de bibliothèques à partir de code d'un niveau de confiance partiel.