ISmartTagExtension.Recognize Method
Searches text in the document for recognized terms.
Namespace: Microsoft.Office.Tools.Word
Assembly: Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)
Syntax
'Declaration
Sub Recognize ( _
text As String, _
site As ISmartTagRecognizerSite, _
tokenList As ISmartTagTokenList, _
context As SmartTagRecognizeContext _
)
void Recognize(
string text,
ISmartTagRecognizerSite site,
ISmartTagTokenList tokenList,
SmartTagRecognizeContext context
)
Parameters
- text
Type: System.String
The text to search for recognized terms.
- site
Type: Microsoft.Office.Interop.SmartTag.ISmartTagRecognizerSite
The location of the text in the workbook or document.
- tokenList
Type: Microsoft.Office.Interop.SmartTag.ISmartTagTokenList
The text to search for recognized terms, broken down into a list of tokens.
- context
Type: Microsoft.Office.Tools.Word.SmartTagRecognizeContext
An object that provides the text from the paragraph that is sent to the recognizer and a method you can call to indicate that the smart tag was found.
Remarks
This method is called by the Visual Studio Tools for Office runtime 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 implement the Recognize method. This implementation compares each smart tag term to the contents of the paragraph. For each smart tag term in the paragraph, the code adds a custom smart tag property and then uses the PersistTag method to recognize the smart tag. This example assumes that you have added a reference to Microsoft.Office.Interop.SmartTag from the .NET tab of the Add Reference dialog box. This code example is part of a larger example provided for the ISmartTagExtension interface.
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);
}
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.