A text conversion method and program product
By using binary integer values and sequence indexing techniques, the target length of characters or phrases to be converted is quickly determined, which solves the problem of inefficiency in the existing technology and realizes efficient text conversion.
Patent Information
- Application Number
- CN202510301613.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-14
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2045-03-14
AI Technical Summary
Existing text conversion schemes require traversal and searching for individual characters and phrases in the mapping dictionary, resulting in inefficiency in processing and performance bottlenecks.
Use binary integer values and binary sequences to mark the target length of the characters or phrases to be converted, quickly determine whether there are convertible characters or phrases through indexes, reduce the number of searches, and optimize the conversion process.
提高了文字转换的效率,减少了查找次数,提升了性能,满足快速转换的使用场景。
Smart Images

Figure CN119808717B_ABST
Abstract
Description
Technical Field
[0001] This application relates to data processing technologies, and more particularly, to a text conversion method and a program product. Background Art
[0002] As application programs face more and more international usage scenarios, application programs need to provide conversion solutions between different languages and between simplified and traditional Chinese based on the user's language environment, geographical information, etc.
[0003] In existing conversion solutions, a mapping dictionary is usually used to establish the correspondence between the text of the type to be converted and the text of the target type. Since there are often one-to-many or many-to-one situations (i.e., conversions) between the text of the type to be converted and the text of the target type, in order to ensure the accuracy of translation, the mapping dictionary usually contains as many different combinations of characters and phrases as possible.
[0004] However, in the specific text conversion process, existing conversion solutions need to traverse and search for each character and phrase in the above mapping dictionary to confirm which characters in the text information need to be converted. This method will greatly reduce the processing efficiency and cause performance bottlenecks. Summary of the Invention
[0005] The purpose of this application is to provide a text conversion method and a program product, which are used to reduce the number of escape lookups and improve performance.
[0006] To achieve the above purpose, the technical solutions adopted in the embodiments of this application are as follows:
[0007] In a first aspect, an embodiment of this application provides a text conversion method, including:
[0008] According to the conversion type of the data to be converted, confirm the corresponding type conversion instance; the data to be converted includes at least one character to be confirmed; the type conversion instance includes the binary integer value corresponding to the convertible character, and each character bit in the binary sequence corresponding to the binary integer value is used to indicate whether there is a convertible character or a convertible phrase for the character to be confirmed at the corresponding length;
[0009] If the binary integer value is not empty, confirm the target length in the binary sequence; each target length is used to indicate that there is a convertible character or a convertible phrase for the character to be confirmed at the corresponding target length;
[0010] For each target length, search in the type conversion instance to see if there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed;
[0011] If it exists, the character to be confirmed is used as the character to be converted, and all the characters to be converted are converted into corresponding target conversion characters or target conversion phrases to obtain the converted text.
[0012] Optionally, before the step of confirming the corresponding type conversion instance according to the conversion type of the data to be converted, the following steps are further included:
[0013] Construct a dictionary mapping data structure according to the loaded property file; the dictionary mapping data structure contains the corresponding relationship between each piece of text information to be converted and the target text information; the text information to be converted includes characters or phrases to be converted.
[0014] According to the dictionary mapping data structure, establish corresponding binary sequences for the characters or phrases to be converted with the same first character; each bit of each binary sequence corresponds to the character length of the character or phrase to be converted containing the corresponding first character.
[0015] Generate a convertible character mapping dictionary according to the binary integer values corresponding to all the binary sequences.
[0016] Optionally, the following steps are further included:
[0017] Generate a character mapping dictionary and a phrase mapping dictionary according to the dictionary mapping data structure; wherein, the character mapping dictionary is used to indicate the mapping relationship between the characters to be converted and the convertible characters; the phrase mapping dictionary is used to indicate the mapping relationship between the phrases to be converted and the convertible phrases.
[0018] Generate a type conversion instance according to the convertible character mapping dictionary, the character mapping dictionary, the phrase mapping dictionary and the conversion method; the conversion method is used to indicate the conversion method corresponding to the data to be converted.
[0019] Optionally, the step of establishing corresponding binary sequences for the characters or phrases to be converted with the same first character according to the dictionary mapping data structure includes:
[0020] Obtain the characters or phrases to be converted with the same first character to form a set of texts with the same first character.
[0021] Construct a corresponding binary sequence for the set of texts with the same first character; wherein, each bit of each binary sequence corresponds to the character length of the character or phrase to be converted containing the corresponding first character; if there is a corresponding character or phrase to be converted at any bit, the bit is configured as 1; if there is no corresponding character or phrase to be converted at any bit, the bit is configured as 0.
[0022] Optionally, after confirming the corresponding type conversion instance according to the conversion type of the data to be converted, it includes:
[0023] Obtain the first character that has not been searched in the data to be converted one by one as the character to be confirmed;
[0024] Obtain the binary integer value from the convertible character mapping dictionary;
[0025] Determine whether the binary integer value is empty;
[0026] If it is not empty, the step of confirming the target length in the binary sequence includes:
[0027] Determine whether the binary integer value is greater than 1;
[0028] If it is greater than 1, check each bit of the binary sequence one by one from the high bit to the low bit; where the number of bits of the binary sequence is proportional to the character length of the corresponding character to be converted or the character group to be converted from high to low;
[0029] The step of respectively searching for whether there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed in the type conversion instance for each of the target lengths includes:
[0030] When the target bit of the binary sequence is configured as 1, search in the phrase mapping dictionary for whether there is a target conversion phrase with the same character length as the character of the target bit;
[0031] If it exists, use the character to be confirmed as the character to be converted, and convert all the characters to be converted into the corresponding target conversion phrases to obtain the converted text.
[0032] Optionally, after confirming the corresponding type conversion instance according to the conversion type of the data to be converted, it includes:
[0033] If the binary integer value is equal to 1, the step of respectively searching for whether there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed in the type conversion instance for each of the target lengths includes:
[0034] Search in the character mapping dictionary for whether there is a target conversion character corresponding to the character to be confirmed;
[0035] If it exists, use the character to be confirmed as the character to be converted, and convert all the characters to be converted into the corresponding target conversion characters to obtain the converted text.
[0036] Optionally, the step of checking each bit of the binary sequence one by one from the high bit to the low bit includes:
[0037] Obtain the maximum searchable length; the maximum searchable length characterizes the maximum length of querying the binary sequence; the maximum searchable length is less than or equal to the length of the uncompleted search characters in the data to be converted.
[0038] If the maximum searchable length is greater than 1, check the target bit corresponding to the maximum searchable length of the binary sequence according to the maximum searchable length.
[0039] After one check, if no target conversion phrase corresponding to the character to be confirmed is found, the maximum searchable length is decremented, and return to execute the step of checking the target bit corresponding to the maximum searchable length of the binary sequence if the maximum searchable length is greater than 1, until the target bit of the binary sequence is configured as 1 and a target conversion phrase with the same character length as the target bit is found in the phrase mapping dictionary, then the loop ends.
[0040] In a second aspect, an embodiment of the present application provides a text conversion device, including:
[0041] A confirmation module, configured to confirm a corresponding type conversion instance according to the conversion type of the data to be converted; the data to be converted includes at least one character to be confirmed; the type conversion instance includes a binary integer value, and each character bit in the binary sequence corresponding to the binary integer value is used to indicate whether there is a convertible word or a convertible phrase for the character to be confirmed at the corresponding length; if the binary integer value is not empty, confirm the target length in the binary sequence; each target length is used to indicate that there is a convertible character or a convertible phrase for the character to be confirmed at the corresponding target length.
[0042] A search module, configured to search whether there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed in the type conversion instance for each target length respectively.
[0043] A conversion module, configured to, if it exists, use the character to be confirmed as the character to be converted, and convert all the characters to be converted into corresponding target conversion characters or target conversion phrases to obtain the converted text.
[0044] In a third aspect, an embodiment of the present application provides an electronic device, including:
[0045] A memory, configured to store one or more programs;
[0046] A processor;
[0047] When the one or more programs are executed by the processor, the method described in any one of the first aspects above is implemented.
[0048] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method described in any one of the above first aspects is implemented.
[0049] In a fifth aspect, an embodiment of the present application provides a program product, which, when executed by a processor, implements the method described in any one of the above first aspects.
[0050] Compared with the prior art, for a text conversion method and a program product provided by an embodiment of the present application, by using the binary integer value as an index between a character to be confirmed and a target conversion character or a target conversion phrase group, and marking the target length of whether there is an escaped corresponding "target conversion character or target conversion phrase group" for the leading character according to different bit positions of the binary sequence, it is possible to quickly determine whether there are convertible characters or convertible phrase groups that may need to be converted in the character to be confirmed, reducing the process of traversing and matching each character in the conventional technical solution and reducing the range of character or phrase search hits. Furthermore, after confirming the existence of the above possible convertible characters or convertible phrase groups, for each target length, check whether there is a corresponding target conversion character or target conversion phrase group for the character to be confirmed in the type conversion instance. Thereby reducing the number of escape searches, improving performance, and meeting the usage scenarios of fast conversion in production.
[0051] To make the above objects, features, and advantages of the present application more obvious and understandable, the following specifically enumerates preferred embodiments and, in conjunction with the accompanying drawings, makes the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] To more clearly illustrate the technical solutions of the embodiments of the present application, the following briefly introduces the drawings required for the embodiments. It should be understood that the following drawings only show some embodiments of the present application and should not be regarded as limiting the scope. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.
[0053] Figure 1 It is a schematic flowchart of simple-to-complex conversion in a conventional solution;
[0054] Figure 2 It is a schematic flowchart of a text conversion method provided by an embodiment of the present invention;
[0055] Figure 3 It is a schematic flowchart of another text conversion method provided by an embodiment of the present invention;
[0056] Figure 4 It is a schematic flowchart of another text conversion method provided by an embodiment of the present invention;
[0057] Figure 5 A schematic flowchart of another text conversion method provided by an embodiment of the present invention;
[0058] Figure 6 A schematic diagram of data to be converted and character indexes provided by an embodiment of the present invention;
[0059] Figure 7 Another schematic diagram of data to be converted and character indexes provided by an embodiment of the present invention;
[0060] Figure 8 A schematic diagram of a text conversion device provided by an embodiment of the present invention;
[0061] Figure 9 Another schematic diagram of a text conversion device provided by an embodiment of the present invention;
[0062] Figure 10 A schematic structural diagram of an electronic device provided by an embodiment of the present invention. Detailed implementation manners
[0063] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Apparently, the described embodiments are some but not all of the embodiments of the present application. Usually, the components of the embodiments of the present application described and illustrated in the accompanying drawings herein can be arranged and designed in various different configurations.
[0064] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application claimed, but merely represents selected embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative efforts shall fall within the scope of protection of the present application.
[0065] It should be noted that: like reference numerals and letters denote like items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of the present application, the terms "first", "second", etc. are only used for descriptive distinction and cannot be understood as indicating or implying relative importance.
[0066] It should be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising a..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the said element.
[0067] In conventional technical solutions, in the conversion solutions for providing different languages and between simplified and traditional Chinese, a mapping dictionary is usually used to establish the correspondence between the text of the type to be converted and the text of the target type. The mapping dictionary will include as many combinations of different characters and phrases as possible.
[0068] However, in the specific text conversion process, the existing conversion solutions need to traverse and search for each character and phrase in the above mapping dictionary to confirm which characters in the text information need to be converted. This method will greatly reduce the processing efficiency and cause performance bottlenecks at the same time.
[0069] Specifically, taking the simplified and traditional Chinese conversion as an example, a conversion tool (such as ZHConverter) is usually used, and its conversion implementation process is as follows. Specifically, Figure 1 For the flow diagram of the simplified and traditional Chinese conversion in the conventional solution, see Figure 1 , this method includes:
[0070] Step 100: Select and load the property file for simplified to traditional or traditional to simplified conversion according to the conversion type.
[0071] Step 101: Property file data processing: Process to form an escape dictionary mapping (charMap) and conversion characters or phrases (conflictingSets).
[0072] Taking the character with the first letter "Heng" as an example, the characters or phrases involved are as shown in Table 1 below:
[0073]
[0074] Table 1
[0075] Referring to Table 1, it can be found that for "恒", based on usage habits, when it is used alone and appears in a phrase, there may be different conversion situations. For example, when it exists alone, it can be converted between simplified and traditional Chinese. However, in some specific phrases, such as "恒生銀行", it will not be converted between simplified and traditional Chinese. It depends on the specific usage habits of a certain character, which is not limited in this application.
[0076] Accordingly, the conversion character or phrase needs to cover all intermediate states of the character or phrase consisting of the above 1 to 5 characters, as shown in Table 2 below:
[0077]
[0078] Table 2: Intermediate state set with the first character "恒"
[0079] Step 102: Use the conversion method to obtain converted data.
[0080] Steps 102-1 to 102-4 are detailed steps of step 102, and are as follows:
[0081] Step 102-1: Add a buffer of characters to be output and a buffer of characters to be processed.
[0082] Step 102-2: Loop through each character in the string:
[0083] 1 Add the character to the character buffer to be processed;
[0084] 2 If the character to be processed exists in conflictingSets:
[0085] 2.1 If it exists, continue to process the next character;
[0086] 2.2 If it does not exist, determine whether the string to be processed is in the charMap: if it exists, obtain the corresponding conversion string in the charMap and add it to the string to be output; if it does not exist, remove the string to be processed and obtain the first n-1 characters, and further process this part of the data in the same way as step 102-3.
[0087] Specifically, for example, add the character "恒" to the buffer of characters to be processed. At this time, search from the intermediate state of the characters in "conflictingSets", that is, refer to the above text, first determine whether "恒" is in the intermediate state set shown in Table 2 above, if it is, it indicates that there may be a longer phrase or phrase that needs to be translated. Then continue with the next character "生", check whether "恒生" is in the intermediate state set, if it is, it indicates that there may be a translation of a longer phrase or phrase; then continue with the next character "银"... until the character to be processed is not in the intermediate state.
[0088] Step 102-3: If the character buffer to be processed is used as the data to be processed, perform the following processing: Determine whether the string to be processed is not empty and exists in charMap. If it exists, add the converted string in charMap to the string to be output; if it is not empty and does not exist in charMap, obtain and remove the first character of the string to be processed and add it to the string to be output, and repeat step 102-3.
[0089] Step 102-4: Return the string to be output.
[0090] Obviously, with the above solution, it is necessary to store and map all characters in the intermediate state whose conversion cannot be determined, resulting in a large space occupation. Moreover, it is a conversion scheme that searches for longer phrases from front to back. That is, as in the above example, for the character "Heng", based on the existence of its corresponding intermediate state, starting from the shortest length of the character to be confirmed, search for the character or phrase (conflictingSets) in the conversion characters or phrases one by one from short to long, that is, search from "Heng", "Hengsheng", "Hengsheng Bank" until the character to be confirmed at a certain character length cannot find the corresponding intermediate state. This indicates that there is no possibility of a shorter or longer phrase. At this time, starting from the current length position of the character to be confirmed, search backward to confirm whether there is a possibility of a convertible phrase under the longest intermediate state length of this search. If not, perform character conversion one by one.
[0091] For example, for "Hengsheng Bank Family", the last found intermediate state is "Hengsheng Bank", so the character length of the current intermediate state is "3". Search backward in the escape dictionary mapping (charMap) to see if there is a convertible phrase or character among the 3-bit phrases, 2-bit phrases, or 1-bit characters. Of course, if a corresponding convertible phrase is found among the 3-bit phrases, the search stops.
[0092] In addition, in the above solution, when traversing each character in a loop, search from front to back for each character to see if it is in the conversion characters or phrase "conflictingSets". When "conflictingSets" is not hit, then search to see if the escape dictionary mapping (charMap) is hit for string conversion. The logic is complex and the frequent acquisition of strings of a specified length and multiple dictionary lookups bring unnecessary performance losses.
[0093] To address the above problems, the embodiments of the present application introduce the concepts of "binary sequence" and its corresponding "binary integer value", and the purpose is: Use this "binary integer value" as an index, mark whether there is a target length of the "target conversion character or target conversion phrase" corresponding to the escape of the character according to different bit numbers of the binary sequence, and preferentially confirm the target conversion character or target conversion phrase from the high bit. Thereby reducing the number of escape lookups, improving performance, and meeting the usage scenarios of fast conversion.
[0094] That is, in combination with the above example, in the present application, after determining the "binary integer value" of "恒", it will first confirm whether "恒生银行工作" is in the "target conversion character or target conversion phrase" mapped in the binary sequence. Once it is hit, compared with the conventional technical solution's search method from front to back and from short to long. Obviously, compared with the conventional solution's process of using conversion characters or phrases (conflictingSets) to confirm the maximum length of convertible phrases or phrases, the present application can greatly improve efficiency and performance.
[0095] Specifically, Figure 2 A flowchart of a text conversion method provided by an embodiment of the present invention is shown in FIG. Figure 2 , the method comprising:
[0096] Step 205: According to the conversion type of the data to be converted, a corresponding type conversion instance is confirmed.
[0097] The data to be converted includes at least one character to be confirmed; the type conversion instance includes a binary integer value corresponding to the convertible character; the convertible character can be all characters that can be converted based on the attribute file when constructing the dictionaries below. The character to be confirmed can be any one of the convertible characters. Each character bit in the binary sequence corresponding to each binary integer value is used to indicate whether there is a convertible character or a convertible phrase in the corresponding length of the character to be confirmed. The conversion type is used to indicate the conversion type of the data to be converted, for example, translation between different languages, simplified-traditional conversion (simplified to traditional, traditional to simplified), etc.
[0098] It should be noted that, for the "characters" and "phrases" described in various examples of this application, taking Chinese as an example, "character" is the basic unit of the Chinese writing system, usually referring to a single Chinese character or a single punctuation mark. Each character has its own unique shape, pronunciation and meaning.
[0099] And in the examples of this application, characters are the most basic conversion unit, for example:
[0100] The traditional Chinese character "漢" corresponds to the simplified Chinese character "汉".
[0101] The traditional Chinese character "國" corresponds to the simplified Chinese character "國".
[0102] A "phrase" is a language unit consisting of two or more characters that has a specific meaning. A phrase can be a collocation, an idiom, an idiom, or a common expression.
[0103] For example, in the conversion between traditional and simplified Chinese, the phrase needs to be converted as a whole, not just a simple replacement of a single character, and the overall meaning and context need to be considered during the conversion. For example:
[0104] The Traditional Chinese phrase "calculator" corresponds to the Simplified Chinese phrase "computer".
[0105] The Traditional Chinese phrase "網絡" corresponds to the Simplified Chinese phrase "網絡".
[0106] Continue to see Figure 2 , step 209, if the binary integer value is not empty, confirm the target length in the binary sequence.
[0107] Each target length is used to indicate that the character to be confirmed has a convertible character or a convertible phrase at the corresponding target length.
[0108] Step 210: for each target length, search in the type conversion instance whether there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed.
[0109] Specifically, if it exists, execute step 211; if it does not exist, confirm not to convert.
[0110] Step 211: The characters to be confirmed are used as characters to be converted, and all characters to be converted are converted into corresponding target conversion characters or target conversion phrases to obtain converted text.
[0111] The text conversion method provided by the embodiment of the present invention uses the binary integer value as the index between the character to be confirmed and the target conversion character or target conversion phrase, and quickly determines whether the character to be confirmed has a convertible character or convertible phrase that may need to be converted according to the target length of the "target conversion character or target conversion phrase" corresponding to the escape of the head character of the binary sequence with different digits, thereby reducing the process of traversing and matching each character one by one in the conventional technical solution, and reducing the range of character or phrase search hits. After confirming the existence of the above-mentioned possible convertible characters or convertible phrases, for each target length, it is searched in the type conversion instance whether there is a target conversion character or target conversion phrase corresponding to the character to be confirmed. This reduces the number of escape searches, improves performance, and meets the use scenario of rapid production conversion.
[0112] exist Figure 2 Before the conversion process shown in the figure, a dictionary mapping data structure (dictMap) can be constructed based on the specific needs of the scenario and application. The following is a possible implementation method. Specifically, in Figure 2 On the basis of Figure 3 A flowchart of another text conversion method provided by an embodiment of the present invention is shown in FIG. Figure 3 , before step 204, further comprising:
[0113] Step 200: Construct a dictionary mapping data structure according to the loaded attribute file.
[0114] Among them, the dictionary mapping data structure contains the corresponding relationship between each piece of text information to be converted and the target text information; the text information to be converted includes the characters or phrases to be converted.
[0115] Step 201: According to the dictionary mapping data structure, establish corresponding binary sequences for the characters or phrases to be converted with the same first character among them.
[0116] Specifically, each bit of each binary sequence corresponds to the character length of the character or phrase to be converted containing the corresponding first character.
[0117] Step 202: Generate a convertible character mapping dictionary (headConflictingMaps) according to the binary integer values corresponding to all the binary sequences.
[0118] Optionally, the convertible character mapping dictionary can contain each convertible character and the corresponding binary integer value. For example, "Heng" and "41" as shown above. And in the subsequent search process, the binary sequence of the corresponding convertible character is obtained through this binary integer value.
[0119] This solution may also include possible implementation ways of constructing "instance attributes", continue to refer to Figure 3 This method further includes:
[0120] Step 203: Generate a character mapping dictionary and a phrase mapping dictionary according to the dictionary mapping data structure.
[0121] Optionally, the character mapping dictionary is used to indicate the mapping relationship between the characters to be converted and the convertible characters; the phrase mapping dictionary is used to indicate the mapping relationship between the phrases to be converted and the convertible phrases.
[0122] In this embodiment, the character mapping dictionary and the phrase mapping dictionary are separated, so that when looking up a phrase in the phrase mapping dictionary, and looking up a single character in the character mapping dictionary. Compared with the conventional technical solutions that all look up the same conversion dictionary, when the amount of data in the conversion dictionary mapping is large, the query efficiency is indeed improved after the above-mentioned slice mapping.
[0123] This solution may also include possible implementation ways of constructing "type conversion instances", continue to refer to Figure 3 Before step 205, it further includes:
[0124] Step 204: Generate a type conversion instance according to the convertible character mapping dictionary, the character mapping dictionary, the phrase mapping dictionary and the conversion method.
[0125] Among them, the conversion method is used to indicate the conversion method corresponding to the data to be converted.
[0126] An exemplary description of how to construct a "binary sequence" is given below. Specifically, based on Figure 3 ... Figure 4 FIG. is a schematic flowchart of another text conversion method provided by an embodiment of the present invention. Refer to Figure 4 ..., step 201 includes:
[0127] Step 201-1: Obtain the characters or character groups to be converted with the same leading character, and form a set of characters with the same leading character.
[0128] Step 201-2: Construct a corresponding binary sequence for the set of characters with the same leading character.
[0129] Wherein, each bit of each binary sequence corresponds to the character length of the character or character group to be converted containing the corresponding leading character; if there is a corresponding character or character group to be converted for any bit, the bit is configured as 1; if there is no corresponding character or character group to be converted for any bit, the bit is configured as 0.
[0130] For example, taking the scenario of simplified and traditional Chinese conversion as an example, when the leading character is "Heng", taking a financial software program as an example, the set of characters with the same leading character it may involve includes but is not limited to: Hang Seng Bank, Hang Seng Stock Price Index, Hang Seng Index, and Heng. If it is constructed in the order of the serial numbers in Table 3 below when constructing the set of characters with the leading character. Then the first phrase "Hang Seng Bank" has a character length of 4 bits, corresponding to setting 1 at the 4th position in the binary sequence. Further, the second phrase "Hang Seng Stock Price Index" has a character length of 6 bits, corresponding to setting 1 at the 6th position in the binary sequence. Further, the third phrase "Hang Seng Index" also has a character length of 4 bits. Since the 4th bit has been set to 1, the binary sequence remains unchanged at this time. Further, the fourth character "Heng" also has a character length of 1 bit, corresponding to setting 1 at the 1st position in the binary sequence. Finally, the binary sequence is: "0000 0000 0010 1001", and the corresponding binary integer value is: 41.
[0131]
[0132] Table 3
[0133] It should be noted that the total number of bits of this binary sequence is 16 bits, and it can also be determined according to specific scenario requirements, which is not limited here.
[0134] Continue to refer to Figure 4 ..., after step 205, it further includes:
[0135] Step 206: Obtain one by one the leading characters in the data to be converted that have not completed the search as the characters to be confirmed.
[0136] Step 207: Obtain a binary integer value from the convertible character mapping dictionary.
[0137] Step 208: Determine whether the binary integer value is empty.
[0138] Specifically, if it is not empty, then execute step 209-1. If it is empty, then confirm not to convert.
[0139] Correspondingly, step 209 includes:
[0140] Step 209-1: Determine whether the binary integer value is greater than 1.
[0141] Specifically, if it is greater than 1, execute step 209-2; if it is equal to 1, execute step 210-2.
[0142] Step 209-2: Check each bit of the binary sequence one by one from high bit to low bit.
[0143] The number of bits of the binary sequence from high to low is proportional to the length of the corresponding character to be converted or the character length of the phrase to be converted.
[0144] For example, taking the binary sequence "0000 0000 0010 1001" in Table 2 as an example, from high to low, the 6th bit is set to 1, that is, this bit is the target bit, which means that the first character is "恒", and there is a target conversion phrase with a character length of 6 bits. Of course, at this time, the target conversion phrase is only a possibility, and it does not mean that the phrase composed of "恒" and the following characters is the target conversion phrase of this 6-bit character.
[0145] In a possible implementation, step 209-2 can also check the bits set to 1 in the binary sequence one by one from high to low. Taking the binary sequence "0000 0000 0010 1001" in Table 2 as an example, the 6th bit is set to "1", then step 210-1 searches the phrase mapping dictionary for a target conversion phrase with a length of 6 characters. If not found, continue to search at the next position set to "1", that is, the 4th bit. This method can further improve the search efficiency.
[0146] Accordingly, step 210 includes
[0147] Step 210 - 1 : When the target bit of the binary sequence is configured as 1, a search is performed in the phrase mapping dictionary to determine whether there is a target conversion phrase with the same character length as the target bit.
[0148] Specifically, if it exists, execute step 211. If it does not exist, confirm not to convert.
[0149] Accordingly, see Figure 4 , step 210, comprising:
[0150] Step 210-2: Check if there is a target conversion character corresponding to the character to be confirmed in the character mapping dictionary.
[0151] Specifically, if there is, execute Step 211. If not, confirm no conversion.
[0152] Optionally, for Step 209-2, one possible way is as follows:
[0153] Step 209-2a: Obtain the maximum searchable length.
[0154] Optionally, the maximum searchable length represents the maximum length of the query binary sequence; the maximum searchable length is less than or equal to the length of the characters in the data to be converted that have not been searched.
[0155] Step 209-2b: If the maximum searchable length is greater than 1, check the target bit corresponding to the maximum searchable length of the binary sequence.
[0156] After one check, if no target conversion phrase corresponding to the character to be confirmed is found; then the maximum searchable length is decremented, and return to execute the step of checking the target bit corresponding to the maximum searchable length of the binary sequence if the maximum searchable length is greater than 1, until the target bit of the binary sequence is configured as 1, and a target conversion phrase with the same character length as the target bit is found in the phrase mapping dictionary, then the loop ends.
[0157] Optionally, to illustrate the text conversion method provided in the above examples of the present application, the following uses the character "Heng" and the process of loading and searching for phrases as an example. In an actual program, this solution applies to all characters or phrases that can be converted. Specifically, Figure 5 is a schematic flowchart of another text conversion method provided by an embodiment of the present invention. Refer to Figure 5 , this method includes:
[0158] Attribute file loading (program startup phase):
[0159] Step 300: Construct a dictionary mapping data structure through the loaded attribute file.
[0160] Optionally, this dictionary mapping data structure is as shown in Table 1 above.
[0161] Type conversion instance generation (program startup phase):
[0162] Step 301: Construct a set of characters with the same first character according to the dictionary mapping data structure.
[0163] That is, for each first character, a corresponding set of characters with the first character should be established.
[0164] Step 302: For each set of first-character texts, construct a corresponding binary sequence and binary integer value.
[0165] Optionally, the corresponding binary sequence and binary integer value are as shown in Table 2 above.
[0166] Step 303: Generate a convertible character mapping dictionary (headConflictingMaps) based on the above set of first-character texts and the corresponding binary sequence and binary integer value.
[0167] Step 304: Generate a character mapping dictionary and a phrase mapping dictionary according to the dictionary mapping data structure.
[0168] Step 305: Generate a type conversion instance based on the convertible character mapping dictionary, the character mapping dictionary, the phrase mapping dictionary, and the conversion method.
[0169] Type conversion instance generation (during program startup):
[0170] For example, the data to be converted is: "I work at Hang Seng Bank!", and at this time, the following process is executed in combination with the various type conversion instances generated in the previous stage.
[0171] Step 306: Find the corresponding type conversion instance according to the conversion type of the data to be converted.
[0172] Furthermore, call the corresponding conversion method to execute Step 307. That is, if the conversion method indicates to perform simple-traditional conversion, then the process corresponding to "simple-traditional conversion" is executed subsequently. If the conversion method indicates to perform traditional-simple conversion, then the process corresponding to "traditional-simple conversion" is executed subsequently, etc. In this example, the conversion method is illustrated by taking "simple-traditional conversion" as an example.
[0173] Step 307: Initialize a data output object (outString) and a temporary data object (stackString).
[0174] Among them, the temporary data object (stackString) is used to store the current character to be confirmed at each moment.
[0175] Step 308: Initialize the loop variable (character index = 0).
[0176] Step 309: Determine whether the character index has moved to the end.
[0177] If so, output the converted text. If not, execute Step 310.
[0178] Step 310: Determine whether there is a character to be confirmed in the convertible character mapping dictionary.
[0179] If yes, execute step 313; if no, execute step 311.
[0180] Step 311: Add the original character to the data output object (outString).
[0181] Specifically, the character to be confirmed does not exist in the "headConflictingMaps" mentioned above. Then the character to be confirmed in the temporary data object (stackString), that is, the original character, is added to the data output object (outString), and the temporary data object (stackString) is cleared.
[0182] Specifically, Figure 6 A schematic diagram of data to be converted and character index provided by an embodiment of the present invention, see Figure 6 , where at time T1, the character index = 0, which points to the 0th bit of the data to be converted "I work at Hang Seng Bank", that is, "I", and thus "I" does not need to be converted between traditional and simplified Chinese. The original character "I" is added to the data output object. And since the data to be converted has completed the judgment of 1 bit, N = 1, and step 312 is executed.
[0183] Step 312: The loop variable is incremented by N.
[0184] For step 311, the loop variable is incremented by N to 1. That is, after the increment is completed, at time T2 ( Figure 6 (not shown in the figure), at this time, the character index = 1, which points to the first bit of the data to be converted "I work at Hang Seng Bank", that is, "在". Then, the process returns to step 310.
[0185] Step 313: Determine whether the binary integer value corresponding to the character to be confirmed is greater than 1.
[0186] If yes, then execute step 316; if no, then execute step 314. Figure 6 , assuming that at time T3, the character index = 2, which points to the second bit of the data to be converted "I work at Hang Seng Banker", namely "恒". Combined with Table 2 above, it can be seen that the binary integer value corresponding to "恒" = 41, which is greater than 1. This means that for the data to be converted with the first character "恒", there may be characters or phrases that need to be converted.
[0187] Step 314: Determine whether there is a target conversion character corresponding to the character to be confirmed in the character mapping dictionary.
[0188] Specifically, for the case where the binary integer value = 1, it means that only the first bit of the binary sequence is set to "1", that is, there is only one character corresponding to the binary sequence that needs to be converted, and there is no phrase. At this time, whether there is a target conversion character corresponding to the character to be confirmed in the character mapping dictionary, if so, execute step 315. If the binary integer value = 0, it means that there is no character bit set to "1" corresponding to the binary sequence, that is, the character to be confirmed does not need to be converted, and then execute step 311.
[0189] Step 315: The character to be confirmed is used as the character to be converted, and the target conversion character corresponding to the conversion character is added to the data output object (outString). Optionally, after the character to be confirmed is added as the character to be converted to the data output object (outString), the temporary data object (stackString) is cleared.
[0190] Step 316: Check each bit of the binary sequence one by one from high bit to low bit.
[0191] In a possible implementation, when performing step 316, the longest phrase may be prioritized for judgment, such as Figure 6 As shown, after confirming that the binary integer value corresponding to "恒" = 41, 41 is greater than 1, the bits set to 1 in the binary sequence are checked one by one from high to low. Therefore, first check whether there is a mapping of "恒生银家工作" in the phrase mapping dictionary. If not, then check whether there is "恒生银家" in the phrase mapping dictionary. If none of them are found, then at this time, only the lowest target bit of the binary sequence is set to 1, and then step 314 is executed. Figure 6 For example, assume that at time T3, the character index = 2, which points to the second bit of the data to be converted "I work at Hang Seng Bank", that is, "恒". Combined with Table 2 above, it can be seen that the binary sequence corresponding to "恒" is: "0000 0000 0010 1001".
[0192] For this binary sequence, search for the number of digits that are 1 from high to low. This sequence indicates that "恒" may have a 6-digit or 4-digit phrase or phrase. Get the 6-digit string to be translated starting from the current character, such as "恒生银家工作", and determine whether it is in the phrase mapping dictionary.
[0193] In a possible implementation, the default maximum searchable length in the previous example, such as 14 bits, can be used to check the binary sequence. During the first check, the 14th bit of the binary sequence is "0", indicating that there is no phrase starting with "constant" and consisting of 14 characters. Then, continue to check towards the lower bits. It can be determined whether there are target bits in the binary sequence, that is, the character bits set to "1" in the binary sequence. If there are, for all target bits, step 317 is executed.
[0194] It should be noted that the maximum searchable length can be flexibly configured based on the actual application scenario to match the characters and phrases in the actual scenario. For example, the maximum searchable length can be defaulted to 12; the upper limit value of the maximum searchable length can be defined as 15. In some scenarios, such as when the binary integer value is less than 16 and greater than or equal to 8, the maximum searchable length can be configured as 4. It can also be ensured that the maximum searchable length is less than the length of the remaining convertible characters. For example, when there are 2 remaining characters, obviously a maximum searchable length of 14 is unnecessary, and the maximum searchable length can be 1 at this time. Therefore, for the maximum searchable length in this embodiment, its specific setting is not limited.
[0195] In a possible implementation, the relationship between the maximum searchable length (maxFindSize) and the binary integer value (k) is as follows:
[0196] When k >= 16, maxFindSize = 12.
[0197] When 8 <= k < 16, maxFindSize = 4.
[0198] When 4 <= k < 8, maxFindSize = 3.
[0199] When k < 4, maxFindSize = 2.
[0200] Step 317: When the target bit = 1, determine whether there is a target conversion phrase in the phrase mapping dictionary that is the same length as the character of the target bit.
[0201] Specifically, if there is a target conversion phrase in the phrase mapping dictionary corresponding to the character to be confirmed with the current character length, then step 318 is executed. If not, continue step 316 to search from the high bit to the low bit. If after traversing all target bits in 316, no match is found in step 317, then step 314 is executed.
[0202] Continue with Figure 6For example, the binary sequence corresponding to "恒" is: "0000 0000 0010 1001". Its 6th, 4th and 1st bits are set to "1". At this time, it is necessary to confirm whether there is a target conversion phrase with a length of 6 bits and a length of 4 bits in the phrase mapping dictionary. Figure 6 In the example, the 6th and 4th bits are not hit. Then the 1st bit is set to "1", that is, step 316 has checked to the lowest target bit, and then step 314 is executed. That is, it is confirmed whether "恒" has a corresponding target conversion character in the character mapping dictionary. Referring to the above example, the target conversion character corresponding to "恒" is "恆", so at time T3, step 318 is executed. And the character index +1, that is, at time T4 ( Figure 6 (not shown), character index = 3, which points to the third bit in the data to be converted "I work at Hang Seng Banker", namely "生".
[0203] Step 318: The character to be confirmed is used as the character to be converted, and the target conversion phrase corresponding to the conversion character is added to the data output object (outString).
[0204] Specifically, continue with Figure 6 For example, at time T5, the character index = 4, which points to the 4th bit in the data to be converted, that is, "银". The binary sequence corresponding to "银" is: "0000 0000 0000 0011". Its corresponding binary integer value = 3. Refer to the description of steps 313 to 317 above. In this example, since the second bit of "银" is 1, the target conversion phrase corresponding to "银家" is not found in the phrase mapping dictionary. Therefore, step 314 is executed, that is, after confirming "銀", it means that "银" in the data to be converted is the character to be converted. At this time, "我在恒生銀" is added to the data output object (outString).
[0205] Furthermore, since the character to be converted is 4 bits, N=4 at this time, and step 312 is executed, that is, the character index=4+1=5, which points to "家".
[0206] In order to more clearly reflect the difference between the conventional solution and this solution, the following will continue to use the data to be converted as "I work at Hang Seng Bank!" as an example to illustrate the execution process of the conventional solution and this solution.
[0207] First, combined with the intermediate state diagram in Table 2 above, the execution flow of the conventional solution is as follows:
[0208] 1. Execute the character [I]. The character to be processed is [I]. Check whether [I] exists in the conversion set. If it does not exist, check the dictionary mapping [I]. If it does not exist, clear the character to be processed and output the character [I].
[0209] 2. Execute the character '[zài]', the character to be processed is '[zài]'. Check if '[zài]' exists in the conversion set. If not, check the dictionary mapping for '[zài]'. If it doesn't exist, clear the character to be processed and output the character 'I am at'.
[0210] 3. Execute the character '[héng]', the character to be processed is '[héng]'. Check if '[héng]' exists in the conversion set. It exists.
[0211] 4. Execute the character '[shēng]', the character to be processed is '[Hengsheng]'. Check if '[Hengsheng]' exists in the conversion set. It exists.
[0212] 5. Execute the character '[yín]', the character to be processed is '[Hengsheng Yin]'. Check if '[Hengsheng Yin]' exists in the conversion set. It exists.
[0213] 6. Execute the character '[jiā]', the character to be processed is '[Hengsheng Yinjia]'. Check if '[Hengsheng Yinjia]' exists in the conversion set. If not: (For the character string to be processed: when there are multiple characters and it doesn't exist, do it in reverse).
[0214] 6.1 Check the dictionary mapping for '[Hengsheng Yinjia]'. It doesn't exist.
[0215] 6.2 Check the dictionary mapping for '[Hengsheng Yin]'. It doesn't exist.
[0216] 6.3 Check the dictionary mapping for '[Hengsheng]'. It doesn't exist.
[0217] 6.4 Check the dictionary mapping for '[héng]'. It exists, continue translating character by character: Check '[shēng]', it doesn't exist; check '[yín]', it exists; check '[jiā]', it doesn't exist.
[0218] 6.5 Get the translated content of the character string to be processed as '[Hengsheng Yinjia]', clear the character to be processed, and output the character 'I am at Hengsheng Yinjia'.
[0219] 7. Execute the character '[shàng]', the character to be processed is '[shàng]'. Check if '[shàng]' exists in the conversion set. If not: Check the dictionary mapping for '[shàng]'. It doesn't exist, clear the character to be processed, and output the character 'I am at Hengsheng Yinjia on'.
[0220] 8. Execute the character '[bān]', the character to be processed is '[bān]'. Check if '[bān]' exists in the conversion set. If not: Check the dictionary mapping for '[bān]'. It doesn't exist, clear the character to be processed, and output the character 'I am at Hengsheng Yinjia going to work'.
[0221] 9. Execute the character '[!]', the character to be processed is '[!]'. Check if '[!]' exists in the conversion set. If not: Check the dictionary mapping for '[!]'. It doesn't exist, clear the character to be processed, and output the character 'I am at Hengsheng Yinjia going to work!'.
[0222] In the above example of the conventional scheme, the number of set lookups is 21 times.
[0223] In contrast, in combination with the various embodiments of the previous application, the execution process of the present application is as follows:
[0224] 1. Execute the character [I]. The character to be confirmed is [I]. Check the binary integer value of the character [I]. If it does not exist, clear the character to be confirmed in the temporary data object (stackString) and output the character [I].
[0225] 2. Execute the character [在], the character to be confirmed is [在], check the binary integer value of the character [在], if it does not exist, clear the character to be confirmed in stackString and output the character [我在].
[0226] 3. Execute the character [恒], the character to be confirmed is [恒], check that the binary integer value of the character [恒] is 41 (corresponding binary sequence: 0000 0000 0010 1001), which is greater than 1, and search for 1 from high to low.
[0227] 3.1 Traverse the first binary 1 to the 6th bit and check whether [Hang Seng Bank Home Work] is in the phrase mapping dictionary. It does not exist.
[0228] 3.2 Traverse the second binary 1 to the 4th bit and check whether [Hang Seng Silver House] is in the phrase mapping dictionary. It does not exist.
[0229] 3.3 No phrase or word group is found, the unit digit is 1, check whether [恒] is in the character mapping dictionary, if it exists, clear the characters to be confirmed in stackString, and output the converted characters [我在在恆].
[0230] 4. Execute the character [生], the character to be confirmed is [生], check the binary integer value of the character [生], if it does not exist, clear the character to be confirmed in stackString, and output the converted character [我在恒生].
[0231] 5. Execute the character [银], the character to be confirmed is [银], check whether the binary integer value of the character [银] is 1, check whether [银] is in the character mapping dictionary, if it exists, clear the character to be confirmed in stackString, and output the converted character [我在恆生銀].
[0232] 6. Execute the character [家], the character to be confirmed is [家], check the binary integer value of the character [家], if it does not exist, clear the character to be confirmed in stackString, and output the converted character [我在遆生銀家].
[0233] 7. Execute the character '[Up]'. The character to be confirmed is '[Up]'. Check the binary integer value of the character '[Up]'. If it does not exist, clear the character to be confirmed in stackString and output the converted character 'I am at Hang Seng Bank'.
[0234] 8. Execute the character '[Shift]'. The character to be processed is '[Shift]'. Check the binary integer value of the character '[Shift]'. If it does not exist, clear the character to be confirmed in stackString and output the converted character 'I am at Hang Seng Bank for work'.
[0235] 9. Execute the character '!'. The character to be processed is '!'. Check the binary index value of the character '!'. If it does not exist, clear the character to be confirmed in stackString and output the converted character 'I am at Hang Seng Bank for work!'.
[0236] In the example of the solution of this application above, the number of set lookups is only 12 times. Compared with the conventional solution, the number of lookups is greatly reduced.
[0237] Optionally, take 'I am at Hang Seng Bank for work!' as an example to exemplarily illustrate the execution processes of the conventional solution and this solution. For comparison with the case of 'I am at Hang Seng Bank for work!' in the above example.
[0238] First, combined with the intermediate state schematic in Table 2 in the previous text, the execution process of the conventional solution is as follows:
[0239] 1. Execute the character 'I'. The character to be processed is 'I'. Check whether 'I' exists in the conversion set. If it does not exist: check the dictionary mapping of 'I'. If it does not exist, clear the character to be processed and output the character 'I'.
[0240] 2. Execute the character 'at'. The character to be processed is 'at'. Check whether 'at' exists in the conversion set. If it does not exist: check the dictionary mapping of 'at'. If it does not exist, clear the character to be processed and output the character 'I am at'.
[0241] 3. Execute the character 'Heng'. The character to be processed is 'Heng'. Check whether 'Heng' exists in the conversion set. If it exists.
[0242] 4. Execute the character 'Sheng'. The character to be processed is 'Hang Seng'. Check whether 'Hang Seng' exists in the conversion set. If it exists.
[0243] 5. Execute the character 'Yin'. The character to be processed is 'Hang Seng Yin'. Check whether 'Hang Seng Yin' exists in the conversion set. If it exists.
[0244] 6. Execute the [行] character. The character to be processed is [恒生银行]. Check whether [恒生银行] exists in the conversion set. If it does not exist: (The string to be processed: if it is multiple characters, if it does not exist, proceed in reverse).
[0245] 6.1 Check the dictionary mapping [Hang Seng Bank], if it exists, get the translation content of the string to be processed [Hang Seng Bank], clear the characters to be processed, and output the characters [I am in Hang Seng Bank].
[0246] 7. Execute the character [上], the character to be processed is [上], check whether [上] exists in the conversion set, if not: check the dictionary mapping [上], if not, clear the character to be processed, and output the character [我在恒生银行].
[0247] 8. Execute the character [班], the character to be processed is [班], check whether [班] exists in the conversion set, if not: check the dictionary mapping [班], if not, clear the character to be processed, and output the character [我工作恒生银行].
[0248] 9. Execute the [!] character. The character to be processed is [!]. Check whether [!] exists in the conversion set. If it does not exist, check the dictionary mapping [!]. If it does not exist, clear the character to be processed and output the character [I work at Hang Seng Bank!].
[0249] In the above example of the conventional scheme, the number of set lookups is 15 times.
[0250] In contrast, in combination with the various embodiments of the previous application, the execution process of the present application is as follows:
[0251] 1. Execute the character [I]. The character to be confirmed is [I]. Check the binary integer value of the character [I]. If it does not exist, clear the character to be confirmed in stackString and output the character [I].
[0252] 2. Execute the character [在], the character to be confirmed is [在], check the binary integer value of the character [在], if it does not exist, clear the character to be confirmed in stackString and output the character [我在].
[0253] 3. Execute the character [恒], the character to be confirmed is [恒], check that the binary integer value of the character [恒] is 41 (corresponding binary sequence: 0000 0000 0010 1001), which is greater than 1, and search for "1" from high to low.
[0254] 3.1 Traverse the first binary 1 as the 6th bit and check whether [Hang Seng Bank working] is in the phrase mapping dictionary. It does not exist.
[0255] 3.2 Traverse the second binary 1 as the 4th bit, check whether [Hang Seng Bank] is in the phrase mapping dictionary, if it exists, get the target conversion phrase [Hang Seng Bank], clear the characters to be confirmed in stackString, and output the characters [I am in Hang Seng Bank].
[0256] Specifically, Figure 7 Another schematic diagram of data to be converted and character index provided by an embodiment of the present invention is shown in FIG. Figure 7 At time T3, the character index = 2, and the binary sequence corresponding to "恒" is: "0000 0000 0010 1001". Its 6th, 4th and 1st bits are set to "1". At this time, it is necessary to confirm whether there are target conversion phrases of 6 bits and 4 bits in the phrase mapping dictionary. In this example, the 4th bit finds the corresponding target conversion phrase in the phrase mapping dictionary, that is, "恒生银行". At this time, since the character "恒" to be converted is 2 bits, and the conversion is completed from the beginning to the next 4 bits, for time T4, its character index = 2+4=6, that is, at time T4, the character index points to "上". 4. Execute the character [上], the character to be confirmed is [上], check the binary index value of the character [上], it does not exist, clear the character to be confirmed in stackString, and output the character [我在恒生銀行].
[0257] 5. Execute the character [班], the character to be confirmed is [班], check the binary index value of the character [班], if it does not exist, clear the character to be confirmed in stackString, and output the character [我工作恒生银行].
[0258] 6. Execute the [!] character. The character to be confirmed is [!]. Check the binary index value of the [!] character. If it does not exist, clear the character to be confirmed in stackString and output the character [I work at Hang Seng Bank!].
[0259] In the above example of the present application solution, the number of set searches is only 8. Compared with conventional solutions, the number of searches is greatly reduced.
[0260] It should be noted that compared with the previous example "I work at Hang Seng Bank!", in this example, in 3.2, the 4th position checked that "Hang Seng Bank" exists in the phrase mapping dictionary. Therefore, the 4-character phrase is directly output. In the example "I work at Hang Seng Bank!", since the corresponding phrase "Hang Seng Bank" in 3.2 is not checked in the phrase mapping dictionary, step 3.3 is executed to check 1 position, that is, to check whether "恒" is in the character mapping dictionary. If it is confirmed to exist, only the simplified Chinese character "恒" is converted to the traditional Chinese character "恆".
[0261] In contrast, in the example of "I work at Hang Seng Bank!", since the character "恒" in "恒生银行" is usually in simplified Chinese, the traditional Chinese phrase corresponding to "恒生銀行" in the phrase mapping dictionary is "恒生銀行". Therefore, in the converted output characters "我工作恒生銀行!" in this example, "恒" is still in simplified Chinese.
[0262] In addition, for the case where the data to be converted contains other characters, numbers or English letters, a possible implementation method is given below. For example, the data to be converted is "Hang Seng Bank Building A 202 work!", when the character index points to English, numbers and symbols, in a possible implementation method, such as in the traditional and simplified Chinese conversion scenario, the corresponding binary integer value can be 0, that is, the characters corresponding to English, numbers and symbols are not converted. Of course, in some other scenarios, the binary integer value may not be 0, and the above-mentioned example process is executed to convert the corresponding characters or phrases.
[0263] It can be found that the conversion of a single character contained in the phrase mapping dictionary in the present application may be different from that of the same character in the character mapping dictionary, which is based on the usage convention of characters in actual situations.
[0264] In summary, the inventor collected the conventional technical solutions and the solution of this application for continuous calling test cases for more than 10 minutes (local Windows computer, relevant instances are preloaded in advance). Compared with the conventional technical solutions, the performance of the solution of this application in the short, medium and long scenarios of the existing test samples is improved by 12.9%, 50.7% and 57.8% respectively. As shown in Table 4 below
[0265]
[0266] Table 4
[0267] Optionally, the present application also provides a text conversion device, which is used to execute each step of the above example to achieve the corresponding technical effect. Figure 8 A schematic diagram of a text conversion device provided by an embodiment of the present invention, see Figure 8 The device 40 includes: a confirmation module 400, a search module 401 and a conversion module 402. The confirmation module 400 is used to confirm the corresponding type conversion instance according to the conversion type of the data to be converted.
[0268] The search module 401 is used to search, for each target length, in the type conversion instance to see whether there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed.
[0269] A conversion module 402, which, if any, uses the character to be confirmed as the character to be converted, and converts all the characters to be converted into corresponding target converted characters or target converted character groups to obtain the converted text.
[0270] Optionally, in order to construct the dictionary mapping data structure, binary sequence, convertible character mapping dictionary, instance attributes, conversion method, type conversion instance, and set of texts with the same first character in the above example, the text conversion device provided by this application may further include a construction module. Specifically, based on Figure 8 this, Figure 9 Another schematic diagram of the text conversion device provided by an embodiment of the present invention is shown in Figure 9 , and the device 40 further includes: a construction module 403.
[0271] The construction module 403 is used to construct a dictionary mapping data structure according to the loaded attribute file; establish a corresponding binary sequence for the characters or character groups to be converted with the same first character in the dictionary mapping data structure; generate a convertible character mapping dictionary according to the binary integer values corresponding to all the binary sequences; generate a character mapping dictionary and a phrase mapping dictionary according to the dictionary mapping data structure; and generate a type conversion instance according to the convertible character mapping dictionary, character mapping dictionary, phrase mapping dictionary, and conversion method.
[0272] Optionally, the construction module 403 is specifically used to obtain the characters or character groups to be converted with the same first character, form a set of texts with the same first character, and construct a corresponding binary sequence for the set of texts with the same first character.
[0273] The search module 401 is specifically used to sequentially obtain the first characters in the data to be converted that have not been searched as the characters to be confirmed; obtain the binary integer value from the convertible character mapping dictionary; determine whether the binary integer value is empty; if not, determine whether the binary integer value is greater than 1; if it is greater than 1, sequentially check each bit of the binary sequence from the high bit to the low bit; when the target bit of the binary sequence is configured as 1, search in the phrase mapping dictionary to see if there is a target converted phrase with the same character length as the character at the target bit.
[0274] Correspondingly, the conversion module 402 is specifically used to, if any, use the character to be confirmed as the character to be converted, and convert all the characters to be converted into corresponding target converted phrases to obtain the converted text.
[0275] The search module 401 is specifically used to search in the character mapping dictionary to see if there is a target converted character corresponding to the character to be confirmed.
[0276] Correspondingly, the conversion module 402 is specifically configured to use the character to be confirmed as the character to be converted if it exists, and convert all characters to be converted into corresponding target converted characters to obtain the converted text.
[0277] Optionally, the search module 401 is specifically configured to obtain the maximum searchable length. If the maximum searchable length is greater than 1, the target bit corresponding to the maximum searchable length is checked according to the check binary sequence. After one check, if the target conversion phrase corresponding to the character to be confirmed is not found; the maximum searchable length is decremented, and the step of checking the target bit corresponding to the maximum searchable length according to the maximum searchable length is returned until the target bit of the binary sequence is configured to 1 and the target conversion phrase with the same character length as the target bit is found in the phrase mapping dictionary, and then the loop ends.
[0278] The invention embodiment also provides an electronic device, which can execute all the steps of the above examples of the invention embodiment to achieve the corresponding technical effects. Specifically, Figure 10 is a schematic structural diagram of an electronic device provided by an embodiment of the present invention. Refer to Figure 10 The electronic device 50 includes: a memory 501 and a processor 500;
[0279] The memory 501 is used to store one or more programs;
[0280] The processor 500;
[0281] When one or more programs are executed by the processor, when the electronic device 50 is used to execute the steps shown in the above method examples, it can achieve each step and the corresponding technical effects.
[0282] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions, and operations of devices, methods, and computer program products according to multiple embodiments of the present application. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code, and the module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, as well as the combination of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.
[0283] In addition, in each embodiment of the present application, the functional modules can be integrated together to form an independent part, or each module can exist separately, or two or more modules can be integrated to form an independent part.
[0284] If the function is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a program product. This program product is stored in a computer-readable storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods in each embodiment of the present application. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs that can store program codes.
[0285] The above are only the preferred embodiments of the present application and are not used to limit the present application. For those skilled in the art, the present application can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
[0286] It will be apparent to those skilled in the art that the present application is not limited to the details of the above-described exemplary embodiments, and that the present application can be implemented in other specific forms without departing from the spirit or essential characteristics of the present application. Therefore, in any regard, the embodiments should be regarded as exemplary and non-limiting. The scope of the present application is defined by the appended claims rather than the above description. Accordingly, all changes that fall within the meaning and scope of the equivalent elements of the claims are intended to be embraced within the present application. No drawing reference numeral in the claims should be construed as limiting the claim concerned.
Claims
1. A text conversion method, characterized in that, Including: Confirm a corresponding type conversion instance according to the conversion type of the data to be converted; the conversion type is translation between different languages or conversion between simplified and traditional Chinese characters; The data to be converted includes at least one character to be confirmed; the type conversion instance includes the binary integer value corresponding to the convertible character, and each character bit in the binary sequence corresponding to the binary integer value is used to indicate whether there is a convertible character or a convertible phrase for the character to be confirmed at the corresponding length; If the binary integer value is not empty, confirm the target length in the binary sequence; each target length is used to indicate that there is a convertible character or a convertible phrase for the character to be confirmed at the corresponding target length; For each of the target lengths, check whether there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed in the type conversion instance; If there is, use the character to be confirmed as the character to be converted, and convert all the characters to be converted into the corresponding target conversion characters or target conversion phrases to obtain the converted text.
2. The method according to claim 1, characterized in that, Before the step of confirming a corresponding type conversion instance according to the conversion type of the data to be converted, it further includes: Construct a dictionary mapping data structure according to the loaded property file; the dictionary mapping data structure includes the corresponding relationship between each piece of text information to be converted and the target text information; the text information to be converted includes the character or phrase to be converted; According to the dictionary mapping data structure, establish a corresponding binary sequence for the characters or phrases to be converted with the same first character; each bit of each binary sequence corresponds to the character length of the character or phrase to be converted including the corresponding first character; Generate a convertible character mapping dictionary according to the binary integer values corresponding to all the binary sequences.
3. The method according to claim 2, wherein It also includes: Generate a character mapping dictionary and a phrase mapping dictionary according to the dictionary mapping data structure; wherein, the character mapping dictionary is used to indicate the mapping relationship between the character to be converted and the convertible character; the phrase mapping dictionary is used to indicate the mapping relationship between the phrase to be converted and the convertible phrase; Generate a type conversion instance according to the convertible character mapping dictionary, the character mapping dictionary, the phrase mapping dictionary and the conversion method; the conversion method is used to indicate the conversion method corresponding to the data to be converted.
4. The method according to claim 2, characterized in that, The step of establishing a corresponding binary sequence for the characters or phrases to be converted with the same first character according to the dictionary mapping data structure includes: Obtain the characters or phrases to be converted with the same first character to form a set of texts with the same first character; Construct a corresponding binary sequence for the set of texts with the same first character; wherein, each bit of each binary sequence corresponds to the character length of the character or phrase to be converted including the corresponding first character; if there is a corresponding character or phrase to be converted at any bit, the bit is configured as 1; if there is no corresponding character or phrase to be converted at any bit, the bit is configured as 0.
5. The method according to claim 3, characterized in that After the step of confirming a corresponding type conversion instance according to the conversion type of the data to be converted, it includes: Obtain the first character in the data to be converted that has not been searched for, one by one, as the character to be confirmed; Obtain the binary integer value from the convertible character mapping dictionary; Determine whether the binary integer value is empty; If it is not empty, the step of confirming the target length in the binary sequence includes: Determine whether the binary integer value is greater than 1; If it is greater than 1, check each bit of the binary sequence one by one from the high bit to the low bit; wherein the number of bits of the binary sequence is proportional to the character length of the corresponding character or character group to be converted from high to low; The step of respectively searching for whether there is a target conversion character or target conversion character group corresponding to the character to be confirmed in the type conversion instance for each of the target lengths includes: When the target bit of the binary sequence is configured as 1, search in the phrase mapping dictionary for whether there is a target conversion phrase with the same character length as that of the target bit; If it exists, use the character to be confirmed as the character to be converted, and convert all the characters to be converted into the corresponding target conversion phrases to obtain the converted text.
6. The method according to claim 5, characterized in that, After confirming the corresponding type conversion instance according to the conversion type of the data to be converted, it includes: If the binary integer value is equal to 1, the step of respectively searching for whether there is a target conversion character or target conversion character group corresponding to the character to be confirmed in the type conversion instance for each of the target lengths includes: Search in the character mapping dictionary for whether there is a target conversion character corresponding to the character to be confirmed; If it exists, use the character to be confirmed as the character to be converted, and convert all the characters to be converted into the corresponding target conversion characters to obtain the converted text.
7. The method according to claim 5, characterized in that, The step of checking each bit of the binary sequence one by one from the high bit to the low bit includes: Obtain the maximum searchable length; the maximum searchable length represents the maximum length of searching the binary sequence; the maximum searchable length is less than or equal to the character length of the data to be converted that has not been searched for; If the maximum searchable length is greater than 1, check the target bit corresponding to the maximum searchable length of the binary sequence according to the maximum searchable length; After one check, if no target conversion phrase corresponding to the character to be confirmed is found; then the maximum searchable length is decremented, and return to execute the step of if the maximum searchable length is greater than 1, check the target bit corresponding to the maximum searchable length of the binary sequence until when the target bit of the binary sequence is configured as 1, and a target conversion phrase with the same character length as that of the target bit is found in the phrase mapping dictionary, then the loop ends.
8. A text conversion device, characterized in that Includes: A confirmation module, configured to confirm a corresponding type conversion instance according to the conversion type of data to be converted; the conversion type is translation between different languages or traditional-simplified conversion; the data to be converted includes at least one character to be confirmed; the type conversion instance includes a binary integer value, and each bit in the binary sequence corresponding to the binary integer value is used to indicate whether there is a convertible word or convertible phrase for the character to be confirmed at the corresponding length; if the binary integer value is not empty, confirm the target length in the binary sequence; each of the target lengths is used to indicate that there is a convertible character or convertible phrase for the character to be confirmed at the corresponding target length. A search module, configured to search, for each of the target lengths, whether there is a target conversion character or target conversion phrase corresponding to the character to be confirmed in the type conversion instance. A conversion module, configured to, if there is a corresponding one, use the character to be confirmed as a character to be converted, and convert all the characters to be converted into corresponding target conversion characters or target conversion phrases to obtain the converted text.
9. An electronic device, characterized in that, Comprising: A memory, configured to store one or more programs. A processor. When the one or more programs are executed by the processor, the method according to any one of claims 1-7 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, the method according to any one of claims 1-7 is implemented.
11. A program product, characterized in that, When the program product is executed by the processor, the method according to any one of claims 1-7 is implemented.
Citation Information
Patent Citations
Conversion method for converting data files of dictionary into binary files
CN101751380A
Character query method and device, equipment and medium
CN117633312A