String, string set processing method, computer device and storage medium
By setting weight data for string calculation and correcting editing distance and aggregating similar strings, the problem of difficulty in aggregation of threads or storage paths in distributed systems is solved, and fault location efficiency and service performance are improved.
Patent Information
- Application Number
- CN202210515837.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-12
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2042-05-12
AI Technical Summary
In distributed systems, when developers need to locate failures in a large number of threads or storage paths, traditional technologies are difficult to effectively aggregate similar threads or storage paths, resulting in inefficient diagnostics.
By setting weight data for some characters in the string, calculating the correction editing distance, and determining the similarity between strings based on the correction editing distance, replacing the difference characters with specified characters when certain conditions are met, a pattern string is obtained, thereby aggregating Similar strings, reducing the number of threads or storage paths developers need to view.
Improves the ability to quickly locate problems in a large number of threads or storage paths, improves the accuracy and service performance of string classification, and reduces the chance of service unavailability caused by dimension explosions.
Smart Images

Figure CN114757153B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present specification relate to the field of cloud computing technology, and specifically to a string, a string set processing method, a computer device, and a storage medium. Background Art
[0002] With the expansion of Internet architecture, distributed systems are becoming increasingly complex, and more and more components are becoming distributed, such as microservices, message sending and receiving, distributed databases, distributed caches, distributed object storage, and cross-domain calls. These components together constitute a complex distributed network.
[0003] Tracing Analysis can provide developers with complete call link restoration, call request statistics, link topology, application dependency analysis and other tools, which can help developers quickly analyze and diagnose performance bottlenecks under distributed application architecture and improve development and diagnosis efficiency in the microservice era.
[0004] However, in traditional technologies, distributed systems involve a large number (such as thousands or even tens of thousands) of threads, and developers need to locate faults in a large number of threads. Summary of the invention
[0005] In view of this, the embodiments of this specification are dedicated to providing a method for processing a string or a set of strings, a computer device, and a storage medium, which aggregate similar threads or storage paths by category, reduce the number of threads or storage paths that developers need to view, and facilitate rapid location of problems in a large number of threads or storage paths.
[0006] An embodiment of the present specification provides a method for processing a character string, the method comprising: calculating a modified edit distance between a first character string and a second character string; wherein at least some characters in the first character string respectively correspond to weight data; the modified edit distance is obtained by adjusting the edit distance generated by an edit operation of converting the first character string into the second character string based on the weight data; determining the similarity between the first character string and the second character string according to the modified edit distance; and when the similarity satisfies a character string convergence condition, replacing the difference characters between the first character string and the second character string with a specified character to obtain a corresponding first pattern character string.
[0007] An embodiment of the present specification provides a method for processing a string set, the method comprising: receiving a target string; determining a first similarity value that satisfies a preset similarity condition in a similarity set; wherein the similarity value in the similarity set is the similarity between any two strings in the string set; wherein the similarity value in the similarity set has a corresponding pattern string in a pattern string set; wherein the pattern string in the pattern string set is obtained by replacing the difference characters between any two strings in the string set with specified characters; wherein the pattern string corresponding to the first similarity value is used as a target pattern string; calculating the similarity value between the target string and each string in the string set, wherein the similarity value that satisfies the preset similarity condition is used as a second similarity value; when the second similarity value is less than the first similarity value, replacing the two strings corresponding to the first similarity value in the string set with the target string and the target pattern string to obtain an updated string set.
[0008] The embodiment of the present specification provides a string processing device, the device comprising: a modified distance calculation module, used to calculate the modified edit distance between a first string and a second string; wherein at least some characters in the first string respectively correspond to weight data; the modified edit distance is obtained by adjusting the edit distance generated by the editing operation of converting the first string into the second string based on the weight data; a similarity determination module, used to determine the similarity between the first string and the second string according to the modified edit distance; a difference character replacement module, used to replace the difference characters between the first string and the second string with specified characters to obtain the corresponding first pattern string when the similarity meets the string convergence condition.
[0009] The embodiment of the present specification provides a device for processing a string set, the device comprising: a string receiving module, for receiving a target string; a first value determining module, for determining a first similarity value satisfying a preset similarity condition in a similarity set; wherein the similarity value in the similarity set is the similarity between any two strings in the string set; wherein the similarity value in the similarity set has a corresponding pattern string in a pattern string set; wherein the pattern string in the pattern string set is obtained by replacing the difference characters between any two strings in the string set with designated characters; wherein the pattern string corresponding to the first similarity value is used as a target pattern string; a similarity value calculating module, for calculating the similarity value between the target string and each string in the string set, wherein the similarity value satisfying the preset similarity condition is used as a second similarity value; and a string replacing module, for replacing two strings corresponding to the first similarity value in the string set with the target string and the target pattern string when the second similarity value is less than the first similarity value, to obtain an updated string set.
[0010] An embodiment of the present specification provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the method steps in the above embodiment when executing the computer program.
[0011] The embodiments of this specification provide a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the method steps in the above embodiments are implemented.
[0012] An embodiment of the present specification provides a computer program product, wherein the computer program product includes instructions, and when the instructions are executed by a processor of a computer device, the computer device is enabled to perform the method steps in the above-mentioned embodiment.
[0013] In the implementation mode of this specification, by setting weight data for at least part of the characters in the first string, the edit distance between the first string and the second string is adjusted based on the weight data, so as to obtain a modified edit distance that is more in line with actual needs, so that the similarity between the first string and the second string can be accurately determined according to the modified edit distance; and then, when the similarity meets the string convergence condition, the difference characters between the first string and the second string are replaced with the specified characters to obtain the corresponding first pattern string, and the strings of the same type or cluster are clustered together as much as possible to improve the accuracy of string classification. In particular, when the threads or storage paths in the form of strings converge, similar threads or storage paths can be aggregated according to categories, reducing the number of threads or storage paths that developers need to view, which is conducive to quickly locating problems in a large number of threads or storage paths, improving service performance, and reducing the probability of overall service unavailability due to dimensionality explosion problems. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] Figure 1 The figure is a flow chart of a method for processing a character string in a scenario example provided by an implementation method;
[0015] Figure 2a FIG. 1 is a flow chart of a method for processing a character string provided by an embodiment;
[0016] Figure 2b Shown is a schematic diagram of a conventional edit distance formula provided by an embodiment;
[0017] Figure 3 FIG. 1 is a flow chart of a method for processing a character string provided by an embodiment;
[0018] Figure 4 FIG. 1 is a flow chart of a method for processing a character string provided by an embodiment;
[0019] Figure 5 FIG. 1 is a flow chart of a method for processing a character string provided by an embodiment;
[0020] Figure 6 FIG. 1 is a flow chart of a method for processing a character string provided by an embodiment;
[0021] Figure 7 FIG. 1 is a flow chart of a method for processing a string set provided by an embodiment;
[0022] Figure 8 FIG. 1 is a structural block diagram of a string processing device provided by an embodiment;
[0023] Fig. 9 FIG. 1 is a structural block diagram of a device for processing a string set provided by an embodiment;
[0024] Fig.10 Shown is a diagram of the internal structure of a computer device provided by one embodiment. DETAILED DESCRIPTION
[0025] The following will be combined with the drawings in the embodiments of this specification to clearly and completely describe the technical solutions in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this specification.
[0026] In a specific scenario example, in the fields of information theory, linguistics, and computer science, the Levenshtein distance is an indicator used to measure the similarity between two sequences. In layman's terms, the Levenshtein distance refers to the distance between two strings.<string1,string2> The minimum number of editing operations required to convert one string string1 into another string string2. Editing operations include: inserting a character, deleting a character, and replacing a character. It can be understood that the editing operations in this specification can be single-character editing operations. If this specification mentions "an editing operation to convert string A into string B", string A can be understood as the object targeted by the editing operation, and string B can be understood as the object referenced by the editing operation.
[0027] In this scenario example, the character length of string1 is m, and the character length of string2 is n. Define matrix A, the size of matrix A is (m+1)*(n+1), and the array elements in matrix A are recorded as d[i][j]. d[i][j] represents the minimum number of editing operations required to convert the first i characters of string1 into the first j characters of string2. In other words, d[i][j] represents the editing distance between the substring from 0 to i in string1 and the substring from 0 to j in string2. Since the three operations of insertion, replacement, and deletion affect one character of string1 each time, calculating d[i][j] involves the values of d[i-1][j], d[i][j-1], and d[i-1][j-1].
[0028] If the i-th character a of string1 i and the jth character b of string2 j Similarly, the number of editing operations to convert the first i characters to the first j characters is equal to the number of editing operations to convert the first i-1 characters to the first j-1 characters, so we can get the relationship: d[i][j]=d[i-1][j-1].
[0029] When the i-th character of string1 is different from the j-th character of string2, if the first i-1 characters of string1 have been converted to the first j characters of string2, the i-th character of string1 needs to be deleted when converting. The weight data corresponding to the deletion operation is W del , then we can get the relationship: d[i][j]=d[i-1][j]+W del . Delete the weight data W corresponding to the operation del It can change monotonically with i and j.
[0030] In the case where the i-th character of string1 is different from the j-th character of string2, if the first i characters of string1 have been converted to the first j-1 characters of string2, then further operations are performed on string1, and a character that is the same as the j-th character of string2 is inserted. The weight data corresponding to the insertion operation is W ins , then we can get the relationship: d[i][j]=d[i][j-1]+W ins . Insert the weight data W corresponding to the operation ins It can change monotonically with i and j.
[0031] In the case where the i-th character of string1 is different from the j-th character of string2, if the first i-1 characters of string1 have been converted to the first j-1 characters of string2, we only need to replace the i-th character of string1 with the j-th character of string2. The weight data corresponding to the replacement operation is W rep , then we can get the relationship: d[i][j]=d[i-1][j-1]+W rep . Replace the weight data W corresponding to the operation rep It can change monotonically with i and j.
[0032] Based on the above relationship of d[i][j], and using the different results solved previously, the minimum number of editing operations is required. Therefore, the revised edit distance formula is:
[0033] d[0][0]=0
[0034] d[i][0]=W ins
[0035] d[0][j]=W del
[0036]
[0037] In this scenario, the weight data W ins , weight data W del , weight data W rep The weight data W in this example can be set to change monotonically with i and j according to the actual application scenario requirements, such as monotonically increasing, exponentially increasing, monotonically decreasing, or exponentially decreasing. ins , weight data W del , weight data W rep Indicator function in the regular Levenshtein distance formula Furthermore, the weight data W ins , weight data W del , weight data W rep It is related to the position of the difference character in the string, while the indicator function in the conventional edit distance formula is It has nothing to do with the position. When each character in the string is edited, the value of the indicator function is in a i Equal to b j When the value is 0, i Not equal to b j The value is 1. In some application scenarios, the weight data W ins , weight data W del , weight data W rep It can be set as a constant according to the actual application scenario requirements.
[0038] In the actual process of comparing the similarity of two strings, the weight data of the deletion, addition and replacement operations are determined by the positions of the different characters in the strings. Different weight data are preset for characters at different positions. When performing editing operations (any of the deletion, addition and replacement operations) on characters at different positions, the edit distance can be corrected based on the weight data to obtain the corrected edit distance between the two strings, and the degree of difference between the two strings is measured based on the corrected edit distance.
[0039] Exemplarily, the first path string is / api / v1 / userId / 1, the second path string is / api / v2 / userId / 11, and the third path string is / api / v1 / userId / 11; the third path string is converted to the first path string, and an editing operation of deleting character 1 needs to be performed between the third path string and the first path string, and the edit distance calculated based on the conventional edit distance formula is 1. It should be noted that the deleted character 1 is located at the end of the third path string. Further, the third path string is converted to the second path string, and an editing operation of replacing character 1 with character 2 needs to be performed between the third path string and the second path string, and the edit distance calculated based on the conventional edit distance formula is 1. It should be noted that the replaced character 1 is located at the head of the second path string.
[0040] In this example, if the similarity is determined based on the conventional edit distance formula, since the edit distances determined based on the conventional edit distance formula are equal, the similarity between the third path string and the first path string is equal to the similarity between the third path string and the second path string. However, in the storage path aggregation scenario, since the deleted character 1 is at the end of the third path string and the replaced character 1 is at the head of the second path string, the similarity between the third path string and the first path string is higher than the similarity between the third path string and the second path string. It can be seen that the similarity determined using the conventional edit distance formula cannot reflect the actual degree of string difference in this scenario.
[0041] In this example, if the similarity is determined based on the modified edit distance formula, since different weight data are set for the characters at the end position of the string and the characters at the head position of the string, the modified edit distance between the third path string and the first path string calculated using the modified edit distance formula is different from the modified edit distance between the third path string and the first path string, so that the similarity between the third path string and the first path string is different from the similarity between the third path string and the second path string. Specifically, the modified edit distance between the third path string and the first path string is calculated using the modified edit distance formula. Since the weight data for the last character in the third path string targeted by the deletion operation is W del , then the modified edit distance between the third path string and the first path string is 1*W del The edit distance between the third path string and the second path string is calculated using the modified edit distance formula. Since the weight data of the head character targeted by the replacement operation of the third path string is W rep, then the modified edit distance between the third path string and the second path string is 1*W rep The modified edit distance W between the third path string and the first path string del The modified edit distance W between the third path string and the second path string rep It can be seen that the similarity determined by using the modified edit distance formula more accurately reflects the actual situation of the degree of difference of the strings in this scenario.
[0042] Exemplarily, the non-blocking thread pool includes several threads, such as the first thread http-nio-8080-exec-1 and the second thread http-nio-8080-exec-2. The blocking thread pool includes several threads, such as the third thread http-nio-8090-exec-1; a replacement operation needs to be performed between the thread name of the first thread and the thread name of the second thread, and a replacement operation needs to be performed between the thread name of the first thread and the thread name of the third thread. According to the conventional edit distance formula, the edit distance between the thread name of the first thread and the thread name of the second thread is 1, and the edit distance between the thread name of the first thread and the thread name of the second thread is 1. The similarity between the first thread and the second thread is the same as the similarity between the first thread and the third thread, thereby mistakenly classifying the first thread, the second thread, and the third thread as the same type of thread. In actual practice, the first thread and the second thread are threads in the non-blocking thread pool. The third thread is a thread in the blocking thread pool. The categories of the first thread, the second thread, and the third thread are not the same.
[0043] According to the modified edit distance formula, the modified edit distance between the thread name of the first thread and the thread name of the second thread is W rep 1. The modified edit distance between the thread name of the first thread and the thread name of the third thread is W rep 2. Since the difference between http-nio-8080-exec-1 and http-nio-8080-exec-2 is at the end of the thread name, and the difference between http-nio-8080-exec-1 and http-nio-8090-exec-1 is in the middle of the thread name, W rep 1Different from W rep 2. According to the similarity, the first thread and the second thread are classified into the same category, and the first thread and the third thread are classified into different categories. Finally, the first thread and the second thread are aggregated into one category, and the third thread is classified into another category. It can be seen that the result obtained by converging the thread names using the modified edit distance formula is consistent with the actual situation.
[0044] In another specific scenario example, the edit distance formula is modified based on weight data related to the character position relationship to obtain a modified edit distance formula. The string similarity is determined using the modified edit distance formula, and the strings are converged according to the string similarity. It should be noted that string convergence can be understood as aggregating strings based on the similarity between strings, so as to divide strings that meet the preset similarity conditions into the same category or cluster, so that the similarity of strings in the same category or cluster is relatively large, and the difference between strings in different categories or clusters is as large as possible.
[0045] In this scenario example, similarity can be calculated based on the modified edit distance in the above scenario example. Specifically, the similarity between string A and string B can be calculated using the following formula: similarity(A, B). The modified edit distance is recorded as distance(A, B), the length of string A is recorded as length(A), and the length of string B is recorded as length(B).
[0046]
[0047] See also Figure 1 In this scenario, an initial string set R is set, and the strings in the initial string set R are recorded as r0, r1, r2, ... r i-1 . Set the upper limit of the final result set after the string convergence processing to p. The number of strings in the initial string set R is less than or equal to p. According to the value of the upper limit p of the result set, construct a two-dimensional matrix M and a two-dimensional matrix N of order p. Among them, M can be an initial similarity matrix, and the elements in the initial similarity set are initial similarity values, such as the initial similarity value can be -1. N can be an initial pattern string matrix, and the elements in the initial pattern string set are initial strings, such as the initial string can be an empty string (null). The elements M[i][j] in the matrix M can be used to store the similarity between the i-th item and the j-th item in the initial string set R based on the modified edit distance. The elements N[i][j] in the matrix N can be used to store the pattern strings corresponding to the i-th item and the j-th item in the initial string set R. The pattern strings corresponding to the i-th item and the j-th item can be obtained by replacing the different characters in the i-th item and the j-th item with a specified character (such as *). After receiving the i-th string A i In the case of , the matrix M and the matrix N can be updated. It can be understood that the process of updating the matrix M and the matrix N is to update the initial string set R and the string A i The process of convergence processing.
[0048] In this scenario, after receiving the i-th string Ai In the case of i With each string in the initial string set R (r0, r1, r2...r i-1 ) to calculate the similarity. Determine whether i is less than p. If i is less than p, it means that there is still space in the matrix M and N to accommodate the string A. i , that is, the number of strings in the current result set has not yet reached the upper limit of the final result set, string A can be i Directly add to the current result set. Therefore, using string A i Respectively with the strings r0, r1, r2...r i-1 Calculate the similarity and update the obtained similarity into the matrix M. Based on the string A i and string r0, string r1, string r2, ... string r i-1 Calculate the pattern strings respectively, and update the obtained pattern strings into the matrix N.
[0049] In this scenario, if i is not less than p, it means that there is no free space in the matrix M and the matrix N to accommodate the string A. i , that is, the number of strings in the current result set has reached the upper limit of the final result set, and string A needs to be i和 The current result set is converged. Therefore, in order to cluster strings of the same class or cluster together as much as possible and separate strings of different classes or clusters, the steps to be performed include: (1) traversing the similarities in the matrix M and determining the maximum similarity M[g][h]. The maximum similarity M[g][h] corresponds to the pattern string N[g][h] in the matrix N. (2) Using the string A i Respectively with the strings r0, r1, r2...r i-1 Calculate the similarity and determine the maximum similarity q from the obtained similarities. The maximum similarity q is the string A i With the string r k Replace string A with the specified character i With the string r k The difference characters between them are used to obtain the corresponding pattern string U. (3) Compare the maximum similarity M[g][h] with the maximum similarity q. (4) If M[g][h] is greater than q, it means that the string r g and the string r h The similarity between them is greater than string A i With the string r k The similarity between the two can be g and the string r h Converge, so that the string r g and the string rh Merge into pattern string N[g][h], and save the position in the current result set to place string A i From another perspective, it can also be said that using string A i 、The pattern string N[g][h] replaces the string r in the current result set g and the string r h (5) If M[g][h] is less than q, it means that the string r g and the string r h The similarity between them is less than string A i With the string r k If the similarity between i With the string r k Converge, so that the string A i With the string r k Merge into pattern string U. From another perspective, it can also be said that pattern string U replaces string r in the current result set. k The above steps are executed repeatedly until the final result set is output, and the final result set can be understood as the result of convergence processing on the string set.
[0050] In this scenario example, it should be noted that the maximum similarity M[g][h] is the string r g and the string r h The pattern string N[g][h] is to replace the string r with the specified characters. g and the string r h The difference between the characters is obtained.
[0051] The embodiments of this specification provide a string convergence system, and the string processing method or string set processing method provided in this specification is applied to the string convergence system. The string convergence system may include a hardware environment formed by a server. The server may be an electronic device with certain computing and processing capabilities. It may have a network communication module, a processor, a memory, etc. The above-mentioned server may also be a distributed server, which may be a system with multiple processors, memories, network communication modules, etc. operating in collaboration. Alternatively, the server may also be a server cluster formed by several servers. Alternatively, with the development of science and technology, the server may also be a new technical means that can realize the corresponding functions of the embodiments of the specification. For example, it may be a new form of "server" based on quantum computing.
[0052] See also Figure 2a The embodiment of the present specification provides a method for processing a string. The method for processing a string is applied to a server and may include the following steps.
[0053] Step S210: Calculate the modified edit distance between the first character string and the second character string.
[0054] At least some characters in the first character string are respectively associated with weight data. The modified edit distance is obtained by adjusting the edit distance generated by the edit operation of converting the first character string into the second character string based on the weight data.
[0055] In some cases, the similarity is determined based on the edit distance, for example, the similarity uses the inverse of the edit distance. The accuracy of the similarity depends on the accuracy of the edit distance. For example, if the edit distances are equal, the similarity is consistent, and if the edit distances are not equal, the similarity is inconsistent. Therefore, in order to obtain a similarity that fits different application scenarios, this embodiment corrects the edit distance in the traditional technology. Specifically, corresponding weight data is set for at least part of the characters in the first character string. Weight data can be set for some characters in the first character string, or weight data can be set for all characters in the first character string. The weight data of each character can be set in combination with the actual needs of the application scenario, for example, the corresponding weight data can be set according to the character position, and the corresponding weight data can be set according to the type of character.
[0056] In this embodiment, the corrected edit distance between the first character string and the second character string can be calculated recursively. When each editing operation converts the first character string into the second character string, the weight data can be used to correct the edit distance generated by this editing operation to obtain the corrected edit distance generated by this editing operation. For example, in the traditional technology, the edit distance generated by an editing operation for any character is recorded as 1, and in this embodiment, the edit distance 1 can be adjusted using the weight data corresponding to the arbitrary character to obtain the corrected edit distance generated by the editing operation. By analogy, the final corrected edit distance generated from the editing operation for the first character in the first character string to the editing operation for the last character in the first character string is the corrected edit distance between the first character string and the second character string.
[0057] In this embodiment, a dynamic programming method can be used to calculate the modified edit distance between the first character string and the second character string, and the weight data can be used to replace Figure 2b The indicator function in the conventional edit distance formula is shown to obtain the modified edit distance formula. Since the three operations of insertion, replacement, and deletion affect one character of the first string each time, when converting the 0th to ith substrings in the first string to the 0th to ith substrings in the second string, we can start from d[i-1][j]+W del , d[i][j-1]+W ins and d[i-1][j-1]+W repThe minimum value is selected as the modified edit distance between the first character string and the second character string.
[0058] Step S220: determining the similarity between the first character string and the second character string according to the modified edit distance.
[0059] Specifically, in some cases, the reciprocal of the modified edit distance can be directly used as the similarity between the first character string and the second character string. In some cases, in order to further improve the accuracy of the similarity, the similarity is not affected by the units of the relevant parameters, and a normalization process can be used to determine the similarity between the first character string and the second character string based on the modified edit distance. Specifically, the similarity S between the first character string S1 and the second character string S2 is calculated using the following formula. The modified edit distance between the first character string S1 and the second character string S2 is distance(S1, S2). The length of the first character string S1 is denoted as length(S1), and the length of the second character string S2 is denoted as length(S2).
[0060]
[0061] Step S230: When the similarity satisfies the string convergence condition, the different characters between the first string and the second string are replaced with designated characters to obtain a corresponding first pattern string.
[0062] In some cases, for some strings of the same type that need to be classified, such as classifying threads with similar names and storage paths with similar paths, a string convergence condition is set for converging the strings. The string convergence condition can be set according to actual needs. The string convergence condition can be a similarity threshold or an upper limit on the number of result sets after the string converges. When the similarity meets the string convergence condition, the convergence processing of the string can be triggered, and the two strings whose similarity meets the string convergence condition are merged or aggregated into one category to reduce the number of strings. Specifically, after determining the similarity based on the modified edit distance, it is determined whether the similarity meets the string convergence condition. When the similarity meets the string convergence condition, it indicates that the first string and the second string can be converged, and the first string and the second string are compared to determine the difference characters, and the difference characters between the first string and the second string are replaced with the specified characters to obtain the corresponding first pattern string. In this embodiment, the string convergence condition can adopt a similarity threshold. When the similarity reaches the similarity threshold, the difference characters between the first string and the second string are replaced with the specified characters to obtain the corresponding first pattern string, and the first string and the second string are aggregated into the first pattern string.
[0063] The above-mentioned string processing method, by setting weight data for at least part of the characters in the first string, adjusts the edit distance between the first string and the second string based on the weight data, and obtains a modified edit distance that is more in line with actual needs, so that the similarity between the first string and the second string can be accurately determined according to the modified edit distance; and then, when the similarity meets the string convergence condition, the difference characters between the first string and the second string are replaced with the specified characters to obtain the corresponding first pattern string, and the same type or cluster strings are clustered together as much as possible to improve the accuracy of string classification. In particular, when the threads or storage paths in the form of strings converge, similar threads or storage paths can be aggregated according to categories, reducing the number of threads or storage paths that developers need to view, which is conducive to quickly locating problems in a large number of threads or storage paths, improving service performance, and reducing the probability of overall service unavailability due to dimensionality explosion problems.
[0064] In some implementations, the weight data is determined based on a character position of a first substring targeted by the editing operation in the first string and a character position of a second substring referenced by the editing operation in the second string.
[0065] Specifically, when a first string is converted to a second string through an editing operation (such as any one of deletion, replacement, and insertion), the first string can be understood as the object targeted by the editing operation, and the second string can be understood as the object referenced by the editing operation. In some embodiments, the first substring can be a portion of the characters targeted by the editing operation in the first string. The second substring can be a portion of the characters referenced by the editing operation in the second string. Since characters at different positions have different effects on the degree of similarity between strings, when calculating the edit distance, the position of the character in the string can be appropriately considered, and the weight data of each character can be determined based on the position of the character in the string. The weight data can be determined by the character position of the first substring targeted by the editing operation in the first string, and the character position of the second substring referenced by the editing operation in the second string.
[0066] Exemplarily, the first string is abcdef, and the second string is abcdmnq. If abcdef needs to be converted to abcdmnq, abcdef and abcdmnq are compared. Since abcd in the first string is consistent with abcd in the second string, the first substring targeted by the editing operation can be considered as ef, and the second substring referenced by the editing operation can be considered as mnq. The characters e and f of the first substring are located at the fifth and sixth positions of the first string. When the operation is performed on the fifth character e of the first string, the character e can be replaced with the fifth character m of the second string. The weight data of this replacement operation is related to the position of the character e in the first string and the position of the character m in the second string. When the operation is performed on the sixth character f of the first string, the character f can be replaced with the sixth character n of the second string. The weight data of this replacement operation is related to the position of the character f in the first string and the position of the character n in the second string. Finally, the seventh character q of the second string is inserted into the first string, and the first string abcdef is converted to the second string abcdmnq.
[0067] Exemplarily, the first string is abced, and the second string is abcmd. If abced needs to be converted into abcmd, compare the first string abced and the second string abcmd. First, extract the first substring a from the first string, extract the second substring a from the second string abcmd, and compare the first substring and the second substring. The two are the same. By analogy, extract the first substring abc from the first string, extract the second substring abc from the second string abcmd, and compare the first substring and the second substring. The two are the same. Extract the first substring abce from the first string, extract the second substring abcm from the second string abcmd, and compare the first substring and the second substring. The e in the first substring is different from the m in the second substring, and the e in the first substring needs to be replaced with m, and the weight data of this replacement operation can be jointly determined by the character position of the first substring in the first string and the character position of the second substring in the second string.
[0068] In this implementation, the weight data of the editing operation is determined by the character position of the first substring targeted by the editing operation in the first string and the character position of the second substring referenced by the editing operation in the second string, thereby realizing the calculation of the editing distance based on the character position, and obtaining a modified editing distance that better meets the actual scene requirements.
[0069] In some implementations, the weight data varies monotonically with the sum of a first character position of the last character of the first substring in the first character string and a second character position of the last character of the second substring in the second character string.
[0070] Among them, the last character of the first substring may be the last character of the first substring, and the last character of the second substring may be the last character of the second substring. In some cases, the weight data Wins, the weight data Wdel, and the weight data Wrep may be set according to the character position. In scenarios such as thread name convergence and url convergence, the string prefix is the same, and the part of the string near the back is differentiated. In these cases, the weights of the front characters and the back characters of the entire string should be different for the same replacement, insertion, and deletion operations, for example, the weight of the back characters is less than the weight of the front characters. The weight data may be monotonically decreasing or exponentially decreasing. In similar convergence scenarios for English addresses, the string prefix is differentiated, and the part of the string near the back is the same. In this case, the weights of the front characters and the back characters of the entire string should be different, for example, the weight of the front characters is less than the weight of the back characters. The weight data may be monotonically increasing or exponentially increasing. Specifically, the first character position of the last character of the first substring in the first character string and the second character position of the last character of the second substring in the second character string are determined, the sum of the first character position and the second character position is calculated, and the weight data changes monotonically with the sum of the first character position and the second character position.
[0071] In this implementation, for different application scenarios, the weight data changes monotonically with the sum of the first character position and the second character position, thereby improving the accuracy of the edit distance calculation.
[0072] In some embodiments, the weight data is a function value of a weight function, wherein the input parameters of the weight function include the character position of the first substring in the first string and the character position of the second substring in the second string.
[0073] Specifically, in order to improve the convenience of editing distance calculation, the weight data can be the function value of the weight function, and the weight function is used to replace the indicator function in the conventional editing distance. The weight function corresponding to the deletion operation is op del , the weight function corresponding to the insertion operation is op ins , the weight function corresponding to the replacement operation is op rep . The modified edit distance is determined using the following modified edit distance formula. Wherein, i represents the character position of the first substring in the first string, and j represents the character position of the second substring in the second string. Exemplarily, i may represent the character position of the last character of the first substring in the first string, and j represents the character position of the last character of the second substring in the second string. The modified edit distance of converting the first substring in the first character (from the 0th to the ith character) to the second substring in the second character (from the 0th to the jth character) is d[i][j].
[0074] d[0][0]=0
[0075] d[i][0]=op ins (i)
[0076] d[0][j] = op del (j)
[0077]
[0078] In some embodiments, the weight function changes monotonically, including any one of monotonically increasing, exponentially increasing, monotonically decreasing, and exponentially decreasing. Exemplarily, the weight function may be a monotonically increasing function, such as a linear function with a positive slope k. The weight function may be an exponentially increasing function, such as an exponential function with a base a greater than 1. The weight function may be a monotonically decreasing function, such as a linear function with a negative slope k. The weight function may be an exponentially decreasing function, such as an exponential function with a base a greater than 0 and less than 1.
[0079] In some embodiments, the first character string and the second character string are at least part of the character strings in the character string set. When the similarity satisfies the character string convergence condition, replacing the difference characters between the first character string and the second character string with the specified character to obtain the corresponding first pattern character string may include: when the similarity is greater than the similarity threshold, replacing the difference characters between the first character string and the second character string with the specified character to obtain the first pattern character string; wherein the first pattern character string is used to replace the first character string and the second character string in the character string set to obtain the updated character string set.
[0080] In some cases, in order to assist developers in quickly locating problems, the strings whose similarity meets the string convergence conditions are subjected to convergence processing. Specifically, a similarity threshold is set according to the actual situation, and after the similarity is determined based on the modified edit distance, the similarity is compared with the similarity threshold. When the similarity is greater than the similarity threshold, it means that the first string and the second string can be aggregated into a type of string, then the difference characters between the first string and the second string are determined, and the difference characters are replaced with preset specified characters to obtain the first pattern string corresponding to the first string and the second string. The first pattern string is used to replace the first string and the second string in the string set. In other words, the first string and the second string are deleted from the string set, and the first pattern string is inserted into the string set to update the string set.
[0081] For example, in a high-traffic scenario, some threads in the HSF server thread pool are in a blocked state due to synchronous log writing, and the thread pool is quickly filled, resulting in service unavailability. When developers discover this problem, they need to master the threads of the server application to locate the problem in these threads and reduce the probability of service unavailability. The first string and the second string can be the names of different threads, that is, the first string is the name of the first thread, and the second string is the name of the second thread. The thread pool includes the first thread name and the second thread name. The similarity between the first thread name and the second thread name is calculated based on the modified edit distance, and the similarity is compared with the similarity threshold. When the similarity is greater than the similarity threshold, the specified character * is used to replace the difference character between the first thread name and the second thread name to obtain the thread name class. The thread name class is used to replace the first thread name and the second thread name in the thread pool, and the thread pool is updated. For example, the first thread is http-nio-8080-exec-1 and the second thread is http-nio-8080-exec-2, and the first thread and the second thread are aggregated into http-nio-8080-exec-*.
[0082] In some implementations, the first string and the second string are at least part of a string set. Figure 3 , the string processing method may further include the following steps.
[0083] Step S310: Obtain a third character string.
[0084] Step S320: calculating the similarity between the third character string and each character string in the character string set; wherein the similarity that satisfies the preset similarity condition is taken as the first similarity; wherein the first similarity corresponds to the fourth character string in the character string set.
[0085] Step S330: Compare the first similarity with a preset similarity threshold.
[0086] Step S340: when the first similarity is greater than the similarity threshold, replace the different characters between the third character string and the fourth character string with the specified character to obtain a corresponding second pattern character string; wherein the second pattern character string is used to replace the fourth character string in the character string set.
[0087] Step S350: when the first similarity is less than the similarity threshold, insert the third character string into the character string set.
[0088] In some cases, the string set includes a first string and a second string. After receiving the third string, it is necessary to calculate the similarity between the third string and each string in the string set, determine whether to trigger the string convergence condition, and thus decide whether to perform convergence processing on the third string and the string set. Specifically, there is already a string set, and the first string and the second string are at least part of the strings in the string set. In order to classify strings of the same type as much as possible, the string categories are divided according to the similarity. Therefore, after obtaining the third string, the similarity between the third string and each string in the string set is calculated, and in the calculated similarities, the similarity that meets the similarity preset condition is determined as the first similarity. The similarity that meets the similarity preset condition can be the maximum similarity, that is, the maximum similarity is the first similarity. The similarity that meets the similarity preset condition can also be several similarities ranked at the top, that is, several similarities ranked at the top are the first similarity, and the similarity that meets the similarity preset condition can also be the similarity specified in the calculated similarity according to the pre-condition, that is, the specified similarity is the first similarity.
[0089] In this embodiment, after determining the first similarity, the first similarity is compared with a preset similarity threshold. If the first similarity is greater than the similarity threshold, it indicates that the third character string is highly similar to the fourth character string corresponding to the first similarity and satisfies the character string convergence condition, and the third character string and the fourth character string can be aggregated into a second pattern character string. Specifically, the difference characters between the third character string and the fourth character string are replaced with the specified characters to obtain the corresponding second pattern character string, and the fourth character string in the character string set is replaced with the second pattern character string to update the character string set.
[0090] In this embodiment, if the first similarity is less than the similarity threshold, it indicates that the similarity between the third string and the fourth string corresponding to the first similarity does not meet the string convergence condition, that is, the third string and the fourth string do not belong to the same category, and there is no need to aggregate the third string and the fourth string. Therefore, the third string is directly added to the string set, and the string set is updated.
[0091] In this implementation, by setting a similarity threshold, different operations are performed on the third character string in combination with actual conditions, thereby improving the accuracy of character string classification, aggregating qualified character strings, reducing occupied resources, and improving service performance.
[0092] In some embodiments, see Figure 4 , the string processing method may further include the following steps.
[0093] Step S410: constructing an initial similarity set and an initial pattern character string set.
[0094] Step S420: using the similarity between the first character string and the second character string to update the initial similarity value at the corresponding position in the initial similarity set, to obtain a similarity set.
[0095] Step S430: using the first pattern string corresponding to the first string and the second string to update the initial string at the corresponding position in the initial pattern string set, to obtain the pattern string set.
[0096] Among them, the elements in the initial similarity set are initial similarity values. The initial similarity set can be in the form of a two-dimensional matrix. In some implementations, the two-dimensional matrix can be a symmetric matrix. The initial similarity set can also be in the form of a one-dimensional array. The initial similarity value can be set in combination with actual conditions, such as being set to -1. The elements in the initial pattern string set are initial strings. The initial string can be set in combination with actual conditions, such as being set to an empty string. The initial pattern string set can be in the form of a two-dimensional matrix or a one-dimensional array. Among them, the initial similarity value corresponds one-to-one to the initial string.
[0097] In some cases, due to the limitation of server memory, it is necessary to pre-set the upper limit of the number of strings. If the number of strings included in the string set exceeds the upper limit of the number of strings, it may lead to a waste of service resources or even service unavailability. Therefore, the initial similarity set and the initial pattern string set are set according to the upper limit of the number of strings. If a one-dimensional array is used, the number of elements in the initial similarity set is equal to the upper limit of the number of strings, and the number of elements in the initial pattern string set is equal to the upper limit of the number of strings. If a two-dimensional matrix is used, the matrix dimension of the initial similarity set is equal to the upper limit of the number of strings, and the matrix dimension of the initial pattern string set is equal to the upper limit of the number of strings.
[0098] Specifically, an initial similarity set and an initial pattern string set of corresponding dimensions are constructed in combination with actual conditions. When the first string and the second string are obtained, the first string and the second string are used as strings in the string set, and the similarity between the first string and the second string is calculated. According to the positions of the first string and the second string in the string set, the similarity between the first string and the second string is used to update the initial similarity value at the corresponding position in the initial similarity set to obtain a similarity set. Similarly, the first pattern string corresponding to the first string and the second string is calculated, and according to the positions of the first string and the second string in the string set, the first pattern string corresponding to the first string and the second string is used to update the initial string at the corresponding position in the initial pattern string set to obtain a pattern string set.
[0099] In this implementation, the initial similarity set and the initial pattern character string set are constructed in combination with the actual situation of the server, thereby preventing waste of service resources and reducing the probability of service unavailability.
[0100] In some implementations, the first string and the second string are at least part of a string set. Figure 5 , the string processing method may further include the following steps.
[0101] Step S510: Obtain a fifth character string.
[0102] Step S520: when there is an initial similarity value in the similarity set and an initial string in the pattern string set, calculate the similarity between the fifth string and each string in the string set, and the pattern string corresponding to the fifth string and each string in the string set.
[0103] Step S530: using the similarity between the fifth character string and each character string in the character string set, updating the initial similarity value at the corresponding position in the similarity set.
[0104] Step S540: using the fifth character string and the pattern character strings corresponding to the character strings in the character string set, updating the initial character string at the corresponding position in the pattern character string set.
[0105] Among them, the string set includes a first string and a second string. In some cases, due to the limitation of server memory, it is necessary to pre-set an upper limit on the number of strings. If the number of strings included in the string set exceeds the upper limit on the number of strings, it may lead to a waste of service resources or even unavailability of the service. Therefore, after receiving the fifth string, it is necessary to determine whether the number of strings included in the string set exceeds the upper limit on the number of strings. When the number of strings included in the string set does not exceed the upper limit on the number of strings, there is an initial similarity value in the similarity set and an initial string in the pattern string set. At this time, it is necessary to calculate the similarity between the fifth string and each string in the string set, and update the similarity set using the calculated similarity. It is necessary to calculate the pattern string corresponding to the fifth string and each string in the string set, and update the pattern string set using the obtained pattern string.
[0106] Specifically, the number of dimensions of the similarity set and the number of dimensions of the pattern string set are set in combination with the actual situation of the server. The number of dimensions needs to be less than or equal to the upper limit of the number of strings in the string set. Therefore, when the fifth string newly input into the string set is received, if the upper limit of the number of strings has not been reached, it indicates that convergence processing does not need to be performed, and the fifth string can be directly added to the string set to obtain an updated string set. Further, a corresponding similarity set and pattern string set are set for the string set. After the string set is updated, the similarity set and the pattern string set need to be synchronously updated based on the updated string set. Therefore, the similarity between the fifth string and each string in the string set is calculated, and the similarity between the fifth string and each string in the string set is used to update the initial similarity value at the corresponding position in the similarity set. The pattern string corresponding to the fifth string and each string in the string set is calculated, and the pattern string corresponding to the fifth string and each string in the string set is used to update the initial string at the corresponding position in the pattern string set.
[0107] Exemplarily, the string set has stored the 1st to i-1st strings, and the similarity set is a two-dimensional matrix M of order p. The pattern string set is a two-dimensional matrix N of order p. The i-th string is received as input. The size of i and p is determined. If i is less than p, it indicates that the number of strings in the string set has not reached the upper limit of the number of strings, there is an initial similarity value in the two-dimensional matrix M, and there are similarities of corresponding strings in the 1st to the i-1th rows in the two-dimensional matrix M. There is an initial string in the two-dimensional matrix N, and there are pattern strings of corresponding strings in the 1st to the i-1th rows in the two-dimensional matrix N. The i-th string is used to calculate the similarity with any string from the 1st to the i-1th strings, and the obtained similarity is updated to the i-th row in the two-dimensional matrix M. The pattern string is calculated with the i-th string and any string from the 1st to the i-1th strings, and the obtained pattern string is updated to the i-th row in the two-dimensional matrix N.
[0108] In some implementations, the first string and the second string are at least part of a string set. Figure 6 , the string processing method may further include the following steps.
[0109] Step S610: Obtain a fifth character string.
[0110] Step S620: when there is no similarity initial value in the similarity set and no initial string in the pattern string set, determine a second similarity that meets the similarity preset condition in the similarity set; wherein the second similarity corresponds to the sixth string and the seventh string in the string set.
[0111] Step S630: calculating the similarity between the fifth character string and each character string in the character string set; wherein the similarity that satisfies the preset similarity condition is taken as the third similarity; wherein the third similarity corresponds to the eighth character string in the character string set.
[0112] Step S640: Compare the third similarity with the second similarity.
[0113] Step S650: when the third similarity is greater than the second similarity, the eighth character string in the character string set is replaced with a pattern character string corresponding to the fifth character string and the eighth character string to obtain an updated character string set.
[0114] Step S660: when the third similarity is less than the second similarity, the sixth and seventh character strings in the character string set are replaced with the fifth character string and the pattern character strings corresponding to the sixth and seventh character strings in the pattern character string set to obtain an updated character string set.
[0115] In some cases, due to the limitation of server memory, it is necessary to pre-set an upper limit on the number of strings. If the number of strings included in the string set exceeds the upper limit on the number of strings, it may lead to a waste of service resources or even unavailability of the service. Therefore, after receiving the fifth string, it is necessary to determine whether the number of strings included in the string set exceeds the upper limit on the number of strings. When the number of strings included in the string set exceeds the upper limit on the number of strings, there is no initial similarity value in the similarity set and there is no initial string in the pattern string set. At this time, it is necessary to perform convergence processing on the fifth string and the string set. How to perform convergence processing on the fifth string and the string set can be determined based on the similarity between the fifth string and each string in the string set and the similarity in the similarity set.
[0116] Specifically, the similarity set is traversed to determine the second similarity that satisfies the preset similarity condition. The similarity that satisfies the preset similarity condition may be the maximum similarity, that is, the maximum similarity is the second similarity. The similarity that satisfies the preset similarity condition may also be several similarities that are ranked first, that is, several similarities that are ranked first are the second similarity. The similarity that satisfies the preset similarity condition may also be a similarity specified in the calculated similarity according to a pre-condition, that is, the specified similarity is the second similarity. Furthermore, since the elements in the similarity set are the similarities between any two strings in the string set, the two strings corresponding to the second similarity in the string set may be recorded as the sixth string and the seventh string.
[0117] The similarity between the fifth character string and each character string in the character string set is calculated, and the similarity that satisfies the preset similarity condition is taken as the third similarity. The third similarity is the similarity between the fifth character string and a character string in the character string set, and the character string corresponding to the third similarity can be recorded as the eighth character string.
[0118] In order to update the string set and converge the same string as much as possible, the third similarity is compared with the second similarity to find a relatively large similarity, so that the same string can be found and the accuracy of the convergence process is improved. Specifically, when the third similarity is greater than the second similarity, it indicates that the multiplication degree between the fifth string and the eighth string is greater than the similarity between the sixth string and the seventh string. Therefore, it is necessary to perform convergence processing on the fifth string and the eighth string. The difference characters between the fifth string and the eighth string are replaced by the specified character to obtain the pattern string corresponding to the fifth string and the eighth string, and the eighth string in the string set is replaced to update the string set. When the third similarity is less than the second similarity, it indicates that the multiplication degree between the fifth string and the eighth string is less than the similarity between the sixth string and the seventh string. Therefore, it is necessary to perform convergence processing on the sixth string and the seventh string. The sixth string and the seventh string have corresponding pattern strings in the pattern string set. So far, the sixth string and the seventh string have been merged into the corresponding pattern string, and a position is saved in the string set for placing the fifth string. That is, the sixth character string and the seventh character string in the pattern character string set are replaced with the fifth character string and the pattern character strings corresponding to the sixth character string and the seventh character string in the pattern character string set, so as to update the character string set.
[0119] In this embodiment, by comparing the third similarity with the second similarity, similar character strings are converged into one category as much as possible, and different character strings are distinguished, thereby improving the accuracy of character string processing. Moreover, by preparing a similarity set and a pattern character string set in advance, the second similarity and the corresponding pattern character string are directly determined from the similarity set and the pattern character string set, thereby reducing the calculation pressure.
[0120] See also Figure 7 The embodiment of the present specification provides a method for processing a string set. The method for processing a string set is applied to a server, and the method for processing a string set may include the following steps.
[0121] Step S710: receiving a target character string.
[0122] Step S720: determining a first similarity value that meets a preset similarity condition in the similarity set.
[0123] Step S730: calculating the similarity value between the target character string and each character string in the character string set, wherein the similarity value that satisfies the preset similarity condition is used as the second similarity value.
[0124] Step S740: when the second similarity value is less than the first similarity value, two character strings corresponding to the first similarity value in the character string set are replaced with the target character string and the target pattern character string to obtain an updated character string set.
[0125] wherein the similarity value in the similarity set is the similarity between any two strings in the string set; wherein the similarity value in the similarity set has a corresponding pattern string in the pattern string set; wherein the pattern string in the pattern string set is obtained by replacing the difference characters between any two strings in the string set with specified characters; wherein the pattern string corresponding to the first similarity value is used as the target pattern string.
[0126] Specifically, a set of strings to be processed already exists in advance. In some cases, due to the limitation of server memory, if the number of strings included in the string set exceeds the upper limit of the number of strings, it may lead to waste of service resources or even unavailability of service. Therefore, it is necessary to pre-set the upper limit of the number of strings, and set the order of the similarity set and the order of the pattern string set according to the upper limit of the number of strings. In this embodiment, a target string input into the string set is received, and convergence processing is performed on the target string and the string set. First, the similarity set is traversed, and a first similarity value that satisfies the similarity preset condition in the similarity set is found, such as the first similarity value being the maximum value in the similarity set. The target string is used to calculate the similarity with each string in the string set, and the similarity value between the target string and each string in the string set is obtained. Among these obtained similarity values, the similarity value that satisfies the similarity preset condition is determined to be a second similarity value, such as the second similarity value being the maximum value among these obtained similarity values. Compare the second similarity value with the first similarity value. When the second similarity value is less than the first similarity value, it indicates that the similarity between the two strings corresponding to the first similarity value is relatively high, and convergence processing is required. The similarity between the target string and the string corresponding to the second similarity value in the string set is relatively low, and no convergence processing is required. In addition, because the two strings corresponding to the first similarity value correspond to the target pattern string in the pattern string set, the two strings corresponding to the first similarity value are converged into the target pattern string, and the target string is placed in the saved string position.
[0127] In some embodiments, the string set processing method may include the following steps: when the second similarity value is greater than the first similarity value, using specified characters to replace the difference characters between the target string and the string corresponding to the second similarity value in the string set to obtain a corresponding pattern string; using the obtained pattern string to replace the string corresponding to the second similarity value to obtain an updated string set.
[0128] Specifically, the second similarity value is compared with the first similarity value. When the second similarity value is greater than the first similarity value, it indicates that the similarity between the two character strings corresponding to the first similarity value is relatively small, and no convergence processing is required. However, the similarity between the target character string and the character string corresponding to the second similarity value in the character string set is relatively high, and convergence processing is required. The difference characters between the target character string and the character string corresponding to the second similarity value in the character string set are replaced with the specified characters to obtain the corresponding pattern character string, and the character string corresponding to the second similarity value in the character string set is replaced to obtain the updated character string set.
[0129] In this embodiment, by comparing the third similarity with the second similarity, similar character strings are converged into one category as much as possible, and different character strings are distinguished, thereby improving the accuracy of character string processing. Moreover, by preparing a similarity set and a pattern character string set in advance, the second similarity and the corresponding pattern character string are directly determined from the similarity set and the pattern character string set, thereby reducing the calculation pressure.
[0130] For specific limitations on the string set processing method, please refer to the limitations on the string set processing method above, which will not be repeated here.
[0131] It should be understood that, although the various steps in the above flowchart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the above flowchart may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0132] See also Figure 8 The embodiment of the present specification provides a string processing device, which includes: a modified distance calculation module, a similarity determination module and a difference character replacement module.
[0133] A modified distance calculation module is used to calculate a modified edit distance between a first character string and a second character string; wherein at least some characters in the first character string correspond to weight data respectively; the modified edit distance is obtained by adjusting the edit distance generated by the editing operation of converting the first character string into the second character string based on the weight data.
[0134] A similarity determination module is used to determine the similarity between the first character string and the second character string according to the modified edit distance.
[0135] The difference character replacement module is used to replace the difference characters between the first character string and the second character string with a specified character when the similarity meets the character string convergence condition, so as to obtain a corresponding first pattern character string.
[0136] For the specific definition of the string processing device, please refer to the definition of the string processing method above, which will not be repeated here. Each module in the above string processing device can be implemented in whole or in part by software, hardware and a combination thereof. The above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0137] See also Fig. 9 The embodiment of the present specification provides a string set processing device, which includes: a string receiving module, a first value determination module, a similarity value calculation module and a string replacement module.
[0138] The string receiving module is used to receive the target string.
[0139] The first value determination module is used to determine a first similarity value that meets a preset similarity condition in the similarity set.
[0140] Wherein, the similarity value in the similarity set is the similarity between any two strings in the string set; wherein the similarity value in the similarity set has a corresponding pattern string in the pattern string set; wherein the pattern string in the pattern string set is obtained by replacing the difference characters between any two strings in the string set with specified characters; wherein the pattern string corresponding to the first similarity value is used as the target pattern string.
[0141] The similarity value calculation module is used to calculate the similarity value between the target character string and each character string in the character string set, wherein the similarity value that meets the preset similarity condition is used as the second similarity value.
[0142] The string replacement module is used to replace two strings corresponding to the first similarity value in the string set with the target string and the target pattern string to obtain an updated string set when the second similarity value is less than the first similarity value.
[0143] For the specific definition of the string set processing device, please refer to the definition of the string set processing method above, which will not be repeated here. Each module in the above-mentioned string set processing device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0144] In some embodiments, a computer device is provided, which may be a terminal, and its internal structure diagram may be as shown in FIG. Fig.10 As shown. The computer device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, an operator network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, the above-mentioned string processing or string set processing method is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a button or touch pad set on the computer device housing, or an external keyboard, touch pad or mouse, etc.
[0145] Those skilled in the art will understand that Fig.10 The structure shown in the figure is merely a block diagram of a portion of the structure related to the solution disclosed in this specification, and does not constitute a limitation on the computer device to which the solution disclosed in this specification is applied. Specifically, the computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0146] In some embodiments, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the method steps in the above embodiments when executing the computer program.
[0147] In some embodiments, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the method steps in the above embodiments are implemented.
[0148] In some embodiments, a computer program product is also provided, wherein the computer program product includes instructions, and the instructions can be executed by a processor of a computer device to implement the method steps in the above embodiments.
[0149] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned implementation methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the implementation methods of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the various implementations provided in this specification may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0150] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0151] The above description is only a preferred implementation of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, etc. made within the spirit and principles of this specification should be included in the protection scope of this specification.
Claims
1. A method for processing a character string, characterized in that: The method comprises: Calculating a modified edit distance between a first character string and a second character string; wherein at least some characters in the first character string respectively correspond to weight data; the modified edit distance is obtained by adjusting the edit distance generated by an edit operation of converting the first character string into the second character string based on the weight data; determining the similarity between the first character string and the second character string according to the modified edit distance; When the similarity satisfies a string convergence condition, replacing the difference characters between the first string and the second string with a specified character to obtain a corresponding first pattern string; The weight data is determined based on the character position of the first substring targeted by the editing operation in the first character string and the character position of the second substring referenced by the editing operation in the second character string, and characters at different positions are pre-set with different weight data.
2. The method according to claim 1, characterized in that: The weight data is a function value of a weight function; wherein the input parameters of the weight function include the character position of the first substring in the first character string, and the character position of the second substring in the second character string.
3. The method according to claim 2, characterized in that The monotonic change mode of the weight function includes any one of monotonically increasing, exponentially increasing, monotonically decreasing, and exponentially decreasing.
4. The method according to claim 1, characterized in that The first character string and the second character string are at least part of a character string set; when the similarity satisfies a character string convergence condition, using a specified character to replace the difference characters between the first character string and the second character string to obtain a corresponding first pattern character string includes: When the similarity is greater than a similarity threshold, the specified character is used to replace the difference character between the first character string and the second character string to obtain the first pattern character string; wherein the first pattern character string is used to replace the first character string and the second character string in the character string set to obtain an updated character string set.
5. The method according to claim 1, characterized in that The first character string and the second character string are at least part of a character string set; the method further includes: Get the third string; Calculating the similarity between the third character string and each character string in the character string set; wherein the similarity that satisfies the preset similarity condition is taken as the first similarity; wherein the first similarity corresponds to the fourth character string in the character string set; When the first similarity is greater than a similarity threshold, the specified character is used to replace the difference character between the third character string and the fourth character string to obtain a corresponding second pattern character string; wherein the second pattern character string is used to replace the fourth character string in the character string set; or When the first similarity is less than a similarity threshold, the third character string is inserted into the character string set.
6. The method according to claim 1, characterized in that The method further comprises: Constructing an initial similarity set and an initial pattern string set; wherein the elements in the initial similarity set are initial similarity values, and the elements in the initial pattern string set are initial strings; wherein the initial similarity values correspond one to one to the initial strings; Using the similarity between the first character string and the second character string, updating the initial similarity value at the corresponding position in the initial similarity set to obtain a similarity set; The first pattern character string is used to update the initial character string at the corresponding position in the initial pattern character string set to obtain a pattern character string set.
7. The method according to claim 6, characterized in that The first character string and the second character string are at least part of a character string set; the method further includes: Get the fifth string; When there is an initial similarity value in the similarity set and there is an initial character string in the pattern character string set, calculating the similarity between the fifth character string and each character string in the character string set, and the pattern character string corresponding to the fifth character string and each character string in the character string set; Using the similarity between the fifth character string and each character string in the character string set, updating the initial similarity value at the corresponding position in the similarity set; The fifth character string and the pattern character string corresponding to each character string in the character string set are used to update the initial character string at the corresponding position in the pattern character string set.
8. The method according to claim 6, characterized in that The first character string and the second character string are at least part of a character string set; the method further includes: Get the fifth string; In the case that there is no similarity initial value in the similarity set and there is no initial character string in the pattern character string set, determining a second similarity that meets the similarity preset condition in the similarity set; wherein the second similarity corresponds to the sixth character string and the seventh character string in the character string set; Calculating the similarity between the fifth character string and each character string in the character string set; wherein the similarity that satisfies the preset similarity condition is taken as the third similarity; wherein the third similarity corresponds to the eighth character string in the character string set; When the third similarity is greater than the second similarity, the eighth character string in the character string set is replaced with a pattern character string corresponding to the fifth character string and the eighth character string to obtain an updated character string set; or When the third similarity is less than the second similarity, the sixth character string and the seventh character string in the character string set are replaced with the fifth character string and the pattern character string corresponding to the sixth character string and the seventh character string in the pattern character string set to obtain an updated character string set.
9. A method for processing a string set, characterized in that: The method comprises: Receive the target string; Determine a first similarity value that meets a preset similarity condition in a similarity set; wherein the similarity value in the similarity set is the similarity between any two strings in the string set; wherein the similarity value in the similarity set has a corresponding pattern string in a pattern string set; wherein the pattern string in the pattern string set is obtained by replacing the difference characters between any two strings in the string set with specified characters; wherein the pattern string corresponding to the first similarity value is used as a target pattern string, and the similarity is determined based on a modified edit distance between any two strings, and the modified edit distance is obtained by adjusting the edit distance between the two strings based on weight data corresponding to at least some characters in the strings, and the weight data is determined by the positions of the difference characters between the two strings in the strings, and characters at different positions are pre-set with different weight data; Calculating a similarity value between the target character string and each character string in the character string set, wherein a similarity value that satisfies a preset similarity condition is used as a second similarity value; When the second similarity value is smaller than the first similarity value, two character strings corresponding to the first similarity value in the character string set are replaced with the target character string and the target pattern character string to obtain an updated character string set.
10. The method according to claim 9, characterized in that The method further comprises: When the second similarity value is greater than the first similarity value, using a specified character to replace the difference characters between the target character string and the character string corresponding to the second similarity value in the character string set to obtain a corresponding pattern character string; The obtained pattern character string is used to replace the character string corresponding to the second similarity value to obtain an updated character string set.
11. A computer device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the method according to any one of claims 1 to 10.
12. A computer-readable storage medium, characterized in that: When the instructions in the computer-readable storage medium are executed by a processor of a computer device, the computer device is enabled to perform the method according to any one of claims 1 to 10.
13. A computer program product, characterized in that The computer program product includes instructions, and when the instructions are executed by a processor of a computer device, the computer device is enabled to perform the method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Method and device for correcting numeric string based on human-computer interaction
CN105468582A
Character string processing method and device
CN111324784A