Abstract:
A method of encoding the characters of a character set, wherein the characters have a plurality of attributes (e.g., base, diacritical, and case), and wherein each attribute may have a plurality of values. The method comprises the steps of: dividing a multi-digit code into a plurality of parts, assigning each attribute to a different part, and, within each part, assigning a different numerical code to each different value of the attribute.

Description:
BACKGROUND OF THE INVENTION 
     The invention relates to encoding characters. 
     Many ways exist to encode characters. For example, the American Standard Code for Information Interchange (ASCII) and the Multinational Character Set (MCS) assign a binary code to each character where the value of the code is the position of the character in an arbitrarily ordered character set. ASCII, for instance, includes alphabet letters (&#34;A-Z&#34; and &#34;a-z&#34;), numerals (&#34;0-9&#34;), and other characters (e.g., &#34;!&#34;, &#34;#&#34;, &#34;$&#34;, &#34;%&#34;, or &#34;&amp;&#34;). Each character has a position in the set the value of which is the character&#39;s code. The characters &#34;A&#34;, &#34;B&#34;, and &#34;C&#34;, for example, are in positions 65, 66, and 67, and are assigned codes 1000001, 1000010, and 1000011, respectively. 
     MCS, on the other hand, subsumes the ASCII character set and further includes so-called &#34;multinational&#34; characters. These multinational characters include phonetic characters, such as ligatures (e.g., &#34; &#34;) and characters having diacritical markings (e.g., &#34;A&#34;, &#34;E&#34;, and &#34;O&#34;), as well as other characters such as &#34; &#34; and &#34; &#34;. Again, each character has a position in the set the value of which is the character&#39;s code. The characters &#34;A&#34;, &#34;A&#34;, and &#34;A&#34;, for example, are in positions 193, 194, and 195, and are assigned codes 11000001, 11000010, and 11000011, respectively. 
     The codes in ASCII and MCS are often used to compare two characters from the same character set. A first character is greater than, less than, or equal to a second character if the value of its code is greater than, less than, or equal to the value of the code of the second character. For example, in MCS, &#34;A&#34; is less than &#34;A&#34; because 1000001 is less than 11000001. 
     The codes in ASCII and MCS are also used to compare strings of two or more characters from the same character set. To compare a first string and a second string, the character comparison described above is applied to a character in the first string and its corresponding character in the second string. The comparisons are repeated on successive corresponding characters until a character from the first string is greater than or less than its corresponding character in the second string, an operation referred to as a &#34;character by character&#34; comparison. 
     For example, a character by character comparison of the strings, &#34;canoes&#34; and &#34;canons&#34; indicates that &#34;canoes&#34; is less than &#34;canons&#34; because although the codes for &#34;c&#34;, &#34;a&#34;, &#34;n&#34;, and &#34;o&#34; are equal, the value of the code for &#34;e&#34; (01100101) is less than the value of the code for &#34;n&#34; (01101110). Note, however, that a character by character comparison ends once unequal characters are found. In the present example, the character &#34;s&#34; is never compared. This aspect of the character by character comparison can produce undesired results when strings contain a mixture of uppercase characters, lowercase characters, and phonetic characters. For example, in MCS, a character by character comparison indicates that &#34;McDougal&#34; is less than &#34;Mcdonald&#34; and that &#34;Muttle&#34; is less &#34;Muller&#34;. One method used to compare strings that contain a mixture of uppercase, lowercase, and phonetic characters is the &#34;three pass comparison&#34; described below. 
     In the three pass comparison method, the steps of the first pass are to 1) convert the characters of two strings to all uppercase characters, 2) reduce any phonetic characters to their base character, and 3) perform a character by character comparison on the remaining characters. For example, &#34;Muller&#34; and &#34;Muller&#34; become &#34;MULLER&#34; and &#34;MULLER&#34;, &#34;MacDonald&#34; and &#34;Macdonald&#34; become &#34;MACDONALD&#34; and &#34;MACDONALD&#34;, &#34;MacDougal&#34; and &#34;MacDougal&#34; become &#34;MACDOUGAL&#34; and&#34;MACDOUGAL&#34;, and &#34;Muttle&#34; and &#34;Muller&#34; become &#34;MUTTLE&#34; and &#34;MULLER&#34;. If the character by character comparison returns a value of equal, then the method proceeds to the second pass. For example, &#34;MULLER&#34;=&#34;MULLER&#34;, &#34;MACDONALD&#34;=&#34;MACDONALD&#34;, and &#34;MACDOUGAL&#34;=&#34;MACDOUGAL&#34;. Otherwise, the comparison returns either a result of greater than or less than and the method ends. For example, &#34;MUTTLE&#34;&gt;&#34;MULLER&#34;. 
     The steps of the second pass are to 1) convert the characters of the two strings to all uppercase characters with phonetic characters left in, and 2) compare the strings character by character. For example, &#34;Muller&#34; and &#34;Muller&#34; become &#34;MULLER&#34; and &#34;MULLER&#34;, &#34;MacDonald&#34; and &#34;Macdonald&#34; become &#34;MACDONALD&#34; and &#34;MACDONALD&#34;, and &#34;MacDougal&#34; and &#34;MacDougal&#34; become &#34;MACDOUGAL&#34; and &#34;MACDOUGAL&#34;. If the comparison returns that the strings are equal, then the method proceeds to the third pass. For example, &#34;MACDONALD&#34;=&#34;MACDONALD&#34; and &#34;MACDOUGAL&#34;=&#34;MACDOUGAL&#34;. Otherwise, the comparison returns a result of greater than or less than and the method ends. For example, &#34;MULLER&#34;&lt;&#34;MULLER&#34;. 
     The steps of the third pass are to 1) convert the strings to mixed uppercase and lowercase characters with phonetic characters, and 2) compare the strings character by character. For example, &#34;MacDonald&#34; and &#34;Macdonald&#34; become &#34;MacDonald&#34; and &#34;Macdonald&#34;, and &#34;MacDougal&#34; and &#34;MacDougal&#34; become &#34;MacDougal&#34; and &#34;MacDougal&#34;. If the comparison returns a result of equal, the method ends. For example, &#34;MacDougal&#34;=&#34;MacDougal&#34;. Otherwise, if the comparison returns a result of greater than or less than, the method ends. For example, &#34;MacDonald&#34;&gt;&#34;Macdonald&#34;. 
     SUMMARY OF THE INVENTION 
     In general the invention features a method of encoding the characters of a character set, wherein the characters have a plurality of attributes (e.g., base, diacritical, and case), and wherein each attribute may have a plurality of values. The method comprises the steps of: dividing a multi-digit code into a plurality of parts, assigning each attribute to a different part, and, within each part, assigning a different numerical code to each different value of the attribute. 
     In preferred embodiments, the length, i.e., the number of digits, of each part varies from character to character in the character set, depending on the number of different values of an attribute; the total length of the code is the same for all characters in the character set; and the attributes comprise a base attribute, a diacritical attribute, and a case attribute. Depending on the number of diacritical values for a particular base attribute, the length of the part assigned to the diacritical attribute is longer than the length of the part assigned to the base attribute. The method is used to encode each character in a string of characters. Parts of the code corresponding to the same attribute from each character in the string are concatenated, thereby producing for each attribute a segment of concatenated parts from each character, and the segments are themselves concatenated to form an overall concatenated code representing the character string, with the order of concatenation such that the segment corresponding to the attribute of primary significance in the collating sequence has the highest order position in the overall concatenated code and remaining segments are ordered in accordance with descending significance in the collating sequence. A field of null characters can be interposed between two concatenated segments of different attributes to prevent a collating sequence error arising from overlap of the two segments. Compare operations are performed on the overall concatenated code to determine the relative position of two character strings in a prescribed collating sequence; the compare operation constitutes a single comparison of the concatenated segments. Particular codes for primary and secondary attributes (e.g., base and diacritical attributes) are selected by counting, for each value of the primary attribute, the number of different values of the secondary attribute, and the length of the part of the code assigned to the secondary attribute is varied depending on the count (e.g., enough bits are provided to represent all possible values of the attribute). 
     An advantage of the invention is that a compare operation on two character strings is accomplished in one step. Another advantage is that a user may vary the collating sequence (i.e., the sorting order) as desired, without being constrained by the arbitrary order of the standard code (e.g., MCS code) for the characters. Thus, if it was desired, for example, to have &#34;c&#34; come after &#34;d&#34; instead of before it in a particular alphabet, the fact that the standard code used to represent the character (e.g., MCS) has &#34;c&#34; coming before &#34;d&#34; would not be a constraint. Still a further advantage is that two-letter characters, e.g., &#34;ch&#34; and &#34;ll&#34; of Spanish, can be treated as single characters in establishing a collating sequence. 
     Other features and advantages of the invention will be apparent from the following description of a preferred embodiment and from the claims. 
    
    
     DESCRIPTION OF THE PREFERRED EMBODIMENT 
     FIG. 1 is a block diagram of the components of an encoding system according to the present invention. 
     FIG. 2 is a flowchart of the general steps followed in assigning a value to a part. 
    
    
     The invention involves encoding, comparing, and relating characters such as those found in a text file or database. Such a character has a number of possible attributes including a base character, a diacritical marking, and a case, each of which has a one or more possible values. The value of the base attribute can be, for example, &#34;A&#34;, &#34;B&#34;, or &#34;C&#34;. The value of the diacritical attribute can be, for example, a circumflex &#34; &#34;, grave accent &#34; &#34;, or tilde &#34;˜&#34;. And the value of the case attribute can be uppercase, lowercase, or a combination of uppercase and lowercase, e.g., as in Spanish characters &#34;CH&#34;, &#34;ch&#34;, &#34;Ch&#34;, &#34;cH&#34;. For example, the character &#34;a&#34; has a base the value of which is &#34;A&#34;, a diacritical the value of which is a grave accent &#34; &#34;, and a case the value of which is lowercase. A description of the code generated according to the attributes of a character follows. 
     In a first aspect of the invention, a character is encoded according to its attributes. A code for a character is divided into parts and each part of the code is assigned to an attribute of the character. In the description below, the code for a character is nine bits long and is divided into three variable length parts: a base part, a diacritical part, and a case part, which are assigned to the base attribute, diacritical attribute, and case attribute of the character, respectively. For example, the character &#34;a&#34; has a base part the value of which is 00110, a diacritical part the value of which is 000, and a case part the value of which is 0. Table 1 shows a sampling of characters and their codes. 
     
                       TABLE 1______________________________________Character    Base Part   Diacritic Part                           Case Part______________________________________a          00110      000       0c         0011101      0        0c         0011101      1        0C         0011101      0        1E           010      00000      1E           010      00001      1E           010      00010      1E           010      00011      1E           010      00100      1e           010      00000      0e           010      00001      0e           010      00010      0e           010      00011      0e           010      00100      0o          1000       1000      0o          1000       1011      0p        10010000               0t        10110000               0______________________________________ 
    
     Referring to Table 1 and as noted above, the parts of a code vary in length. For example, the base part of the code for &#34;t&#34; is eight bits long, while the base part of the code for &#34;e&#34; is only three bits long. This is done to account for the variance in the number of possible values an attribute has. For example, &#34;e&#34; has many possible values in its diacritical attribute. Thus, the lengths of the parts assigned to the other attributes of &#34;e&#34; are shortened to provide enough bits in the part assigned to the diacritical attribute to represent each possible value. 
     Further, any characters that have the same value in an attribute can have the same value in the part of their code assigned to that attribute. For example, &#34;E&#34; and &#34;E&#34;  have the same values in their base and case attributes, but do not have the same value in their diacritical attribute. Therefore, &#34;E&#34; and &#34;E&#34; have the same value in their base parts (010) and case parts (1), but do not have the same value in their diacritical parts. The system and method used to encode characters and create a table similar to Table 1 are described next in connection with FIG. 1. 
     Referring to FIG. 1, an encoding system 10 includes a collating sequence 11 provided by a particular character set, e.g., MCS, and a list of modifications 12 provided by the user to alter the collating sequence 11. As described in detail below, a table generator 14 uses the collating sequence 11 and the modifications 12 to produce a table of encoded characters 16 similar to Table 1. The table of encoded characters 16 further includes codes for special case characters such as &#34;ch&#34; and &#34;ll&#34; which are considered one character in Spanish and &#34; &#34; in German which is considered as two characters &#34;ss&#34;. These special case characters are described in detail later in connection with various relational operations. However, first a description of the collating sequence 11 and the modifications 12 is provided. 
     The user modifies the sequence 11 of a character set by defining in the modifications 12 a number of attribute classes each of which corresponds to one of the attributes discussed above. All characters having one value for an attribute fall into one attribute class, while all characters having another value for the selected attribute fall into another attribute class. For example, &#34;A&#34;, &#34;a&#34;, &#34;A&#34;, &#34;a&#34;, &#34;A&#34;, and &#34;a&#34; all have a base attribute value of &#34;A&#34; and fall into one attribute class, while &#34;B&#34; and &#34;b&#34; have a base attribute value of &#34;B&#34; and fall into another attribute class. Within each attribute class, there are one or more attribute values. For example, the &#34;A&#34; attribute class has one base attribute value, four diacritical attribute values, and two case attribute values. The method of assigning the attribute values is described below in connection with the flowchart of FIG. 2 with reference to the components of FIG. 1. 
     In preparation for the steps shown in FIG. 2, the table generator 14 reads the modifications 12 and sets up the attribute classes. That is, for each character in the character set, the table generator 14 adds the character to any and all attribute classes to which it belongs, and increments the number of characters in those attribute classes by one. 
     Referring to FIG. 2, once all of the characters in the character set are read, the table generator 14 calculates the length of the code for a character (step 100), i.e., the length needed to represent the number of characters in the collating sequence 11. For example, up to 512 characters can be represented in 9 bits. The first attribute class to be processed is that of the first character in the collating sequence. Therefore, the variable representing the first base part value (b --  value) is initialized to 1 (step 102). Note at this point that it is often desirable to design the overall code in such a manner that several combinations of bits in a particular attribute may not be used. For example, if there are five diacriticals associated with an &#34;A&#34;, three bits are required for the diacritical part. Since the three bits can represent up to eight diacritical parts, three bit combinations are not used. 
     Next, for each attribute class (step 104) and each character in that attribute class (step 106), the table generator 14 calculates a value for the parts assigned to the character&#39;s various attribute. First, the table generator 14 calculates the number of bits needed to represent the various case attribute values (step 108). Note that in step 105, the variable representing the value of the diacritic part (d --  value) is initialized to 0 before processing each character. 
     For each character in the attribute class, the table generator 14, calculates the number of bits needed to represent the various case attribute values (step 108) and assigns a case part value for the character (step 110). 
     To assign a value for the diacritic part of the character, the table generator 14 calculates the number of bits needed to represent the various diacritic attribute values (step 112), assigns a diacritic part value for the character equal to d --  value (step 114), and increments the d --  value variable (step 116). For example, more than one value for the diacritical attributes exists in the &#34;A&#34; attribute class. Therefore, the diacritic part values for the characters in the &#34;A&#34; attribute class are calculated depending on when the character was added to the attribute class. Next, to assign a value for the base part of the character, the table generator 14 uses the remaining bits to represent the base attribute value of the character, i.e., b --  value, (step 118) and increments the b --  value (step 120). 
     Having assigned the part values for the various attributes of the character, the table generator 14 returns to step 106 to process the next character in the attribute class (step 122). If there are no other characters in the attribute class, the table generator 14 returns to step 104 to process the next attribute class (step 124). If there are no other attribute classes, the process ends (step 126). 
     In another aspect of the invention, once the table 16 is generated, a pair of character strings 22 can be compared. The strings 22 (represented by a standard code, e.g., MCS) are submitted to a translator 24 which applies the strings to the table 16 to generate translated strings 25. The translated strings 25 are then concatenated in the translator 24 to permit a one step compare operation. 
     First, for each string, the base parts of the codes of each character are concatenated with one another. For example, given the character set in Table 1, the base parts of the strings &#34;cote&#34; and &#34;cote&#34; are concatenated as follows. ##STR1## 
     Next, the base parts are then concatenated with a five bit null character pad as shown below. (The null character pad ensures that strings of different length are compared properly as shown in a later example.) ##STR2## 
     Next, the base parts and null character pad are concatenated with the diacritic parts of the characters, which are concatenated with one another. ##STR3## 
     Finally, the base parts, null character pad, and diacritic parts are concatenated with the case parts of the characters, which are concatenated with one another. The translated strings are: ##STR4## 
     As mentioned above the null character pad ensures that strings of different length are compared properly. Errors in comparing translated strings can arise when concatenated parts of an attribute, i.e., a segment of the translated string, overlap with segments produced from another attribute, specifically in cases where two strings of different length are equal up to the point where one of the strings ends. In such cases, the null character pad prevents the base parts of the longer string from being compared with the diacritical or case parts of the shorter string. For example, compare the translated strings &#34;c&#34; and &#34;ca&#34; without the null character pad: ##STR5## 
     In this example, the diacritical part of character &#34;c&#34; in the string &#34;c&#34; corresponds with the base part of the character &#34;a&#34; in the string &#34;ca&#34;. The result of comparing the strings is &#34;c&#34; &gt; &#34;ca&#34;, which is opposite of that intended, i.e., the string &#34;c&#34; should be less than, not greater than the string &#34;ca&#34;. To prevent such a result, the null character pad is concatenated between the base parts and diacritical parts of every string. The null character pad and its application to the above example are discussed below. 
     The null character pad is composed entirely of zeros, which ensures that the pad is always less than any base part with which the pad is compared. (Note that no base part is composed entirely of zeros or has leading zeros in excess of the number of zeros in the null character pad.) Thus, in cases where two strings of different length are equal to the point where one of the strings ends, the null character pad in the shorter string corresponds with the base part of the next character in the longer string, which effectively prevents the shorter string from being greater than the longer string. For example, compare the strings &#34;c&#34; and &#34;ca&#34; with the null character pad: ##STR6## 
     In this example, the null character pad for the string &#34;c&#34; is compared with the base part for the character &#34;a&#34; in the string &#34;ca&#34;. The result is &#34;c&#34;&lt;&#34;ca&#34; as intended. 
     To complete the translation example, the following strings are translated: 
     
         ______________________________________cot  =     0011101 1000  10110000 00000 0 1000 000cope =     0011101 1000 10010000 010 00000 0 1000 00000 0000cat  =     0011101 00110 10110000 00000 0 000  000Cope =     0011101 1000 10010000 010 00000 0 1000 00000 1000Cot  =     0011101 1000  10110000 00000 0 1000 100______________________________________ 
    
     Referring again to FIG. 1, the translator 24 submits translated strings 25 similar to those above to a compare operation 26, which accepts two operands and a length and returns a result of less than, greater than, or equal. A sort algorithm 28 then takes the result and orders the strings 22 accordingly. For example, the strings translated above are sorted as: 
     
         ______________________________________cat    =     00111010011010110000000000000000cope   =     00111011000100100000100000001000000000000Cope   =     00111011000100100000100000001000000001000cot    =     00111011000101100000000001000000Cot    =     00111011000101100000000001000100cote   =     00111011000101100000100000001000000000000______________________________________ 
    
     In another aspect of the invention, various relational operations such as &#34;MATCHING&#34;, &#34;CONTAINING&#34;, and &#34;STARTING WITH&#34; use the table of encoded characters 16 to compare and match strings and substrings of characters. These operations are useful, for example, when searching a text file or database for a certain string of characters. Of particular interest here is the matching of the so-called special case characters mentioned earlier in connection with the table of encoded characters 16. 
     Each relational operation returns a value of true or false depending on the value of the codes for the characters in the strings being compared and matched. The &#34;MATCHING&#34; operation returns a value of true if a first string matches any substring of a second string. The &#34;CONTAINING&#34; operation returns a value of true if a first string is found within a second string. The &#34;STARTING WITH&#34; operation returns a value of true if the initial characters in a first string match the initial characters in a second string. 
     Performing relational operations on the characters discussed so far is fairly straightforward and uses the character by character comparison described above, i.e., successive single characters in the first string are compared with corresponding single characters in the second string. However, special case characters such as &#34;ch&#34;, &#34;ll&#34;, and   must be treated differently. For example, the operation &#34;STARTING WITH C&#34; should not return a value of true for &#34;chile&#34; in Spanish since &#34;ch&#34; is one character in Spanish. 
     In order to compare special case characters, then, the relational operations first attempt to locate each character in a string in a section of the table of encoded characters 16 that contains special case characters such as &#34;ch&#34;. A table of encoded characters for the Spanish character set is attached as an appendix. (Note that the table relates directly to the source code in the attached microfiche appendix. Therefore, the parts values are read right to left for reasons discussed below in connection with the source code. However, the principles of operation remain the same.) For example, using the Spanish table of encoded characters shown in the attached appendix, if the operation &#34;STARTING WITH T&#34; encounters a &#34;T&#34; in a string, it checks the section of special cases to see if &#34;T&#34; is the first character in any special case character. Since &#34;T&#34; is not the first character in any special case character, the operation locates &#34;T&#34; in the section of the table 16 that contains non-special case characters and uses the code found there. 
     On the other hand, if the operation &#34;STARTING WITH C&#34; encounters a &#34;C&#34; in a string, it checks the section of special cases to see if &#34;C&#34; is the first character in any special case character. Since &#34;C&#34; is the first character in the special case character &#34;CH&#34;, the operation checks to see if the next character in the string is an &#34;H&#34;. If so, the operation uses the code for &#34;CH&#34; found in the section of special case characters in the table 16. However, if the &#34;C&#34; was not followed by an &#34;H&#34;, then the operation locates &#34;C&#34; in the section of the table that contains non-special case characters and uses the code found there. For example, &#34;STARTING WITH C&#34; returns a value of false for &#34;chile&#34; and returns a value of true for &#34;casa&#34;. 
     Pursuant to CFR 37 §1.96 (b), the source code that embodies the table generator 14 is attached as a microfiche appendix containing 62 frames and is incorporated herein by reference. The programming language used is Bliss, (VAX Bliss-32 V4.3-808), a programming language of Digital Equipment Corporation, the specification of which is published and available from Digital as the BLISS Language Reference Manual AA-H275D-TK, May 1987. The source code was compiled using Bliss Compiler 4.3-808 on a VAX 8800 computer running under the VMS 5.2 operating system. Note that the architecture of the VAX computer considers the leftmost bit of a string to be the most significant bit of a byte. Therefore, the source code embodiment encodes characters so that they are read and concatenated from right to left. The order of bits in translated strings is then reversed before the strings are compared, an operation sometimes referred to as &#34;flipping the bits&#34;. The methods of encoding and concatenation are discussed above in a left to right orientation for ease of reading and understanding. 
     Other embodiments are within the following claims.