Text compression technique using frequency ordered array of word number mappers

Abstract: A text-compression technique utilizes a plurality of word-number mappers ("WNMs") in a frequency-ordered hierarchical structure. The particular structure of the set of WNMs depends on the specific encoding regime, but can be summarized as follows. Each WNM in the set is characterized by an ordinal WNM number and a WNM size (maximum number of tokens) that is in general a non-decreasing function of the WNM number. A given token is assigned (52) a number pair, the first being one of the WNM numbers, and the second being the token's position or number in that WNM. Typically, the most frequently occurring tokens are mapped with a smaller-numbered WNM. The set of WNMs is generated on a first pass through the database to be compressed. The database is parsed into tokens, and a rank- order list based on the frequency of occurrence is generated. This list is partitioned in a manner to define the set of WNMs. Actual compression of the data base occurs on a second pass, using the set of WNMs generated on the first pass. The database is parsed into tokens, and for each token, the set of WNMs is searched to find the token. Once the token is found, it is assigned the appropriate number pair and is encoded (55). This proceeds until the entire database has been compressed.

Description: The present invention relates generally to data compression techniques, and more specifically to a text compression technique that is suitable for compressing text databases having a large number of different words. Computer users are coming to expect large text databases at their fingertips, and this trend will continue as portable and hand-held computerized devices become more common. Compression ratio is a major issue, since many of the reference works that are candidates for being made available are rather long. A separate issue is whether the text has to be decompressed in order to search for particular strings. Many techniques are efficient in terms of compression ratio, but are context sensitive (i.e., searching the text requires decompression and decompressing one part requires decompressing other unrelated parts). This extra decompression step may slow down the search process to an unacceptable degree, thereby necessitating the use of faster (and more expensive) hardware components. One technique that has shown considerable promise and that has found its way into a number of commercial products in the last few years uses a data structure referred to as a word- number mapper ("WNM"). The WNM can be regarded conceptually as a table wherein each distinct word and punctuation mark, referred to as a token, in the database has an associated unique number. The table thus provides a unique bidirectional word-number mapping. The actual WNM is implemented as a highly compressed data structure. Compression of the database occurs generally as follows. First the text is parsed into a sequence of alternating word and punctuation mark tokens, which are accumulated to build up the table. The table only includes one entry for each token type, no matter how often that type occurs in the text database. In a second pass, the text is again parsed into tokens, and each token is encoded by its unique number in the table. In one regime, most of the tokens are encoded as a two-byte number, but some are encoded as a single byte. By way of specific example, the Bible was found to have approximately 13,000 different token types while the Physician's Desk Reference was found to have approximately 25,000 different token types. Decompression is the inverse process to compression. The numerical codes in the compressed string are converted to the corresponding uncompressed tokens using the same WNM that was used to compress the text in the first place. Account must be taken of the manner that the string of numerical codes was stored in the compression process. The present invention provides a method of performing text compression according to claims 1 and 4 of the appended claims. This technique is characterized by a relatively high compression ratio (on the order of 4:1 as opposed to the more typical 2.5:1). The technique is especially useful where the text database contains a very large number of distinct token types, and is based in part on the recognition that certain of the prior art techniques would break down if the number of distinct token types were to exceed the largest number that could be encoded in a particular size code. In brief, the present invention utilizes a plurality of word-number mappers ("WNMs") in a Frequency-ordered hierarchical structure. The particular structure of the set of WNMs depends on the specific encoding regime, but can be summarized as follows. Each WNM in the set is characterized by an ordinal WNM number and a WNM size (maximum number of tokens) that is in general a non-decreasing function of the WNM number. A given token is assigned a number pair, the first being one of the WNM numbers, and the second being the token's position or number in that WNM. Typically, the most frequently occurring tokens are mapped with a smaller-numbered WNM. This means that they can be represented by a shorter code (fewer bits). The set of WNMs is generated on a first pass through the database to be compressed. The database is parsed into tokens, and a rank-order list based on the frequency of occurrence is generated. This list is partitioned in a manner to define the set of WNMs, with the particular details depending on the particular encoding regime. In a specific embodiment, the coding is on a nibble (four-bit) basis, with a given code having a variable number of nibbles. Provision is made so that the length of a particular code can be determined. In the specific embodiment, one of the bits is used to signify whether or not that nibble is the last nibble in the possibly multi-nibble code. In the context of this particular coding regime, the eight most frequently occurring token types are assigned a three-bit number and are coded in a single nibble. These tokens define the first, eight-token WNM. The 64 next most frequently occurring token types are assigned a six-bit number and are coded in two nibbles. These tokens define the second, 64-token WNM. The 512 next most frequently occurring token types are assigned a 9-bit number and are coded in three nibbles. This encoding in increasing length codes based on lower frequency of occurrence continues until all of the token types have been assigned a number pair. Actual compression of the data base occurs on a second pass, using the set of WNMs generated on the first pass. The database is parsed into tokens, and for each token, the set of WNMs is searched to find the token. Once the token is found, it is assigned the appropriate number pair and is encoded. This proceeds until the entire database has been compressed. Searching for a particular string does not require decompression. Rather, the target string, as entered by the user, is compressed according to the same regime to yield a string of one or more nibbles, and a suitable substring searching algorithm is employed. Once the compressed search string is found in the compressed database, a suitable amount of the surrounding text (e.g., the paragraph that contains the search string) may be decompressed. The text can be searched backward and forward from the located search string to find the immediately preceding paragraph and immediately following paragraph breaks if it is desired to display the entire paragraph containing the search string. A further aspect of the present invention is that it can be adapted for use with a database that is different from the database that was used to generate the set of WNMs. When the database that is to be compressed is different, there is no guarantee that the set of WNMs constructed using the original database will contain all the tokens in the new database. In fact, there is a strong likelihood that there will be some new tokens that are missing from the set of WNMs. According to this aspect of the invention, a unique number pair is assigned to each possible individual character during the construction of the WNMs. When it is discovered during the compression that a token is absent from the WNMs, an auxiliary scheme is used. In one such scheme, the token is encoded as a plurality of individual character codes. This guarantees the ability to encode every possible string. While this tends to make the coded representation of the token longer than its original (say ASCII) representation, the provision of this facility allows normal search and decompression procedures to be carried out without modification. With such a set of WNMs, it is also possible to break a missing token into fragments that include multiple-character combinations which are already included in the WNMs. It is also possible to assign number pairs to a collection of common word segments so that words that are absent from the WNMs can be encoded as concatenations of word segments, individual characters, and known words that are present. This may permit unknown tokens to be represented in fewer bits than their original representations. A further understanding of the nature and advantages of the present invention may be realized by reference to the remaining portions of the specification and the drawings, in which: Fig. 1A is a block diagram of a general-purpose computer system embodying the present invention; Fig 1B is a block diagram of a computer suitable for an end user; Fig 2 is a flow diagram of the first phase of text compression according to the invention. Fig 3 illustrates schematically the variable length encoding of tokens; Fig 4 is a flow diagram illustrating the second phase of text compression according to the invention; Fig 5 is a flow diagram of text decompression according to the invention; Fig 6 illustrates schematically the extraction of number pairs from coded data, and vice versa; and Fig. 7 is a flow diagram of text compression with possibly missing tokens. Overview The present invention relates to a text compression technique with associated search and decompression techniques. The starting point is a raw text database such as a dictionary, encyclopedia, or novel, which may be in ASCII of any other format. In the first of two phases, the text database is analyzed and certain database-dependent data structures are generated. The data structures are then used to compress the database. In the present invention the data structures include a set of word-number mappers ("WNMs"). In the second phase, an end user, having been provided with the compressed database and relevant portions of the data structures, is able to decompress selected portions of the text, perhaps in response to a search for a particular target string. Accordingly, the computer system or systems on which the software routines are developed and tested and on which the uncompressed text is processed are likely to be fairly powerful machines, such as a high-end personal computer or workstation. The end user machine can also be one of these, but can also be a small hand-held consumer device dedicated solely to searching and decompressing the particular text. Fig. 1A is a block diagram of a typical general- purpose computer system 10 that might be used for developing the compressed database and data structures. The actual computer architecture is standard, including a processor 12, which communicates with a number of peripherals via a bus subsystem 13. The peripherals typically include a keyboard 15 for user inputs, a display 17 for input echoes and visual outputs, a memory including RAM 18 for processing data, and disk storage 20 for storing the WNMs 22, the compressed database 25, suitable programs 27, and possibly the raw text database 28. The computer would presumably be provided with I/O ports and other peripherals, which are not shown. Fig 1B is a block diagram of a typical computer 10' as might be embodied in a hand-held consumer device allowing the user to access the database. Primed reference numerals will be used for elements that functionally correspond to those in Fig. 1A. The computer includes a processor 12', a keyboard or other input device 15', a display 17', RAM 18', and a ROM 30 in which are stored WNMs 22', compressed database 25', as well as the routines 27' necessary to access and display desired portions or the compressed database in uncompressed form. Generating WNMs Fig. 2 is a flow diagram illustrating a technique for generating the WNMs. First, the original database is accessed, one token at a time, and a rank order list of tokens is generated (step 40). To this end, the text is parsed into a sequence of alternating word and punctuationmark substring tokens. For example, the text string "Actually, the quick brown dog jumped over the lazy fox." would be parsed into the sequence: "Actually" ", " "the" " " "quick" " " "brown" " " "dog" " " "jumped" " " "over" " " "the" " " "lazy" " " "fox" "." The most commonly-occurring punctuation sequence, normally a single space, is defined as a default separator. All occurrences of that token are removed, with the understanding that unless there is a specific mark (e g.,_) to indicate otherwise, the default separator is assumed to be present between every pair of tokens. Following this convention, the sample text becomes. "Actually" "_," "the" "quick" "brown" "dog" "jumped" "over" "the" "lazy" "dog" " _._ " The tokens are listed in order of frequency occurrence with each token being listed only once. The rank order list of tokens is then subdivided and an ordered set of WNMs is constructed (step 42). The list is segmented in a manner that depends on the particular coding regime. In the particular embodiment, the code digit is a four-bit nibble, and a token may comprise one or more code digits. Fig 3 shows encoded tokens 45(1), 45(2), and 45(3) having one, two, and three nibbles, respectively. The letters A-J signify possible bit values (1 or 0). One bit (the high- order bit) in each code digit is reserved as a continuation bit, indicating whether that digit is the last digit of all the digits that make up a particular coded token. For the general case where the code digit is n bits with one bit as a continuation bit, there are 2 (n-1) possible distinct tokens that can be encoded in i digits. In the specific case, there are eight possible single-nibble codes, 64 possible two-nibble codes, 512 possible three-nibble codes, etc. The eight most common tokens are represented as a single nibble (45(1)), with the continuation bit set to "1" to indicate that the nibble is the last (and only) nibble in the coded token. The 64 next most frequently-occurring tokens are encoded in two nibbles (45(2)), the first nibble having the continuation bit set to "0" and the second having it set to "1". Each WNM is characterized by an ordinal WNM number and a WNM size that is the maximum number of tokens for the WNM. The first WNM assigns a unique number between 0 and 7 to each of the eight most frequently-occurring tokens, the second WNM assigns a unique number between 0 and 63 to each of the 64 next most frequently occurring tokens, the third WNM assigns a unique number between 0 and 511 to the 512 next most commonly- occurring tokens, and so on. Thus, each token type has an associated unique number pair, namely the number of the WNM in which the token is stored and the token's number or position in that WNM. The WNMs are constructed using finite state machine ("FSM") technology, with the resulting data structure requiring only about one byte per word. The token lists for the first three WNMs for a representative database (Random-House Encyclopedia) is set out in Appendix A of USSN 07/942,665, a copy of which was filed with the present application. The underscore character is the no-space indicator; the vertical up arrow indicates that the letter that follows is uppercase; two up arrows indicate that the word that follows is all uppercase; the vertical bar indicates a carriage return; two backslashes indicate a tab; the left and right curly brackets indicate the start and end of a cross-reference; and other special characters represent special characters or formatting information. While the list within which a token occurs is indicative of frequency, the order of tokens within a given list is not. Compression, Decompression and Searching Fig. 4 is a flow diagram illustrating a technique for compressing the text database. The uncompressed text string is read in and parsed into tokens as discussed above, and the next token (which in the first instance is the first) is extracted (step 50). The token is communicated to the WNM set, which provides the unique word number pair associated with that token (step 52). Based on the number pair, the token is encoded as illustrated in Fig. 3 (step 55). In general, the number of nibbles used is determined by the ordinal WNM number. The encoded token, which may be from one nibble to as many nibbles as there are WNMs in the set, is output for insertion into the compressed database (step 57). A check is made (step 60) to determine whether there are any more tokens in the database that have not been encoded. If there are, a branch is taken to step 50 where the next token is obtained; otherwise the compression is considered complete. The above sequence repeats until all the tokens in the input string have been encoded. Fig. 5 is a flow diagram illustrating a technique for decompressing a string of compressed text. The technique is basically the inverse of the compression technique described above. The next token boundary (which in the first instance is the first token boundary) is found (step 70), and the number pair is extracted from the encoded token (step 72). As discussed above, the token boundary is determined by a nibble having its high-order bit set. This first number in the number pair is determined by the number of nibbles in the encoded token, and the second number is generated by concatenating the data portions of the nibbles. This is accomplished by shifting and ORing the various trios of data bits, or by any other suitable technique. This transformation and its inverse are shown schematically in Fig. 6. The number so generated is communicated to the appropriate numbered WNM, and the decoded token is output (step 75) to become part of the decompressed text string. A check is made (step 77) to determine whether there are any more tokens in the string. If there are, a branch is taken to step 72 where the next token is obtained; otherwise, the decompression is considered complete. Searching for a target string in the compressed database is carried out in a straightforward manner and does not require decompression. The target string, which may be entered by the user, is compressed according to the same regime that was used to compress the original database. The search for the compressed target string in the compressed database can be conducted by any efficient substring searching algorithm, such as the well known Boyer-Moore algorithm (and derivatives) and the Knuth-Morris-Pratt algorithm. See for example, Daniel M Sunday, "A Very Fast Substring Search Algorithm", Communications ACM, Aug. 1990, Vol. 33, No. 8, pp. 32-142. When a match is found, a simple test is performed to confirm that the matched string is not the suffix of a longer string of code digits encoding some other word. In particular, it is determined whether the continuation bit of the immediately preceding code digit is set to 1. If so, the matching string is the desired one; otherwise the search continues. Once the target string is found, it is decompressed. In some instances, some amount of surrounding text is also decompressed. This can be accomplished by decompressing a given number of tokens in each direction, or by searching for paragraph breaks in both directions and decompressing the intervening tokens, depending on what is desired. Database with Missing Tokens Fig 7 is a flow diagram illustrating an adaptation of the compression technique described above to accommodate a situation where the database to be compressed is different from the database that was used to create the WNM tables. Thus, while the above discussion assumed that every token would be present in the set of WNMs, the situation being discussed here is that some tokens in the input text stream are not present in the WNMs. These may be referred to as missing tokens. The adaptation described below can also be applied to the prior art compression technique using a single WNM. The basic technique entails two modifications. First, the WNM(s) are provided with an additional set of tokens that include at least the individual characters that are not already in the database. For example, "a" and "I" are likely to be in the database because they are common words, but "b" and "t" are unlikely to be present. Therefore, a possibility is to reserve tokens in the three-nibble range (the 512-token WNM) for the single characters. The additional set of tokens may also include common word fragments such as suffixes and prefixes. Examples would be "un", "non-", "ment", and "ing". The fragment tokens would be delimited by the "no-space" character. The second modification is that an auxiliary coding scheme is provided for the case where a token is not found in the WNM(s). In the preferred scheme, the missing tokens are decomposed into fragments, which may be words that were in the original database or may be the additional tokens discussed above. These fragments are encoded in the same way other tokens are encoded. The basic flow is generally as described above in connection with Fig. 4, and corresponding reference numerals are used where appropriate. The modifications include a check (step 80) whether the incoming token was found in the WNM(s). If it was, encoding of the token and output to the compressed database occurs (steps 55 and 57). If not, a branch is taken to break the missing token into fragments (step 82). The fragments are made available as the input stream at step 50 and processing continues. At step 82, it is not generally assumed that the fragment will be present in the WMN(s), and each fragment is therefore subject to further fragmentation if it is found to be missing (and is more than one character long). There are a number of possible strategies for fragmenting a missing token, and the precise flow will depend on the particular strategy chosen. For example, a missing token can be decomposed into single characters and each character encoded. This simple scheme guarantees that each fragment will be found More elaborate schemes would attempt to produce larger fragments that would be found. For example, one possible scheme would send the largest possible fragment (say all but the last letter of the missing token), and if that fragment were found to be missing, the next largest fragment (say all but the last two letters of the missing token) would be sent. This process would be repeated until a fragment of some size was found not to be missing. At that point, the remaining fragment would be sent, and if it were found to be missing, successively smaller fragments would be sent. If the missing token will be made up of at least some multi-character tokens, the net result may well be shorter than the original ASCII. There is obviously a trade-off between compression time and compression ratio. As a practical matter, the overall result would not be significantly degraded since the number of missing tokens is likely to be a small percentage of the overall number of tokens. The elements that are concatenated to make up a missing word must all be connected without intervening spaces. This could be accomplished by placing a cancel-separator (no- space) token between each fragment, but this might increase the size of the compaction compared to an alternative method. In the alternative, a small set of special strings is added to the database only for the purpose of being used in fragments. These special strings can therefore have the cancel-separator mark included on one side or the other. If _ is the cancel- separator mark, then we add the strings "a_", "b_", "c_", not only for letters but also for all other possible byte codes. Then a missing word, say "aardvark", can be encoded as the sequence of tokens "a_" "a _" "r_" "d_" "v_" "a_" "r_" "k_". If this is followed by a space in the original text, then another token must be added at the end to cancel out the final cancel-separator. The token "" (the empty string) can serve this purpose. The space that normally would appear before this token is suppressed by the "k _", leaving only the space that would normally appear afterwards. With strings of this kind, every possible string can be encoded in no more than N + 1 tokens, where N is the length of the string. Longer word fragments such as prefixes and suffixes can also be coded according to this strategy. Common prefixes will always have a cancel-separator attached to their ends, so that they can simply be concatenated with the root-word to the right, while common suffixes will have the cancel mark to the left. Thus, "untalkative" could be coded as "un_" "talk" "_ative". These additional tokens can be distributed into the different WNMs according to an intuitive estimate or how likely they are to be used in coding missing strings. Alternatively, a more precise allocation of fragments to WNMs can be accomplished in the following way. A fairly large corpus is gathered of the sort of texts that the system will typically be applied to. That corpus is divided into two halves, at random, and one half is used to build the list of known tokens. Then this token list is used to tokenize the second half, except that now fragments are used to tokenize words that are not already in the first-half list. The WNMs are then built from the ranklist obtained from tokenizing the second half of the corpus in this way. Conclusion In conclusion, it can be seen that the present invention provides a particularly effective compression technique. The technique is readily adaptable to databases with a large number of distinct tokens, and further can be used with unknown databases. While the above is a complete description of a specific embodiment of the invention, alternatives are possible. For example, the encoding could be by a different regime. For example, with eight-bit code digits, there would be seven bits of precision, which means that a smaller percentage of the bits would be devoted to overhead (continuation bits). However, the most frequently occurring eight words would require twice the number of bits in their compressed form. The steepness of the frequency distribution determines which digit encoding is most advantageous. While it is possible to have digits of varying length in a single token (e.g., 4-4-8-8), such an encoding scheme makes it impossible to search backwards.

Claims: A method, performed in a digital processor, for building a text compression engine based on a predetermined encoding regime using n-bit code digits, comprising the steps of: receiving a text string corresponding to a text database; parsing the text string into a sequence of substring tokens; producing a rank-order list of token types based on the relative frequency of occurrence of the tokens in the database, so parsed; constructing an ordered set of N word-number mappers (WNMs), each WNM being characterized by an ordinal WNM number i in the range of 1 to N and a WNM size S(i), the WNM size being a non-decreasing function of the WNM number, the function being determined by a predetermined encoding regime; and assigning each token type to a particular WNM and assigning each token type a unique number in that token type is assigned WNM so that each token type has an associated pair of numbers, the first number corresponding to the WNM number of the assigned WNM, and the second number corresponding to the assigned number in the assigned WNM; wherein a token whose token type is characterized by the first and second numbers j and k, when encoded according to the predetermined encoding regime, comprises the number j of n-bit code digits with: (a) a dedicated bit in each code digit being reserved to provide information permitting a determination of the number of code digits in a given encoded token by testing the dedicated bit in each of a string of code digits containing the given encoded token; and, (b) the remaining (n-1)*j bits of the j code digits providing a binary representation of the number k. The method of claim 1 wherein; the S(1) most frequently occurring token types are assigned to the first WNM; and the S(2) next most frequently occurring token types are assigned to the second WNM. The method of claim 1 or claim 2 wherein the maximum size of the WNM having ordinal number i is 2 (n-1)*i . A method, performed in a digital processor, for compressing an input text string using n-bit code digits comprising the steps of: providing an ordered set of N word-number mappers (WNMs), each WNM being characterized by an ordinal WNM number i in the range of 1 to N and WNM size S(i), the maximum size of the WNM having ordinal number i being 2 (n-1)*i the set of WNMs providing a unique number pair for each of a set of token types, the first number corresponding to a WNM number, and the second number corresponding to a number in the WNM; parsing the input text string into a sequence of substring tokens; for each token, so parsed, determining the number pair designated j and k for the token's type; and for each token, so parsed, for which the number pair can be determined, encoding that token according to the number pair, so determined, so that the encoded token comprises the number j of n-bit code digits with: (a) a dedicated bit in each code digit being reserved to provide information permitting a determination of the number of code digits in a given encoded token by testing the dedicated bit in each of a string of code digits containing the given encoded token; and (b) the remaining (n-1) * j bits of the j code digits providing a binary representation of the number k. The method of claim 4 wherein; the WNMs are constructed from a text database; the S(1) most frequently occurring token types in the text database are assigned to the first WNM; and the S(2) next most frequently occurring token types in the text database are assigned to the second WNM. The method of claim 4 or claim 5 wherein; the reserved bit for each particular n-bit code digit in an encoded token is used to signify whether the particular code digit is the final code digit in the encoded token; and the maximum size of the WNM having ordinal number i is 2 (n-1)*i . The method of any of claims 4 to 6 wherein at least one of the WNMs includes a set of sub-word tokens for encoding, as a series of encoded sub-word tokens, a token having a token type that is not present in any of the WNMs. The method of claim 7 wherein the set of sub-word tokens includes individual characters. The method of claim 4 wherein at least one of the WNMs includes a set of sub-word tokens, and further comprising the steps, carried out before said encoding step only if a token is encountered whose number pair cannot be determined, of: breaking the token into a series of sub-word tokens; and subjecting each sub-word token in the series to said determining and encoding steps.

Inventors: KAPLAN RONALD M, MAXWELL III JOHN T, KAPLAN, RONALD M., MAXWELL III, JOHN T.
Applicants: XEROX CORP, XEROX CORPORATION
Application year: 1993
Main classification: G06F17
IPC codes: H03M7, G06F17, G06F5