IDENTIFYING LANGUAGE AND CHARACTER SET OF DATA REPRESENTING TEXT

Abstract: The present invention provides a facility for identifying the unknown language of text represented by a series of data values in accordance with a character set that associates character glyphs with particular data values. The facility first generates a characterization that characterizes the series of data values in terms of the occurrence of particular data values on the series of data values. For each of a plurality of languages, the facility then retrieves a model that models the language in term of the statistical occurrence of particular data values in representative samples of text in that language. The facility then compares the retrieved models to the generated characterization of the series of data values, and identifies as the distinguished language the language whose model compares most favorably to the generated characterization of the series of data values.

Description: IDENTIFYING LANGUAGE AND CHARACTER SET OF DATA REPRESENTING TEXT TECHNICAL FIELD The present invention is directed toward the field of text analysis, and, in particular, to the field of statistical text analysis. BACKGROUND OF THE INVENTION It is common for modern computer systems to provide facilities for storing and processing data representing text. Bodies of data stored by a computer system that represent a textual document are referred to as "digital document representations." Digital document representations are stored in a computer system, like other data, as a series of values called "bytes." Text is converted to these byte values using a "character set" — a mapping between the identities of different characters, herein referred to as "character glyphs," and different byte values. Character sets, also referred to as "code pages," are generally defined by standards organizations, such as the American National Standards Institute ("ANSI") or the International Standards Organization ("ISO"). Some character sets, called "multiple-byte character sets," map each character glyph to a value comprised of two or more bytes. It is generally possible to correctly display the document represented by a digital document representation only where the character set used to create the digital document representation is known. Converting a digital document representation from its current character set into a different target character set is also typically possible only where the current character set of the digital document representation is known. Text generally comprises a series of words each taken from one or more languages. Natural language processing tools, such as spelling checkers, grammar checkers, and summarizers, may be applied to such documents. In order to correctly process a document, however, these tools must be advised of the language or languages from which the words in the document are taken. For example, when a spell checker tool encounters the word "bitte" in a document known to be in German, it does not regard the word as misspelled. However, when the spell checker tool encounters the same word in a document known to be in English, it regards the word as a misspelling of the word "bitter." Some information retrieval tools, such as word breakers (which identify the boundaries between words) and word stemmers (which remove suffixes in order to match different words having the same root), also must be advised of the language or languages occurring in digital document representations upon which these tools operate. In addition to the needs of automated tools, knowledge of the language in which the document is written is useful to human readers, who may read only one or a small handful of the large number of languages in which documents are written, to determine whether they will be able to read the document. Thus, it is generally desirable for each digital document representation that is stored to be accompanied by an explicit indication of the character set used to generate it and the language or languages from which its words are taken. While such information is stored for many digital document representations, especially those that have been created recently, it is unavailable for many other digital document representations. For example, many of the HTML documents available via the world wide web fail to identify their character sets and languages. In the case of some digital document representations, information identifying the character set and language of the digital document representation has never been associated with the digital document representation. This is often the case where this information was originally implied by the identity of the computer on which it was stored. For example, this information is implicit in digital document representations originally created in a single-language, single-character set environment. When such digital document representations are moved to a computer system that uses several languages and character sets, or made available to such computer systems via a network such as the Internet, the character set and language of such digital document representations is unavailable. For other digital document representations, information identified in the character set and language of the digital document representation was at some point associated with the digital document representation, but is not presently available. For instance, such information may be stored in a separate file that is at some point deleted. On the other hand, the information may still be in existence, but nonetheless be unavailable. For instance, the file containing the information may be inaccessible to the user or program trying to determine the character set and language of the digital document representation. Such information may further be accessible, but be in a format that is unintelligible to the user or program seeking to determine the character set and language of the digital document representation. Thus, for a variety of reasons, the character set and language of a digital document representation may be unavailable. Because the language and character set needed to display and process digital document representations are frequently unavailable, an automated approach to discerning the character set and language or languages of a digital document representation, especially one that has reasonable storage requirements and is straightforwardly extensible to new character sets and languages, would have significant utility. SUMMARY OF THE INVENTION The present invention provides a software facility ("the facility") that, given raw data that represents a textual document in some language expressed using some character set, automatically identifies that language and character set. The facility first generates a statistical model of documents in each of a number of known languages and character sets in a "training phase," then applies these models to identify the language and character set of an input document in a "detection phase." The statistical models of languages and character sets used by the facility are tailored to emphasize character values that tend to distinguish between different languages and character sets, while at the same time minimizing the amount of space in the models dedicated to character values that do not tend to differentiate languages or character sets, by the use of specialized reductive mappings. In the training phase, the facility generates the statistical models of languages and character sets used in the detection phase to identify the language and character set of input documents. For each combination of language and character set to be detected, the facility reads sample documents known to be in that language and character set, each comprising a series of byte values. The facility then (A) maps the byte values in the series from the 256 different possible values that can be represented in a byte to a smaller number of possible values, (B) records the number of times that each different fixed-length series of mapped byte values, or "n-grams," occurs in the mapped version of document, (C) aggregates these "frequency statistics" for each language and character set, and (D) normalizes the frequency statistics across the languages and character sets. N-grams of different lengths, as well as different mappings, are preferably used based on the characteristics of each language and character set. The facility further adjusts the frequency statistics to emphasize high- frequency n-grams whose occurrence tends to distinguish a document of one language and character set from documents of other languages and character sets, and to de- emphasize high-frequency n-grams whose occurrence does not tend to distinguish a document of one language and character set from documents of other languages and character sets. In the detection phase, the facility uses the normalized and adjusted frequency statistics generated in the training phase to identify the language and character set for an input document whose language and/or character set is unknown. The facility first maps the byte values of the input document to a smaller number of possible values using the same mapping(s) used in the training phase. The facility then determines the number of times each n-gram occurs in the mapped input document. For each language, the frequency of each n-gram in the mapped input document is multiplied by the frequency of the same n-gram in the training frequency statistics for the current language, and these products are summed. The sum for each language represents the relative likelihood that the language is the one in which the input document is written. After the language having the largest sum is identified, this detection process is repeated using character set statistics for that language to determine in which of the known character sets for the identified language the input document is written. The facility preferably analyzes contiguous units of training and input documents whose length corresponds to the length of a typical paragraph. In this way, when a document contains text in more than one language or character set, the facility can identify each of these languages and character sets. The facility preferably further uses similar statistical analysis techniques to identify the language or languages of digital document representations expressed in the large Unicode character set. In identifying some groups of similar languages in Unicode digital document representations, the facility preferably utilizes custom reductive mappings automatically generated to differentiate between languages in the group. BRIEF DESCRIPTION OF THE DRAWINGS Figure 1 is a high-level block diagram showing the computer system upon which the facility preferably executes. Figure 2 is an overview flow diagram showing the phases in which the facility operates. Figure 3 is a flow diagram showing the steps preferably performed by the facility in the training phase. Figure 4 is a flow diagram showing the steps preferably performed by the facility in order to augment the models for the character set and primary language identified for a particular sample digital document representation in accordance with step 304. Figure 5 is a flow diagram showing the steps preferably performed by the facility to generate a characterization of a sample digital document representation. Figure 6 is a flow diagram showing the steps preferably performed by the facility in order to identify the character set and language of an input digital document representation for which this information is not known. Figure 7 is a flow diagram showing the steps preferably performed by the facility in order to detect the character set and/or language of the input digital document representation. Figure 8 is a flow diagram showing the steps preferably performed by the facility in order to detect multiple languages, as well as the character set, of an input digital document representation. Figure 9 is a flow diagram showing the steps preferably performed by the facility in order to select a character set for the input digital document representation from among those character sets detected for segments of the input digital document representation. Figure 10 is a flow diagram showing the steps preferably performed by the facility in the training phase in order to generate a custom reductive mapping for a Unicode language group used to differentiate between languages of the language group. Figure 11 is a flow diagram showing the steps preferably performed by the facility in order to detect the languages occurring in an input digital document representation expressed in the Unicode character set. Figure 12 is a flow diagram showing the steps preferably performed by the facility in order to detect the language of a segment of an input digital document representation expressed in the Unicode character set. DETAILED DESCRIPTION OF THE INVENTION The present invention provides a software facility ("the facility") that, given raw data that represents a textual document in some language expressed using some character set, automatically identifies that language and character set. The facility first generates a statistical model of documents in each of a number of known languages and character sets in a "training phase," then applies these models to identify the language and character set of an input document in a "detection phase." The statistical models of languages and character sets used by the facility are tailored to emphasize character values that tend to distinguish between different languages and character sets, while at the same time minimizing the amount of space in the models dedicated to character values that do not tend to differentiate languages or character sets, by the use of specialized reductive mappings. In the training phase, the facility generates the statistical models of languages and character sets used in the detection phase to identify the language and character set of input documents. For each combination of language and character set to be detected, the facility reads sample documents known to be in that language and character set, each comprising a series of byte values. The facility then (A) maps the byte values in the series from the 256 different possible values that can be represented in a byte to a smaller number of possible values, (B) records the number of times that each different fixed-length series of mapped byte values, or "n-grams," occurs in the mapped version of document, (C) aggregates these "frequency statistics" for each language and character set, and (D) normalizes the frequency statistics across the languages and character sets. N-grams of different lengths, as well as different mappings, are preferably used based on the characteristics of each language and character set. The facility further adjusts the frequency statistics to emphasize high- frequency n-grams whose occurrence tends to distinguish a document of one language and character set from documents of other languages and character sets, and to de- emphasize high-frequency n-grams whose occurrence does not tend to distinguish a document of one language and character set from documents of other languages and character sets. In the detection phase, the facility uses the normalized and adjusted frequency statistics generated in the training phase to identify the language and character set for an input document whose language and/or character set is unknown. The facility first maps the byte values of the input document to a smaller number of possible values using the same mapping(s) used in the training phase. The facility then determines the number of times each n-gram occurs in the mapped input document. For each language, the frequency of each n-gram in the mapped input document is multiplied by the frequency of the same n-gram in the training frequency statistics for the current language, and these products are summed. The sum for each language represents the relative likelihood that the language is the one in which the input document is written. After the language having the largest sum is identified, this detection process is repeated using character set statistics for that language to determine in which of the known character sets for the identified language the input document is written. The facility preferably analyzes contiguous units of training and input documents whose length corresponds to the length of a typical paragraph. In this way, when a document contains text in more than one language or character set, the facility can identify each of these languages and character sets. The facility preferably further uses similar statistical analysis techniques to identify the language or languages of digital document representations expressed in the large Unicode character set. In identifying some groups of similar languages in Unicode digital document representations, the facility preferably utilizes custom reductive mappings automatically generated to differentiate between languages in the group. Figure 1 is a high-level block diagram showing the computer system upon which the facility preferably executes. As shown in Figure 1, the computer system 100 comprises a central processing unit (CPU) 110, input/output devices 120, and a computer memory (memory) 130. Among the input/output devices is a storage device 121, such as a hard disk drive; a computer-readable media drive 122, which can be used to install software products, including the facility, which are provided on a computer-readable medium, such as a CD-ROM; and a network connection 123 for connecting the computer system 100 to other computer systems (not shown). The memory 130 preferably contains a facility 131, sample digital document representations 132 used to generate models of character sets and languages 133, and an input digital document representation whose character set and language(s) the facility is to determine. While the facility is preferably implemented on a general-purpose computer system configured as described above, those skilled in the art will recognize that it may also be implemented on computer systems having different configurations. Figure 2 is an overview flow diagram showing the phases in which the facility operates. In step 201, in the training phase, the facility models the character sets and languages that it is to detect using sample digital document representations known to have been generated in these character sets and known to primarily contain these languages. The sample digital document representations used in step 201 are preferably obtained from newspaper stories and legal opinions discussing subject matters intrinsic to a locale to which its primary language is indigenous. That is, sample digital document representations are sought that have local content, such as newspaper articles and judicial opinions, as the vocabulary used in such digital document representations is likely to distinguish the primary language of the sample digital document representation from other languages. Step 201 is discussed in greater detail below in conjunction with Figure 3. The facility performs step 201 once. After step 201 has been performed, the training phase concludes. The models generated in the training phase in step 201 are used in the detection phase to detect the character set and language(s) in each of any number of input digital document representations. In step 202, the facility receives a new input digital document representation. In step 203, the facility detects the character set and language(s) of the input digital document representation received in step 202 using the models generated in step 201. The details of step 203 are discussed in greater detail below in conjunction with Figure 3. After detecting the character set and language(s) of the input digital document representation in step 203, the facility continues in step 202 to receive the next input digital document representation, thus remaining in the detection phase. While Figure 2 portrays the facility as never reentering the training phase, those skilled in the art will appreciate that it may be desirable to repeat the training phase in order to incorporate additional sample digital document representations in the models generated in the training phase, either to extend the facility to detect additional languages and character sets, or to enhance the models for existing languages and character sets using the text of additional sample digital document representations. Figure 3 is a flow diagram showing the steps preferably performed by the facility in the training phase. In step 301, the facility selects sample digital document representations whose character sets and primary languages are known. As the number of sample digital document representations directly affects the statistical accuracy of the models generated by the facility and therefore the level of the facility's performance, a large number of sample digital document representations is preferably selected in step 301. In steps 302-304, the facility loops through each sample digital document representation selected in step 301. In step 303, the facility augments the model for the character set and primary language identified for the sample digital document representation. Step 303 is discussed in greater detail below in conjunction with Figure 4. In step 304, if one or more selected sample digital document representations remain to be processed, the facility continues at step 302 to process the next selected sample digital document representation. If all of the selected sample digital representations have been processed, then the facility continues in step 305. In step 305, the facility normalizes the models generated as a result of augmentation in step 303. The normalization performed in step 305 preferably involves proportionally increasing or decreasing the counters of each model so that the average counter value in each model is the same. In step 306, the facility adjusts the normalized models to more effectively differentiate their character sets and languages, by, for each model, (a) increasing the counts for n-grams whose counts are the highest relative to the counts for the same n-gram in other models and (b) decreasing the counts for n-grams whose counts are high relative to the other counts for that model, but not high relative to the counts for the same n-gram in other models. In a preferred embodiment, this adjustment is accomplished by doubling each count of each model, then subtracting the average of the corresponding counts among all models. After step 306, these steps, and the training phase, conclude. Figure 4 is a flow diagram showing the steps preferably performed by the facility in order to augment the models for the character set and primary language identified for a particular sample digital document representation in accordance with step 304. The facility preferably utilizes different reductive mappings, and maintains frequency data for different size «-grams, depending upon the type of character set used to create the current sample digital document representation. In step 401, if the current sample digital document representation is a Latin-based single byte character set, then the facility continues at step 402 to perform steps 402-405, else the character set of the current sample digital document representation is either a multiple byte character set (in which each character is represented by two or more byte values) or a single byte character set for a non-Latin-based language and the facility continues in step 406 to perform steps 406 and 407. Examples of Latin-based single byte character sets include: Microsoft character sets 1250 and 28592 for Czech, Hungarian, and Polish; Microsoft character set 1252 for Danish, Dutch, English, Finnish, French, German, Italian, Norwegian, Portuguese, Spanish, and Swedish; Microsoft character set 28591 for Finnish, French, German, Norwegian, Portuguese, and Swedish; Microsoft character set 28592 for German, Hungarian, and Polish; and Microsoft character set 1257 for Lithuanian. Examples of multiple byte character sets or non-Latin-based single byte character sets include Microsoft character sets 936 and 950 for Chinese, Microsoft character sets 932 and 51932 for Japanese, Microsoft character set 949 for Korean, and character sets for Greek and Hebrew. In steps 402-405, the facility augments both a three-dimensional model of the primary language of the sample digital document representation and a one- dimensional model of the combination of that primary language and the character set of the sample digital document representation with characterizations of the sample digital document representation. The three-dimensional model is used by the facility to detect input digital document representations having the same primary language as this sample digital document representation, while the one-dimensional model is used to detect input digital document representations having the same primary language and character set as this sample digital document representation. In step 402, the facility generates a three-dimensional characterization of the current sample digital document representation using the mapping shown below in Table 1 and frequency statistics for character trigrams occurring in the sample digital document representation. Table 1 : Mapping to Detect Language of Latin-Based SBCS The details of step 402 for generating a characterization of the sample digital document representation are discussed in greater detail below in conjunction with Figure 5. As part of the generating process, the facility maps each byte value in the sample digital document representation to a target value using the mapping shown in Table 1. Based upon a determination that languages expressed in a Latin-based single byte character set can be most effectively differentiated based upon the identities, irrespective of case, of the letters occurring therein, the mapping shown in Table 1 maps the source values corresponding to each letter to a different target value. For example, the sources values 0x41 and 0x61, corresponding to the character glyphs "A" and "a", respectively, are both mapped to the target value 2, source value 0x42 and 0x62, representing the character glyphs "B" and "b", respectively, are mapped to the target value 3, and so forth. Besides the target values assigned to letters, the mapping in Table 1 defines only two further target values: the target value 1 for "extended character" source values having their high-order bit set, i.e., 0x80-0xFF; and the target value 0 for source values not having their high-order bit set and not representing letters — these source values generally correspond to numerals, punctuation characters and other symbols, and control characters. By mapping source values in this manner, the facility reduces 256 source values to only 28 target values, thereby reducing storage requirements for trigram frequency statistics by over 99%. As an example, consider the following sample text string: snow, called "POWDER." Table 2 below shows, in its "byte value" column, the series of byte values that make up the sample string in a sample digital document representation. The "target value" column of Table 2 shows the series of target values to which the byte values are mapped using the mapping shown in Table 1. Table 2 It can be seen from Table 2 that each distinct letter has its own target value. For example, the lowercase character "o" and the uppercase character "O" both map to target value 16. It can further be seen that all of the punctuation character glyphs, including the comma, space, quotation mark, and period, map to a single target value, target value 0. Thus, it is the identities of the distinct letters that are used to distinguish different languages in digital document representations expressed in Latin-based single byte character sets. The mapping shown in Table 1 may further be used to generate models and characterizations for character sets such as Microsoft character set 50220 for Japanese that, while technically double byte character sets, do not use byte values between 0x80 and OxFF. In step 403, the facility sums the three-dimensional characterization of the sample digital document representation generated in step 402 into a three- dimensional model of the language identified as the primary language of the sample digital document representation. This summing process involves adding the value of each entry in the three-dimensional characterization of the sample digital document representation into the corresponding entry in the three-dimensional model of the primary language. Steps 404 and 405 mirror steps 402 and 403, respectively, in that step 404 generates a characterization of the sample digital document representation and step 405 sums that characterization into a model of a language and character set. In step 404, the facility generates a one-dimensional characterization of the current sample digital document representation using the mapping shown below in Table 3 and frequency statistics for character unigrams occurring in the sample digital document representation. Table 3: Mapping to Detect Character Set of Latin-Based SBCS It can be seen from Table 3 that the mapping for detecting the correct character set among the Latin-based single byte character sets maps each source value having its high-order bit set to a different target value. For example, the source value 0x80 is mapped to the target value 1, the source value 0x81 is mapped to the target value 2, and so forth. In single byte character sets, only these "extended character byte values" represent different characters in different character sets ~ on the other hand, each of the byte values 0-0x7F generally represent the same character in all of these character sets. It is therefore these extended character byte codes that serve to best differentiate between different Latin-based single byte character sets. In addition to the 128 target values that are each assigned to one of the source values between 0x80 and OxFF, the mapping defines one further target value: the target value 0 is assigned to all of the source values between 0 and 0x7F. By mapping source values in this manner, the facility reduces 256 source values to only 129 target values, thereby reducing storage requirements for unigram frequency statistics by nearly 50%. In step 405, the facility sums the one-dimensional characterization of the sample digital document representation generated in step 404 into a one-dimensional model of the combination of the primary language and character set of the sample digital document representation. After completing step 405, these steps conclude. In steps 406-407, the facility generates a single characterization of the sample digital document representation and sums it into a single model for both the primary language and the character set of the sample digital document representation. In step 406, the facility generates a two-dimensional characterization of the sample digital document representation using the mapping shown below in Table 4 and frequency statistics for character bigrams occurring in the sample digital document representation. Table 4: Mapping to Detect Language and Character Set of Non-Latin-Based SBCS or DBCS It can be seen that the mapping in Table 4 is essentially a union of the different target values defined by the two mappings shown in Table 1 and Table 3. This mapping reduces 256 source values to 155 target values, thereby reducing the storage requirements for bigram frequency statistics by over 63%. In step 407, the facility sums the two-dimensional characterization of the sample digital document representation generated in step 406 into a two-dimensional model of the combination of the primary language and character set of the sample digital document representation. After step 407, these steps conclude. Figure 5 is a flow diagram showing the steps preferably performed by the facility to generate a characterization of a sample digital document representation. The steps shown in Figure 5 are preferably performed by the facility as part of steps 402, 404, and 406. As is shown in steps 402, 404, and 406, a characterization generated in accordance with the steps of Figure 5 utilizes a particular reductive mapping and has a specified number of dimensions directly corresponding to the length of the n-grams for which frequency statistics are maintained in the characterization. For example, in accordance with step 406 for multiple-byte character sets and non-Latin-based single byte character sets, the facility uses the mapping shown in Table 3 and generates a two- dimensional characterization that contains the frequency of each possible bigram of target values. In step 501, the facility uses the reductive mapping specified for the characterization to map each byte of the digital document representation from the source value for the byte to a target value. For example, for the characters shown in Table 2, the facility would map the byte or source values to the target values shown in Table 2. In step 502, the facility constructs and initializes a matrix to contain the characterization. The matrix has a number of dimensions corresponding directly to the length, in characters, specified for n-grams for this combination of language and character set. For example, because step 406 specifies the use of bigram frequency statistics, the facility constructs a two-dimensional matrix when performing step 502. In each of its dimensions, the matrix preferably has one position for each possible target value in the reductive mapping. In steps 503-505, the facility loops through each n-gram occurrence of the specified length among the series of target values created in step 501. That is, where bigram frequency statistics are specified, the facility begins by considering the first and second target values in the series, then considers the second and third target values in the series, and so on until it considers the second-to-last and last target values in the series of target values. In step 504, for the current n-gram occurrence, the facility increments the element of the matrix constructed in step 502 that corresponds to the target value n-gram currently being considered. That is, the matrix element that is incremented is the one whose first index has the first target value of the n-gram. whose second index has the second target value of the n-gram, and so on. For example, when collecting the trigram frequencies for the first trigram shown in Table 2 having target values 20, 15, and 16, the facility would increment the value of the matrix at (20, 15, 16). In step 505, if any target value n-gram occurrences remain, then the facility continues at step 503 to consider the next one. Otherwise, these steps conclude. At the conclusion of these steps, the matrix constructed in step 502 reflects the number of occurrences of each target value n-gram in the digital document representation. Figure 6 is a flow diagram showing the steps preferably performed by the facility in order to identify the character set and language of an input digital document representation for which this information is not known. In step 601, the facility determines whether the input digital document representation is likely expressed in a Latin-based single byte character set. If the majority of bytes of the input digital document representation before mapping have a value smaller than 0x80, i.e., do not have their high-order bit set, then the facility determines that the input digital document representation is expressed in a Latin-based single byte character set and the facility continues in step 602 to perform steps 602-605, else the facility determines that the input digital document representation is expressed in a multiple byte character set or a non-Latin-based character set and continues in step 606 to perform steps 606 and 607. In step 602, in a manner similar to that of step 402, the facility generates a three-dimensional characterization of the input digital document representation using the mapping shown in Table 1 and trigrams. In step 603, the facility detects the language of the input digital document representation using the three-dimensional characterization of the input digital document representation generated in step 602 and the three-dimensional models of languages generated in step 201 of the training phase. This detection process is discussed in greater detail below in conjunction with Figure 7. In step 604, after detecting the language of the input digital document representation, the facility generates a one-dimensional characterization of the input digital document representation in a manner similar to that of step 404 using the mapping shown in Table 3 and unigrams. In step 605, the facility detects the character set of the input digital document representation using the one-dimensional characterization of the input digital document representation generated in step 604 and the one-dimensional models of combinations of languages and character sets that include the detected language. This detection process is discussed in greater detail below in conjunction with Figure 7. After step 605, these steps conclude. In step 606, in a manner similar to that of step 406, the facility generates a two-dimensional characterization of the input digital document representation using the mapping shown in Table 4 and bigrams. In step 607, the facility detects both the language and the character set of the input digital document representation using the two-dimensional characterization of the input digital document representation generated in step 606 and the two-dimensional models of combinations of languages and character sets generated in step 201 of the training phase. Again, this detection process is described in greater detail below in connection with Figure 7. After step 607, these steps conclude. Figure 7 is a flow diagram showing the steps preferably performed by the facility in order to detect the character set and/or language of the input digital document representation in accordance with step 603, 605, or 607. In these steps, the facility compares the present characterization of the input digital document representation to each candidate model. The language and/or character set of the candidate model that is most similar to the characterization of the input digital document representation is detected for the input digital document representation. In steps 701-703, the facility loops through each candidate model of a language and/or character set as specified in steps 603, 605, or 607. In step 702, the facility computes the scalar product of the matrices that constitute the current candidate model and the characterization of the input digital document representation. Such computation involves multiplying the value at each location in the candidate model matrix with the corresponding value in the characterization matrix, and summing these products to obtain a single value, called a "score," that represents the similarity of the candidate model to the characterization. In step 703, if additional candidate models remain to be processed, then the facility continues in step 701 to process the next candidate model, else the facility continues in step 704. In step 704, the facility identifies the candidate model for which the highest score was computed in step 702. In step 705, the facility detects the input digital document representation to be of the language and/or character set of the candidate model identified in step 704. After step 705, these steps conclude. The steps shown in Figure 6, because they assess the input digital document representation as a whole, detect a single dominant language for the input digital document representation. For input digital document representations containing text in more than one language, however, detecting each of these languages often has significant utility. Figure 8 is a flow diagram showing the steps preferably performed by the facility in order to detect multiple languages occurring in an input digital document representation, as well as the character set in which the input digital document representation is expressed. These steps involve dividing the input digital document representation into a number of shorter segments, detecting the language and character set of each segment, and reporting the union of the languages detected for the segments as well as a detected character set. In step 801, the facility divides the input digital document representation into segments. In a first embodiment, these segments are the size of a typical sentence, or about 75 characters. In an alternative embodiment, the segments are the size of a typical paragraph, or about 400 characters. This segment size is preferably configurable, allowing the facility to be adapted to detecting text of different languages in chunks of various sizes. Decreasing segment size increases the number of languages that may be detected in a multi-lingual input digital document representation, while increasing segment size reduces processing time in the detection phase. In steps 802-804, the facility loops through each segment. In step 803, the facility detects the language and character set of the current segment in accordance with the steps shown in Figure 6. In step 804, if additional segments remain to be processed, then the facility continues in step 802 to process them, else the facility continues in step 805. In step 805, the facility reports that the input digital document representation contains each language that was detected in an iteration of step 803 for one of the segments, in the decreasing order of the number of segments for which the language was detected. In one embodiment, the detected languages reported in step 805 are limited to those that were detected in a threshold number of segments larger than 1. In a further preferred embodiment, the reported union of detected languages is further sorted to promote double byte character set languages or non-Latin-based languages above Latin-based single byte character set languages in the list. In step 806, the facility selects a character set from among the character sets detected in iterations of step 803. Step 806 is described in further detail below in conjunction with Figure 9. In step 807, the facility reports the character set selected in step 806. After step 807, these steps conclude. Figure 9 is a flow diagram showing the steps preferably performed by the facility in order to select a character set for the input digital document representation from among those character sets detected for segments of the input digital document representation. In step 901, if all of the detected character sets are Latin-based single byte character sets, then the facility continues in step 902, else the facility continues in step 904. In step 902, the facility selects the language detected for the largest number of segments as the language of the input digital document representation. In step 903, the facility selects the character set detected along with the language selected in step 902 in the largest number of segments. After step 903, these steps conclude. In step 904, the facility selects the language that was detected with a multiple byte character set or a non-Latin-based single byte character set that was detected in the largest number of segments. In step 905, the facility selects the multiple byte character set or a non-Latin- based single byte character set detected with the language selected in step 904 that was detected for the largest number of segments. After step 905, these steps conclude. The foregoing discusses the use of the facility to detect both the character set and languages of an input digital document representation in which this information is unknown. The facility is further capable of detecting the languages used in an input digital document representation known to be expressed in the special Unicode character set. The Unicode character set, as defined by the Unicode Consortium of San Jose, California in The Unicode Standard, Version 2.0, is a large character set designed to represent most of the character glyphs used in a large number of the world's languages. Because the Unicode character set can represent the text of so many different languages, it is useful to be able to detect the languages present in an input digital document representation known to be expressed in the Unicode character set. The Unicode character set utilizes 16-bit character values, allowing for 65,536 different characters. The Unicode character set is partitioned into a number of "script ranges" that group together the characters generally used in one language or in a group of related languages. Table 5 below shows some of the "single-language" script ranges containing characters that are used in only one language. Table 5: Single-Language Unicode Script Ranges It can be seen from Table 5, for example, that the script range from 0x0400 to 0x04FF is used only in Russian. Table 6 below, on the other hand, shows some of the "multiple-language" script ranges containing characters that are each used in a group of two or more languages. Table 6: Multiple-Language Unicode Script Ranges It can be seen, for example, that the script range from 0x4E00 to 0x9FFF is used in each of the "CJK group" of languages, Chinese, Japanese, and Korean. Where the characters in a segment of a Unicode input digital document representation are predominantly within one of the single-language script ranges, the facility detects the language of the segment to be the single language of that script range. On the other hand, where the characters of a segment are predominantly within a multiple-language script range, the facility preferably maps the source values of the segment to generate a statistical characterization of the segment, then compares that characterization to models of the languages in the language group in a manner discussed above. For segments that are predominantly composed of characters in one or more script ranges of the "Latin" language group which contains the Latin-based languages such as those listed above, the facility preferably utilizes the mapping shown below in Table 7 to map the source values of the segment to the same 28 target values as the mapping shown in Table 1 for detecting the language of a Latin-based single byte character set. Table 7: Mapping to Detect Language of Latin-Based Unicode As is discussed in more detail below, the facility detects the Latin-based language within the Latin group by comparing a three-dimensional characterization of the segment using this mapping to the three-dimensional models of languages in the Latin group already generated by the facility in accordance with Figure 3. For segments predominantly composed of character values in a multiple- language script range for a language group other than the Latin language group, the facility uses a custom mapping generated by the facility specifically for that language group in a manner designed to distinguish between the different languages of the language group. These custom mappings, like the mapping shown in Table 7, map from all of the 65,536 Unicode character values to a much smaller number of target values, such as 256. The custom mapping for the language group is used to construct a one-dimensional characterization of the segment, which is then compared to one- dimensional models of the different languages in the language group generated using the same custom mapping. Figure 10 is a flow diagram showing the steps preferably performed by the facility in the training phase in order to generate a custom reductive mapping for a Unicode language group used to differentiate between the languages of the language group. These steps are preferably performed for each group of languages that rely heavily on the same script range. For example, the Chinese, Japanese, and Korean languages all rely heavily on the script ranges shown for the "CJK" language group in Table 6. As a further example, a group of Indian languages also rely heavily on a single script range. These steps are performed once for each such group, generating a custom mapping for the group designed to distinguish the languages of the group. In a preferred embodiment, the custom mapping has 256 target values. In alternative embodiments, the custom mapping maps to a number of target values larger or smaller than 256. In steps 1001-1004, the facility loops through each language in the language group. In step 1002, the facility assigns any source values in the current language's exclusive script range to a unique target value. In step 1003, the facility counts the number of occurrence of each distinct source value. In step 1004, if additional languages remain to be processed, then the facility continues in step 1001 to process the next language in the language group, else the facility continues in step 1005. In steps 1005-1008, the facility again loops through each language in the language group. In step 1006, the facility assigns the source values occurring only in the corpus of the current language to a unique target value. In step 1007, the facility assigns each group of 100 source values that occur mostly in the corpus of the current language to a unique target value. In step 1008, if additional languages remain to be processed, then the facility continues in step 1005 to process the next language in the language group, else the facility continues in step 1009. In step 1009, the facility assigns the remaining source values to the remaining target values. After step 1009, the custom mapping maps each source value to one of the 256 target values and these steps conclude. After generating custom reductive mappings for each Unicode language group in accordance with Figure 10, the facility preferably uses each custom mapping to generate a one-dimensional statistical model of each of the languages in the language group. The facility performs such generation in accordance with the steps shown in Figure 3. Figure 11 is a flow diagram showing the steps preferably performed by the facility in order to detect the languages occurring in an input digital document representation expressed in the Unicode character set. In step 1101, the facility divides the input digital document representation into segments, such as paragraph-length segments having about 400 characters. In steps 1102-1104, the facility loops through each segment. In step 1103, the facility detects the language of the segment. This detection process is discussed further below in conjunction with Figure 12. In step 1104, if additional segments remain to be processed, then the facility continues in step 1102 to process the next segment, else the facility continues in step 1105. In step 1005, the facility reports the union of the languages detected in step 1103, in decreasing order of the number of segments in which the language was detected. After step 1105, these steps conclude. Figure 12 is a flow diagram showing the steps preferably performed by the facility in order to detect the language of a segment of an input digital document representation expressed in the Unicode character set. In steps 1201-1204, the facility counts the number of Unicode character occurrences in the segment that are within each script range shown in Tables 5 and 6. In steps 1201-1204, the facility loops through each Unicode character occurrence in the segment. In step 1202, if the character occurrence is within a script range, then the facility continues in step 1203 to increment a counter for the script range, else the facility continues in step 1204. In step 1204, if Unicode character occurrences remain to be processed, then the facility continues in step 1201 to process the next Unicode character occurrence in the segment, else the facility continues in step 1205. In step 1205, if the script range whose counter has the highest value is a single-language script range, then the facility continues in step 1206, else the script range whose counter has the highest value is a multiple-language script range and the facility continues in step 1207. In step 1206, the facility detects the language of the segment to be the language of the single-language script range. After step 1206, these steps conclude. In step 1207, if the language group of the script range whose counter has the highest value is the Latin language group, then the facility continues in step 1208, else the facility continues in step 1210. In step 1208, the facility generates a three- dimensional characterization of the segment using the mapping shown in Table 7 designed to distinguish the languages of the Latin language group. Step 1208 is performed in accordance with the steps shown in Figure 5, discussed above. In step 1209, the facility detects the language of the segment using the generated three- dimensional characterization and three-dimensional models of the languages in the Latin group in accordance with the steps shown in Figure 7. After step 1209, these steps conclude. In step 1210, the facility generates a one-dimensional characterization of the segment using a custom mapping for the language group generated during the training phase in accordance with Figure 10. Step 1210 is performed in accordance with the steps shown in Figure 5, discussed above. In step 1211, the facility detects the language of the segment using the one-dimensional characterization generated in step 1210 and one-dimensional models of the languages in the language group in accordance with the steps shown in Figure 7. After step 1211, these steps conclude. While this invention has been shown and described with reference to preferred embodiments, it will be understood by those skilled in the art that various changes or modifications in form and detail may be made without departing from the scope of the invention. For example, n-grams of longer lengths than discussed above may be used to increase the accuracy of the facility. On the other hand, n-grams of shorter lengths may be used in order to reduce the storage requirements of the facility. Further, while statistical characterizations of digital document representations and statistical models of languages and/or character sets are preferably represented straightforwardly in the facility by utilizing single- or multi-dimensional arrays of values that are between 0 and 255, the facility may be straightforwardly adapted to use other storage schemes, such as arrays having elements of a different size, sparse arrays, or data structures of other types. Additionally, while the facility is described herein with respect to particular written natural languages and character sets, the facility may be straightforwardly applied to model and detect languages and character sets of all types, including those not presently in use.

Claims: CLAIMS I claim: 1. For a series of data values representing text in an unknown distinguished language in accordance with an unknown distinguished character set that associates character glyphs with particular data values, a method in a computer system for identifying the distinguished language using the series of data values, the method comprising the steps of: generating a characterization characterizing the series of data values; for each of a plurality of languages: retrieving a model that models the language in terms of the statistical occurrence of particular data values in representative samples of text in the language, and comparing the retrieved model to the characterization of the series of data values; and identifying as the distinguished language the language among the plurality of languages whose model compares most favorably to the characterization of the series of data values. 2. The method of claim 1 wherein the retrieved models each model a character set as well as a language, and wherein the method further comprises the step of identifying as the distinguished character set the character set whose model compares most favorably to the characterization of the series of data values. 3. The method of claim 1, further comprising the steps of: for each of a plurality of character sets: retrieving a model that models the character set in terms of the statistical occurrence of particular data values in representative samples of text in the character set, and comparing the retrieved model to the characterization of the series of data values; and identifying as the distinguished character set the character set whose model compares most favorably to the characterization of the series of data values. 4. The method of claim 3, further comprising the step of associating with the representation of text constituted by the series of data values an indication of the identified distinguished character set. 5. The method of claim 3, further comprising the step of displaying the text represented by the series of data values using the identified distinguished character set. 6. The method of claim 3, further comprising the step of converting the representation of text constituted by the series of data values from the identified distinguished character set to a target character set. 7. The method of claim 1 , further comprising the step of associating with the representation of text constituted by the series of data values an indication of the identified distinguished language. 8. The method of claim 1, further comprising the step of processing the representation of text constituted by the series of data values using a natural language processing tool based upon the identified distinguished language. 9. The method of claim 1, further comprising the step of processing the representation of text constituted by the series of data values using an information retrieval tool based upon the identified distinguished language. 10. The method of claim 9 wherein the processing step stems words occurring in the representation of text constituted by the series of data values based upon the identified distinguished language. 11. The method of claim 9 wherein the processing step breaks words occurring in the representation of text constituted by the series of data values based upon the identified distinguished language. 12. The method of claim 1 wherein each data value in the series is one of a number of possible data values, and wherein the characterization and the models are both generated using a reductive mapping that maps data values from the number of possible data values to a smaller number of target values to reduce the size of the characterization and the models. 13. The method of claim 1 wherein each data value of the series is one byte. 14. The method of claim 1 wherein each data value of the series is two bytes. 15. A computer system for performing the steps of claim 1. 16. A computer-readable medium whose contents cause one or more computer systems to perform the steps of claim 1. 17. A propagated data signal that causes a computer system to perform the steps of claim 1. 18. A computer memory containing a document characterization data structure characterizing a digital document representation, the digital document representation comprising a series of source values, the data structure comprising, for each possible permutation of a selected length of a set of possible target values, an indication of the number of occurrences in the digital document representation of permutations of the selected length of a set of source values in which each source value is mapped to the corresponding target value by a selected reductive mapping, in which each possible target value is mapped to from at least one possible source value, such that the data structure may be subjected to n-gram analysis techniques for analyzing the digital document representation. 19. The computer memory of claim 18 wherein each indication is a whole number, and wherein the data structure comprises an array of such whole numbers that has a number of dimensions directly corresponding to the selected length. 20. The computer memory of claim 18 wherein the data structure characterizes a digital document representation that is an aggregation of multiple constituent digital document representations, and therefore further characterizes a common characteristic of the multiple constituent digital document representations. 21. The computer memory of claim 20 wherein the data structure characterizes a common language of the multiple constituent digital document representations. 22. The computer memory of claim 20 wherein the data structure characterizes a common character set in which the multiple constituent digital document representations are expressed. 23. The computer memory of claim 20 wherein the data structure characterizes a common character set in which the multiple constituent digital document representations are expressed and a common language used in the multiple constituent digital document representations.

Inventors: POWELL ROBERT DAVID, POWELL, ROBERT, DAVID
Applicants: MICROSOFT CORP, MICROSOFT CORPORATION
Application year: 1998
Main classification: G06F17
IPC codes: G06F17