A Developer's Take on Smart Tags

 

Bill Coan
Microsoft Word MVP
billcoan@wordsite.com
http://www.wordsite.com

February 2005

Applies to:
    Microsoft Office 2003 Editions

Summary: Bill Coan provides a straightforward introduction to smart tags. What are they? What do all the different terms mean? What do they do? Learn this and more in this article. (9 printed pages)

Contents

Smart Tags: The Hardest Working Tags in the Business
What Are Smart Tags, Really?
Putting the "Smart" in Smart Tags, with Recognizers and Actions
Top 10 Questions Asked by Developers About Recognizers and Action Handlers
Creating Your Own Recognizers and Action Handers
Some Final Thoughts on Terminology
Conclusion
About the Author

Smart Tags: The Hardest Working Tags in the Business

With the advent of smart tags, the Microsoft Office System now has the capability to help us interpret the information in our documents and integrate that information with our existing knowledge, so we can make more informed decisions.

These are big claims, so let me back them up with an example.

My brother-in-law happens to be a successful executive for a very large company, so busy that he doesn't have down time to scroll through the Wall Street Journal. Instead, his assistant reads the Journal for him and uses a red pen to underline any items of special interest to him, such as names of customers and suppliers.

My brother-in-law invariably asks questions about the items that are underlined: What's happening with this customer's shares in the stock market? Where is last week's story about the court case involving this supplier? And so on. Answers to these questions help him fully integrate what he's reading with what he already knows.

The assistant is very competent and likes to be prepared. Therefore, before turning over the paper to my brother-in-law, she gathers up anything and everything that he might ask for. When questions pop up, she's ready with answers. This helps my brother-in-law view each underlined item in its full context, connect each item to other items that matter to him, and gain maximum advantage from everything he reads.

Wouldn't it be great if you and I each had an assistant like the one my brother-in-law has? Of course, your interests are different from mine, so your assistant would need to be familiar with your special interests and my assistant would need to be familiar with my special interests. That way, the items underlined in your reading material would be items of special interest to you and the items underlined in my reading material would be items of special interest to me. And if either of us had any questions about an underlined item, the answers to our questions would be right at hand, thanks to the preparations carried out by our assistants.

Smart tags are the assistants we've been waiting for. When you read a document or a spreadsheet or an e-mail message, they underline items of special interest to you. If you have a question about an underlined item or want to do something with it, smart tags provide a gateway to further information and further activities related to that item, specific to your personal needs.

Like so many other features built into the Microsoft Office System, smart tags provide a certain amount of power right out of the box, but their real power becomes most apparent when they are tailored precisely to your needs. Under those circumstances, they help you see items of interest in their full context and they help you connect those items to everything else that matters to you (yes, YOU). When tailored this way, smart tags enable you to fully integrate what you're reading with what you already know, helping you to gain maximum advantage from everything you read.

What Are Smart Tags, Really?

Smart tags are hidden pointers implemented inside a document, spreadsheet, or e-mail message. Text tagged with these hidden pointers appears with a dotted underline so that you know the text is of special interest to you. The hidden pointers aren't displayed on screen, but if they were, they could be represented as a pair of XML tags surrounding your text, like the following:

<st1:author>Bill Coan</st1:author>

Note   In Office 2003 Editions, if you save your work as an XML document with embedded smart tags and then open the resulting file in a text editor (such as Notepad), you'll see smart tags that look just like those shown earlier. You don't have to know anything special about XML tags in order to understand the rest of this article, but if you're interested, you can find an introductory discussion of XML tags in the article Getting into XML with the Microsoft Office System.

Putting the "Smart" in Smart Tags, with Recognizers and Actions

How can a hidden pointer embedded in a document, spreadsheet, or e-mail message be "smart"? Well, actually, smart tags themselves aren't smart. What's smart is the software that puts them there and the software that helps you do things with them. There are two types of software involved:

  • In Microsoft Office applications, a piece of software known as a recognizer applies smart tags to text automatically. A recognizer identifies text of special interest to you. For example, a recognizer might recognize phone numbers or postal codes or names of customers and suppliers. After applying smart tags to your text, the recognizer tells your application to display a dotted line underneath the tagged text, so you'll know the text is of special interest to you.
  • In Microsoft Office applications, when you move your pointer over a smart tag, the application displays a button immediately above the text. If you click the button, the application calls a piece of software known as an actionhandler. The action handler displays a menu of commands appropriate for the tagged text. For example, if you move your pointer over some text tagged as a phone number and then click the button that appears immediately above the phone number, the application calls a phone number action handler. This handler displays a menu of commands for working with the phone number, such as a command to dial the number and a command to perform a reverse directory search on the number. If you click one of the commands, the action handler carries out the command.

The Microsoft Office System comes with recognizers for dates and times, stock ticker symbols, person names, and addresses. Also included is a recognizer that identifies terms stored in special text files on your local hard disk. By editing the terms in the text files, you can add or delete words and phrases recognized by Office applications. Starting with Office 2003 Editions, the text files can store regular expressions (similar to pattern-matching or wildcard expressions), as well as lists of explicit terms, for even greater flexibility in defining text of interest to you. Additional recognizers are available from third-party developers or you can develop them by following the procedures referenced later in this article.

The Microsoft Office System also comes with a number of action handlers, including one that uses dates and times for looking up or scheduling events in Microsoft Office Outlook 2003, one for working with stock ticker symbols, and others for working with names and addresses. An action handler is also included that enables you to visit URLs listed in special text files on your local hard disk. (The text files that store the lists of URLs are the same ones where list of terms and regular expressions are stored.) By editing the URLs in the text files, you can add or delete locations that this action handler will take you to. Additional action handlers are available from third-party developers or you can develop them by following the procedures referenced later in this article.

Top 10 Questions Asked by Developers About Recognizers and Action Handlers

Now that you've been introduced to the basics of smart tags, a number of questions might be popping up in your mind, especially with regard to recognizers and action handlers. In the paragraphs that follow, I will try to answer those questions. I will restate some of the basic concepts already discussed earlier, partly to reinforce those concepts, but also to give you a chance to consider the concepts in a larger context.

  1. What is a recognizer? As noted earlier, a recognizer is a piece of software that evaluates the text in an Office application and places smart tags around any words or phrases recognized as being of special interest to you. The recognizer then tells the application to display a dotted line beneath the recognized text so you know that the text is of special interest to you. The Microsoft Office System comes with a number of recognizers. Additional recognizers are available from Microsoft and from third-party developers.

    **Note   **The tags inserted by a recognizer are not visible on the screen but you can save them in the document along with the text; if the application's Embed Smart Tags option is selected.

  2. What is the Smart Tag Lists Recognizer? The Smart Tag Lists Recognizer is one of the recognizers included with the Microsoft Office System. (In case you're curious, this recognizer is stored in a file called MOFL.dll.) The words and phrases identified by this recognizer are listed in special XML files that can be edited with any text editor, such as Notepad. The special XML files are known as Smart Tag List files or, more simply, as Smart Tag Lists, are stored at C:\Program Files\Common Files\Microsoft Shared\Smart Tag\Lists.

    **Note   **Don't be fooled by the term "Smart Tags List files". These files don't contain lists of smart tags. They contain lists of terms and regular expressions recognized by the "Smart Tag Lists Recognizer". Smart tags themselves are found only in Office application documents and in some Web pages.

    Important   When editing Smart Tag List files, carefully preserve the structure of the text inside the files.

    For more information and instructions for editing Smart Tag List files, see Developing Simple Smart Tags.

    For more information and instructions for using regular expressions (sometimes called pattern-matching or, more simply, wildcards) in Smart Tag List files, see Regular Expression Support in Microsoft Office System Smart Tags.

    **Note   **Office 2003 Editions is the first version of Office to enable the "Smart Tag Lists Recognizer" with the ability to interpret regular expressions in Smart Tag List files.

  3. How do recognizers make themselves known to Office applications? Before a recognizer can be used by Office applications, it must be identified in the system registry under the following key:

    HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Smart Tag\Recognizers\{GUID}

    where {GUID} is a globally unique identifier, assigned by the developer of the recognizer. For example, on my system, the Smart Tag Lists Recognizer included with Office (the one stored in MOFL.dll) is identified by the following key:

    HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Smart Tag\Recognizers\{64AB6C69-B40E-40AF-9B7F-F5687B48E2B5}

    The {GUID} value helps Office applications look up (elsewhere in the registry) important information about the recognizer, including the name and location of the file where the recognizer's executable code is stored. This information is available in the registry under HKEY_CLASSES_ROOT\CLSID\{GUID}. For example, important information about the Smart Tag Lists Recognizer on my system is available in the system registry at:

    HKEY_CLASSES_ROOT\CLSID\{64AB6C69-B40E-40AF-9B7F-F5687B48E2B5}

  4. Can Office applications load more than one recognizer into memory at a time? When an Office application launches, it loads into memory all available recognizers. That is, all recognizers listed in the registry under the following key:

    HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Smart Tag\Recognizers)

    Important   If some other Office application is already running, then each new Office application launched after the first one uses the recognizers already in memory, without loading any new ones. This means that, after a new recognizer is installed and properly listed in the registry, all Office applications must be exited, and then one of them must be restarted, in order to load the new recognizer into memory.

  5. How does an Office application pass its text to a recognizer? The process of passing text from an application to a recognizer is carried out on a background thread—the text is passed to the recognizer when the application isn't busy with other activities. In most cases, the process completes very quickly and the user thinks the text is recognized instantaneously as it is typed.

    **Note   **Office applications pass their text to all of the recognizers that are loaded into memory, except those that are disabled by the user in an application's Smart Tag Options dialog box. Each recognizer uses its own logic when deciding whether to recognize a specified word or phrase. A word recognized by one recognizer is not necessarily recognized by any another recognizer, but it is possible for multiple recognizers to apply multiple smart tags around the same word or phrase.

  6. What is an action handler? As noted earlier, an action handler is a piece of software that displays a menu of commands when you move your mouse over text that is tagged with a pair of smart tags and then click the button that appears above the text. If you click one of the commands on the menu, the action handler is also what carries out the command.

  7. What is the "Smart Tag Lists Action Handler"? The Smart Tag Lists Action Handler is one of the action handlers included with the Microsoft Office System. This handler is stored in a file called MOFL.dll, which also contains the Smart Tag Lists Recognizer. Like any other action handler, the Smart Tag Lists Action handler displays a menu of commands when you move your mouse over text that is tagged with a pair of smart tags and then click the button that appears immediately above the button.

    The menu of commands displayed by the Smart Tag Lists Action handler is limited to commands that enable you to visit URLs listed in special text files. You can edit the text files with any text editor, such as Notepad. The special files are known as Smart Tag List files or, more simply, as Smart Tag Lists, and are stored in the following path:

    C:\Program Files\Common Files\Microsoft Shared\Smart Tag\Lists

    These are the same text files where lists of terms and regular expressions are stored for use by the Smart Tag Lists Recognizer.

    **Note   **Don't be fooled by the term "Smart Tags List files." These files do not contain lists of smart tags. They contain lists of URLS used by the Smart Tag Lists Action Handler and lists of terms and regular expressions used by the Smart Tag Lists Recognizer. Smart tags are found only in Office application documents and in some Web pages.

    Important   When editing Smart Tag List files, take care to preserve the structure of the text inside the files.

    For more information and instructions for editing Smart Tag List files, see Developing Simple Smart Tags.

    For more information and additional instructions about editing Smart Tag List files, see Regular Expression Support in Microsoft Office System Smart Tags.

  8. How do Action Handlers make themselves known to Office applications? Before Office applications can use an action handler, it must be identified in the system registry under the following:

    HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Smart Tag\Actions\{GUID}

    where {GUID} is a globally unique identifier, assigned by the developer of the action handler. For example, on my system, the Smart Tag Lists action handler included with Office (the one stored in MOFL.dll) is identified by the following key:

    HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Smart Tag\Actions\{64AB6C69-B40E-40AF-9B7F-F5687B48E2B5}

    The {GUID} value helps Office applications look up (elsewhere in the registry) important information about the action handler, including the name and location of the file where the action handler's code is stored. This information is available in the registry under HKEY_CLASSES_ROOT\CLSID\{GUID}. For example, important information about the Smart Tag Lists action handler on my system is available in the system registry at:

    HKEY_CLASSES_ROOT\CLSID\{64AB6C69-B40E-40AF-9B7F-F5687B48E2B5}

  9. Can Office applications load more than one action handler into memory at a time? When an Office application launches, it loads into memory all available action handlers—all action handlers listed in the registry under the following key:

    HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Smart Tag\Actions

    Important   If another Office application is already running, then each new Office application launched after the first one uses the action handler already in memory, without loading any new ones. This means that, even if a new action handler is installed and identified in the registry, you must exit all Office applications before any of the applications can load the new action handler into memory.

  10. What happens when multiple action handlers are present? When you move your mouse over text that is tagged with a pair of smart tags and then click the button that appears above the text, your application displays a menu of available commands. The commands displayed on the menu may derive from a single action handler or from multiple action handlers. For example, some of the commands may derive from an action handler included with Office, while others may derive from a custom third-party action handler.

    When you move your mouse over some text that is tagged with a pair of smart tags and then click the button that appears immediately above the text, your application checks all of the smart tag action handlers currently loaded in memory to see which ones offer commands for those particular smart tags. The menu that appears includes commands from all of the action handlers that have actions for the smart tags involved.

Creating Your Own Recognizers and Action Handers

Recognizers and action handlers are stored in Microsoft ActiveX .dll files or in Microsoft .NET Framework class libraries with COM wrappers that make the libraries available to Office applications, as if the libraries were ActiveX .dll files.

Important   A single .dll file or .NET class library can contain both a recognizer and an action, but this is not a requirement. An action handler stored in a completely different .dll file or .NET Framework class library can respond to smart tags by a recognizer stored in a .dll file or .NET Framework class library. An action handler does not care which recognizer applied a pair of smart tags. The action handler only pays attention to the namespace and the element name.

For more information and instructions for creating recognizers and actions in Microsoft Visual Basic 6.0, see Developing Smart Tag DLLs.

For more information and instructions for creating recognizers and actions in Microsoft Visual Studio .NET, see Building Smart Tags in Microsoft Visual Basic .NET.

Some Final Thoughts on Terminology

To help you remember some of the concepts discussed in this article, and to better prepare you for the terminology you will find in other articles about smart tags, the following table defines a number of common smart tag terms.

Table 1. Common smart tag terms

Smart Tag Term Definition
smart tag Hidden pointers implemented inside a document, spreadsheet, or e-mail message. Text tagged with these hidden pointers is displayed with a dotted underline so that you know the text is of special interest to you. The hidden pointers aren't displayed on screen, but if they were, they could be represented as a pair of XML tags surrounding your text, like this:
<st1:author>Bill Coan</st1:author>
smart tag text A word or phrase of special interest to you that is surrounded by smart tags.
smart tag button The button that appears above smart tag text when you move your mouse over the text.
smart tag menu The menu that appears when you click a smart tag button.
smart tag command A command that appears on a smart tag menu.
smart tag recognizer A piece of software that evaluates the text in an Office application and places smart tags around any words or phrases recognized as being of special interest to you. A number of recognizers are included with the Microsoft Office System. Others are available from Microsoft and from third-party developers.
smart tag lists recognizer One of the recognizers included with the Microsoft Office System. The words and phrases recognized by this recognizer are listed in special text files that you can edit with any text editor, such as Notepad. The special text files are known as smart tag list files or, more simply, as smart tag lists.
smart tag action A piece of software that displays a menu of commands when you hover your mouse over text that is tagged with a pair of smart tags and then click the button that appears above the text. (If you click one of the commands on the menu, the action handler also carries out the command.)
smart tag lists action One of the action handlers included with the Microsoft Office System. Displays a menu of commands that enable you to visit URLs listed in special text files that you can edited with any text editor, such as Notepad. The special files are known as smart tag list files or, more simply, as smart tag lists. (These are the same text files where lists of terms and regular expressions are stored for use by the smart tag lists recognizer.)
smart tag list file See smart tag list.
smart tag list Special XML files that you can edit with any text editor, such as Notepad. They contain lists of URLS used by the smart tag lists action handler and lists of terms and regular expressions used by the smart tag lists recognizer. smart tag lists are stored at C:\Program Files\Common Files\Microsoft Shared\Smart Tag\Lists.
term list A list of words or phrases stored in a smart tag list and recognized by the smart tag lists recognizer included with the Microsoft Office System.
regular expression A pattern-matching/wildcard expression stored in a Smart Tag List and recognized by the smart tag lists recognizer included with the Microsoft Office System.
smart tag .dll A COM object that can contain a smart tag recognizer and/or a smart tag action.
smart tag class library A Microsoft .NET class library that can contain a smart tag recognizer and/or a smart tag action.

Conclusion

In the hands of a knowledgeable developer, smart tags have the potential to reshape user interactions with Microsoft Office documents.

The immediate result is that users see items of interest to them in full context. This helps them integrate what they're reading with what they already know, and this, in turn, helps them arrive at better-informed decisions. A follow-on result is that users can take immediate action simply be clicking on a Smart Tag command.

For developers, smart tags represent an opportunity to have a dramatic impact on user productivity and the richness of the user experience, and that means smart tags represent an opportunity for developers to shine.

About the Author

Bill Coan is a recognized leader in the development of custom Microsoft Office solutions. His thoughts on the Microsoft Office System and other software technologies have been featured in eWeek, PC Magazine, PC PRO, Information Week, Microsoft Developer Network, and nearly a score of other print and electronic media outlets. For information about his professional services, see http://www.wordsite.com/services/services.htm.

© Microsoft Corporation. All rights reserved.