Character string matching method and device, electronic equipment, medium and product
The method improves string matching accuracy and efficiency by identifying target substrings based on positional relationships, addressing inefficiencies in pre-trained models for small data scenarios.
Patent Information
- Application Number
- CN202411132097.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-16
- Publication Date
- 2024-12-17
- Estimated Expiration
- 2044-08-16
AI Technical Summary
Pre-trained search models for string matching are inefficient and wasteful of computing resources when applied to scenarios with small data volumes.
A method for string matching that involves obtaining a first character string and a query string, identifying candidate substrings, determining target substrings based on positional relationships, and marking these substrings to improve accuracy and efficiency.
Reduces computing costs and resource consumption while enhancing the accuracy and efficiency of string matching in scenarios with small data volumes.
Smart Images

Figure CN119149786A_ABST
Abstract
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 the related art, for application scenarios with large data volumes, pre-trained search models can be used for string matching. Since pre-trained search models usually require a large amount of computing resources for training and reasoning, if they are used for string matching in scenarios with small data volumes, computing resources may be wasted. 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, wherein the first character string includes a plurality of 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] Determine a target character substring corresponding to the first character substring in the character string to be queried 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, used for acquiring 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 in 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 character string to be queried based on a first position corresponding to the candidate character substring and a positional relationship between first positions corresponding to a plurality of candidate character substrings;
[0013] The marking module is used to mark the target character substring to obtain a matching result of the character string to be queried 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 are communicatively connected to each other, the memory stores computer instructions, and the processor executes the string matching method of the above-mentioned first aspect or any corresponding embodiment thereof by executing the computer instructions.
[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, including computer instructions, wherein the computer instructions are used to enable a computer to execute the string matching method of the first aspect or any corresponding embodiment thereof.
[0017] The string matching method provided in the present embodiment, when the first character substring and the string to be queried are clear, clarifies the target character substring corresponding to the first character substring in the string to be queried by means of 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 perform string matching processing in application scenarios with a small amount of data, 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 drawings required for use in the specific embodiments or the description of the prior art will be briefly introduced below. 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 method for matching strings provided according to an embodiment of the present disclosure;
[0020] Figure 2 is a character marking schematic diagram 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 It is a schematic diagram of the hardware structure of the electronic device provided by the embodiment of the present disclosure. DETAILED DESCRIPTION
[0026] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution 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, rather than all the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative work are 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 usually require a large amount of computing resources for training and reasoning, if they are applied to scenarios with small data volumes for string matching, computing resources may be wasted. For example, scenarios with small data volumes and the need for string matching may include: scenarios for string matching for small-scale text data sets, scenarios for string matching for small data sets in specific fields, scenarios for string matching for personal data management, etc. Small-scale text data sets may include small document collections, short messages, or emails, etc. Small data sets in specific fields may include product descriptions, code snippets, etc. for specific industries. Personal data management may include personal notes, to-do lists, etc.
[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, which 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 method for matching a character string is provided, which can be used in the above-mentioned electronic devices, such as tablets, computers, etc. Figure 1 is a flowchart of a method for matching a string according to an embodiment of the present disclosure, such as Figure 1 As shown, the process includes the following steps:
[0031] Step S101, obtaining 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 substrings. 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 an object that needs 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 according to actual needs.
[0034] Step S102, 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.
[0035] In order to determine the matching of the first character substring in the character string to be queried, the first character substring is used as a reference to search for candidate characters matching the first character substring in the character string to be queried, and then, when the candidate character substring corresponding to the first character substring is determined, the first position of the candidate character substring in the character string to be queried is determined. Among them, for each first character substring, when determining the candidate character substring corresponding to the character string to be queried, the search and matching process is the same, thereby reducing unnecessary complexity and changes, thereby effectively reducing the difficulty of searching and improving matching efficiency.
[0036] Step S103, 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, determine the target character substring corresponding to the first character substring in the character string to be queried.
[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, in order 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, which 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 obtained matching result can be made more intuitive, thereby facilitating further analysis and processing. The marking methods include but are not limited to: adding underline, highlighting, etc.
[0040] The string matching method provided in the present embodiment, when the first character substring and the string to be queried are clear, clarifies the target character substring corresponding to the first character substring in the string to be queried by means of 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 perform string matching processing in application scenarios with a small amount of data, 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] Step a1, matching the first character substring bit by bit with the characters in the string to be queried, in response to traversing all the characters in the string to be queried, obtaining 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.
[0043] Specifically, the first character of the first character substring is matched bit by bit with the characters in the string to be queried. If the same character as the first character appears in the string to be queried, the next character of the character is compared with the second character of the first character substring, and so on, until all characters of the first character substring are successfully matched with the corresponding characters in the string to be queried, or no matching characters are found in the string to be queried.
[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 is continued to find all candidate character substrings that match the first character substring in the query string and their corresponding first positions, which can effectively reduce the occurrence of missed matches and help improve the accuracy of matching.
[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, according to multiple characters and the corresponding first character sequence, match the first character substring with the characters in the query character string bit by bit. 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 a 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] According to the first character sequence, the characters in the first character substring are compared one by one with the characters in the character string to be queried. If a second character substring is found in the character string to be queried that is completely identical to the characters in the first character substring and has the same arrangement sequence as the characters in the first character substring, it indicates that there is a character substring corresponding to the first character substring in the character string to be queried, so the second character substring is used as a candidate character substring corresponding to the first character substring.
[0050] The above method for determining the candidate character substring is to match strictly in the order of characters, thereby ensuring that the obtained candidate character substring is a character substring that is completely consistent with the first character substring, thereby effectively improving the accuracy of the match. In addition, the logic of the above matching process is relatively intuitive and easy to understand, and can be widely used in various scenarios that require string processing, such as text search, pattern matching, etc., and has 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 afterhour, day after day, to turn dreams into reality, hr after hr, to achieve outstanding results. The process of determining the candidate character substrings of each first character substring in the query character string and the corresponding first position 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 FIG. 1 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, 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. 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 character 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 method for matching a character string is provided, which can be used in the above-mentioned electronic devices, such as tablets, computers, etc. Figure 4 is a flowchart of a method for matching a string according to an embodiment of the present disclosure, such as Figure 4 As shown, the process includes the following steps:
[0056] Step S401, obtain 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 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. Figure 1 Step S102 of the illustrated embodiment will not be described in detail here.
[0058] Step S403, 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, determine the target character substring corresponding to the first character substring in the character string to be queried.
[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] Since different character substrings may have some of the same characters, in order to improve the quality of the matching results and reduce the occurrence of repeated recognition, it is determined 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. That is, the first candidate character substring can be understood as a character substring in which some or all of the characters in the query character string overlap with the 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. Therefore, 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 language type corresponding to the first character substring being 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 character string to be queried. 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 character string to be queried according to 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 overlapping with the first position of the candidate character substring in the first positions corresponding to other candidate character substrings.
[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 prone to repeated recognition or confused recognition 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 that overlaps with the first position of the candidate character substring in the first position corresponding to other candidate character substrings. 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 character string to be queried, it can be determined that the candidate character substring is an incomplete character substring and is deleted.
[0074] 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 corresponding to the first position of the candidate character substring, and the length of the second position interval is the length of the position interval corresponding to the first position of the first candidate character substring. 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 length is not the longest may be deleted, so that repeated matching characters can be deleted through deduplication, thereby achieving the purpose of improving 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 length of the first position interval is 7; the first candidate character substrings are box, and, and sand. The second position corresponding to box is [16,18], and the length of the second position interval is 3; the second position corresponding to and is [13,15], and the length of the second position interval is 3; the second position corresponding to sand is [12,15], and the length of the second position interval is 4. By comparison, it can be seen that the position interval length of sandbox is the longest. Therefore, sandbox with the first position [12,18] is used as the target character substring corresponding to the first character substring in the query string. Delete box with the second position [16,18], and with the second position [13,15], and sand with the second position [12,15].
[0078] Step S4033: 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.
[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 character string to be queried.
[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 length of the position interval 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 string to be queried 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 process of string matching is as follows:
[0083] Mark each character in the first character substring in order, and get Figure 2 The tagging result shown is then segmented to obtain the following multiple first character substrings: box, sandbox, and, sand, hour, hr. The first character sequence 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 of 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 string to be queried and the length of the corresponding position interval, each candidate character string is deduplicated, and the box of [16,18], the and of [13,15], and the sand of [12,15] are deleted, leaving the box of [46,48] and the sandbox of [12,18]. However, the intervals of hour and hr in the string to be queried do not overlap with each other, so they are retained. Therefore, the retained candidate character substring is used as the target character substring corresponding to the first character substring in the string to be queried, and is specifically marked, so as to obtain the matching result of the string to be queried 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 yes, 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 proceed to step 3.
[0091] Step 3, compare whether the current character and the current first character substring in the query string exist and are consistent, otherwise end and go to step 5. If they exist and are consistent, go 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. If no, 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 go to step 9.
[0099] Step 11, calculate the corresponding position intervals of these first positions in the set N of character string intervals to be queried, and remove the covered position intervals therein, and end.
[0100] In the present embodiment, a string matching device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0101] This embodiment provides a string matching device, such as Figure 6 As shown, including:
[0102] An acquisition module 601 is used 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 used to match each first character substring in 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;
[0104] Processing module 603, for 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;
[0105] The marking module 604 is used to mark the target character substring to obtain a matching result of the to-be-queried character string corresponding 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, used 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 according to 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 is used to determine, based on the first position corresponding to the candidate character substring, 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;
[0113] A third processing unit is used for, 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, taking 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 implementations, 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 according to 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 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 if the candidate character substring is a complete character substring.
[0123] In some optional implementations, the second processing unit further includes:
[0124] The fifth execution unit is used 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 schematic diagram of the structure 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 are connected to each other using different buses for communication, 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 the 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 a dedicated 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 executable by at least one processor 10, so that at least one processor 10 executes 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, an application required for at least one function; the data storage area may store data created according to 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 arranged 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 example of connecting through bus is taken in the following.
[0134] The input device 30 can receive input digital or character information, and generate key signal input related to the user settings and function control of the electronic device, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator rod, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 may include a display device, an auxiliary lighting device (e.g., an LED) and a tactile feedback device (e.g., a vibration motor), etc. 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 can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium and downloaded through a network, 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 part 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 existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and 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 accessible to the computer.
[0137] It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, scope of use, usage scenarios, etc. of the personal information involved in the present 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 receiving an active request from a user, a prompt message is sent to the user to clearly prompt the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can autonomously choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present disclosure according to the prompt message.
[0139] As an optional but non-limiting implementation, in response to receiving an active request from the user, 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. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.
[0140] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet the 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 in conjunction with 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: Obtain 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 in 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; 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 the positional relationship between the first positions corresponding to multiple candidate character substrings; The target character substring is marked to obtain a matching result of the character string to be queried corresponding to the first character string.
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, and 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: Determine a plurality of characters in the first character substring and a corresponding first character sequence; 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, characterized in that: 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: According to the first position corresponding to the candidate character substring, determining 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; If there are any of the 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, 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.
5. The method according to claim 4, characterized in that 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.
6. The method according to claim 4, 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 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 overlapping with the first position of the candidate character substring in the first positions corresponding to other candidate character substrings.
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 overlapping with the first position of the candidate character substring in the first position corresponding to other candidate character substrings, further includes: 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 character string to be queried according to the first position corresponding to the candidate character substring; 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 overlapping with the first position of the candidate character substring in the first positions corresponding to other candidate character substrings.
8. The method according to claim 7, characterized in that The determining, based on the first position corresponding to the candidate character substring, whether there is a first candidate character substring overlapping with the first position of the candidate character substring in the first position corresponding to other candidate character substrings, further includes: If the candidate character substring is an incomplete character substring, the candidate character substring is deleted.
9. A string matching device, characterized in that: The device comprises: An acquisition module, used for acquiring 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 in 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 a plurality of candidate character substrings; The marking module is used to mark the target character substring to obtain a matching result of the to-be-queried character string corresponding to the first character string.
10. 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 8 by executing the computer instructions.
11. 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 8.
12. 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 8.
Citation Information
Patent Citations
Text matching method and device
CN108182222A
File virus detection method and device, terminal and storage medium
CN111177721A
Text highlight display method and device, equipment and storage medium
CN114637839A
Account information fuzzy search method and device, equipment and storage medium
CN115829707A
Location name identification method and device, equipment and storage medium
CN118297067A
Cited By
Transforming semantically equivalent data using large language models
US20260178844A1
