Text fuzzy matching method, apparatus, electronic device and readable storage medium
By calculating the modification cost and edit distance variants of the matching template and the text to be matched, the text matching problem caused by errors in speech recognition and optical character recognition is solved, achieving higher robustness and accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- UBTECH ROBOTICS CORP LTD
- Filing Date
- 2023-02-28
- Publication Date
- 2026-05-26
Smart Images

Figure CN116450896B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and particularly to a text fuzzy matching method, apparatus, electronic device, and readable storage medium. Background Art
[0002] In existing text processing systems, matching remains a stable and effective recognition method. The strictest matching method is exact matching, which requires that the character order and glyphs of the two to be matched are exactly the same, and there should be no other interfering characters during the sequence process. Fuzzy matching is based on certain assumptions or prerequisite conditions and allows for a certain degree of error during the matching process, not necessarily requiring exact consistency. Matching operations can generally be divided into two types according to the relationship to be matched: one is keyword matching, whose characteristic is that one of the matching objects is included in the other object. The other is full-sentence matching, which often uses similarity as the basis for judging the degree of matching. When the similarity is 1, that is, when the two texts are exactly the same, it is exact matching. Its characteristic is that the matching relationship has reflexivity. Different from similarity discrimination, the source of the text used for comparison in full-sentence matching is reliable and controllable.
[0003] In existing keyword matching methods, most are based on the assumption of string similarity. For example, for the string "c%a%b%cda" and the content to be matched "abc", under the condition of exact matching, the corresponding content cannot be matched. However, when "%" is regarded as an interfering character and a certain degree of interference is allowed between the content to be matched, the corresponding result can be fuzzy-matched. In addition, there are also fuzzy matching methods for missing content to be matched. That is, when the string is "Mik has gone.", and the content to be matched is "Mike", it is easy to know that the difference between "Mik" and "Mike" is only one 'e', and fuzzy matching can be performed according to the rules. Existing rules can better handle the error of more or fewer characters caused by human input errors. However, they are not effective in dealing with errors brought by existing speech recognition and optical character recognition technologies.
[0004] For speech recognition, there may be misrecognition due to inaccurate pronunciation. For example, the misrecognition of "that’s" and "thus" due to liaison in English, the similar pronunciations of "老虎" and "老夫" in Chinese, or, due to the untimely update of the speech recognition vocabulary, such as "新冠" being recognized as "新官", etc. In optical character recognition technology, there are misrecognitions of similar characters such as "兔" and "免". When these words are used as the content to be matched, it is difficult to determine the misrecognized results only by the similarity of the strings.
[0005] Existing full-sentence matching techniques often rely on character intersection-union sets and deep learning models. However, they perform poorly when misidentified characters occur. This is because similar characters in the character intersection-union set are treated as completely different entities, and the meanings of similar characters in deep learning models may be entirely different, leading to incorrect information extraction and affecting the final result. In summary, existing text matching techniques suffer from relatively large pre-system errors. Summary of the Invention
[0006] To address the aforementioned technical problems, this application provides a text fuzzy matching method, apparatus, electronic device, and readable storage medium.
[0007] Firstly, this application provides a text fuzzy matching method, the method comprising:
[0008] The initial matching score is obtained based on the modification cost of each character in the matching template and each character in the text to be matched.
[0009] The final matching score between the subsequence of the matching template and the subsequence of the text to be matched is obtained based on the initial matching score, insertion cost, and deletion cost.
[0010] The highest matching score is determined from multiple final matching scores, and the average score per character is determined based on the number of characters in the matching template and the highest matching score.
[0011] If the average score of a single character is greater than the preset matching threshold, then the matching path is determined according to the matching template;
[0012] Edit the text to be matched according to the matching path to obtain the modified text;
[0013] The modified text is matched with the matching template.
[0014] In one embodiment, obtaining the corresponding initial matching score based on the modification cost of each character in the matching template and each character in the text to be matched includes:
[0015] If the modification cost is greater than the preset cost threshold, the initial matching score is set to 0.
[0016] If the modification cost is less than or equal to a preset cost threshold, then the modification cost is used as the initial matching score.
[0017] In one embodiment, obtaining the final matching score between the subsequence of the matching template and the subsequence of the text to be matched based on the initial matching score, insertion cost, and deletion cost includes:
[0018] Iterate through each of the initial matching scores and determine the first adjacent initial matching score, the second adjacent initial matching score, and the third adjacent initial matching score of the current initial matching score;
[0019] Based on the sum of the first adjacent initial matching score and the current initial matching score, calculate the first difference between the second adjacent initial matching score and the insertion cost, and the second difference between the third adjacent initial matching score and the deletion cost;
[0020] The maximum value among the sum, the first difference, and the second difference is determined as the final matching score.
[0021] In one embodiment, the step of calculating the sum based on the first adjacent initial match score and the current initial match score includes:
[0022] When the first adjacent initial matching score is not 0, the sum is calculated based on the first adjacent initial matching score, the current initial matching score, and the preset compensation score.
[0023] In one embodiment, the method further includes:
[0024] If the current initial matching score has no first adjacent initial matching score, second adjacent initial matching score, and third adjacent initial matching score, then set the first adjacent initial matching score, second adjacent initial matching score, and third adjacent initial matching score of the current initial matching score to 0.
[0025] In one embodiment, obtaining the modification cost of each character in the matching template and each character in the text to be matched includes:
[0026] If the source of error is image recognition error, then the similarity of a single character is determined based on the character shape-related features, and the similarity of the single character is used as the modification cost;
[0027] If the source of the error is speech recognition error, then phoneme similarity is used as the modification cost.
[0028] In one embodiment, editing the text to be matched according to the matching path to obtain modified text includes:
[0029] The modification operation and the matching substring are determined based on the matching path;
[0030] The modified text is obtained by editing the text to be matched according to the modification operation and the matched substring.
[0031] Secondly, this application provides a text fuzzy matching apparatus, the apparatus comprising:
[0032] The first acquisition module is used to obtain the corresponding initial matching score based on the modification cost of each character in the matching template and each character in the text to be matched;
[0033] The second acquisition module is used to obtain the final matching score between the subsequence of the matching template and the subsequence of the text to be matched based on the initial matching score, insertion cost, and deletion cost.
[0034] The first determining module is used to determine the highest matching score from multiple final matching scores, and to determine the average score per character based on the number of characters in the matching template and the highest matching score.
[0035] The second determining module is used to determine the matching path based on the matching template if the average score of the single character is greater than the preset matching threshold.
[0036] The editing module is used to edit the text to be matched according to the matching path to obtain the modified text;
[0037] The matching module is used to match the modified text with the matching template.
[0038] Thirdly, this application provides an electronic device, including a memory and a processor, wherein the memory is used to store a computer program, and the computer program executes the text fuzzy matching method provided in the first aspect when the processor is running.
[0039] Fourthly, this application provides a computer-readable storage medium storing a computer program that, when run on a processor, executes the text fuzzy matching method provided in the first aspect.
[0040] The text fuzzy matching method, apparatus, electronic device, and readable storage medium provided in this application obtain corresponding initial matching scores based on the modification costs of each character in the matching template and each character in the text to be matched; obtain final matching scores between subsequences of the matching template and subsequences of the text to be matched based on the initial matching scores, insertion costs, and deletion costs; determine the highest matching score from multiple final matching scores; determine the average score per character based on the number of characters in the matching template and the highest matching score; if the average score per character is greater than a preset matching threshold, determine a matching path based on the matching template; edit the text to be matched according to the matching path to obtain modified text; and perform matching processing between the modified text and the matching template. This approach has higher tolerance for pre-system errors, is less prone to missed recognition, and is less likely to be affected by pre-system errors in text matching, thus providing higher robustness for both local and overall systems. Attached Figure Description
[0041] To more clearly illustrate the technical solutions of this application, the accompanying drawings used in the embodiments will be briefly described below. It should be understood that the following drawings only show some embodiments of this application and should not be considered as a limitation on the scope of protection of this application. In the various drawings, similar components are numbered similarly.
[0042] Figure 1 A flowchart of the text fuzzy matching method provided in this application is shown;
[0043] Figure 2 A flowchart of the text fuzzy matching method provided in this application is shown;
[0044] Figure 3 A flowchart of the text fuzzy matching method provided in this application is shown;
[0045] Figure 4 A schematic diagram of the text fuzzy matching device provided in this application is shown.
[0046] Main icons: 400 - Text fuzzy matching device, 401 - First acquisition module, 402 - Second acquisition module, 403 - First determination module, 404 - Second determination module, 405 - Editing module, 406 - Matching module. Detailed Implementation
[0047] The technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.
[0048] The components of this application, typically described and illustrated in the accompanying drawings, can be arranged and designed in a variety of different configurations. Therefore, the following detailed description of embodiments of this application provided in the drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0049] In the following, the terms “comprising,” “having,” and their cognates, which may be used in various embodiments of this application, are intended only to indicate a particular feature, number, step, operation, element, component, or combination thereof, and should not be construed as excluding, firstly, the presence of one or more other features, numbers, steps, operations, elements, components, or combinations thereof, or adding the possibility of one or more features, numbers, steps, operations, elements, components, or combinations thereof.
[0050] In addition, terms such as "first", "second", "third", etc. are only used for differential description and should not be construed as indicating or implying relative importance.
[0051] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which various embodiments of the present application pertain. The terms (such as those defined in a commonly used dictionary) will be interpreted as having the same meaning as the contextual meaning in the relevant technical field and will not be interpreted as having an idealized meaning or being overly formal, unless clearly defined in various embodiments of the present application.
[0052] Embodiment 1
[0053] The present application provides a text fuzzy matching method.
[0054] Refer to Figure 1 , the text fuzzy matching method includes steps S101 - S106, and each step will be described below.
[0055] Step S101, obtain the corresponding initial matching score according to the modification cost of each character of the matching template and each character of the text to be matched.
[0056] In this embodiment, the text to be matched is the input text, which can be a string input by the user. For example, the user input string is "How can individuals protect themselves against the golden coronavirus?", and the text to be matched can also be other strings, which are not limited herein. Multiple matching templates can be stored in the matching library, and each matching template can be a key string manually annotated or a key string identified by artificial intelligence. For example, the matching template can be "novel coronavirus".
[0057] It should be noted that due to different error sources, the modification cost of each character of the matching template and each character of the text to be matched is calculated by different methods. For example, in image recognition, the misrecognition probability between the characters "rabbit" and "avoid" should be much higher than that between the characters "rabbit" and "tiger". In speech recognition, the error between "golden crown" and "novel crown" should be smaller, so the modification costs of these two methods of image recognition and speech recognition should be different. Exemplarily, the modification cost can be determined by the error source. For text from image recognition sources, glyph-related features can be extracted and the single-character similarity can be calculated as the modification cost. For text from speech recognition sources, the phoneme similarity is used as the modification cost. It should be additionally noted that a phoneme is the smallest speech unit divided according to the natural attributes of speech. Commonly, for example, Chinese pinyin and English phonetic notations can both be used as phonemes.
[0058] In one embodiment, obtaining the modification cost of each character in the matching template and each character in the text to be matched includes:
[0059] If the source of error is image recognition error, then the similarity of a single character is determined based on the character shape-related features, and the similarity of the single character is used as the modification cost;
[0060] If the source of the error is speech recognition error, then phoneme similarity is used as the modification cost.
[0061] As an example, for speech recognition errors, similarity can be determined between Chinese Pinyin and English phonetic symbols. Based on the phoneme confusion cost determined by human experience, the correction cost can be calculated. For image recognition errors, the similarity of individual characters is determined based on character shape-related features, and the correction cost is determined from the similarity of individual characters.
[0062] In this way, appropriate modification costs can be determined based on different sources, incorporating bias information from error sources to accommodate potential errors in the pre-recognition technology. Using phonemes and glyphs as the basis for the pre-editing distance cost reduces matching errors caused by typos, recognition mistakes, and untimely updates to the hot word system.
[0063] See Figure 2 Step S101 includes:
[0064] Step S1011: If the modification cost is greater than a preset cost threshold, then the initial matching score is set to 0.
[0065] Step S1012: If the modification cost is less than or equal to a preset cost threshold, then the modification cost is used as the initial matching score.
[0066] In this embodiment, the preset cost threshold can be a threshold set based on experience. For example, the preset cost threshold can be set to 0.5, or other values, which are not limited here. By determining whether the modification cost is greater than the preset cost threshold, the modification difficulty of each character in the matching template and each character in the text to be matched can be distinguished. If the modification cost is greater than the preset cost threshold, the modification difficulty of the characters in the matching template and the characters in the text to be matched is relatively high, that is, the matching degree of the characters in the matching template and the characters in the text to be matched is low, and the initial matching score of the characters in the matching template and the characters in the text to be matched can be determined as 0. If the modification cost is less than or equal to the preset cost threshold, the modification difficulty of the characters in the matching template and the characters in the text to be matched is relatively low, that is, the matching degree of the characters in the matching template and the characters in the text to be matched is high, and the modification cost of the characters in the matching template and the characters in the text to be matched can be used as the initial matching score to characterize the matching degree of the characters in the matching template and the characters in the text to be matched.
[0067] Step S102: Obtain the final matching score between the subsequence of the matching template and the subsequence of the text to be matched based on the initial matching score, insertion cost, and deletion cost.
[0068] It's important to note that for two strings, insertion and deletion operations are generally considered equivalent. For example, if there are two text segments A and B, inserting a character into A and deleting a character into B have the same effect. Therefore, the cost of deletion and insertion can be set to the same value. For instance, the cost of deletion and insertion can be set to 0.4.
[0069] See Figure 3 Step S102 includes:
[0070] Step S1021: Traverse each of the initial matching scores and determine the first adjacent initial matching score, the second adjacent initial matching score, and the third adjacent initial matching score of the current initial matching score;
[0071] Step S1022: Calculate the sum of the first adjacent initial matching score and the current initial matching score, and calculate the first difference between the second adjacent initial matching score and the insertion cost, and the second difference between the third adjacent initial matching score and the deletion cost.
[0072] Step S1022: The maximum value among the sum, the first difference, and the second difference is determined as the final matching score.
[0073] In this embodiment, an initial matching score table can be obtained based on the initial matching scores of each character in the matching template and each character in the text to be matched. The first column of the table sequentially includes each character in the matching template, and the first row of the table sequentially includes each character in the text to be matched. The table in row i and column j stores the initial matching scores corresponding to the i-th character of the matching template and the j-th character of the text to be matched. If the current initial matching score is the initial matching score in the table in row i and column j, then the first adjacent initial matching score is the initial matching score in the table in row i-1 and column j-1, the second adjacent initial matching score is the initial matching score in the table in row i-1 and column j, and the third adjacent initial matching score is the initial matching score in the table in row i and column j-1.
[0074] In this embodiment, the method further includes:
[0075] If the current initial matching score has no first adjacent initial matching score, second adjacent initial matching score, and third adjacent initial matching score, then set the first adjacent initial matching score, second adjacent initial matching score, and third adjacent initial matching score of the current initial matching score to 0.
[0076] It should be noted that, for the aforementioned initial matching score table, when the current initial matching score exceeds the table in the upward and leftward directions, the values of its first adjacent initial matching score, second adjacent initial matching score, and third adjacent initial matching score are considered to be 0.
[0077] As an example, for the initial match score in the second row, second column cell, since there are no corresponding initial match scores in the first row, first column, first row, second column, and second row, first column, the initial match score in the second row, second column cell has no first adjacent initial match score, second adjacent initial match score, and third adjacent initial match score. According to the rules, the first adjacent initial match score, second adjacent initial match score, and third adjacent initial match score of the initial match score in the second row, second column cell can all be set to 0. Thus, since there are no initial match scores in the tables above and to the left of the second row, second column cell, the initial match scores of the first row, first column cell, first row, second column cell, and second row, first column cell need to be considered 0 for data supplementation. The initial match scores of the other cells, such as the second row, j column cell and the i row, second column cell, can also be set to 0 according to the aforementioned rules, which will not be elaborated upon here.
[0078] It should be noted that the final matching score in this embodiment can be understood as the similarity between a subsequence in the matching template and a subset of subsequences in the text to be matched. This similarity can also be called a variant of the edit distance, and the subset of subsequences in the text to be matched can also be called key sequences. In most matching scenarios, the content of the key sequence is any subsequence of the text to be matched.
[0079] Existing full-text matching techniques are susceptible to various recognition errors, while deep learning-based fuzzy matching methods based on the entire sequence perform poorly with key sequences that have a low proportion of occurrence and are easily affected by context-independent information. The edit distance variant in this invention enables fuzzy matching regardless of the proportion of key sequences in the entire sequence, eliminating the influence of context-independent information. The process of calculating the final matching score is equivalent to calculating the edit distance variant.
[0080] It should be further explained that edit distance in existing technologies is a common sequence similarity feature. Text is a type of sequence, and when explaining content related to edit distance, the meanings of text and sequence can be approximately equivalent. The definition of calculating edit distance can be expressed as follows: Assuming there are sequences A and B whose similarity features need to be calculated, there are three operations in the calculation process: inserting, deleting, and modifying an element at any position. Each operation requires its own cost score. The edit distance is the minimum value of the sum of the cost scores of transforming the two sequences into the same state using the above three transformations. Common edit distance calculations calculate the distance between two sequences, while in this embodiment, the process of calculating the edit distance variant is the aforementioned process of calculating the final matching score. The edit distance variant is used to calculate the relevance between the matching template and the text to be matched. This edit distance variant can ignore irrelevant contextual information and only retrieve the degree of keyword matching.
[0081] In one embodiment, the step of calculating the sum based on the first adjacent initial match score and the current initial match score includes:
[0082] When the first adjacent initial matching score is not 0, the sum is calculated based on the first adjacent initial matching score, the current initial matching score, and the preset compensation score.
[0083] As an example, when the first adjacent initial match score is not 0, the sum of the first adjacent initial match score, the current initial match score, and the preset compensation score is calculated; when the first adjacent initial match score is 0, the sum of the first adjacent initial match score and the current initial match score is calculated. This increases the likelihood of selecting longer matching sequences by adding a preset compensation score. The preset compensation score can be a small score less than 1, for example, 0.1; there is no limitation on this.
[0084] See Table 1 below, which is a sample table of final matching scores.
[0085] Table 1. Final Matching Score Diagram
[0086]
[0087] It should be noted that in the initial matching score table described above, the initial matching score between "gold" and "new" is 0.8, the initial matching score between "poison" and "protect" is 0.3, and the initial matching scores of the rest of the exact matches are 1; the insertion cost and the deletion cost are both 0.4, the preset supplementary score is 0.01, and the preset matching threshold is 0.8. According to the foregoing steps, the final matching score schematic table shown in Table 1 is calculated. As shown in Table 1, the first column is successively each character of "novel coronavirus" of the matching template, and the first row is successively each character of "protect gold coronavirus" of the text to be matched. The value recorded in the i-th row and the j-th column of the table is the final matching score of the first character to the i-th character of the matching template and the first character to the j-th character of the text to be matched. For example, in Table 1, the value in the table where the row where the character "poison" is located in the first column intersects with the column where the character "poison" is located in the first row is 3.43, representing the final matching score of "novel coronavirus" up to the character "poison".
[0088] Step S103: Determine the highest matching score from the multiple final matching scores, and determine the average score per character according to the number of characters of the matching template and the highest matching score.
[0089] Exemplarily, in Table 1, the highest matching score determined from the multiple final matching scores in Table 1 is 3.43. Since the matching template is "novel coronavirus" and has 4 characters, the calculation process of its average score per character is: 3.43 / 4 = 0.8575. The average score per character 0.8575 is greater than the preset matching threshold 0.8, and a matching path can be obtained. When the average score per character is less than or equal to the preset matching threshold, due to insufficient matching degree, the current matching template can be discarded, and other matching templates are searched from the matching library for the foregoing processing process until a matching template with an average score per character greater than the preset matching threshold is found.
[0090] Step S104: If the average score per character is greater than the preset matching threshold, determine the matching path according to the matching template.
[0091] Exemplarily, in Table 1, the average score per character 0.8575 is greater than the preset matching threshold 0.8, then the matching path of the text to be matched "how individuals protect gold coronavirus" can be determined according to "novel coronavirus".
[0092] Step S105: Edit the text to be matched according to the matching path to obtain a modified text.
[0093] It should be noted that the modified text obtained based on the foregoing steps is a text obtained by using fewer modification operations and is a low-cost modified text.
[0094] Exemplarily, replace the characters in the text to be matched with the corresponding characters in the matching template. For example, in Table 1, "Golden Coronavirus" will be replaced with "New Coronavirus", where "Golden" is replaced with "New", and the extra character "状" will be retained for subsequent traditional fuzzy matching such as similarity matching.
[0095] In this way, modify and correct the text to be matched before the whole sentence matching operation to prevent semantic extraction errors caused by recognition errors and thus incorrect matching results.
[0096] Step S106, perform a matching process on the modified text and the matching template.
[0097] In this embodiment, perform a matching process on the modified text and the matching template to prevent semantic extraction differences caused by recognition errors in long texts and thus avoid misjudgment of the text processing system.
[0098] In one implementation, step S106 includes:
[0099] Determine the modification operation and the matching string substring according to the matching path;
[0100] Edit the text to be matched according to the modification operation and the matching string substring to obtain the modified text.
[0101] Exemplarily, for example, in Table 1, the matching path is to match "Golden Coronavirus" as "New Coronavirus". The modification operation is to change "Golden" in "Golden Coronavirus" to "New", and the matching string substring is "Golden Coronavirus". By changing "Golden" in "Golden Coronavirus" to "New" and retaining the character "状", the modified text obtained is "New Coronavirus".
[0102] Aiming at the situation that the existing keyword matching is easily affected by factors such as recognition errors and untimely update of the system word library, resulting in changes in the text to be matched and affecting the matching results, this embodiment proposes a text fuzzy matching method, and uses the pre-system error as the cost of the editing operation to tolerate the errors brought by the pre-system and improve the robustness of the overall system. Aiming at the situation that misrecognition in full sentence matching causes errors in text matching results, an error correction mechanism based on editing cost is added to perform different error corrections on each matching template to tolerate the errors brought by pre-system recognition and obtain a more robust result.
[0103] Compared to existing error correction techniques, which use the same language model assumptions for all texts and require timely updates to the hot word database, the fuzzy text matching method in this embodiment considers errors in the text source and attempts to reduce these errors as a basis for matching. The difference between this embodiment and existing error correction techniques lies in the fact that existing techniques use the same language model for all results, while this embodiment's fuzzy text matching method is based on templates and prior system errors; the same text will produce different error correction results on different templates. For example, if the text to be matched is "Hu Jinguan virus expert," existing error correction might result in either "Hu Jinguan|virus expert" or "Hu|COVID-19 virus|expert," while this embodiment's fuzzy text matching method can successfully match both.
[0104] The text fuzzy matching method provided in this embodiment obtains the corresponding initial matching score based on the modification cost of each character in the matching template and each character in the text to be matched; it obtains the final matching score between the subsequence of the matching template and the subsequence of the text to be matched based on the initial matching score, insertion cost, and deletion cost; it determines the highest matching score from multiple final matching scores, and determines the average score per character based on the number of characters in the matching template and the highest matching score; if the average score per character is greater than a preset matching threshold, it determines the matching path based on the matching template; it edits the text to be matched according to the matching path to obtain the modified text; and it performs matching processing between the modified text and the matching template. This method has higher tolerance for pre-system errors, is less prone to missed recognition, and is less likely to be affected by pre-system errors in text matching, thus providing higher robustness for both local and overall systems.
[0105] Example 2
[0106] In addition, this application provides a text fuzzy matching device.
[0107] like Figure 4 As shown, the text fuzzy matching device 400 includes:
[0108] The first acquisition module 401 is used to obtain the corresponding initial matching score based on the modification cost of each character in the matching template and each character in the text to be matched;
[0109] The second acquisition module 402 is used to acquire the final matching score between the subsequence of the matching template and the subsequence of the text to be matched based on the initial matching score, insertion cost, and deletion cost.
[0110] The first determining module 403 is used to determine the highest matching score from multiple final matching scores, and to determine the average score per character based on the number of characters in the matching template and the highest matching score.
[0111] The second determining module 404 is used to determine the matching path according to the matching template if the average score of the single character is greater than the preset matching threshold.
[0112] Editing module 405 is used to edit the text to be matched according to the matching path to obtain modified text;
[0113] The matching module 406 is used to match the modified text with the matching template.
[0114] In one embodiment, the first acquisition module 401 is further configured to determine the initial matching score as 0 if the modification cost is greater than a preset cost threshold;
[0115] If the modification cost is less than or equal to a preset cost threshold, then the modification cost is used as the initial matching score.
[0116] In one embodiment, the second acquisition module 402 is further configured to traverse each of the initial matching scores and determine the first adjacent initial matching score, the second adjacent initial matching score, and the third adjacent initial matching score of the current initial matching score.
[0117] Based on the sum of the first adjacent initial matching score and the current initial matching score, calculate the first difference between the second adjacent initial matching score and the insertion cost, and the second difference between the third adjacent initial matching score and the deletion cost;
[0118] The maximum value among the sum, the first difference, and the second difference is determined as the final matching score.
[0119] In one embodiment, the second acquisition module 402 is further configured to calculate the sum based on the first adjacent initial matching score, the current initial matching score, and the preset compensation score when the first adjacent initial matching score is not 0.
[0120] In one embodiment, the text fuzzy matching device 400 further includes:
[0121] The first processing module is used to set the first adjacent initial matching score, the second adjacent initial matching score, and the third adjacent initial matching score of the current initial matching score to 0 if the current initial matching score has no first adjacent initial matching score, the second adjacent initial matching score, and the third adjacent initial matching score.
[0122] In one embodiment, the text fuzzy matching device 400 further includes:
[0123] The second processing module is used to determine the single character similarity based on the character shape-related features if the error source is image recognition error, and use the single character similarity as the modification cost.
[0124] If the source of the error is speech recognition error, then phoneme similarity is used as the modification cost.
[0125] In one embodiment, the editing module 405 is further configured to determine the modification operation and the matching string substring based on the matching path;
[0126] The modified text is obtained by editing the text to be matched according to the modification operation and the matched substring.
[0127] The text fuzzy matching device 400 provided in this embodiment can implement the text fuzzy matching method provided in Embodiment 1. To avoid repetition, it will not be described again here.
[0128] The text fuzzy matching device provided in this embodiment obtains the corresponding initial matching score based on the modification cost of each character in the matching template and each character in the text to be matched; it obtains the final matching score between the subsequence of the matching template and the subsequence of the text to be matched based on the initial matching score, insertion cost, and deletion cost; it determines the highest matching score from multiple final matching scores, and determines the average score per character based on the number of characters in the matching template and the highest matching score; if the average score per character is greater than a preset matching threshold, it determines the matching path based on the matching template; it edits the text to be matched according to the matching path to obtain the modified text; and it performs matching processing between the modified text and the matching template. This approach has higher tolerance for pre-system errors, is less prone to missed recognition, and is less likely to be affected by pre-system errors in text matching, thus providing higher robustness for both local and overall systems.
[0129] Example 3
[0130] In addition, this application provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the computer program executes the text fuzzy matching method provided in Embodiment 1 when it is run on the processor.
[0131] The electronic device provided in this embodiment can implement the text fuzzy matching method provided in Embodiment 1. To avoid repetition, it will not be described again here.
[0132] Example 4
[0133] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the text fuzzy matching method provided in Embodiment 1.
[0134] In this embodiment, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.
[0135] The computer-readable storage medium provided in this embodiment can implement the text fuzzy matching method provided in Embodiment 1. To avoid repetition, it will not be described again here.
[0136] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal that includes that element.
[0137] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, 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 is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0138] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A text fuzzy matching method, characterized in that, The method includes: The initial matching score is obtained based on the modification cost of each character in the matching template and each character in the text to be matched. The final matching score between the subsequence of the matching template and the subsequence of the text to be matched is obtained based on the initial matching score, insertion cost, and deletion cost. The highest matching score is determined from multiple final matching scores, and the average score per character is determined based on the number of characters in the matching template and the highest matching score. If the average score of a single character is greater than the preset matching threshold, then the matching path is determined according to the matching template; Edit the text to be matched according to the matching path to obtain the modified text; The modified text is matched against the matching template. The step of obtaining the initial matching score based on the modification cost of each character in the matching template and each character in the text to be matched includes: If the modification cost is greater than the preset cost threshold, the initial matching score is set to 0. If the modification cost is less than or equal to a preset cost threshold, then the modification cost is used as the initial matching score.
2. The method according to claim 1, characterized in that, The step of obtaining the final matching score between the subsequence of the matching template and the subsequence of the text to be matched based on the initial matching score, insertion cost, and deletion cost includes: Iterate through each of the initial matching scores and determine the first adjacent initial matching score, the second adjacent initial matching score, and the third adjacent initial matching score of the current initial matching score; Based on the sum of the first adjacent initial matching score and the current initial matching score, calculate the first difference between the second adjacent initial matching score and the insertion cost, and the second difference between the third adjacent initial matching score and the deletion cost; The maximum value among the sum, the first difference, and the second difference is determined as the final matching score; The step of traversing each of the initial matching scores to determine the first adjacent initial matching score, the second adjacent initial matching score, and the third adjacent initial matching score of the current initial matching score includes: An initial matching score table is obtained based on the initial matching scores of each character in the matching template and each character in the text to be matched. The first column of the initial matching score table includes each character in the matching template, and the first row of the initial matching score table includes each character in the text to be matched. The table in row i and column j stores the initial matching scores corresponding to the i-th character of the matching template and the j-th character of the text to be matched. If the current initial matching score is the initial matching score in the table in row i and column j, then the first adjacent initial matching score is the initial matching score in the table in row i-1 and column j-1, the second adjacent initial matching score is the initial matching score in the table in row i-1 and column j, and the third adjacent initial matching score is the initial matching score in the table in row i and column j-1.
3. The method according to claim 2, characterized in that, The step of calculating the sum based on the first adjacent initial matching score and the current initial matching score includes: When the first adjacent initial matching score is not 0, the sum is calculated based on the first adjacent initial matching score, the current initial matching score, and the preset compensation score.
4. The method according to claim 2, characterized in that, The method further includes: If the current initial matching score has no first adjacent initial matching score, second adjacent initial matching score, and third adjacent initial matching score, then set the first adjacent initial matching score, second adjacent initial matching score, and third adjacent initial matching score of the current initial matching score to 0.
5. The method according to claim 1, characterized in that, Obtain the modification cost of each character in the matching template and each character in the text to be matched, including: If the source of error is image recognition error, then the similarity of a single character is determined based on the character shape-related features, and the similarity of the single character is used as the modification cost; If the source of the error is speech recognition error, then phoneme similarity is used as the modification cost.
6. The method according to claim 1, characterized in that, The step of editing the text to be matched according to the matching path to obtain the modified text includes: The modification operation and the matching substring are determined based on the matching path; The modified text is obtained by editing the text to be matched according to the modification operation and the matched substring.
7. A text fuzzy matching device, characterized in that, The device includes: The first acquisition module is used to obtain the corresponding initial matching score based on the modification cost of each character in the matching template and each character in the text to be matched; The second acquisition module is used to obtain the final matching score between the subsequence of the matching template and the subsequence of the text to be matched based on the initial matching score, insertion cost, and deletion cost. The first determining module is used to determine the highest matching score from multiple final matching scores, and to determine the average score per character based on the number of characters in the matching template and the highest matching score. The second determining module is used to determine the matching path based on the matching template if the average score of the single character is greater than the preset matching threshold. The editing module is used to edit the text to be matched according to the matching path to obtain the modified text; The matching module is used to match the modified text with the matching template. The step of obtaining the initial matching score based on the modification cost of each character in the matching template and each character in the text to be matched includes: If the modification cost is greater than the preset cost threshold, the initial matching score is set to 0. If the modification cost is less than or equal to a preset cost threshold, then the modification cost is used as the initial matching score.
8. An electronic device, characterized in that, It includes a memory and a processor, the memory storing a computer program that executes the text fuzzy matching method according to any one of claims 1 to 6 when the processor is running.
9. A computer-readable storage medium, characterized in that, It stores a computer program that, when run on a processor, executes the text fuzzy matching method according to any one of claims 1 to 6.