15.7 A Speller You want the user environment for chip queries to be helpful when the user enters an unknown table name or variable name . You also want the UE to allow the user to enter queries in any combination of uppercase and lowercase, although the engine is case-sensitive. You can use a speller to achieve these aims. One technique for maintaining a preferred spelling of known words is to keep a dictionary whose key/value pairs are composed of a known word spelled in all lowercase, followed by the preferred spelling of the word. For example, such a dictionary would contain customerid -> CustomerID This lets the UE accept customerid as a valid variable name. This dictionary is also a registry of known names , so the UE will detect, for example, that CustId is not merely misspelled but also an unknown variable name. As Figure 15.14 shows, this chapter uses a Speller interface and a ChipSpeller implementation of it to support the proper spelling of class and variable names. Figure 15.14. The ChipSpeller class. This class records the proper capitalization in the spelling of all class names and variable names in the Chip object model. The constructor for ChipSpeller calls the two load methods . The loadClassNames() method adds each class name from the Chip object model into the ChipSpeller object's dictionary of class names. The loadVariableNames() method uses the query templates from ChipSource to detect the variable names in the object model. Given any capitalization of a class name or variable name, a ChipSpeller object can look up the proper capitalization. It does this by converting the given spelling to all lowercase and then looking up this string in the appropriate dictionary. |