A text correction method and apparatus

By using preset string templates and multiple text correction algorithms to correct characters in the text recognition results, calculating the correction cost, and selecting the result with the lowest cost, the problem of excessive time consumption and low accuracy of existing methods is solved, and efficient and accurate text correction is achieved.

CN115984869BActive Publication Date: 2026-07-31JILUO TECH (SHANGHAI) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
JILUO TECH (SHANGHAI) CO LTD
Filing Date
2022-12-27
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

Existing text correction methods are too time-consuming and have low accuracy, making them unsuitable, especially in scenarios where time-consuming recognition is required.

Method used

By using a preset string template and multiple text correction algorithms, each character in the text recognition result is corrected, the correction cost is calculated, and the correction result with the lowest cost is selected as the target result.

Benefits of technology

It speeds up the correction process, improves recognition accuracy, and reduces the number of times the text recognition model needs to re-recognize.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115984869B_ABST
    Figure CN115984869B_ABST
Patent Text Reader

Abstract

This invention provides a text correction method and apparatus, comprising: acquiring a text recognition result, wherein the text recognition result is a string; correcting each character in the string sequentially based on a preset string template and using one or more preset text correction algorithms to obtain one or more correction results corresponding to the characters; obtaining a correction cost corresponding to each character based on the correction results and their corresponding text correction algorithms; and determining a target correction result from all correction results based on the correction cost. This invention can automatically correct erroneous recognition results, accelerate the correction rate, and improve recognition accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of text recognition technology, and in particular to a text correction method and apparatus. Background Technology

[0002] Text correction is an important research direction in the field of natural language processing. This technology enables the detection and correction of errors in text, thereby improving text accuracy. Text correction can be applied to multiple fields, such as correcting errors in handwritten text, correcting errors in text recognized by Automatic Speech Recognition (ASR), and correcting errors in text recognized by Optical Character Recognition (OCR).

[0003] Existing text correction methods all rely on template matching to determine whether the recognition result conforms to the template format. Specifically, this is determined by matching methods such as string length and character type. If multiple template matching attempts fail, the corresponding text recognition model needs to be run multiple times to re-recognize the text. The above text correction process is too time-consuming and is not suitable for scenarios with high recognition time requirements. It also leads to low accuracy of text correction results. Summary of the Invention

[0004] This invention provides a text correction method and apparatus to solve the above-mentioned problems.

[0005] This invention provides a text correction method, comprising:

[0006] Obtain the text recognition result, wherein the text recognition result is a string;

[0007] Based on a preset string template, and using one or more preset text correction algorithms, each character in the string is corrected sequentially to obtain one or more correction results corresponding to the character;

[0008] The correction cost for each character is obtained based on the correction result and its corresponding text correction algorithm, and the target correction result is determined from all correction results based on the correction cost.

[0009] According to a text correction method provided by the present invention, the preset text correction algorithm is one or more of a first correction algorithm, a second correction algorithm, or a third correction algorithm; the preset string template includes data type information corresponding to the template character at each position in the template string;

[0010] Accordingly, the step of correcting each character in the string sequentially using a preset string template and one or more preset text correction algorithms to obtain one or more correction results corresponding to the character includes:

[0011] Based on the data type information corresponding to each template character and the data type information corresponding to the current character, the current character is corrected using the first correction algorithm and / or the second correction algorithm and / or the third correction algorithm to obtain the first correction result and / or the second correction result and / or the third correction result;

[0012] The step of obtaining the correction cost for each character based on the correction result and its corresponding text correction algorithm, and determining the target correction result from all correction results based on the correction cost, includes:

[0013] Based on the historical character correction costs and the algorithm cost values ​​corresponding to the first correction algorithm and / or the second correction algorithm and / or the third correction algorithm, the first correction cost and / or the second correction cost and / or the third correction cost corresponding to the current character are calculated.

[0014] Based on the first correction cost and / or the second correction cost and / or the third correction cost, the correction result with the lowest cost is determined as the target correction result from the first correction result and / or the second correction result and / or the third correction result.

[0015] According to a text correction method provided by the present invention, the first correction algorithm is a character replacement algorithm;

[0016] Accordingly, based on the preset string template, the current character is corrected using the first correction algorithm to obtain the first correction result, including:

[0017] The template character corresponding to the current character is selected from the preset string template and / or similar character template library and used as the current template character;

[0018] The character replacement algorithm is used to replace the current character with the current template character, forming a new string as the first correction result;

[0019] Accordingly, the step of calculating the first correction cost corresponding to the current character based on the historical character correction cost and the algorithm cost value corresponding to the first correction algorithm includes:

[0020] Obtain the replacement algorithm cost value corresponding to the character replacement algorithm;

[0021] Get the historical correction cost between the previous template character and the previous character;

[0022] The cost value of the replacement algorithm and the sum of the historical correction costs between the previous template character and the previous character are calculated, and the calculation result is used as the first correction cost between the current character and the current template character.

[0023] According to a text correction method provided by the present invention, the data type information includes at least a fixed character type;

[0024] Accordingly, selecting the template character corresponding to the current character from the preset string template as the current template character includes:

[0025] If the data type of the current character is different from the data type of the template character in the preset string template, determine whether the data type of the template character is a fixed character type.

[0026] If the data type corresponding to the template character is a fixed character type, the template character of the fixed character type will be used as the current template character.

[0027] According to a text correction method provided by the present invention, the method selects a template character corresponding to the current character from the similar character template library as the current template character, including:

[0028] If the data type corresponding to the template character is not a fixed character type, a similar template character corresponding to the current character is obtained from the similar character template library and used as the current template character.

[0029] According to a text correction method provided by the present invention, the second correction algorithm is a character deletion algorithm;

[0030] Accordingly, based on the preset string template, the current character is corrected using the second correction algorithm to obtain the second correction result, including:

[0031] The current character is deleted using a character deletion algorithm to obtain a new string as the second correction result;

[0032] Accordingly, the step of calculating the second correction cost corresponding to the current character based on the historical character correction cost and the algorithm cost value corresponding to the second correction algorithm includes:

[0033] Obtain the deletion algorithm cost value corresponding to the character deletion algorithm;

[0034] Get the historical correction cost between the previous character and the current template character;

[0035] The deletion algorithm cost value is calculated as the sum of the historical correction costs between the previous character and the current template character, and the calculation result is used as the second correction cost between the current character and the current template character.

[0036] According to a text correction method provided by the present invention, the second correction algorithm is a character insertion algorithm;

[0037] Accordingly, based on the preset string template, the current character is corrected using a third correction algorithm to obtain the third correction result, including:

[0038] The current template character is inserted before the current character using a character insertion algorithm to obtain a new string as the third correction result;

[0039] Accordingly, the step of calculating the third correction cost corresponding to the current character based on the historical character correction cost and the algorithm cost value corresponding to the third correction algorithm includes:

[0040] Obtain the insertion algorithm cost value corresponding to the character insertion algorithm;

[0041] Get the historical correction cost between the current character and the previous template character;

[0042] The insertion algorithm cost value is calculated as the sum of the historical correction costs between the current character and the previous template character, and the calculation result is used as the third correction cost between the current character and the current template character.

[0043] According to a text correction method provided by the present invention, the replacement algorithm cost value includes a first replacement algorithm cost value and a second replacement algorithm cost value;

[0044] If the data type corresponding to the current character is the same as that corresponding to the current template character, the algorithm cost value is determined to be the first replacement algorithm cost value;

[0045] If the data type corresponding to the current character is different from that of the current template character, the algorithm cost value is determined to be the second replacement algorithm cost value.

[0046] According to a text correction method provided by the present invention, the data type information further includes numeric type and alphabetic type.

[0047] The present invention also provides a text correction device, comprising:

[0048] The recognition result acquisition module is used to acquire text recognition results, wherein the text recognition results are strings.

[0049] The correction module is used to correct each character in the string sequentially based on a preset string template and using one or more preset text correction algorithms to obtain one or more correction results corresponding to the character.

[0050] The target correction determination module is used to obtain the correction cost corresponding to each character based on the correction result and its corresponding text correction algorithm, and to determine the target correction result from all correction results based on the correction cost.

[0051] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement any of the text correction methods described above.

[0052] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the text correction methods described above.

[0053] The text correction method and apparatus provided by the present invention correct each character in the string sequentially using one or more preset text correction algorithms based on a preset string template to obtain one or more correction results corresponding to the character; the correction cost corresponding to each character is obtained according to the correction result and its corresponding text correction algorithm; and the target correction result is determined from all correction results based on the correction cost, thereby automatically correcting erroneous recognition results, speeding up correction efficiency, and improving recognition accuracy. Attached Figure Description

[0054] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0055] Figure 1 This is one of the flowcharts illustrating the text correction method provided in this embodiment of the invention;

[0056] Figure 2 This is a second flowchart illustrating the text correction method provided in this embodiment of the invention;

[0057] Figure 3 This is a schematic diagram of the text correction device structure provided in an embodiment of the present invention;

[0058] Figure 4 This is a schematic diagram of the physical structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0059] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.

[0060] The text correction method and apparatus proposed in this invention will be described below with reference to the accompanying drawings.

[0061] Figure 1 This is one of the flowcharts illustrating the text correction method provided in this embodiment of the invention; Figure 2 This is a second flowchart illustrating the text correction method provided in this embodiment of the invention; as shown below. Figure 1 as well as Figure 2 As shown, the text correction method includes:

[0062] S101, Obtain the text recognition result, wherein the text recognition result is a string.

[0063] In this step, the text recognition result can be obtained by recognizing handwritten text using a neural network model, or by recognizing text through automatic speech recognition technology, or by recognizing text through optical character recognition technology. This invention does not limit the method of obtaining the text recognition result.

[0064] S102, based on a preset string template, and using one or more preset text correction algorithms, each character in the string is corrected sequentially to obtain one or more correction results corresponding to the character.

[0065] The preset string template includes the length information of the template string and the data type information corresponding to the template character at each position in the template string. The data type information includes numeric type, alphanumeric type, numeric or alphanumeric type, and fixed character type. The numeric type, alphanumeric type, and fixed character type mentioned above refer to the data type corresponding to the template character at a certain position being a single numeric, alphanumeric, or fixed character. The numeric or alphanumeric type refers to the data type corresponding to the template character at a certain position being either numeric or alphanumeric, meaning the data type is not unique.

[0066] The aforementioned preset string templates are designed based on the requirements corresponding to the text recognition results. For example, if the text recognition result is an ID card number, the preset string template format is "number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number / letter", and the length of this string template is 18. If the text recognition result is a fixed asset number, the fixed asset number consists of numbers and letters, such as Company A 0001. Here, the fixed character "Company A" is the company code (which can be text, letters, numbers, etc.), and 0001 corresponds to the code of a certain fixed asset. Correspondingly, the length of the string template is 5, the first character in the string template is a fixed character, and the data type of the last four characters is numbers.

[0067] Different correction algorithms are used to correct the same character, resulting in different correction results. Taking the string template "fixed letter A + number + number + number" as an example, assuming the text recognition result is 1A412, the data type at each position in the text recognition result does not completely correspond to the data type in the string template. Correction begins with the first character "1" in "1A412". First, the first character "1" is a number, while the first character in the string template is the fixed character "A". If a replacement algorithm is used for "1", it is replaced with "A", resulting in "AA412". If a deletion algorithm is used, "1" is deleted, resulting in "A412". If an insertion algorithm is used, the fixed character "A" is inserted before the first character "1", resulting in "A1A412". The correction cost for each correction result is calculated based on the algorithm cost values ​​corresponding to different correction algorithms and the historical character correction costs.

[0068] After comparing and correcting the data type of the first character in the text recognition result with the character at the first position in the string template, the data type of the first character in the text recognition result is compared and corrected with the character at the second position in the string template. This process is repeated until the corrected result of the entire text recognition result and the entire string template is obtained. Based on the corresponding correction cost, the target correction result is determined from all the correction results.

[0069] It should be noted that the new character obtained after each character correction, combined with the other characters in the original string, forms a new string, which is the correction result. After correcting the last character in the string and determining the target correction result, this target correction result is the final output corrected text.

[0070] In addition, if the data type of the characters in the text recognition result is the same as the data type of the template characters in the string template, no correction is performed on the characters; if the data types are different, different correction algorithms are used and the characters in the text recognition result are corrected according to each template character in the string template.

[0071] S103, obtain the correction cost corresponding to each character based on the correction result and its corresponding text correction algorithm, and determine the target correction result from all correction results based on the correction cost.

[0072] In this step, the correction cost is determined based on the character's position information and the text correction algorithm, including the historical correction cost and the incremental correction cost. The specific calculation of the correction cost is described in detail below.

[0073] After obtaining all correction costs, the correction result with the minimum correction cost is taken as the target correction result. The correction result with the minimum correction cost is the result that corrects the predicted text recognition result to the result that conforms to the template format with minimal changes, and its corresponding correction accuracy is also the highest.

[0074] Furthermore, existing correction methods all rely on template matching. If a mismatch occurs, the text recognition model re-identifies the text and outputs a prediction result. Our method, however, corrects most text recognition results through deletion, insertion, and replacement. Only for the small number of uncorrectable text recognition results is the text recognition model re-identified, thus improving the efficiency of text recognition result correction.

[0075] The string template only specifies the data type corresponding to each template character. Except for the fixed character which is a certain character, the data types of other characters are uncertain. Taking the above string template as "fixed letter A + number + number + number" as an example, if the recognition result is A41, A444, etc., which can match the data type of the string template, then it cannot be corrected at this time, that is, the template does not match, and the text recognition model needs to re-recognize.

[0076] The text correction method provided in this invention corrects each character in a string sequentially using one or more preset text correction algorithms based on a preset string template, thereby obtaining one or more correction results corresponding to the character. The correction cost for each character is obtained based on the correction result and its corresponding text correction algorithm. A target correction result is then determined from all correction results based on the correction cost, thus automatically correcting erroneous recognition results, accelerating correction efficiency, and improving recognition accuracy.

[0077] In some embodiments of the present invention, the preset text correction algorithm is one or more of a first correction algorithm, a second correction algorithm, or a third correction algorithm.

[0078] The preset string template includes data type information corresponding to the template character at each position in the template string.

[0079] Accordingly, the step of correcting each character in the string sequentially using a preset string template and one or more preset text correction algorithms to obtain one or more correction results corresponding to the character includes:

[0080] Based on the data type information corresponding to each template character and the data type information corresponding to the current character, the current character is corrected using a first correction algorithm and / or a second correction algorithm and / or a third correction algorithm to obtain a first correction result and / or a second correction result and / or a third correction result. That is, when the data type of the current character is different from that of the template character, a conventional character correction algorithm (e.g., replacement, deletion, insertion, etc.) is used to correct the current character in string R (the current character is the character at the i-th position in the text recognition result R), thereby obtaining a correction result corresponding to the correction algorithm.

[0081] The step of obtaining the correction cost for each character based on the correction result and its corresponding text correction algorithm, and determining the target correction result from all correction results based on the correction cost, includes:

[0082] Based on the historical character correction costs and the algorithm cost values ​​corresponding to the first correction algorithm and / or the second correction algorithm and / or the third correction algorithm, the first correction cost and / or the second correction cost and / or the third correction cost corresponding to the current character are calculated.

[0083] Specifically, different text correction algorithms have different methods for calculating correction costs. For example, in the case of replacement, since it is to replace "the i-th character in R" with "the j-th character in M", it is necessary to obtain C[i-1][j-1]; while deletion only involves the i-th character in R, so it is only necessary to obtain C[i-1][j].

[0084] Based on the first correction cost and / or the second correction cost and / or the third correction cost, the correction result with the lowest cost is determined as the target correction result from the first correction result and / or the second correction result and / or the third correction result.

[0085] When multiple correction results are obtained, the correction result with the lowest correction cost is taken as the target correction result. When there is only one correction result, that correction result is directly taken as the target correction result.

[0086] In some embodiments of the present invention, the first correction algorithm is a character replacement algorithm.

[0087] Accordingly, based on the preset string template, the current character is corrected using the first correction algorithm to obtain the first correction result, including:

[0088] The template character corresponding to the current character is selected from the preset string template and / or similar character template library and used as the current template character.

[0089] The character replacement algorithm is used to replace the current character with the current template character, forming a new string as the first correction result. For example, if the recognition result is AA12, then A is replaced with the adjacent digit character 4, and the correction result is A412. If the recognition result is 1412, then the first character 1 is replaced with the fixed letter A, and the correction result is A412.

[0090] Accordingly, the step of calculating the first correction cost corresponding to the current character based on the historical character correction cost and the algorithm cost value corresponding to the first correction algorithm includes:

[0091] Obtain the replacement algorithm cost value corresponding to the character replacement algorithm.

[0092] The replacement algorithm cost value includes a first replacement algorithm cost value and a second replacement algorithm cost value;

[0093] If the data types corresponding to the current character and the current template character are the same, the algorithm cost value is determined to be the first replacement algorithm cost value.

[0094] If the data type corresponding to the current character is different from that of the current template character, the algorithm cost value is determined to be the second replacement algorithm cost value.

[0095] Get the historical correction cost between the previous template character and the previous character.

[0096] The cost value of the replacement algorithm is calculated as the sum of the historical correction costs between the previous template character and the previous character, and the calculation result is used as the first correction cost between the current character and the current template character.

[0097] Specifically, the i-th character in string R is replaced with the j-th template character in string template M.

[0098] Assuming the cost value of the character replacement algorithm is either 0 or 1, the cost value is 0 when the data type of the i-th character in string R is the same as that of the j-th template character in string template M; otherwise, the cost value is 1.

[0099] After determining the cost value of the replacement algorithm, the historical correction cost C[i-1][j-1] between the previous template character and the previous character is obtained. Then, the first correction cost C1[i][j] between the current character and the current template character is C[i-1][j-1] + const, where const is the cost value of the replacement algorithm, and its value is determined according to the data types of the current character and the current template character.

[0100] Furthermore, based on the above embodiments, the present invention proposes two replacement methods. The first method is to replace according to a string template.

[0101] Specifically, the data type information includes at least a fixed character type, that is, a fixed character exists in the string template.

[0102] Accordingly, selecting the template character corresponding to the current character from the preset string template as the current template character includes:

[0103] If the data type of the current character is different from the data type of the template character in the preset string template, determine whether the data type of the template character is a fixed character type.

[0104] In other words, the data type of the i-th character in the text recognition result R is compared with the j-th template character in the string template M. If the data types are the same, the j-th template character is ignored, and the data type of the i-th character is compared with the (j+1)-th template character. If the data types of the i-th character and the j-th template character are different, it is further determined whether the data type of the j-th template character is a fixed character type.

[0105] When the data type corresponding to the template character is a fixed character type, the template character of the fixed character type is used as the current template character. That is, when the j-th template character is a fixed character, the j-th template character is used as the current template character and replaced with the i-th character to obtain the corresponding correction result.

[0106] The second method involves replacing characters based on a pre-defined library of similar character templates. This library is built according to actual needs and includes characters that are similar in form, such as the number 0 and the letter O, the number 4 and the letter A, etc., which are character pairs with different data types but similar in form.

[0107] Specifically, selecting the template character corresponding to the current character from the similar character template library as the current template character includes:

[0108] If the data type corresponding to the template character is not a fixed character type, a similar template character corresponding to the current character is obtained from the similar character template library and used as the current template character. For example, if the data type of the i-th character is the letter O and the data type of the j-th character is a number, and the two are different, then the number 0 corresponding to the letter O is obtained from the similar character template library, thereby completing the replacement.

[0109] The text correction method provided in this invention improves the accuracy of the correction results through various replacement methods.

[0110] In some embodiments of the present invention, the second correction algorithm is a character deletion algorithm.

[0111] Accordingly, based on the preset string template, the current character is corrected using the second correction algorithm to obtain the second correction result, including:

[0112] The current character is deleted using a character deletion algorithm to obtain a new string as the second correction result.

[0113] Accordingly, the step of calculating the second correction cost corresponding to the current character based on the historical character correction cost and the algorithm cost value corresponding to the second correction algorithm includes:

[0114] Obtain the deletion algorithm cost value corresponding to the character deletion algorithm.

[0115] Get the historical correction cost between the previous character and the current template character.

[0116] The deletion algorithm cost is calculated as the sum of the historical correction costs between the previous character and the current template character, and the result is used as the second correction cost between the current character and the current template character.

[0117] Specifically, deleting the i-th character in string R has a deletion algorithm cost of 1.

[0118] Get the historical correction cost C[i-1][j] between the previous character and the current template character, and calculate the second correction cost C2[i][j] = C[i-1][j] + 1 between the current character and the current template character.

[0119] In some embodiments of the present invention, the second correction algorithm is a character insertion algorithm.

[0120] Accordingly, based on the preset string template, the current character is corrected using a third correction algorithm to obtain the third correction result, including:

[0121] A character insertion algorithm is used to insert the current template character before the current character to obtain a new string as the third correction result. For example, if the text recognition result is 412, then the fixed letter A is inserted before the first character 4, and the correction result is A412.

[0122] Accordingly, the step of calculating the third correction cost corresponding to the current character based on the historical character correction cost and the algorithm cost value corresponding to the third correction algorithm includes:

[0123] Obtain the insertion algorithm cost value corresponding to the character insertion algorithm.

[0124] Get the historical correction cost between the current character and the previous template character.

[0125] The insertion algorithm cost is calculated as the sum of the historical correction cost between the current character and the previous template character, and the result is used as the third correction cost between the current character and the current template character.

[0126] Specifically, the j-th template character in the string template M is inserted before the i-th character in the string R, and the cost of the corresponding insertion algorithm is 1.

[0127] Get the historical correction cost C[i][j-1] between the current character and the previous template character, and calculate the third correction cost C3[i][j] = C[i][j-1] + 1 between the current character and the current template character.

[0128] In some embodiments of the present invention, the text correction method includes the following steps:

[0129] Get the length of the string len(R) and the length of the string template len(M). Calculate the correction cost C[i][j] between the current character (i.e., the i-th character in R) and the current template character (i.e., the j-th template character in M) based on the correction method and historical correction costs:

[0130]

[0131] In the above formula, C[i-1][j-1]+const is the correction cost for replacement, C[i-1][j]+1 is the correction cost for deletion, and C[i][j-1]+1 is the correction cost for insertion. The minimum value is selected as C[i][j], and the corresponding correction result S[i][j] is recorded based on C[i][j]. The above cost calculation and correction result determination process is repeated until C[len(R)-1][len(M)-1] to achieve the correction between the entire text recognition result and the entire string template. The result of each correction is recorded, and the minimum cost is determined as the final correction result based on the cost of the correction result.

[0132] The text correction device provided by the present invention is described below. The text correction device described below can be referred to in correspondence with the text correction method described above.

[0133] Figure 3 This is a schematic diagram of the text correction device provided in an embodiment of the present invention, as shown below. Figure 3 As shown, the text correction device includes a recognition result acquisition module 301, a correction module 302, and a target correction determination module 303.

[0134] The recognition result acquisition module 301 is used to acquire the text recognition result, wherein the text recognition result is a string.

[0135] In this module, the text recognition result can be obtained by recognizing handwritten text using a neural network model, or by recognizing text through automatic speech recognition technology, or by recognizing text through optical character recognition technology. This invention does not limit the method of obtaining the text recognition result.

[0136] The correction module 302 is used to correct each character in the string sequentially based on a preset string template and using one or more preset text correction algorithms to obtain one or more correction results corresponding to the character.

[0137] The preset string template includes the length information of the template string and the data type information corresponding to the template character at each position in the template string. The data type information includes numeric type, alphanumeric type, numeric or alphanumeric type, and fixed character type. The numeric type, alphanumeric type, and fixed character type mentioned above refer to the data type corresponding to the template character at a certain position being a single numeric, alphanumeric, or fixed character. The numeric or alphanumeric type refers to the data type corresponding to the template character at a certain position being either numeric or alphanumeric, meaning the data type is not unique.

[0138] The aforementioned preset string templates are designed based on the requirements corresponding to the text recognition results. For example, if the text recognition result is an ID card number, the preset string template format is "number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number + number / letter", and the length of this string template is 18. If the text recognition result is a fixed asset number, the fixed asset number consists of numbers and letters, such as Company A 0001. Here, the fixed character "Company A" is the company code (which can be text, letters, numbers, etc.), and 0001 corresponds to the code of a certain fixed asset. Correspondingly, the length of the string template is 5, the first character in the string template is a fixed character, and the data type of the last four characters is numbers.

[0139] Different correction algorithms are used to correct the same character, resulting in different correction results. Taking the string template "fixed letter A + number + number + number" as an example, assuming the text recognition result is 1A412, the data type at each position in the text recognition result does not completely correspond to the data type in the string template. Correction begins with the first character "1" in "1A412". First, the first character "1" is a number, while the first character in the string template is the fixed character "A". If a replacement algorithm is used for "1", it is replaced with "A", resulting in "AA412". If a deletion algorithm is used, "1" is deleted, resulting in "A412". If an insertion algorithm is used, the fixed character "A" is inserted before the first character "1", resulting in "A1A412". The correction cost for each correction result is calculated based on the algorithm cost values ​​corresponding to different correction algorithms and the historical character correction costs.

[0140] After comparing and correcting the data type of the first character in the text recognition result with the character at the first position in the string template, the data type of the first character in the text recognition result is compared and corrected with the character at the second position in the string template. This process is repeated until the corrected result of the entire text recognition result and the entire string template is obtained. Based on the corresponding correction cost, the target correction result is determined from all the correction results.

[0141] It should be noted that the new character obtained after each character correction, combined with the other characters in the original string, forms a new string, which is the correction result. After correcting the last character in the string and determining the target correction result, this target correction result is the final output corrected text.

[0142] In addition, if the data type of the characters in the text recognition result is the same as the data type of the template characters in the string template, no correction is performed on the characters; if the data types are different, different correction algorithms are used and the characters in the text recognition result are corrected according to each template character in the string template.

[0143] The target correction determination module 303 is used to obtain the correction cost corresponding to each character based on the correction result and its corresponding text correction algorithm, and to determine the target correction result from all correction results based on the correction cost.

[0144] In this module, the correction cost is determined based on the character's position information and the text correction algorithm, including the historical correction cost and the incremental correction cost. The specific calculation of the correction cost is described in detail below.

[0145] After obtaining all correction costs, the correction result with the minimum correction cost is taken as the target correction result. The correction result with the minimum correction cost is the result that corrects the predicted text recognition result to the result that conforms to the template format with minimal changes, and its corresponding correction accuracy is also the highest.

[0146] Furthermore, existing correction methods all rely on template matching. If a mismatch occurs, the text recognition model re-identifies the text and outputs a prediction result. Our method, however, corrects most text recognition results through deletion, insertion, and replacement. Only for the small number of uncorrectable text recognition results is the text recognition model re-identified, thus improving the efficiency of text recognition result correction.

[0147] The string template only specifies the data type corresponding to each template character. Except for the fixed character which is a certain character, the data types of other characters are uncertain. Taking the above string template as "fixed letter A + number + number + number" as an example, if the recognition result is A41, A444, etc., which can match the data type of the string template, then it cannot be corrected at this time, that is, the template does not match, and the text recognition model needs to re-recognize.

[0148] The text correction device provided in this embodiment of the invention corrects each character in the string sequentially using one or more preset text correction algorithms based on a preset string template, thereby obtaining one or more correction results corresponding to the character; the correction cost corresponding to each character is obtained according to the correction result and its corresponding text correction algorithm; and the target correction result is determined from all correction results based on the correction cost, thereby automatically correcting erroneous recognition results, accelerating correction efficiency, and improving recognition accuracy.

[0149] Figure 4 This is a schematic diagram of the physical structure of an electronic device provided in an embodiment of the present invention, such as... Figure 4 As shown, the electronic device may include a processor 410, a communications interface 420, a memory 430, and a communication bus 440, wherein the processor 410, the communications interface 420, and the memory 430 communicate with each other via the communication bus 440. The processor 410 can call logical instructions in the memory 430 to execute a text correction method, which includes: acquiring a text recognition result, the text recognition result being a string; correcting each character in the string sequentially based on a preset string template and using one or more preset text correction algorithms to obtain one or more correction results corresponding to the character; obtaining the correction cost corresponding to each character based on the correction result and its corresponding text correction algorithm; and determining a target correction result from all correction results based on the correction cost.

[0150] Furthermore, the logical instructions in the aforementioned memory 430 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0151] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements a text correction method, the text correction method comprising: acquiring a text recognition result, the text recognition result being a string; correcting each character in the string sequentially based on a preset string template and using one or more preset text correction algorithms to obtain one or more correction results corresponding to the character; obtaining a correction cost corresponding to each character based on the correction result and its corresponding text correction algorithm; and determining a target correction result from all correction results based on the correction cost.

[0152] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0153] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of various embodiments or some parts of embodiments.

[0154] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A text correction method characterized by, include: Obtain the text recognition result, wherein the text recognition result is a string; Based on a preset string template, and using one or more preset text correction algorithms, each character in the string is corrected sequentially to obtain one or more correction results corresponding to the character; Based on the correction result and its corresponding text correction algorithm, the correction cost corresponding to each character is obtained, and the target correction result is determined from all correction results based on the correction cost. The preset text correction algorithm is one or more of the first correction algorithm, the second correction algorithm, or the third correction algorithm; the preset string template includes data type information corresponding to the template character at each position in the template string; Accordingly, the step of correcting each character in the string sequentially using a preset string template and one or more preset text correction algorithms to obtain one or more correction results corresponding to the character includes: Based on the data type information corresponding to the template character at each position and the data type information corresponding to the current character, the current character is corrected using the first correction algorithm and / or the second correction algorithm and / or the third correction algorithm to obtain the first correction result and / or the second correction result and / or the third correction result; The step of obtaining the correction cost for each character based on the correction result and its corresponding text correction algorithm, and determining the target correction result from all correction results based on the correction cost, includes: Based on the historical character correction costs and the algorithm cost values ​​corresponding to the first correction algorithm and / or the second correction algorithm and / or the third correction algorithm, the first correction cost and / or the second correction cost and / or the third correction cost corresponding to the current character are calculated. Based on the first correction cost and / or the second correction cost and / or the third correction cost, the correction result with the lowest cost is determined as the target correction result from the first correction result and / or the second correction result and / or the third correction result.

2. The text correction method according to claim 1, characterized in that, The first correction algorithm is a character replacement algorithm; Accordingly, based on the preset string template, the current character is corrected using the first correction algorithm to obtain the first correction result, including: The template character corresponding to the current character is selected from the preset string template and / or similar character template library and used as the current template character; The character replacement algorithm is used to replace the current character with the current template character, forming a new string as the first correction result; Accordingly, the step of calculating the first correction cost corresponding to the current character based on the historical character correction cost and the algorithm cost value corresponding to the first correction algorithm includes: Obtain the replacement algorithm cost value corresponding to the character replacement algorithm; Get the historical correction cost between the previous template character and the previous character; The cost value of the replacement algorithm and the sum of the historical correction costs between the previous template character and the previous character are calculated, and the calculation result is used as the first correction cost between the current character and the current template character.

3. The text correction method according to claim 2, characterized in that, The data type information includes at least a fixed character type; Accordingly, selecting the template character corresponding to the current character from the preset string template as the current template character includes: If the data type of the current character is different from the data type of the template character in the preset string template, determine whether the data type of the template character is a fixed character type. If the data type corresponding to the template character is a fixed character type, the template character of the fixed character type will be used as the current template character.

4. The text correction method according to claim 3, characterized in that, The template character corresponding to the current character is selected from the similar character template library and used as the current template character, including: If the data type corresponding to the template character is not a fixed character type, a similar template character corresponding to the current character is obtained from the similar character template library and used as the current template character.

5. The text correction method according to claim 1, characterized in that, The second correction algorithm is a character deletion algorithm; Accordingly, based on the preset string template, the current character is corrected using the second correction algorithm to obtain the second correction result, including: The current character is deleted using a character deletion algorithm to obtain a new string as the second correction result; Accordingly, the step of calculating the second correction cost corresponding to the current character based on the historical character correction cost and the algorithm cost value corresponding to the second correction algorithm includes: Obtain the deletion algorithm cost value corresponding to the character deletion algorithm; Get the historical correction cost between the previous character and the current template character; The deletion algorithm cost value is calculated as the sum of the historical correction costs between the previous character and the current template character, and the calculation result is used as the second correction cost between the current character and the current template character.

6. The text correction method according to claim 1, characterized in that, The second correction algorithm is a character insertion algorithm; Accordingly, based on the preset string template, the current character is corrected using a third correction algorithm to obtain the third correction result, including: The current template character is inserted before the current character using a character insertion algorithm to obtain a new string as the third correction result; Accordingly, the step of calculating the third correction cost corresponding to the current character based on the historical character correction cost and the algorithm cost value corresponding to the third correction algorithm includes: Obtain the insertion algorithm cost value corresponding to the character insertion algorithm; Get the historical correction cost between the current character and the previous template character; The insertion algorithm cost value is calculated as the sum of the historical correction costs between the current character and the previous template character, and the calculation result is used as the third correction cost between the current character and the current template character.

7. The text correction method according to claim 2, characterized in that, The replacement algorithm cost value includes the first replacement algorithm cost value and the second replacement algorithm cost value; If the data type corresponding to the current character is the same as that corresponding to the current template character, the algorithm cost value is determined to be the first replacement algorithm cost value; If the data type corresponding to the current character is different from that of the current template character, the algorithm cost value is determined to be the second replacement algorithm cost value.

8. The text correction method according to any one of claims 1-5, characterized in that, The data type information also includes numeric and alphabetic types.

9. A text correction device, characterized in that, include: The recognition result acquisition module is used to acquire text recognition results, wherein the text recognition results are strings. The correction module is used to correct each character in the string sequentially based on a preset string template and using one or more preset text correction algorithms to obtain one or more correction results corresponding to the character. The target correction determination module is used to obtain the correction cost corresponding to each character based on the correction result and its corresponding text correction algorithm, and to determine the target correction result from all correction results based on the correction cost. The preset text correction algorithm is one or more of the first correction algorithm, the second correction algorithm, or the third correction algorithm; the preset string template includes data type information corresponding to the template character at each position in the template string; Accordingly, the correction module is specifically used for: Based on the data type information corresponding to the template character at each position and the data type information corresponding to the current character, the current character is corrected using the first correction algorithm and / or the second correction algorithm and / or the third correction algorithm to obtain the first correction result and / or the second correction result and / or the third correction result; The target correction and determination module is specifically used for: Based on the historical character correction costs and the algorithm cost values ​​corresponding to the first correction algorithm and / or the second correction algorithm and / or the third correction algorithm, the first correction cost and / or the second correction cost and / or the third correction cost corresponding to the current character are calculated. Based on the first correction cost and / or the second correction cost and / or the third correction cost, the correction result with the lowest cost is determined as the target correction result from the first correction result and / or the second correction result and / or the third correction result.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the text correction method as described in any one of claims 1 to 8.

11. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the text correction method as described in any one of claims 1 to 8.