Поделиться через


SmartTagBase.Recognize Метод (2007 System)

Обновлен: Ноябрь 2007

Поиск распознанных терминов в тексте.

Пространство имен:  Microsoft.Office.Tools
Сборка:  Microsoft.Office.Tools.Common.v9.0 (в Microsoft.Office.Tools.Common.v9.0.dll)

Синтаксис

'Декларация
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
)

Параметры

  • text
    Тип: System.String
    Текст, в котором необходимо произвести поиск распознанных терминов.
  • site
    Тип: ISmartTagRecognizerSite
    Расположение текста в книге или документе.
  • tokenList
    Тип: ISmartTagTokenList
    Текст, в котором необходимо произвести поиск распознанных терминов, разбитый на список лексем.

Заметки

Вызывается средой выполнения Visual Studio Tools for Office во время простоя для поиска распознанных терминов в тексте. Применяйте этот метод, если требуется применить собственные алгоритма поиска в дополнение к стандартным распознавателям.

Примеры

В следующем примере кода демонстрируется переопределение метода Recognize в классе, производном от класса Microsoft.Office.Tools.Excel.SmartTag. Реализация метода Recognize сравнивает каждый термин смарт-тега с содержимым ячейки листа Microsoft Office Excel. Если в ячейке найден термин смарт-тега, код добавляет пользовательское свойство к смарт-тегу и затем вызывает метод SmartTag.PersistTag(ISmartTagProperties) для распознавания смарт-тега. В данном примере предполагается, что была добавлена ссылка на библиотеку типов Microsoft Smart Tags 2.0 на вкладке COM диалогового окна Добавление ссылки. Данный пример кода является частью большого примера, приведенного в описании класса Microsoft.Office.Tools.Excel.SmartTag.

В этом примере демонстрируется настройка уровня документа.

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

Разрешения

См. также

Ссылки

SmartTagBase Класс

SmartTagBase - члены

Microsoft.Office.Tools - пространство имен