Método ISmartTagExtension.Recognize

Procura texto no documento termos reconhecidos.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (em Microsoft.Office.Tools.Word.dll)

Sintaxe

'Declaração
Sub Recognize ( _
    text As String, _
    site As ISmartTagRecognizerSite, _
    tokenList As ISmartTagTokenList, _
    context As SmartTagRecognizeContext _
)
void Recognize(
    string text,
    ISmartTagRecognizerSite site,
    ISmartTagTokenList tokenList,
    SmartTagRecognizeContext context
)

Parâmetros

  • text
    Tipo: System.String
    O texto a ser pesquisado reconhecido termos.
  • site
    Tipo: Microsoft.Office.Interop.SmartTag.ISmartTagRecognizerSite
    O local do texto no documento ou pasta de trabalho.
  • tokenList
    Tipo: Microsoft.Office.Interop.SmartTag.ISmartTagTokenList
    O texto a ser pesquisado reconhecido termos, divididos em uma lista de tokens.

Comentários

Este método é chamado pelo Visual Studio Tools for Office runtime a pesquisa de texto para termos reconhecido. Implemente este método se você deseja incorporar seus próprios algoritmos de pesquisa para executados juntamente com os reconhecedores de padrão.

Exemplos

O exemplo de código a seguir demonstra como implementar a Recognize método. Essa implementação compara cada termo de marca inteligente para o conteúdo do parágrafo. A cada termo de marca inteligente no parágrafo, o código adiciona uma propriedade de marca inteligente personalizada e, em seguida, usa o PersistTag método para reconhecer o smart tag. Este exemplo assume que você adicionou uma referência a Microsoft.Office.Interop.SmartTag partir do .NET guia de Add Reference caixa de diálogo. Este exemplo de código é parte de um exemplo maior fornecido para a 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);
        }
    }
}

Segurança do .NET Framework

Consulte também

Referência

ISmartTagExtension Interface

Namespace Microsoft.Office.Tools.Word