Character conversion method and program product
By generating binary integer values and sequences, the convertibility of characters to be confirmed is solved, and the problem of low word conversion efficiency in the prior art is achieved, and the requirements of performance improvement and rapid conversion are achieved.
Patent Information
- Application Number
- CN202510301613.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-14
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2045-03-14
AI Technical Summary
In the specific text conversion process, existing text conversion schemes need to traverse and find mapping dictionaries, resulting in low processing efficiency and performance bottlenecks.
By generating binary integer values and binary sequences, as indexes, quickly determine whether there are convertible characters or phrases for confirmation, reduce the number of searches, and find target conversion characters or phrases in type conversion instances.
Reduces the number of escape searches, improves performance, and meets the usage scenarios of fast conversion.
Smart Images

Figure CN119808717A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to data processing technology, and in particular, to a text conversion method and program product. Background Art
[0002] As applications face more and more international usage scenarios, applications need to provide information conversion solutions between different languages and between simplified and traditional Chinese based on the user's language environment, regional information, etc.
[0003] In existing conversion schemes, a mapping dictionary is usually used to establish a correspondence between the text type to be converted and the text type of the target. Since the text type to be converted and the text type of the target are often one-to-many or many-to-one (i.e. conversion), in order to ensure the accuracy of the translation, the mapping dictionary usually contains as many different combinations of characters and phrases as possible.
[0004] However, in the conversion process of specific text, the existing conversion solution needs to traverse and search each character and phrase in the mapping dictionary to confirm which text in the text information needs to be converted. This method greatly reduces processing efficiency and causes performance bottlenecks. Summary of the invention
[0005] The purpose of the present application is to provide a text conversion method and program product, which are used to reduce the number of escape searches and improve performance.
[0006] In order to achieve the above purpose, the technical solution adopted in the embodiment of the present application is as follows: In a first aspect, an embodiment of the present application provides a text conversion method, comprising: According to the conversion type of the data to be converted, a corresponding type conversion instance is confirmed; 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, and each character bit in the binary sequence corresponding to the binary integer value is used to indicate whether the character to be confirmed has a convertible word or a convertible phrase in a corresponding length; If the binary integer value is not empty, then confirm the target length in the binary sequence; 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; For each of the target lengths, searching in the type conversion instance whether there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed; If so, the to-be-confirmed characters are used as the to-be-converted characters, and all of the to-be-converted characters are converted into corresponding target conversion characters or target conversion phrases to obtain converted text.
[0007] Optionally, before the step of confirming a corresponding type conversion instance according to the conversion type of the data to be converted, the method further includes: According to the loaded attribute file, a dictionary mapping data structure is constructed; the dictionary mapping data structure includes a correspondence between each text information to be converted and the target text information; the text information to be converted includes characters to be converted or phrases to be converted; According to the dictionary mapping data structure, for the characters to be converted or phrases to be converted having the same first character, a corresponding binary sequence is established; each bit of the binary sequence corresponds to the character length of the character to be converted or phrase to be converted containing the corresponding first character; A convertible character mapping dictionary is generated according to the binary integer values corresponding to all the binary sequences.
[0008] Optionally, 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 characters to be converted and the convertible characters; and the phrase mapping dictionary is used to indicate the mapping relationship between the phrases to be converted and the convertible phrases; A type conversion instance is generated 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.
[0009] Optionally, the step of establishing a corresponding binary sequence for the characters to be converted or phrases to be converted having the same first character according to the dictionary mapping data structure includes: Obtain characters to be converted or phrases to be converted that have the same first character to form a character set with the same first character; Construct a corresponding binary sequence for the same first-character text set; wherein each bit of the binary sequence corresponds to the character length of the character to be converted or the phrase to be converted containing the corresponding first character; if any bit has a corresponding character to be converted or a phrase to be converted, the bit is configured as 1; if any bit does not have a corresponding character to be converted or a phrase to be converted, the bit is configured as 0.
[0010] Optionally, after confirming the corresponding type conversion instance according to the conversion type of the data to be converted, the method further includes: Obtaining the first characters of the data to be converted that have not been searched for one by one 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 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, then check each bit of the binary sequence one by one from high bit to low bit; wherein the number of bits of the binary sequence from high bit to low bit is proportional to the character length of the corresponding character to be converted or the character length of the phrase to be converted; The step of searching, for each of the target lengths, in the type conversion instance whether there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed comprises: When the target bit of the binary sequence is configured as 1, searching in the phrase mapping dictionary whether there is a target conversion phrase with the same character length as the target bit; If so, the to-be-confirmed characters are used as the to-be-converted characters, and all of the to-be-converted characters are converted into corresponding target conversion phrases to obtain converted text.
[0011] Optionally, after confirming the corresponding type conversion instance according to the conversion type of the data to be converted, the method further includes: If the binary integer value is equal to 1, the step of searching, for each of the target lengths, in the type conversion instance whether there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed comprises: Searching in the character mapping dictionary whether there is a target conversion character corresponding to the character to be confirmed; If so, the to-be-confirmed characters are used as the to-be-converted characters, and all of the to-be-converted characters are converted into corresponding target conversion characters to obtain converted text.
[0012] Optionally, the step of checking each bit of the binary sequence one by one from high bit to low bit comprises: Obtaining a maximum searchable length; the maximum searchable length represents a maximum length of the binary sequence to be queried; the maximum searchable length is less than or equal to the length of the characters that have not been searched in the data to be converted; If the maximum searchable length is greater than 1, checking the target bit of the binary sequence corresponding to the maximum searchable length according to the maximum searchable length; After completing 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 process returns to the step of checking the target position of the binary sequence corresponding to the maximum searchable length according to the maximum searchable length if the maximum searchable length is greater than 1, until the target position of the binary sequence is configured as 1, and the target conversion phrase with the same character length as the target position is found in the phrase mapping dictionary, then the loop ends.
[0013] In a second aspect, an embodiment of the present application provides a text conversion device, comprising: A confirmation module, used for confirming a corresponding type conversion instance according to a conversion type of 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, each character bit in a binary sequence corresponding to the 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; if the binary integer value is not empty, confirming a target length in the binary sequence; each target length is used to indicate whether there is a convertible character or a convertible phrase in the corresponding target length of the character to be confirmed; A search module, for searching, for each of the target lengths, whether there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed in the type conversion instance; The conversion module is used to use the to-be-confirmed characters as the to-be-converted characters if they exist, and convert all the to-be-converted characters into corresponding target conversion characters or target conversion phrases to obtain converted text.
[0014] In a third aspect, an embodiment of the present application provides an electronic device, including: A memory for storing one or more programs; processor; When the one or more programs are executed by the processor, the method as described in any one of the first aspects above is implemented.
[0015] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a method as described in any one of the above-mentioned first aspects.
[0016] In a fifth aspect, an embodiment of the present application provides a program product, which, when executed by a processor, implements a method as described in any one of the above-mentioned first aspects.
[0017] Compared with the prior art, the text conversion method and program product provided by the embodiment of the present application, by using the binary integer value as the index between the character to be confirmed and the target conversion character or target conversion phrase, and marking the head character according to the different digits of the binary sequence to see whether there is a target length of the "target conversion character or target conversion phrase" corresponding to the escape, quickly determines whether there is a convertible character or convertible phrase that may need to be converted in the character to be confirmed, 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. Then, after confirming the existence of the above-mentioned possible convertible characters or convertible phrases, for each target length, respectively, search in the type conversion instance to see 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.
[0018] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0020] Figure 1 This is a schematic diagram of the process of converting between simplified and traditional Chinese in the conventional scheme; Figure 2 A flowchart of a text conversion method provided by an embodiment of the present invention; Figure 3 A flowchart of another text conversion method provided by an embodiment of the present invention; Figure 4 A flowchart of another text conversion method provided by an embodiment of the present invention; Figure 5 A flowchart of another text conversion method provided by an embodiment of the present invention; Figure 6 A schematic diagram of data to be converted and character index provided by an embodiment of the present invention; Figure 7 A schematic diagram of another type of data to be converted and character index provided by an embodiment of the present invention; Figure 8 A schematic diagram of a text conversion device provided by an embodiment of the present invention; Fig. 9A schematic diagram of another text conversion device provided by an embodiment of the present invention; Fig.10 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0021] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations.
[0022] 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 for which protection is sought, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0023] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so 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 this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.
[0024] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0025] In conventional technical solutions, in the solution of providing information conversion between different languages and between simplified and traditional Chinese, a mapping dictionary is usually used to establish a correspondence between the text type to be converted and the text type of the target type. The mapping dictionary will contain as many different combinations of characters and phrases as possible.
[0026] However, in the conversion process of specific texts, 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.
[0027] Specifically, taking the traditional and simplified Chinese conversion as an example, usually a conversion tool (such as ZHConverter) is used, and its implementation process is as follows. Specifically, Figure 1 For the schematic diagram of the traditional and simplified Chinese conversion process in the conventional solution, see Figure 1 , this method includes: Step 100: According to the conversion type, select and load the property file for simplified-to-traditional or traditional-to-simplified conversion.
[0028] Step 101: Property file data processing: Process to form an escape dictionary mapping (charMap) and conversion characters or phrases (conflictingSets).
[0029] Taking the character with the first letter "Heng" as an example, the characters or phrases involved are as shown in Table 1 below:
[0030] Table 1 Referring to Table 1, it can be found that for "Heng", based on usage habits, there may be different conversion situations when it is used alone and when it appears in a phrase. For example, when it exists alone, it can be converted between traditional and simplified Chinese. However, in some specific phrases, such as "Hengsheng Bank", it will not be converted between traditional and simplified Chinese. It depends on the specific usage habits of a certain character, which is not limited in this application.
[0031] Correspondingly, the conversion characters or phrases need to cover all intermediate states of the characters or phrases composed of the above 1- to 5-digit characters, as shown in Table 2 below
[0032] Table 2: Schematic diagram of the intermediate state set with the first character "Heng" Step 102: Use the conversion method to process and obtain the converted data.
[0033] Among them, steps 102-1 to 102-4 are the detailed steps of step 102, which are specifically as follows: Step 102-1: Add a cache for characters to be output, a cache for characters to be processed.
[0034] Step 102-2: Loop through each character in the string: 1 Add the character to the cache of characters to be processed; 2 If the character to be processed exists in conflictingSets: 2.1 If it exists, continue to process the next character; 2.2 If it does not exist, determine whether the string to be processed is in charMap: if it exists, obtain the corresponding conversion string in 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 in step 102-3.
[0035] Specifically, for example, add the character "恒" to the cache of characters to be processed. At this time, search from the intermediate state of the characters in "conflictingSets", that is, refer to the previous text. First, determine whether "恒" is in the intermediate state set shown in Table 2 above. If it exists, it indicates that there may be longer phrases or expressions that need to be translated for this "恒". Then continue with the next character "生" and check whether "恒生" is in the intermediate state set. If it exists, it indicates that there may be a translation of a longer phrase; then continue with the next character "银"..... until the character to be processed is not in the intermediate state.
[0036] Step 102-3: If the cache of characters 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 is in charMap. If it exists, add the conversion 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.
[0037] Step 102-4: Return the string to be output.
[0038] Obviously, with the above solution, it is necessary to store and map all the characters in the intermediate state whose conversion cannot be determined, which occupies a large amount of space. And it is a conversion scheme for searching for longer phrases from front to back. That is, as shown in the above example, for the character "恒", based on whether its corresponding intermediate state exists, search for it one by one in the conversion characters or phrases (conflictingSets) from the shorter length to the longer length of the characters to be confirmed, that is, search from "恒", "恒生", "恒生银" until the characters to be confirmed at a certain character length cannot find the corresponding intermediate state. It means that there is no possibility of a shorter phrase. At this time, search from the length position of the characters to be confirmed at this time from back to front to confirm whether there is a possibility of a convertible phrase under the length of the longest intermediate state found this time. If not, perform character conversion one by one.
[0039] For example, for "Hang Seng Bank", the intermediate state found last is "Hang Seng", so the character length of the current intermediate state is "3". Then, reverse-lookup whether there are convertible phrases or characters in the phrases of 3 digits, 2 digits, or 1 character in the escape dictionary mapping (charMap). Of course, if a corresponding convertible phrase is found in the phrases of 3 digits, the lookup stops.
[0040] In addition, in the above solution, when traversing each character in a loop, it is necessary to check whether each character exists in the conversion characters or phrases "conflictingSets" from front to back. After not hitting "conflictingSets", it is necessary to check whether it hits the escape dictionary mapping (charMap) 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.
[0041] To address the above problems, embodiments of the present application introduce the concepts of "binary sequence" and its corresponding "binary integer value", aiming to: use the "binary integer value" as an index, mark the target length of whether there is an escape corresponding "target conversion character or target conversion phrase" for a 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.
[0042] That is, in combination with the above example, in the solution of the present application, after determining the "binary integer value" of "Heng", it will first confirm whether "Hang Seng Bank Work" exists in the "target conversion character or target conversion phrase" mapped by the binary sequence. Once hit, compared with the conventional technical solution of looking up from front to back and from short to long. Obviously, compared with the process of using the conversion characters or phrases (conflictingSets) in the conventional solution to confirm the maximum length of convertible phrases or phrases, the solution of the present application can greatly improve efficiency and enhance the performance of the solution.
[0043] Specifically, Figure 2 is a schematic flowchart of a text conversion method provided by an embodiment of the present invention. Refer to Figure 2 and the method includes: Step 205: Confirm the corresponding type conversion instance according to the conversion type of the data to be converted.
[0044] Among them, the data to be converted contains at least one character to be confirmed; the type conversion instance contains the binary integer value corresponding to the convertible character; the convertible character can be all the characters that can be converted obtained from the property file when constructing each dictionary below. The character to be confirmed can be any one of the convertible characters. Each bit in the binary sequence corresponding to each binary integer value is used to indicate whether there is a convertible character or convertible phrase for the character to be confirmed at the corresponding length. The conversion type is used to indicate the conversion type of the data to be converted. For example, different language translations, simplified and traditional Chinese conversions (simplified to traditional, traditional to simplified), etc.
[0045] It should be noted that for the "characters" and "phrases" described in each example of this application, taking Chinese as an example, a "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 unique glyph, pronunciation, and meaning.
[0046] And in the examples of this application, a character is the most basic conversion unit. For example: The traditional Chinese character "漢" corresponds to the simplified Chinese character "汉".
[0047] The traditional Chinese character "國" corresponds to the simplified Chinese character "国".
[0048] A "phrase" is a language unit composed of two or more characters and has a specific meaning. A phrase can be a fixed collocation, an idiom, a set phrase, or a common expression.
[0049] For example, in the simplified and traditional Chinese conversion, a phrase needs to be converted as a whole, rather than just a simple replacement of a single character. And when converting, the overall meaning and context need to be considered. For example: The traditional Chinese phrase "計算機" corresponds to the simplified Chinese phrase "计算机".
[0050] The traditional Chinese phrase "網絡" corresponds to the simplified Chinese phrase "网络".
[0051] Continue to refer to Figure 2 Step 209: If the binary integer value is not empty, confirm the target length in the binary sequence.
[0052] Among them, each target length is used to indicate that there is a convertible character or convertible phrase for the character to be confirmed at the corresponding target length.
[0053] Step 210: For each target length, respectively check whether there is a target conversion character or target conversion phrase corresponding to the character to be confirmed in the type conversion instance.
[0054] Specifically, if it exists, execute Step 211; if it does not exist, confirm not to convert.
[0055] 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.
[0056] 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.
[0057] 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: Step 200: Construct a dictionary mapping data structure according to the loaded attribute file.
[0058] The dictionary mapping data structure includes the corresponding relationship between each text information to be converted and the target text information; the text information to be converted includes characters to be converted or phrases to be converted.
[0059] Step 201: According to the dictionary mapping data structure, for the characters to be converted or the phrases to be converted having the same first character, a corresponding binary sequence is established.
[0060] Specifically, each bit of each binary sequence corresponds to the character length of the character to be converted or the phrase to be converted including the corresponding first character.
[0061] Step 202: Generate a convertible character mapping dictionary (headConflictingMaps) according to the binary integer values corresponding to all base sequences.
[0062] Optionally, the convertible character mapping dictionary may include each convertible character and its corresponding binary integer value. For example, "constant" and "41" as shown above. During subsequent lookups, the binary sequence of the corresponding convertible character is obtained through this binary integer value.
[0063] This solution may also include possible implementation ways of constructing "instance attributes", continue to refer to Figure 3 This method further includes: Step 203: Generate a character mapping dictionary and a phrase mapping dictionary according to the dictionary mapping data structure.
[0064] 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.
[0065] 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, the phrase mapping dictionary is used, and when looking up a single character, the character mapping dictionary is used. Compared with the conventional technical solution where the same conversion dictionary is looked up, when the amount of data in the conversion dictionary mapping is large, the query efficiency is improved after the above-mentioned sharded mapping.
[0066] 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: 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.
[0067] Among them, the conversion method is used to indicate the conversion method corresponding to the data to be converted.
[0068] The following is an exemplary description of how to construct a "binary sequence". Specifically, on the basis of Figure 3 continue with Figure 4 FIG. Figure 4 is a schematic flowchart of another text conversion method provided by an embodiment of the present invention. Refer to Step 201 includes:
[0069] Step 201-1: Obtain the characters or phrases to be converted with the same leading character, and form a set of characters with the same leading character.
[0070] Among them, each bit of each binary sequence corresponds to the character length of the character or character group to be converted that contains the corresponding first 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.
[0071] For example, taking the scenario of simplified and traditional Chinese conversion as an example, when the first character is "Heng", taking a financial software program as an example, the set of characters with the same first character that it may involve includes but is not limited to: Hang Seng Bank, Hang Seng Stock Price Index, Hang Seng Index, and Heng. If it constructs the set of characters with the same first character in the order of the serial numbers in Table 3 below. Then the first phrase "Hang Seng Bank" has a character length of 4 bits, corresponding to setting the 4th bit in the binary sequence to 1. Further, the second phrase "Hang Seng Stock Price Index" has a character length of 6 bits, corresponding to setting the 6th bit in the binary sequence to 1. Further, the third phrase "Hang Seng Index" also has a character length of 4 bits. Since the 4th bit has already 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 the 1st bit in the binary sequence to 1. Finally, the binary sequence is: "0000 0000 0010 1001", and the corresponding binary integer value is: 41.
[0072]
[0073] Table 3 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.
[0074] Continue to refer to Figure 4 , after step 205, it further includes: Step 206, obtain one by one the first characters in the data to be converted that have not completed the search as the characters to be confirmed.
[0075] Step 207, obtain the binary integer value from the convertible character mapping dictionary.
[0076] Step 208, determine whether the binary integer value is empty.
[0077] Specifically, if it is not empty, then execute step 209-1. If it is empty, then confirm not to convert.
[0078] Correspondingly, step 209 includes: Step 209-1, determine whether the binary integer value is greater than 1.
[0079] Specifically, if it is greater than 1, then execute step 209-2; if it is equal to 1, then execute step 210-2.
[0080] Step 209-2: Check each bit of the binary sequence one by one from the high bit to the low bit.
[0081] Among them, 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.
[0082] 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. Its meaning is that the first character is "constant", and there is a target conversion character group with a character length of 6 bits. Of course, at this time, this target conversion character group is only a possibility, and it does not mean that the character group composed of this "constant" and the subsequent characters is the target conversion character group of this 6-bit character.
[0083] In a possible implementation manner, in step 209-2, it is also possible to check the bits set to 1 in the binary sequence one by one from the high bit to the low bit. Taking the binary sequence "0000 0000 0010 1001" in Table 2 as an example, the 6th bit is set to "1", then in step 210-1, check whether there is a target conversion character group with a character length of 6 bits in the phrase mapping dictionary. If not found, continue to search at the position where the next bit is set to "1", that is, the 4th bit. This way can further improve the search efficiency.
[0084] Correspondingly, step 210 includes Step 210-1: When the target bit of the binary sequence is configured to 1, check whether there is a target conversion character group in the phrase mapping dictionary whose character length is the same as that of the target bit.
[0085] Specifically, if it exists, execute step 211. If not, confirm no conversion.
[0086] Correspondingly, continue to refer to Figure 4 , step 210 includes: Step 210-2: Check whether there is a target conversion character corresponding to the character to be confirmed in the character mapping dictionary.
[0087] Specifically, if it exists, execute step 211. If not, confirm no conversion.
[0088] Optionally, for step 209-2, one possible way is: Step 209-2a: Obtain the maximum searchable length.
[0089] Optionally, the maximum searchable length represents the maximum length of querying the binary sequence; the maximum searchable length is less than or equal to the character length of the characters in the data to be converted that have not been searched.
[0090] Step 209-2b: If the maximum searchable length is greater than 1, check the target bits corresponding to the maximum searchable length in the binary sequence.
[0091] After one check, if the target conversion phrase corresponding to the character to be confirmed is not found; then the maximum searchable length is decremented, and the step of checking the target bits corresponding to the binary sequence and the maximum searchable length is returned for execution if the maximum searchable length is greater than 1, 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, then the loop ends.
[0092] Optionally, to illustrate the text conversion method provided in the above examples of the present application, the loading and searching processes of the character "Heng" and phrases are used for exemplary illustration below. In an actual program, this solution is applicable 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: Attribute file loading (program startup phase): Step 300: Construct a dictionary mapping data structure through the loaded attribute file.
[0093] Optionally, the dictionary mapping data structure is as shown in Table 1 above.
[0094] Type conversion instance generation (program startup phase): Step 301: Construct a set of characters with the same first character according to the dictionary mapping data structure.
[0095] That is, for each first character, a corresponding set of characters with the first character should be established.
[0096] Step 302: For each set of characters with the same first character, construct the corresponding binary sequence and binary integer value.
[0097] Optionally, the corresponding binary sequence and binary integer value are as shown in Table 2 above.
[0098] Step 303: Generate a convertible character mapping dictionary (headConflictingMaps) according to the above set of characters with the same first character and the corresponding binary sequence and binary integer value.
[0099] Step 304: Generate a character mapping dictionary and a phrase mapping dictionary according to the dictionary mapping data structure.
[0100] Step 305: Generate type conversion instances according to the convertible character mapping dictionary, character mapping dictionary, phrase mapping dictionary and conversion method.
[0101] Type conversion instance generation (program startup phase): For example, the data to be converted is: "I work at Hang Seng Bank!" At this time, the following process is executed in combination with each type conversion instance generated in the previous stage.
[0102] Step 306: Find a corresponding type conversion instance according to the conversion type of the data to be converted.
[0103] Then, the corresponding conversion method is called to execute step 307. That is, if the conversion method indicates to perform a simplified Chinese-Traditional Chinese conversion, then the process corresponding to the "Simplified Chinese-Traditional Chinese conversion" is subsequently executed. If the conversion method indicates to perform a Traditional Chinese-Simplified Chinese conversion, then the process corresponding to the "Traditional Chinese-Simplified Chinese conversion" is subsequently executed. In this example, the conversion method is described by taking the "Simplified Chinese-Traditional Chinese conversion" as an example.
[0104] Step 307: Initialize the data output object (outString) and the temporary data object (stackString).
[0105] Among them, the temporary data object (stackString) is used to store the current character to be confirmed corresponding to each moment.
[0106] Step 308: Initialize loop variables (character index = 0).
[0107] Step 309: Determine whether the character index has moved to the end.
[0108] If yes, the converted text is output. If no, step 310 is executed.
[0109] Step 310: Determine whether there is a character to be confirmed in the convertible character mapping dictionary.
[0110] If yes, execute step 313; if no, execute step 311.
[0111] Step 311: Add the original character to the data output object (outString).
[0112] 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.
[0113] 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 position in the data to be converted, "我在恒生银家上班", that is, "我". Furthermore, "我" does not need to be converted between traditional and simplified Chinese. Then add the original character "我" to the data output object. And since 1 bit of the data to be converted has been judged, N = 1, to execute step 312.
[0114] Step 312: Increment the loop variable N.
[0115] For the situation of step 311, increment the loop variable N by 1 bit. That is, after the increment, at time T2 ( Figure 6 not shown in the figure), the character index = 1, which points to the 1st position in the data to be converted, "我在恒生银家上班", that is, "在". Then return to execute step 310.
[0116] Step 313: Judge whether the binary integer value corresponding to the character to be confirmed is greater than 1.
[0117] If so, execute step 316; if not, execute step 314. Continue to refer to Figure 6 , assuming that at time T3, the character index = 2, which points to the 2nd position in the data to be converted, "我在恒生银行家上班", that is, "恒". Combining with Table 2 above, the binary integer value corresponding to "恒" = 41, and 41 is greater than 1. That means for the data to be converted with the first character being "恒", there may be characters or phrases that need to be converted.
[0118] Step 314: Judge whether there is a target conversion character corresponding to the character to be confirmed in the character mapping dictionary.
[0119] Specifically, for the case where the binary integer value = 1, it means that only the first bit of its binary sequence has a "1" set, that is, there is only one character that needs to be converted in this binary sequence, and there is no phrase. Then, whether there is a target conversion character corresponding to the character to be confirmed in the character mapping dictionary. If so, execute step 315. And if the binary integer value = 0, it means that there is no "1" character bit in this binary sequence, that is, the character to be confirmed does not need to be converted, then execute step 311.
[0120] Step 315: Take the character to be confirmed as the character to be converted, and add the target conversion character corresponding to the conversion character to the data output object (outString). Optionally, after adding the character to be confirmed as the character to be converted to the data output object (outString), clear the temporary data object (stackString).
[0121] Step 316: Check each bit of the binary sequence one by one from the high bit to the low bit.
[0122] In a possible implementation, when performing step 316, it is possible to preferentially judge from the longest phrase. For example, Figure 6 as shown, after confirming that the binary integer value corresponding to "heng" = 41, and 41 is greater than 1, check the bits set to 1 in the binary sequence one by one from the high bit to the low bit. Therefore, first check whether there is a mapping of "Hengsheng Yinjia Shangban" in the phrase mapping dictionary. If not, then check whether there is "Hengsheng Yinjia" in the phrase mapping dictionary. If neither is found, then at this time only the lowest target bit in this binary sequence is set to 1, and then step 314 is executed. Continuing with Figure 6 as an example, assume that at time T3, the character index = 2 at this time, which points to the second bit in the data to be converted "I work at Hengsheng Bank", that is, "heng". Combining with Table 2前文, the binary sequence corresponding to this "heng" is: "0000 0000 0010 1001".
[0123] For this binary sequence, find the number of bits that are 1 from the high bit to the low bit. This sequence indicates that "heng" may have phrases or words of 6 bits or 4 bits. Obtain the 6-bit length string to be translated starting from the current character, such as "Hengsheng Yinjia Shangban", and judge whether it is in the phrase mapping dictionary.
[0124] In a possible implementation, the default maximum searchable length in the previous example, such as 14 bits, can be used to check this binary sequence. In the first check, the 14th bit of this binary sequence is "0", indicating that there is no phrase starting with "heng" and consisting of 14 characters. Then continue to check the lower bits. It can be judged whether there are target bits in this binary sequence, that is, the character bits set to "1" in the binary sequence. If there are, then for all target bits, execute step 317.
[0125] It should be noted that this 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 to 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 at this time can be 1. Therefore, for the maximum searchable length in this embodiment, its specific setting is not limited.
[0126] In a possible implementation, the relationship between the maximum searchable length (maxFindSize) and the binary integer value (k) is as follows: When k >= 16, maxFindSize = 12.
[0127] When 8 <= k < 16, maxFindSize = 4.
[0128] When 4 <= k < 8, maxFindSize = 3.
[0129] When k < 4, maxFindSize = 2.
[0130] 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 length of the target bit.
[0131] 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 execute Step 318. If not, continue with Step 316 to search from the high bit to the low bit. If after traversing all the target bits in 316, no match is found in Step 317, then execute Step 314.
[0132] Continue with Figure 6 as an 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 are target conversion phrases of 6 - bit length and 4 - bit length in the phrase mapping dictionary. In the example of Figure 6 , neither the 6th nor the 4th bit hits. Then the 1st bit is set to "1", that is, Step 316 has checked to the lowest target bit, so execute Step 314. That is, confirm whether there is a corresponding target conversion character for "恒" in the character mapping dictionary. Referring to the above example, the target conversion character corresponding to "恒" is "恆". Therefore, at time T3, execute Step 318. And the character index + 1, that is, at time T4 (not shown in Figure 6 ), the character index = 3, pointing to the 3rd bit in the data to be converted "我在恒生银行家上班", which is "生".
[0133] Step 318: Use the character to be confirmed as the character to be converted, and add the target conversion phrase corresponding to the conversion character to the data output object (outString).
[0134] Specifically, continue with Figure 6For example, at time T5, where the character index = 4, it points to the 4th bit in the data to be converted, which is '银' (silver). The binary sequence corresponding to '银' is: "0000 0000 0000 0011". Its corresponding binary integer value = 3. Referring to the description in the previous steps 313 - 317, in this example, since the 2nd bit 1 of '银' does not find a corresponding target conversion phrase for '银家' in the phrase mapping dictionary, therefore, step 314 is executed. That is, after confirming '銀' (yin), it indicates that '银' in the data to be converted is the character to be converted. At this time, the "我在恆生銀" (I am at Hang Seng Bank) is added to the data output object (outString).
[0135] Moreover, since the character to be converted is 4 bits, at this time N = 4, and step 312 is executed, that is, the character index = 4 + 1 = 5, which points to '家' (home).
[0136] To more clearly show the differences between the conventional scheme and this scheme, below, taking the data to be converted as "我在恒生银家上班!" (I work at Hang Seng Bank!) as an example, the execution processes of the conventional scheme and this scheme are illustrated exemplarily.
[0137] First, combining with the intermediate state schematic diagram in Table 2 in the previous text, the execution process of the conventional scheme is as follows: 1. Execute the character
我
我
我
我
我
[0138] 2. Execute the character
在
在
在
在
我在
[0139] 3. Execute the character
恒
恒
恒
[0140] 4. Execute the character
生
恒生
恒生
[0141] 5. Execute the character
银
恒生银
恒生银
[0142] 6. Execute the character
家
恒生银家
恒生银家
[0143] 6.1 Check the dictionary mapping of
恒生银家
[0144] 6.2 Check the dictionary mapping [Hang Seng Bank], not found.
[0145] 6.3 Check the dictionary mapping [Hang Seng], not found.
[0146] 6.4 Check the dictionary mapping [Heng], found, continue to translate character by character: Check [Sheng], not found; Check [Yin], found; Check [Jia], not found.
[0147] 6.5 Get the translation content of the string to be processed [Heng Sheng Yin Jia], clear the characters to be processed, and output the character [I am at Heng Sheng Yin Jia]. 7. Execute the character [Shang], the character to be processed is [Shang], check if [Shang] exists in the conversion set, not found: Check the dictionary mapping [Shang], not found, clear the character to be processed, and output the character [I am at Heng Sheng Yin Jia Shang].
[0148] 8. Execute the character [Ban], the character to be processed is [Ban], check if [Ban] exists in the conversion set, not found: Check the dictionary mapping [Ban], not found, clear the character to be processed, and output the character [I go to work at Heng Sheng Yin Jia].
[0149] 9. Execute the character [!], the character to be processed is [!], check if [!] exists in the conversion set, not found: Check the dictionary mapping [!], not found, clear the character to be processed, and output the character [I go to work at Heng Sheng Yin Jia!].
[0150] In the example of the above conventional scheme, the number of set lookups is 21 times.
[0151] In contrast, combining the various embodiments of the previous text application, the execution process of the solution of this application is as follows: 1. Execute the character [Wo], the character to be confirmed is [Wo], check the binary integer value of the character [Wo], not found, clear the character to be confirmed in the temporary data object (stackString), and output the character [Wo].
[0152] 2. Execute the character [Zai], the character to be confirmed is [Zai], check the binary integer value of the character [Zai], not found, clear the character to be confirmed in stackString, and output the character [Wo Zai].
[0153] 3. Execute the character [Heng], the character to be confirmed is [Heng], check that the binary integer value of the character [Heng] is 41 (corresponding binary sequence: 0000 0000 0010 1001), greater than 1, and find 1 from high to low.
[0154] 3.1 Traverse the first binary 1 at the 6th bit, check if [Heng Sheng Yin Jia Shang Ban] exists in the phrase mapping dictionary, not found.
[0155] 3.2 Traverse the second binary 1 at the 4th position and check if
Hengsheng Yinjia
[0156] 3.3 No phrase or phrase is found, and the units digit is 1. Check if
Heng
I am in Heng
[0157] 4. Execute the character
Sheng
Sheng
Sheng
I am in Hengsheng
[0158] 5. Execute the character
Yin
Yin
Yin
Yin
I am in Hengsheng Yin
[0159] 6. Execute the character
Jia
Jia
Jia
I am in Hengsheng Yinjia
[0160] 7. Execute the character
Shang
Shang
Shang
I am in Hengsheng Yinjia Shang
[0161] 8. Execute the character
Ban
Ban
Ban
I am in Hengsheng Yinjia Shangban
[0162] 9. Execute the character
!
!
!
I am in Hengsheng Yinjia Shangban!
[0163] 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.
[0164] Optionally, take "I work at Hang Seng Bank!" as an example to exemplarily illustrate the execution processes of the conventional solution and this solution. For comparison with the situation of "I work at Hang Seng Yinjia!" in the above example.
[0165] First, in combination with the intermediate state schematic diagram in Table 2 above, the execution process of the conventional scheme is as follows: 1. Execute the character '我'. The character to be processed is '我'. Check if '我' exists in the conversion set. If not, check the dictionary mapping for '我'. If not found, clear the character to be processed and output the character '我'.
[0166] 2. Execute the character '在'. The character to be processed is '在'. Check if '在' exists in the conversion set. If not, check the dictionary mapping for '在'. If not found, clear the character to be processed and output the character '我在'.
[0167] 3. Execute the character '恒'. The character to be processed is '恒'. Check if '恒' exists in the conversion set. It exists.
[0168] 4. Execute the character '生'. The character to be processed is '恒生'. Check if '恒生' exists in the conversion set. It exists.
[0169] 5. Execute the character '银'. The character to be processed is '恒生银'. Check if '恒生银' exists in the conversion set. It exists.
[0170] 6. Execute the character '行'. The character to be processed is '恒生银行'. Check if '恒生银行' exists in the conversion set. If not: (For the character string to be processed: if it is multiple characters and not found, perform in reverse).
[0171] 6.1 Check the dictionary mapping for '恒生银行'. If found, obtain the translated content of the character string to be processed as '恒生銀行', clear the character to be processed, and output the character '我在恒生銀行'.
[0172] 7. Execute the character '上'. The character to be processed is '上'. Check if '上' exists in the conversion set. If not, check the dictionary mapping for '上'. If not found, clear the character to be processed and output the character '我在恒生銀行上'.
[0173] 8. Execute the character '班'. The character to be processed is '班'. Check if '班' exists in the conversion set. If not, check the dictionary mapping for '班'. If not found, clear the character to be processed and output the character '我在恒生銀行上班'.
[0174] 9. Execute the character '!'. The character to be processed is '!'. Check if '!'. exists in the conversion set. If not, check the dictionary mapping for '!'. If not found, clear the character to be processed and output the character '我在恒生銀行上班!'.
[0175] In the above example of the conventional scheme, the number of times of set lookup is 15 times.
[0176] In contrast, in combination with the various embodiments of the previous text application, the execution process of the solution of this application is as follows: 1. Execute the character "我", the character to be confirmed is "我", check the binary integer value of the character "我", if it does not exist, clear the characters to be confirmed in stackString, and output the character "我".
[0177] 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 characters to be confirmed in stackString, and output the character "我在".
[0178] 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 the high bit to the low bit.
[0179] 3.1 Traverse the first binary 1 at the 6th bit, check whether "恒生银行上班" is in the phrase mapping dictionary, and it does not exist.
[0180] 3.2 Traverse the second binary 1 at the 4th bit, check whether "恒生银行" is in the phrase mapping dictionary, and it exists. Obtain the target conversion phrase "恒生銀行", clear the characters to be confirmed in stackString, and output the character "我在恒生銀行".
[0181] Specifically, Figure 7 Another schematic diagram of the data to be converted and character index provided by the embodiment of the present invention is shown in Figure 7 , at time T3, at this time the character index = 2, and the binary sequence corresponding to this "恒" 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 with 6-bit and 4-bit lengths in the phrase mapping dictionary. In this example, the target conversion phrase corresponding to the 4th bit is found in the phrase mapping dictionary, that is, "恒生银行". At this time, since the character to be converted "恒" is 2 bits, and the conversion is completed for 4 bits starting from it, 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 "上", if it does not exist, clear the characters to be confirmed in stackString, and output the character "我在恒生銀行上".
[0182] 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 characters to be confirmed in stackString, and output the character "我在恒生銀行上班".
[0183] 6. Execute the character
!
!
!
I work at Hang Seng Bank!
[0184] In the example of the solution of the present application above, the number of set lookups is only 8 times. Compared with the conventional solution, the number of lookups is greatly reduced.
[0185] It should be noted that compared with the example of "I work at Hang Seng Silver Family!" in the previous text, in this example, at 3.2, it is checked that "Hang Seng Bank" exists in the phrase mapping dictionary at the 4th position. Therefore, directly output the phrase of these 4 characters. In the example of "I work at Hang Seng Silver Family!", since the corresponding phrase "Hang Seng Silver Family" is not found in the phrase mapping dictionary at the 4th position in 3.2, then step 3.3 is executed, and the 1st position is checked, that is, check whether "Heng" is in the character mapping dictionary. If it is confirmed to exist, only perform the simplified and traditional conversion on this "Heng", that is, convert it to the traditional character "恆".
[0186] In contrast, in the example of "I work at Hang Seng Bank!", since the character "Heng" in "Hang Seng Bank" is usually in simplified form, the corresponding traditional phrase of "Hang Seng Bank" in the phrase mapping dictionary is "Hang Seng銀行". Therefore, in the output character "I work at Hang Seng銀行上班!" after conversion in this example, "Heng" is still in simplified form.
[0187] 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, for the data to be converted "Hang Seng Bank, Building A, 202, go to work!", when the character index points to English, numbers and symbols, in a possible implementation method, such as in the scenario of simplified and traditional conversion of Chinese, its 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, this binary integer value can be non-zero, and then the above example process is executed to perform the corresponding character or phrase conversion.
[0188] It can be found that the conversion situation of a single character contained in the phrase mapping dictionary in the present application and the same character in the character mapping dictionary may be different, which is specifically determined based on the usage convention of Chinese characters in the actual situation.
[0189] In summary, the inventor collected the conventional technical solution and the solution of the present application respectively and continuously called the test cases for more than 10 minutes (local windows computer, and relevant instances were pre-loaded in advance). The solution of the present application has performance improvements of 12.9%, 50.7%, and 57.8% respectively compared with the conventional technical solution in the short, medium, and extra-long scenarios of the existing test samples. As shown in Table 4 below
[0190] Table 4 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.
[0191] 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.
[0192] The conversion module 402 is used to, if any, use the to-be-confirmed characters as characters to be converted, and convert all the characters to be converted into corresponding target conversion characters or target conversion phrases to obtain converted text.
[0193] 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 characters with the same first character in the above examples, the text conversion device provided by the present application may also include a construction module. Specifically, Figure 8 On the basis of Fig. 9 A schematic diagram of another text conversion device provided by an embodiment of the present invention is shown in FIG. Fig. 9 , the device 40 also includes: a construction module 403.
[0194] 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 to be converted or the phrases to be converted having the same first character according to the dictionary mapping data structure; generate a convertible character mapping dictionary according to the binary integer values corresponding to all binary sequences; generate a character mapping dictionary and a phrase mapping dictionary according to the dictionary mapping data structure; generate a type conversion instance according to the convertible character mapping dictionary, the character mapping dictionary, the phrase mapping dictionary and the conversion method.
[0195] Optionally, the construction module 403 is specifically used to obtain characters to be converted or phrases to be converted with the same first character to form a character set with the same first character; and to construct a corresponding binary sequence for the character set with the same first character.
[0196] The search module 401 is specifically used to obtain the first character of the data to be converted that has not been searched 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, determine whether the binary integer value is greater than 1; if it is greater than 1, check each bit of the binary sequence from high bit to low bit; when the target bit of the binary sequence is configured as 1, search in the phrase mapping dictionary whether there is a target conversion phrase with the same character length as the target bit.
[0197] Correspondingly, the conversion module 402 is specifically configured to, if any, use the to-be-confirmed characters as the characters to be converted, and convert all the characters to be converted into corresponding target conversion phrases to obtain converted text.
[0198] The search module 401 is specifically used to search in the character mapping dictionary whether there is a target conversion character corresponding to the character to be confirmed.
[0199] Correspondingly, the conversion module 402 is specifically configured to, if any, use the to-be-confirmed characters as the characters to be converted, and convert all the characters to be converted into corresponding target conversion characters to obtain converted text.
[0200] Optionally, the search module 401 is specifically used to obtain the maximum searchable length. If the maximum searchable length is greater than 1, the target position corresponding to the maximum searchable length is checked according to the binary sequence. After completing one check, if the target conversion phrase corresponding to the character to be confirmed is not found; the maximum searchable length is decreased, and the execution returns to the step of checking the target position corresponding to the maximum searchable length of the binary sequence according to the maximum searchable length if the maximum searchable length is greater than 1, until the target position of the binary sequence is configured as 1, and the target conversion phrase with the same character length as the target position is found in the phrase mapping dictionary, then the loop ends.
[0201] The embodiment of the invention further provides an electronic device, which can execute all the steps of the above examples of the embodiment of the invention to achieve the corresponding technical effects. Specifically, Fig.10 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention, see Fig.10 , the electronic device 50, comprises: a memory 501, a processor 500; Memory 501, used to store one or more programs; Processor 500; 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-mentioned method examples, it can achieve each step and the corresponding technical effects.
[0202] 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 schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to the multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and a part of the module, program segment or code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0203] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0204] If the function is implemented in the form of a software function 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 can be essentially or partly embodied in the form of a program product that contributes to the prior art, and the program product is stored in a computer-readable storage medium, including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, and other media that can store program codes.
[0205] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. 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.
[0206] It will be apparent to those skilled in the art that the present application is not limited to the details of the exemplary embodiments described above, and that the present application can be implemented in other specific forms without departing from the spirit or essential features of the present application. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the present application is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims be included in the present application. Any reference numeral in a claim should not be considered as limiting the claim to which it relates.
Claims
1. A text conversion method, characterized in that: include: According to the conversion type of the data to be converted, a corresponding type conversion instance is confirmed; 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, 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 in the corresponding length of the character to be confirmed; If the binary integer value is not empty, then confirm the target length in the binary sequence; 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; For each of the target lengths, searching in the type conversion instance whether there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed; If so, the to-be-confirmed characters are used as the to-be-converted characters, and all of the to-be-converted characters are converted into corresponding target conversion characters or target conversion phrases to obtain converted text.
2. The method according to claim 1, characterized in that Before the step of confirming the corresponding type conversion instance according to the conversion type of the data to be converted, the method further includes: According to the loaded attribute file, a dictionary mapping data structure is constructed; the dictionary mapping data structure includes a correspondence between each text information to be converted and the target text information; the text information to be converted includes characters to be converted or phrases to be converted; According to the dictionary mapping data structure, for the characters to be converted or phrases to be converted having the same first character, a corresponding binary sequence is established; each bit of the binary sequence corresponds to the character length of the character to be converted or phrase to be converted containing the corresponding first character; A convertible character mapping dictionary is generated according to the binary integer values corresponding to all the binary sequences.
3. The method according to claim 2, characterized in that 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 characters to be converted and the convertible characters; and the phrase mapping dictionary is used to indicate the mapping relationship between the phrases to be converted and the convertible phrases; A type conversion instance is generated 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 to be converted or phrases to be converted having the same first character according to the dictionary mapping data structure comprises: Obtain characters to be converted or phrases to be converted that have the same first character to form a character set with the same first character; Construct a corresponding binary sequence for the same first-character text set; wherein each bit of the binary sequence corresponds to the character length of the character to be converted or the phrase to be converted containing the corresponding first character; if any bit has a corresponding character to be converted or a phrase to be converted, the bit is configured as 1; if any bit does not have a corresponding character to be converted or a phrase to be converted, the bit is configured as 0.
5. The method according to claim 3, characterized in that: After confirming the corresponding type conversion instance according to the conversion type of the data to be converted, the method includes: Obtaining the first characters of the data to be converted that have not been searched for one by one 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 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, then check each bit of the binary sequence one by one from high bit to low bit; wherein the number of bits of the binary sequence from high bit to low bit is proportional to the character length of the corresponding character to be converted or the character length of the phrase to be converted; The step of searching, for each of the target lengths, in the type conversion instance whether there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed comprises: When the target bit of the binary sequence is configured as 1, searching in the phrase mapping dictionary whether there is a target conversion phrase with the same character length as the target bit; If so, the to-be-confirmed characters are used as the to-be-converted characters, and all of the to-be-converted characters are converted into corresponding target conversion phrases to obtain 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, the method includes: If the binary integer value is equal to 1, the step of searching, for each of the target lengths, in the type conversion instance whether there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed comprises: Searching in the character mapping dictionary whether there is a target conversion character corresponding to the character to be confirmed; If so, the to-be-confirmed characters are used as the to-be-converted characters, and all of the to-be-converted characters are converted into corresponding target conversion characters to obtain 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 high bit to low bit comprises: Obtaining a maximum searchable length; the maximum searchable length represents a maximum length of the binary sequence to be queried; the maximum searchable length is less than or equal to the length of the characters that have not been searched in the data to be converted; If the maximum searchable length is greater than 1, checking the target bit of the binary sequence corresponding to the maximum searchable length according to the maximum searchable length; After completing 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 process returns to the step of checking the target position of the binary sequence corresponding to the maximum searchable length according to the maximum searchable length if the maximum searchable length is greater than 1, until the target position of the binary sequence is configured as 1, and the target conversion phrase with the same character length as the target position is found in the phrase mapping dictionary, then the loop ends.
8. A text conversion device, characterized in that: include: A confirmation module, used for confirming a corresponding type conversion instance according to a conversion type of 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, each character bit in a binary sequence corresponding to the 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; if the binary integer value is not empty, confirming a target length in the binary sequence; each target length is used to indicate whether there is a convertible character or a convertible phrase in the corresponding target length of the character to be confirmed; A search module, for searching, for each of the target lengths, whether there is a target conversion character or a target conversion phrase corresponding to the character to be confirmed in the type conversion instance; The conversion module is used to use the to-be-confirmed characters as the to-be-converted characters if they exist, and convert all the to-be-converted characters into corresponding target conversion characters or target conversion phrases to obtain converted text.
9. An electronic device, characterized in that: include: A memory for storing one or more programs; processor; When the one or more programs are executed by the processor, the method according to any one of claims 1 to 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 a processor, the method according to any one of claims 1 to 7 is implemented.
11. A program product, characterized in that When the program product is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Conversion method for converting data files of dictionary into binary files
CN101751380A
Text conversion method and device of application, equipment and storage medium
CN109635251A
Text word segmentation method and device, storage medium and electronic equipment
CN113177410A
Font conversion method, device and equipment and readable storage medium
CN117057311A
Character query method and device, equipment and medium
CN117633312A