ISmartTagExtension.Recognize 方法

在文档的文本中搜索识别的术语。

命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word(在 Microsoft.Office.Tools.Word.dll 中)

语法

声明
Sub Recognize ( _
    text As String, _
    site As ISmartTagRecognizerSite, _
    tokenList As ISmartTagTokenList, _
    context As SmartTagRecognizeContext _
)
void Recognize(
    string text,
    ISmartTagRecognizerSite site,
    ISmartTagTokenList tokenList,
    SmartTagRecognizeContext context
)

参数

  • text
    类型:System.String
    要搜索的文本,搜索的目标是识别的术语。
  • site
    类型:Microsoft.Office.Interop.SmartTag.ISmartTagRecognizerSite
    文本在工作簿或文档中的位置。
  • tokenList
    类型:Microsoft.Office.Interop.SmartTag.ISmartTagTokenList
    分解为标记列表的搜索文本,搜索的目标是识别的术语。

备注

此方法由 Visual Studio Tools for Office Runtime 调用,以便在文本中搜索识别的术语。 如果您除了运行标准识别器以外还要结合自己的搜索算法,请实现此方法。

示例

下面的代码示例演示如何实现 Recognize 方法。 此实现将每个智能标记术语与该段落的内容进行比较。 对于该段落中的每个智能标记术语,该代码添加一个自定义智能标记属性,然后使用 PersistTag 方法识别该智能标记。 此示例假设您已从**“添加引用”对话框的“.NET”选项卡中添加了一个对“Microsoft.Office.Interop.SmartTag”**的引用。 此代码示例摘自为 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);
        }
    }
}

.NET Framework 安全性

请参见

参考

ISmartTagExtension 接口

Microsoft.Office.Tools.Word 命名空间