String matching method, device, electronic device, medium and product

By obtaining and filtering the candidate character substrings of the string and their positional relationships in scenarios with small data orders, the problem of waste of computing resources and low matching efficiency in the prior art is solved, and efficient and accurate string matching is achieved.

CN119149786BActive Publication Date: 2025-08-19BEIJING VOLCANO ENGINE TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411132097.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-16
Publication Date
2025-08-19
Estimated Expiration
2044-08-16

Smart Images

  • Figure CN119149786B_ABST
    Figure CN119149786B_ABST
Patent Text Reader

Abstract

The present disclosure relates to the field of data processing technology, and discloses a method, device, electronic device, medium, and product for matching strings. The present disclosure provides a method for matching strings, including: obtaining a first string and a string to be queried, the first string including multiple first character substrings; matching each first character substring in the string to be queried, determining a candidate character substring corresponding to the first character substring and the first position of the candidate character substring in the string to be queried; determining a target character substring corresponding to the first character substring in the string to be queried based on the positional relationship between the first position corresponding to the candidate character substring and the first positions corresponding to multiple candidate character substrings; marking the target character substring, and obtaining a matching result of the string to be queried corresponding to the first string. This method can not only reduce computing costs and resource consumption, but also improve string matching efficiency and ensure the accuracy of matching results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of data processing technology, and in particular to a string matching method, device, electronic device, medium, and product. Background Art

[0002] In related technologies, for applications with large data volumes, pre-trained search models can be used for string matching. However, since pre-trained search models typically require significant computing resources for training and inference, applying them to string matching in scenarios with smaller data volumes can waste computing resources. Summary of the Invention

[0003] In view of this, the present disclosure provides a string matching method, device, electronic device, medium and product to solve the problem of string matching for small scenes of an order of magnitude.

[0004] In a first aspect, the present disclosure provides a method for matching a string, the method comprising:

[0005] Obtain a first character string and a character string to be queried, where the first character string includes multiple first character substrings;

[0006] For each first character substring, matching is performed in the character string to be queried, and a candidate character substring corresponding to the first character substring and the first position of the candidate character substring in the character string to be queried are determined;

[0007] Determining a target character substring corresponding to the first character substring in the query character string based on a first position corresponding to the candidate character substring and a positional relationship between first positions corresponding to multiple candidate character substrings;

[0008] The target character substring is marked to obtain a matching result of the query character string corresponding to the first character string.

[0009] In a second aspect, the present disclosure provides a string matching device, the device comprising:

[0010] An acquisition module, configured to acquire a first character string and a character string to be queried, wherein the first character string includes a plurality of first character substrings;

[0011] a matching module configured to match each first character substring with the character string to be queried, and determine a candidate character substring corresponding to the first character substring and a first position of the candidate character substring in the character string to be queried;

[0012] A processing module, configured to determine a target character substring corresponding to the first character substring in the query character string based on the first position corresponding to the candidate character substring and a positional relationship between the first positions corresponding to the plurality of candidate character substrings;

[0013] The marking module is used to mark the target character substring and obtain a matching result of the query character string corresponding to the first character string.

[0014] In a third aspect, the present disclosure provides an electronic device comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to thereby execute the string matching method of the first aspect or any corresponding embodiment thereof.

[0015] In a fourth aspect, the present disclosure provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the string matching method of the first aspect or any corresponding embodiment thereof.

[0016] In a fifth aspect, the present invention provides a computer program product, comprising computer instructions for causing a computer to execute the string matching method of the first aspect or any corresponding embodiment thereof.

[0017] The string matching method provided in this embodiment, when the first character substring and the character string to be queried are clearly defined, determines the target character substring corresponding to the first character substring in the character string to be queried through character matching and position relationship, and marks the target character substring, which can make the analysis process relatively simple, thereby improving the accuracy of determining the target character substring and reducing the occurrence of misrecognition, so that it can be applied to string matching processing in application scenarios with a smaller data volume, which can not only reduce computing costs and resource consumption, but also improve the matching efficiency of strings and ensure the accuracy of matching results. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the specific embodiments of the present disclosure or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0019] Figure 1 is a flowchart of a string matching method provided according to an embodiment of the present disclosure;

[0020] Figure 2 is a schematic diagram of character marking provided according to an embodiment of the present disclosure;

[0021] Figure 3 is another character marking schematic diagram provided according to an embodiment of the present disclosure;

[0022] Figure 4 is a flowchart of another string matching method provided according to an embodiment of the present disclosure;

[0023] Figure 5 is a flowchart of another string matching method provided according to an embodiment of the present disclosure;

[0024] Figure 6 is a structural block diagram of a string matching device provided according to an embodiment of the present disclosure;

[0025] Figure 7 Schematic diagram of the hardware structure of the electronic device provided by the embodiment of the present disclosure. DETAILED DESCRIPTION

[0026] To make the purpose, technical solutions, and advantages of the embodiments of the present disclosure more clear, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative efforts shall fall within the scope of protection of the present disclosure.

[0027] For application scenarios with large data volumes, pre-trained search models can be used for string matching. Since pre-trained search models typically require significant computing resources for training and inference, applying them to string matching scenarios with smaller data volumes may waste computing resources. For example, scenarios with smaller data volumes that require string matching include: string matching against small text datasets, string matching against small datasets in specific fields, and string matching for personal data management. Small text datasets can include small document collections, short messages, or emails. Small datasets in specific fields can include product descriptions and code snippets for specific industries. Personal data management can include personal notes, to-do lists, and so on.

[0028] In view of this, for scenarios where the data volume is small and string matching is required, the embodiments of the present disclosure provide a string matching method that can not only improve the accuracy of string matching but also effectively improve the matching efficiency.

[0029] According to an embodiment of the present disclosure, an embodiment of a method for matching a string is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0030] In this embodiment, a character string matching method is provided, which can be used in the above-mentioned electronic devices, such as tablets, computers, etc. Figure 1 is a flow chart of a string matching method according to an embodiment of the present disclosure, such as Figure 1 As shown, the process includes the following steps:

[0031] Step S101: Obtain a first character string and a character string to be queried.

[0032] The first character string can be understood as a character string that needs to be searched in a targeted manner, and the first character string includes multiple first character substrings. For example: if the first character string is: boxsandboxhrhourresult, then the multiple first character substrings can be: box, sandbox, hr, hour, result. In some optional examples, the multiple first character substrings can be obtained after word segmentation processing of the first character string. For example, it can be based on a local or cloud-based vocabulary to identify which characters in the first character string belong to independent character substrings, and then use the independent character substrings as the first character substring. Alternatively, word segmentation processing can be performed based on the character structure, number of character occurrences or semantics of the first character string itself. The specific word segmentation method can be determined according to actual needs and application scenarios.

[0033] The query string can be understood as the object to be matched. The query string can be obtained from local storage or the cloud, or it can be a string currently created or edited. The specific source can be determined based on actual needs.

[0034] Step S102 : For each first character substring, match it with the character string to be queried, determine the candidate character substring corresponding to the first character substring and the first position of the candidate character substring in the character string to be queried.

[0035] To determine whether the first character substring matches the query string, the query string is searched for candidate characters that match the first character substring, using the first character substring as a reference. Once the candidate character substring corresponding to the first character substring is determined, the first position of the candidate character substring in the query string is determined. The search and matching process is the same for each first character substring when determining its corresponding candidate character substring in the query string, thereby reducing unnecessary complexity and variation, thereby effectively lowering search difficulty and improving matching efficiency.

[0036] Step S103 : determining a target character substring corresponding to the first character substring in the character string to be queried based on the first position corresponding to the candidate character substring and the positional relationship between the first positions corresponding to the plurality of candidate character substrings.

[0037] Candidate character substrings can be understood as all character substrings in the query string that can match the first character substring, which may result in invalid character substrings in the obtained candidate character substrings. Therefore, to improve the reliability of string matching, the validity of candidate character substrings is screened based on the first position corresponding to the candidate character substring and the positional relationship between the first positions corresponding to multiple candidate character substrings. This can effectively reduce the occurrence of misidentification, thereby helping to improve the accuracy of determining the target character substring corresponding to the first character substring in the query string.

[0038] Step S104 : marking the target character substring to obtain a matching result of the query character string corresponding to the first character string.

[0039] By marking the target character substring, the matching results can be made more intuitive, thereby facilitating further analysis and processing. The marking methods include, but are not limited to, underlining and highlighting.

[0040] The string matching method provided in this embodiment, when the first character substring and the character string to be queried are clearly defined, determines the target character substring corresponding to the first character substring in the character string to be queried through character matching and position relationship, and marks the target character substring, which can make the analysis process relatively simple, thereby improving the accuracy of determining the target character substring and reducing the occurrence of misrecognition, so that it can be applied to string matching processing in application scenarios with a smaller data volume, which can not only reduce computing costs and resource consumption, but also improve the matching efficiency of strings and ensure the accuracy of matching results.

[0041] In some optional implementations, the above step S102 includes:

[0042] In step a1, the first character substring is matched bit by bit with the characters in the query string. In response to traversing all the characters in the query string, a candidate character substring corresponding to the first character substring and the first position of the candidate character substring in the query string are obtained.

[0043] Specifically, the first character of the first character substring is matched against the characters in the query string bit by bit. If a character that matches the first character appears in the query string, the next character after that character is compared against the second character of the first character substring, and so on, until all characters of the first character substring are matched against the corresponding characters in the query string, or no matching characters are found in the query string.

[0044] If a character sequence that completely matches the first character substring is found in the query string, the character sequence is marked as a candidate character substring and its first position in the query string is recorded. If some characters in the query string are not matched, the traversal continues to find all candidate character substrings in the query string that match the first character substring and their corresponding first positions. This effectively reduces the occurrence of missed matches and helps improve matching accuracy.

[0045] In some optional examples, the process of determining the candidate character substring includes:

[0046] Step b1, determining a plurality of characters in a first character substring and a corresponding first character sequence;

[0047] Step b2: Match the first character substring with the characters in the query string bit by bit based on the multiple characters and the corresponding first character sequence. If there is a second character substring that is the same as the multiple characters and has the same arrangement order as the first character sequence, then the second character substring is used as the candidate character substring corresponding to the first character substring.

[0048] Specifically, in order to clarify the first character substring that needs to be searched currently, multiple characters in the first character substring and the corresponding first character sequence are determined to serve as a search reference, thereby facilitating subsequent targeted searches.

[0049] The characters in the first character substring are compared one by one with the characters in the query string in the first character order. If a second character substring is found in the query string that is identical to the characters in the first character substring and arranged in the same order, it indicates that a character substring corresponding to the first character substring exists in the query string, and therefore the second character substring is selected as a candidate character substring corresponding to the first character substring.

[0050] The above method for determining candidate character substrings strictly matches according to character order, thereby ensuring that the resulting candidate character substring is completely identical to the first character substring, thereby effectively improving matching accuracy. Furthermore, the logic of the above matching process is relatively intuitive and easy to understand, and can be widely applied in various scenarios requiring string processing, such as text searching and pattern matching, with wide applicability.

[0051] In some optional implementation scenarios, the first character string is: boxsandboxhrhourresult, and the query character string is: In the vast Sandbox and SAND of opportunities box, we work hour after hour, day after day, to turn dreams into reality, hr after hr, to achieve outstanding results. The process of determining the candidate character substrings and the corresponding first positions of each first character substring in the query character string can be as follows: first mark each character in the first character substring in order, and obtain the following: Figure 2 The tagging result shown in the figure is then segmented to obtain the following multiple first character substrings: box, sandbox, and, sand, hour, hr. Each character in the query string is marked in order to obtain the following: Figure 3 The marking result shown. According to the multiple characters in the first character substring and the corresponding first character sequence, the first character substring is matched bit by bit with the characters in the character string to be queried. If there is a second character substring that is the same as the multiple characters and has the same arrangement order as the first character sequence, the second character substring is used as the candidate character substring corresponding to the first character substring. In response to traversing all the characters in the character string to be queried, the candidate character substring corresponding to the first character substring and the first position of the candidate character substring in the character string to be queried are obtained. In one example, the first character sequence corresponding to the multiple characters in the first character substring can be represented by its position in the first character string.

[0052] For example: Combine Figure 2 and Figure 3 The marks shown, the multiple characters corresponding to each first character substring, the first character sequence, and the first position of the corresponding candidate character substring in the query string can be as shown in Table 1:

[0053] Table 1

[0054] First character substring Position in the first string First position box [0,2][7,9] [16,18][46,48] sandbox [3,9] [12,18] and [4,6] [13,15][20,22][25,27] sand [3,6] [12,15][24,27] hour [12,15] [59,62][70,73] hr [10,11] [120,121][129,130]

[0055] In this embodiment, a character string matching method is provided, which can be used in the above-mentioned electronic devices, such as tablets, computers, etc. Figure 4 is a flow chart of a method for matching strings according to an embodiment of the present disclosure, such as Figure 4 As shown, the process includes the following steps:

[0056] Step S401: Get the first character string and the character string to be queried. Figure 1Step S101 of the illustrated embodiment will not be described in detail here.

[0057] Step S402: For each first character substring, match it with the query string to determine the candidate character substring corresponding to the first character substring and the first position of the candidate character substring in the query string. Figure 1 Step S102 of the illustrated embodiment will not be described in detail here.

[0058] Step S403 : determining a target character substring corresponding to the first character substring in the character string to be queried based on the first position corresponding to the candidate character substring and the positional relationship between the first positions corresponding to multiple candidate character substrings.

[0059] In some optional implementations, the above step S403 includes:

[0060] Step S4031 , based on the first position corresponding to the candidate character substring, determine whether there is a first candidate character substring in the first positions corresponding to other candidate character substrings that overlaps with the first position of the candidate character substring.

[0061] Because different character substrings may contain some of the same characters, to improve the quality of matching results and reduce duplicate recognition, a determination is made based on the first position of a candidate character substring to determine whether any of the first positions of other candidate character substrings overlap with the first position of the candidate character substring. In other words, a first candidate character substring can be understood as a character substring in which some or all of its characters in the query string overlap with characters in the candidate character substring.

[0062] In some optional implementations, the above step S4031 includes:

[0063] Step c1, determining the language type corresponding to the first character substring;

[0064] Step c2, in response to the language type corresponding to the first character substring being the first language type, determine, based on the first position corresponding to the candidate character substring, whether there is a first candidate character substring in the first positions corresponding to other candidate character substrings that overlaps with the first position of the candidate character substring.

[0065] Specifically, since the character substrings corresponding to different language types express different contents, in order to improve the matching efficiency, the language type corresponding to the first character substring is first determined. The language type may include but is not limited to Chinese, English or a minority language. In response to the fact that the language type corresponding to the first character substring is the first language type, the first character substring representing this type is characterized in the matching process, and the corresponding candidate character substrings are all relatively complete character substrings in the query character string. Therefore, it is possible to directly determine, based on the first position corresponding to the candidate character substring, whether there is a first candidate character substring that overlaps with the first position of the candidate character substring in the first position corresponding to other candidate character substrings, thereby helping to improve the matching efficiency and reduce the occurrence of conflicts and confusion. For example, the first language type may be Chinese.

[0066] In some other optional implementations, the above step S4031 further includes:

[0067] Step c3: in response to the language type corresponding to the first character substring being the second language type, determining whether the candidate character substring is a complete character substring in the query character string based on the first position corresponding to the candidate character substring;

[0068] Step c4: If the candidate character substring is a complete character substring, determine, based on the first position corresponding to the candidate character substring, whether there is a first candidate character substring in the first positions corresponding to other candidate character substrings that overlaps with the first position of the candidate character substring.

[0069] Specifically, if the language type corresponding to the first character substring is the second language type, then during the matching process of the first character substring representing this type, the corresponding candidate character substring is likely to be repeatedly recognized or confusedly recognized in the character string to be queried. Therefore, in order to avoid misjudgment, it is first determined whether the candidate character substring is a complete character substring in the character string to be queried. Then, when it is determined that the candidate character substring is a complete character substring, it is determined based on the first position corresponding to the candidate character substring whether there is a first candidate character substring in the first position corresponding to other candidate character substrings that overlaps with the first position of the candidate character substring. This can avoid repeated processing of candidate character substrings at the same position and improve processing efficiency.

[0070] In some further optional implementations, the above step S4031 further includes:

[0071] Step c5: If the candidate character substring is an incomplete character substring, delete the candidate character substring.

[0072] That is, if the candidate character substring is an incomplete character substring, it indicates that the candidate character substring is a part of the corresponding character substring in the query character string, and is not an independent character substring. Therefore, the candidate character substring is an invalid character substring, so it is deleted to avoid interfering with the determination quality of the target character substring.

[0073] For example, if the candidate character substring is out, and it is a part of outstanding in the query character string, it can be determined that the candidate character substring is an incomplete character substring and is deleted.

[0074] In step S4032, if there are first candidate character substrings with overlapping positions, based on the comparison result between the first position interval length and the second position interval length, the character substring with the longest position interval length is used as the target character substring corresponding to the first character substring in the character string to be queried.

[0075] If there is a first candidate character substring with overlapping positions, it indicates that there may be repeated recognition of characters in some candidate character substrings. Therefore, in order to avoid unnecessary calculations and errors, the length of the first position interval is compared with the length of the second position interval to determine the comparison result. Among them, the length of the first position interval is the length of the position interval of the candidate character substring corresponding to the first position, and the length of the second position interval is the length of the position interval of the first candidate character substring corresponding to the first position. The longer the position interval length, the higher the accuracy of the corresponding candidate character substring and the lower the probability of misrecognition. Therefore, according to the comparison result, the character substring with the longest position interval length is used as the target character substring corresponding to the first character substring in the character string to be queried, thereby improving the effectiveness and accuracy of determining the target character substring.

[0076] In some optional implementations, candidate character substrings with overlapping positions and whose position interval lengths are not the longest can be deleted, so as to remove duplicate matching characters and thereby improve the quality of the target character substring.

[0077] For example, taking Table 1 above as an example, if the candidate character substring is sandbox, its corresponding first position is [12,18], and the first position interval length is 7; the first candidate character substrings are box, and, and sand. The second position corresponding to box is [16,18], and the second position interval length is 3; the second position corresponding to and is [13,15], and the second position interval length is 3; the second position corresponding to sand is [12,15], and the second position interval length is 4. By comparison, it can be seen that the position interval length of sandbox is the longest. Therefore, sandbox with a first position of [12,18] is used as the target character substring corresponding to the first character substring in the query string. Box with a second position of [16,18], and with a second position of [13,15], and sand with a second position of [12,15] are deleted.

[0078] Step S4033: If there is no first candidate character substring with overlapping positions, the candidate character substring is used as the target character substring corresponding to the first character substring in the character string to be queried.

[0079] If there is no first candidate character substring with overlapping positions, it indicates that there is no repeated recognition of characters in the candidate character substring. Therefore, the candidate character substring can be directly used as the target character substring corresponding to the first character substring in the query character string.

[0080] Step S404: Mark the target character substring and obtain the matching result of the query character string corresponding to the first character string. Figure 1 Step S104 of the illustrated embodiment will not be described in detail here.

[0081] The string matching method provided in this embodiment compares the lengths of position intervals and selects the longest character substring as the target character substring. This can more accurately determine the part that matches the first character substring, improve the accuracy of the target character substring, and help avoid repeated processing of candidate character substrings with overlapping positions, which is beneficial to improving matching efficiency.

[0082] As one or more specific application embodiments of the embodiments of the present disclosure, taking the first string as: boxsandboxhrhourresult and the query string as: In the vast Sandbox and SAND ofopportunities box, we work hour after hour, day after day, to turn dreams into reality, hr after hr, to achieve outstanding results as an example, the string matching process is as follows:

[0083] Mark each character in the first character substring in order, and get Figure 2 The tagging result shown in FIG. 1 is then segmented to obtain the following multiple first character substrings: box, sandbox, and, sand, hour, and hr. The order of the first characters corresponding to the multiple characters in the first character substring can be represented by their positions in the first character string.

[0084] Mark each character in the query string in order, and get the following Figure 3 The marking result shown. According to the multiple characters in the first character substring and the corresponding first character sequence, the first character substring is matched bit by bit with the characters in the character string to be queried. If there is a second character substring that is the same as the multiple characters and has the same arrangement order as the first character sequence, the second character substring is used as the candidate character substring corresponding to the first character substring. In response to traversing all the characters in the character string to be queried, the candidate character substring corresponding to the first character substring and the first position of the candidate character substring in the character string to be queried are obtained. The multiple characters corresponding to each first character substring, the first character sequence and the first position of the corresponding candidate character substring in the character string to be queried can be shown in Table 1:

[0085] Table 1

[0086] First character substring Position in the first string First position box [0,2][7,9] [16,18][46,48] sandbox [3,9] [12,18] and [4,6] [13,15][20,22][25,27] sand [3,6] [12,15][24,27] hour [12,15] [59,62][70,73] hr [10,11] [120,121][129,130]

[0087] Based on the first position of each candidate character string in the query string and the length of the corresponding position interval, each candidate character string is deduplicated. The box [16,18], the and [13,15], and the sand [12,15] are deleted, leaving the box [46,48] and the sandbox [12,18]. Since hour and hr do not overlap in the query string interval, they are retained. Therefore, the retained candidate character substrings are used as the target character substrings corresponding to the first character substring in the query string and are specifically labeled, resulting in a match result for the query string corresponding to the first character substring.

[0088] As another one or more specific application embodiments of the present disclosure, the process of performing string matching can be as follows: Figure 5 As shown. Includes:

[0089] Step 1: traverse the first character substring and the query string to find whether there are identical characters. If so, record the position of the current character in the first string and the corresponding position in the query string, and go to step 2. If not, go to step 7.

[0090] Step 2: record the starting character of the current first character substring, and shift the position of the current first character substring and the position of the character string to be queried one position backward, and then proceed to step 3.

[0091] Step 3: Compare the current character in the query string with the current first character substring to see if they exist and are consistent. Otherwise, the process ends and proceeds to step 5. If they exist and are consistent, the process proceeds to step 4.

[0092] Step 4: Splice the current identical characters to the end of the substring, and shift the position of the current first character substring in the first character string and the first position back by one position, and repeat step 3.

[0093] Step 5: Calculate the first position interval (k') of the current substring in the first string, and determine whether k' is a subinterval of any interval in the interval set (K) of the first string. If so, proceed to step 1; otherwise, record k' in K and proceed to step 6.

[0094] Step 6: Determine whether the current first character substring is English. If yes, proceed to step 7. Otherwise, proceed to step 8.

[0095] Step 7: Determine whether the candidate character substring corresponding to the current first character substring is a complete word in the query character string. If yes, proceed to step 8. Otherwise, return to step 1.

[0096] Step 8: Calculate the position interval n' of the candidate character substring in the character string to be queried, record the interval n' in the interval set N of the character string to be queried, and repeat step 1.

[0097] Step 9: Remove the covered intervals in the interval set K and go to step 8.

[0098] Step 10: Calculate the first position of the remaining interval of K in K and proceed to step 9.

[0099] Step 11: Calculate the corresponding position intervals of these first positions in the set N of intervals of the character string to be queried, and remove the covered position intervals, and end.

[0100] In this embodiment, a string matching device is also provided, which is used to implement the above-mentioned embodiments and preferred embodiments. The details already described will not be repeated here. As used below, the term "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.

[0101] This embodiment provides a string matching device, such as Figure 6 Shown, including:

[0102] An acquisition module 601 is configured to acquire a first character string and a character string to be queried, wherein the first character string includes a plurality of first character substrings;

[0103] A matching module 602 is configured to match each first character substring with the query string to determine a candidate character substring corresponding to the first character substring and a first position of the candidate character substring in the query string;

[0104] A processing module 603 is configured to determine a target character substring corresponding to the first character substring in the query character string based on the first position corresponding to the candidate character substring and the positional relationship between the first positions corresponding to the plurality of candidate character substrings;

[0105] The marking module 604 is configured to mark the target character substring and obtain a matching result where the query character string corresponds to the first character string.

[0106] In some optional implementations, the matching module 602 includes:

[0107] The character matching unit is used to match the first character substring with the characters in the character string to be queried bit by bit, and in response to traversing all the characters in the character string to be queried, obtain a candidate character substring corresponding to the first character substring and the first position of the candidate character substring in the character string to be queried.

[0108] In some optional implementations, the character matching unit includes:

[0109] a first determining unit, configured to determine a plurality of characters in a first character substring and a corresponding first character sequence;

[0110] The first processing unit is used to match the first character substring with the characters in the query character string bit by bit based on multiple characters and the corresponding first character sequence. If there is a second character substring that is the same as the multiple characters and has the same arrangement order as the first character sequence, the second character substring is used as a candidate character substring corresponding to the first character substring.

[0111] In some optional implementations, the processing module 603 includes:

[0112] a second processing unit, configured to determine, based on the first position corresponding to the candidate character substring, whether there is a first candidate character substring in the first positions corresponding to other candidate character substrings that overlaps with the first position of the candidate character substring;

[0113] a third processing unit, configured to, if there are first candidate character substrings with overlapping positions, select, based on a comparison result between a first position interval length and a second position interval length, the character substring with the longest position interval length as the target character substring corresponding to the first character substring in the character string to be queried, wherein the first position interval length is the position interval length of the candidate character substring corresponding to the first position, and the second position interval length is the position interval length of the first candidate character substring corresponding to the first position;

[0114] The fourth processing unit is configured to use the candidate character substring as a target character substring corresponding to the first character substring in the character string to be queried if there is no first candidate character substring with overlapping positions.

[0115] In some optional implementations, the processing module 603 further includes:

[0116] The fifth processing unit is used to delete the candidate character substrings that have overlapping positions and whose position interval length is not the longest.

[0117] In some optional embodiments, the second processing unit includes:

[0118] A first execution unit, configured to determine a language type corresponding to the first character substring;

[0119] The second execution unit is used to determine, in response to the language type corresponding to the first character substring being the first language type, whether there is a first candidate character substring overlapping with the first position of the candidate character substring in the first positions corresponding to other candidate character substrings based on the first position corresponding to the candidate character substring.

[0120] In some optional implementations, the second processing unit further includes:

[0121] a third execution unit, configured to, in response to the language type corresponding to the first character substring being the second language type, determine, based on the first position corresponding to the candidate character substring, whether the candidate character substring is a complete character substring in the character string to be queried;

[0122] The fourth execution unit is used to determine, if the candidate character substring is a complete character substring, whether there is a first candidate character substring in the first position corresponding to other candidate character substrings that overlaps with the first position of the candidate character substring based on the first position corresponding to the candidate character substring.

[0123] In some optional implementations, the second processing unit further includes:

[0124] The fifth execution unit is configured to delete the candidate character substring if the candidate character substring is an incomplete character substring.

[0125] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0126] The string matching device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.

[0127] The present disclosure also provides an electronic device having the above Figure 6 The string shown is matched by the device.

[0128] See also Figure 7 , Figure 7 is a structural diagram of an electronic device provided by an optional embodiment of the present disclosure, such as Figure 7 As shown, the electronic device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components utilize different buses to communicate with each other and can be installed on a common mainboard or installed in other ways as needed. The processor can process instructions executed in the electronic device, including instructions stored in or on the memory to display graphical information of a GUI on an external input / output device (such as a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple electronic devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 10 is taken as an example.

[0129] The processor 10 may be a central processing unit, a network processor, or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit, a programmable logic device, or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic, or any combination thereof.

[0130] The memory 20 stores instructions that can be executed by at least one processor 10, so as to enable at least one processor 10 to execute the method shown in the above embodiment.

[0131] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and applications required for at least one function; the data storage area may store data created based on the use of the electronic device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely located relative to the processor 10, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0132] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid-state drive; the memory 20 may also include a combination of the above types of memory.

[0133] The electronic device further includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 may be connected via a bus or other means. Figure 7 The bus connection is taken as an example.

[0134] The input device 30 can receive input digital or character information and generate key signal input related to user settings and function control of the electronic device, such as a touch screen, a keypad, a mouse, a trackpad, a touch pad, an indicator stick, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 can include a display device, an auxiliary lighting device (e.g., an LED), and a tactile feedback device (e.g., a vibration motor). The above-mentioned display device includes but is not limited to a liquid crystal display, a light emitting diode, a display, and a plasma display. In some optional embodiments, the display device can be a touch screen.

[0135] The embodiments of the present disclosure also provide a computer-readable storage medium. The above-mentioned method according to the embodiments of the present disclosure can be implemented in hardware, firmware, or implemented as a computer code that can be recorded in a storage medium, or implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and downloaded through a network and will be stored in a local storage medium, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state drive, etc.; further, the storage medium can also include a combination of the above-mentioned types of memory. It can be understood that a computer, a processor, a microprocessor controller or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor or hardware, the method shown in the above embodiment is implemented.

[0136] A portion of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the form in which the computer program instruction exists in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc. Accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium that can be accessed by the computer.

[0137] It is understandable that before using the technical solutions disclosed in the various embodiments of this disclosure, the type, scope of use, usage scenarios, etc. of the personal information involved in this disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.

[0138] For example, in response to a user's active request, a prompt message is sent to the user to clearly inform the user that the operation requested will require the acquisition and use of the user's personal information. This allows the user to independently choose whether to provide personal information to the electronic device, application, server, storage medium, or other software or hardware that performs the operations of the disclosed technical solution based on the prompt message.

[0139] As an optional but non-limiting implementation, in response to receiving a user's active request, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. Furthermore, the pop-up window may also contain a selection control for the user to select "agree" or "disagree" to provide personal information to the electronic device.

[0140] It is understandable that the above notification and user authorization process are merely illustrative and do not limit the implementation of the present disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of the present disclosure.

[0141] Although the embodiments of the present disclosure have been described with reference to the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present disclosure, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A method for matching a character string, characterized in that: The method comprises: Obtaining a first character string and a character string to be queried, wherein the first character string includes a plurality of first character substrings; For each of the first character substrings, matching is performed on the character string to be queried, and a candidate character substring corresponding to the first character substring and a first position of the candidate character substring in the character string to be queried are determined; Determining a target character substring corresponding to the first character substring in the character string to be queried based on the first position corresponding to the candidate character substring and a positional relationship between the first positions corresponding to multiple candidate character substrings; Marking the target character substring to obtain a matching result of the query character string corresponding to the first character string; The determining, based on the first position corresponding to the candidate character substring and the positional relationship between the first positions corresponding to multiple candidate character substrings, a target character substring corresponding to the first character substring in the character string to be queried, includes: Determining, based on the first position corresponding to the candidate character substring, whether there is a first candidate character substring in the first position corresponding to other candidate character substrings that overlaps with the first position of the candidate character substring; If there are any first candidate character substrings with overlapping positions, based on the comparison result between the first position interval length and the second position interval length, the character substring with the longest position interval length is used as the target character substring corresponding to the first character substring in the query character string, wherein the first position interval length is the position interval length of the candidate character substring corresponding to the first position, and the second position interval length is the position interval length of the first candidate character substring corresponding to the first position; If there is no first candidate character substring with overlapping position, the candidate character substring is used as the target character substring corresponding to the first character substring in the character string to be queried.

2. The method according to claim 1, characterized in that The matching of each of the first character substrings in the character string to be queried to determine a candidate character substring corresponding to the first character substring and a first position of the candidate character substring in the character string to be queried includes: The first character substring is matched bit by bit with the characters in the character string to be queried. In response to traversing all the characters in the character string to be queried, a candidate character substring corresponding to the first character substring and the first position of the candidate character substring in the character string to be queried are obtained.

3. The method according to claim 2, characterized in that The process of determining the candidate character substring includes: determining a plurality of characters in the first character substring and a corresponding first character order; According to the multiple characters and the corresponding first character sequence, the first character substring is matched bit by bit with the characters in the character string to be queried. If there is a second character substring that is the same as the multiple characters and has the same arrangement order as the first character sequence, the second character substring is used as a candidate character substring corresponding to the first character substring.

4. The method according to claim 1, wherein The determining, based on the first position corresponding to the candidate character substring and the positional relationship between the first positions corresponding to multiple candidate character substrings, a target character substring corresponding to the first character substring in the character string to be queried, further includes: Delete the candidate character substrings that have overlapping positions and whose position interval length is not the longest.

5. The method according to claim 1, wherein The determining, based on the first position corresponding to the candidate character substring, whether there is a first candidate character substring in the first position corresponding to other candidate character substrings that overlaps with the first position of the candidate character substring includes: Determining a language type corresponding to the first character substring; In response to the language type corresponding to the first character substring being the first language type, based on the first position corresponding to the candidate character substring, determine whether there is a first candidate character substring in the first position corresponding to other candidate character substrings that overlaps with the first position of the candidate character substring.

6. The method according to claim 5, characterized in that The determining, based on the first position corresponding to the candidate character substring, whether there is a first candidate character substring in the first position corresponding to other candidate character substrings that overlaps with the first position of the candidate character substring further includes: In response to the language type corresponding to the first character substring being the second language type, determining, based on the first position corresponding to the candidate character substring, whether the candidate character substring is a complete character substring in the character string to be queried; If the candidate character substring is a complete character substring, then based on the first position corresponding to the candidate character substring, determine whether there is a first candidate character substring in the first position corresponding to other candidate character substrings that overlaps with the first position of the candidate character substring.

7. The method according to claim 6, characterized in that The determining, based on the first position corresponding to the candidate character substring, whether there is a first candidate character substring in the first position corresponding to other candidate character substrings that overlaps with the first position of the candidate character substring further includes: If the candidate character substring is an incomplete character substring, the candidate character substring is deleted.

8. A string matching device, characterized in that: The device comprises: An acquisition module, configured to acquire a first character string and a character string to be queried, wherein the first character string includes a plurality of first character substrings; a matching module configured to match each of the first character substrings with the character string to be queried, and determine a candidate character substring corresponding to the first character substring and a first position of the candidate character substring in the character string to be queried; A processing module, configured to determine a target character substring corresponding to the first character substring in the character string to be queried based on the first position corresponding to the candidate character substring and a positional relationship between the first positions corresponding to multiple candidate character substrings; a marking module, configured to mark the target character substring and obtain a matching result of the query character string corresponding to the first character string; The processing module includes: a second processing unit, configured to determine, based on the first position corresponding to the candidate character substring, whether there is a first candidate character substring in the first position corresponding to other candidate character substrings that overlaps with the first position of the candidate character substring; a third processing unit, configured to, if there are any first candidate character substrings with overlapping positions, select, based on a comparison result between the first position interval length and the second position interval length, the character substring with the longest position interval length as the target character substring corresponding to the first character substring in the character string to be queried, wherein the first position interval length is the position interval length of the candidate character substring corresponding to the first position, and the second position interval length is the position interval length of the first candidate character substring corresponding to the first position; The fourth processing unit is configured to use the candidate character substring as a target character substring corresponding to the first character substring in the character string to be queried if there is no first candidate character substring with overlapping positions.

9. An electronic device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the character string matching method according to any one of claims 1 to 7 by executing the computer instructions.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the character string matching method according to any one of claims 1 to 7.

11. A computer program product, characterized in that The method comprises computer instructions, wherein the computer instructions are used to cause a computer to execute the character string matching method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Text matching method and device

    CN108182222A