Character string recognition method and device, equipment and medium
By employing a combination of anchor point matching and extended matching rules in the string recognition process, the problems of low string recognition efficiency and high computational resource consumption in existing technologies are solved, achieving efficient and low-resource string recognition.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-27
- Publication Date
- 2026-03-10
AI Technical Summary
Existing string recognition methods based on regular expressions are inefficient when recognizing a large number of string types and consume a lot of computational resources, failing to meet the demand for efficient string recognition.
By combining anchor matching rules and extended matching rules, anchor characters are located in the text and extended matching is performed using them as starting points, which reduces unnecessary text region matching and improves string recognition efficiency.
By splitting the string recognition process into two stages—anchor matching and extended matching—the number of text traversals is reduced, computational resource consumption is decreased, and the efficiency and accuracy of string recognition are improved.
Smart Images

Figure CN121636769A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of this disclosure relate to a string recognition method, a string recognition device, an electronic device, and a computer-readable storage medium. Background Technology
[0002] In some business scenarios, there is a need to identify specific types of strings from text. For example, in security and compliance scenarios, it is necessary to identify email-type strings from text and then encrypt or de-identify them to protect user data security.
[0003] Therefore, achieving efficient string recognition is particularly important. Summary of the Invention
[0004] This summary section is provided to briefly introduce the concepts, which will be described in detail in the detailed description section below. This summary section is not intended to identify key or essential features of the claimed technical solution, nor is it intended to limit the scope of the claimed technical solution.
[0005] At least one embodiment of this disclosure provides a string recognition method, comprising: recognizing whether a first text contains a string of a first type based on a first recognition rule, wherein the first recognition rule includes: at least one first anchor matching rule and at least one first extended matching rule, the first anchor rule being used to recognize a first anchor character; wherein recognizing whether the first text contains a string of the first type includes: recognizing the first anchor character in the first text based on the at least one first anchor matching rule; in response to recognizing the first anchor character in the first text, recognizing the string of the first type in the first text, starting from the first anchor character, based on the at least one first extended matching rule.
[0006] At least another embodiment of this disclosure provides a string recognition device, including: a recognition module configured to: recognize whether a first text contains a string of a first type based on a first recognition rule, wherein the first recognition rule includes: at least one first anchor point matching rule and at least one first extended matching rule, the first anchor point rule being used to recognize a first anchor point character; wherein the recognition module is further configured to: recognize the first anchor point character in the first text based on the at least one first anchor point matching rule; and in response to recognizing the first anchor point character in the first text, recognizing the string of the first type in the first text, starting from the first anchor point character, based on the at least one first extended matching rule.
[0007] At least one further embodiment of this disclosure provides an electronic device, including: a processing device; and a storage device including one or more computer program instructions; wherein the one or more computer program instructions are executed by the processing device to perform the string recognition method provided in at least one embodiment of this disclosure.
[0008] At least one further embodiment of this disclosure provides a computer-readable storage medium that non-transitory stores computer-readable instructions, wherein the string recognition method provided in at least one embodiment of this disclosure is implemented when the computer-readable instructions are executed by a processor.
[0009] At least one embodiment of this disclosure provides a computer program product, including a computer program that, when executed by a processor, implements the string recognition method provided in at least one embodiment of this disclosure. Attached Figure Description
[0010] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale.
[0011] Figure 1 This illustration schematically depicts an application scenario of a string recognition system provided by at least one embodiment of the present disclosure;
[0012] Figure 2 The illustration shows a flowchart of a string recognition method provided in at least one embodiment of the present disclosure;
[0013] Figure 3 This illustration schematically shows a structural diagram of an identification rule set provided in at least one embodiment of the present disclosure;
[0014] Figure 4 The schematic diagram illustrates the structure of a string recognition device provided in at least one embodiment of the present disclosure; and
[0015] Figure 5 The schematic diagram illustrates a structure suitable for implementing at least one embodiment of the present disclosure of an electronic device. Detailed Implementation
[0016] One or more embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.
[0017] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.
[0018] The term "comprising" and its variations as used herein are open-ended inclusions, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the description below.
[0019] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are used only to distinguish different devices, modules or units, and are not used to limit the order of functions performed by these devices, modules or units or their interdependencies.
[0020] It should be noted that the terms "a" and "a plurality of" used in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".
[0021] The names of the messages or information exchanged between the various devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of these messages or information.
[0022] It is understood that the data involved in this technical solution (including but not limited to the data itself, the acquisition, use, storage or deletion of the data) shall comply with the requirements of relevant laws, regulations and related provisions.
[0023] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, relevant users should be informed of the type, scope of use, and usage scenarios of the information involved in this disclosure through appropriate means in accordance with relevant laws and regulations, and authorization should be obtained from the relevant users. Among them, relevant users may include any type of rights holder, such as individuals, enterprises, and groups.
[0024] For example, in response to receiving an active request from a user, a prompt message is sent to the relevant user to clearly indicate that the operation requested by the user will require obtaining and using the user's information. This allows the relevant user to choose whether to provide information to the software or hardware such as the electronic device, application, server, or storage medium that performs the operation of any embodiment of the present disclosure based on the prompt message.
[0025] As an optional but non-restrictive implementation, in response to a user's active request, a prompt message can be sent to the user, such as a pop-up window, where the prompt message can be presented in text format. Furthermore, the pop-up window can also include a selection control allowing the user to choose "agree" or "disagree" to provide information to the electronic device.
[0026] It is understood that the above notification and user authorization process are merely illustrative and do not constitute a limitation on the implementation of this disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of this disclosure.
[0027] String recognition can be understood as the process of extracting a portion of a continuous string from text data. String recognition can be applied in many different scenarios. For example, in security and compliance scenarios, it is necessary to identify email-type strings from text for encryption or de-identification to protect user data security; another example is in information input scenarios, where it is necessary to identify address-type strings from text for automatic string completion, improving information input efficiency.
[0028] In some examples, string recognition is based on regular expressions. For instance, when multiple types of strings need to be recognized, corresponding regular expressions are configured for different types of strings, so that the regular expressions can be used to describe the specific patterns of that type of string. The regular expressions are compiled into finite state automata, a matching engine is built, and then the matching engine is used to match and recognize the text to be recognized, and the recognition result is obtained.
[0029] However, the above-mentioned regular expression-based string recognition method has at least the following problems: when a large number of string types need to be recognized, the regular expression-based string recognition is inefficient and has a serious performance bottleneck; furthermore, in the regular expression-based string recognition method, for a string of a certain type, a regular expression is needed to match the entire text, which consumes a lot of computing resources.
[0030] To at least partially solve the above-mentioned technical problems, at least one embodiment of this disclosure provides a string recognition method, the method comprising: recognizing whether a first text contains a string of a first type based on a first recognition rule, the first recognition rule comprising: at least one first anchor matching rule and at least one first extended matching rule, the first anchor rule being used to recognize a first anchor character; recognizing whether the first text contains a string of the first type comprising: recognizing a first anchor character in the first text based on at least one first anchor matching rule; and in response to recognizing a first anchor character in the first text, recognizing a string of the first type in the first text, starting from the first anchor character, based on at least one first extended matching rule.
[0031] In a string recognition method provided in at least one embodiment of this disclosure, a recognition rule is used to recognize a string of a certain type. The recognition rule includes two parts: an anchor matching rule and an extended matching rule. The string recognition process is divided into two stages: anchor matching and extended matching. Through anchor matching, the anchor character is located in the text where recognition is required (i.e., the first text), and extended matching is performed starting from the anchor character to identify whether a string of that type exists in the text. Thus, by locating the string in the text first and then recognizing it, the text range for string recognition is reduced, matching in unnecessary text areas is avoided, the efficiency of string recognition is improved, and the use of computing resources is reduced.
[0032] Based on the string recognition method provided in at least one embodiment of this disclosure, at least one embodiment of this disclosure also provides a string recognition device, an electronic device, a computer-readable storage medium, and a computer program product.
[0033] The present disclosure and some examples thereof will now be described in detail with reference to the accompanying drawings.
[0034] Figure 1 The illustration shows an application scenario of a string recognition system provided by at least one embodiment of the present disclosure.
[0035] like Figure 1As shown, the application scenario provided in this embodiment may include a string recognition system 100. One or more embodiments of this disclosure do not limit the form of the string recognition system 100. In some embodiments, the string recognition system 100 may be an independent software system. For example, the string recognition system 100 may provide string recognition services in the form of an application (APP), plugin, cloud service, recognition engine, etc. In other embodiments, the string recognition system 100 may also be integrated into other systems. For example, the string recognition system 100 may be integrated into information entry systems, intelligent agents, document systems, and other services related to text data, as a functional module in the services related to text data, providing string recognition services.
[0036] In one or more embodiments of this disclosure, the string recognition system 100 can perform string recognition using anchor and extension modes. For example, the task of the string recognition system 100 is to recognize a specific type of string from unstructured first text 101, where the specific type can be a string with a specific characteristic format, and to configure recognition rules 102 for the recognition of the specific type of string, so that the string recognition system 100 can use the recognition rules 102 to recognize the specific type of string.
[0037] Recognition rule 102 may include anchor matching rule 1021 and extended matching rule 1022. In the string recognition process, string recognition system 100 may first use anchor matching rule to recognize the first text 102, locate anchor character 1011 in the first text 101, and then use anchor character 101 as the starting point to continue extended recognition using extended matching rule 1022, identify extended matching character 1012 that matches extended matching rule 1022 in the first text 101, and then combine anchor character 1011 and extended matching character 1012 to recognize the specific type of string 103 contained in the first text 101.
[0038] The anchor points and extension modes provided by one or more embodiments of this disclosure are described below with reference to specific examples.
[0039] In some embodiments, the string recognition system 100 needs to recognize an email type string from a first text 101. The first text 101 can be: "Contact us at support@example.com or sales@company.org for more information. Visit our website www.example.com or send feedback tofeedback@example.com". In the recognition rule 102 corresponding to the email type string, the anchor matching rule 1021 can be used to recognize the "@" character appearing in the first text 101. In this way, through anchor matching, the anchor character 1011 related to the email type string is located in the first text 101, indicating the possible position of the email type string in the first text 101, avoiding subsequent matching in unnecessary text areas.
[0040] Next, if an anchor character 1011 matching anchor matching rule 1021 exists in the first text 101, extended matching is performed using extended matching rule 1022, starting from anchor character 1011. For example, the string recognition system 100 can use anchor character 1011 as the starting point and perform extended matching in the forward or reverse direction of anchor character 1011 to ensure the accuracy of string recognition. Alternatively, the string recognition system 100 can flexibly configure multiple extended matching rules 1022 according to the string type to be recognized, performing multi-step extended matching. When an unmatched extended matching rule 102 is generated... At step 2, the overall match is deemed to have failed, meaning that the first text 101 does not contain a string of a specific type. For example, when it is necessary to identify a string of a specific type that starts with "139" and consists of 8 consecutive digits, the anchor character 1011 can be "139", and the first text 101 can be "ab139d341d239c42ff10". The extended matching rule 1022 can be used to match the remaining 5 consecutive digits. However, the character after the anchor character "139" is "d", which is not a number and does not match the extended matching rule, resulting in a match failure. The string recognition process is stopped in time to reduce the consumption of computing resources.
[0041] The following will combine Figure 2 and Figure 3 A string recognition method provided by at least one embodiment of the present disclosure will be described in detail.
[0042] Figure 2 The illustration shows a flowchart of a string recognition method provided in at least one embodiment of the present disclosure.
[0043] like Figure 2As shown, the string recognition method of this embodiment includes step S201. In some embodiments, the executing entity of the string recognition method can be an electronic device with a client deployed, an electronic device with a server deployed, or any electronic device that communicates between the client and the server; one or more embodiments of this disclosure do not limit this. The string recognition method includes:
[0044] Step S201: Based on the first recognition rule, identify whether the first text contains a string of the first type.
[0045] The first text can be understood as text data that requires string recognition. For example, the first text can be text data entered or uploaded by the user, or it can be text data generated by other text-related systems.
[0046] In one or more embodiments of this disclosure, the identification rule can be understood as a rule used to identify strings of a specific type. For example, the identification rule can be used to identify email address type strings, Internet Protocol (IP) address type strings, etc. The identification rule can include at least one anchor matching rule and at least one extended matching rule. The anchor matching rule can be used to match anchor characters, that is, to find anchor characters related to a specific type of string in the first text. The extended matching rule can be used to match extended matching characters, that is, to enable extended matching at the position of the anchor character in the first text and find whether the consecutive strings adjacent to the anchor character satisfy the characteristics of a specific type of string.
[0047] The first recognition rule can be understood as a recognition rule used to identify strings of the first type. That is, the first recognition rule is used to perform string recognition on the first text to determine whether a string of the first type exists in the first text. The first recognition rule may include at least one first anchor point matching rule and at least one first extended matching rule. The first anchor point matching rule can be used to identify the first anchor point character.
[0048] In some embodiments, multiple types of string recognition can be performed on the first text simultaneously. For example, a set of recognition rules can be configured, which may include a first recognition rule and at least one second recognition rule, the first recognition rule and at least one second recognition rule being used to recognize different types of strings.
[0049] Strings of the same type can be understood as strings with the same characteristic format and the same meaning. Different recognition rules are configured for different types of strings to identify that type of string. When recognizing strings in the first text, multiple recognition rules can be flexibly combined according to the actual string recognition needs to form a set of recognition rules to recognize multiple different types of strings in the first text.
[0050] Furthermore, based on the first recognition rule and at least one second recognition rule, it is determined whether the first text contains strings of different types corresponding to the first recognition rule and at least one second recognition rule, respectively.
[0051] In other words, by configuring a set of recognition rules, multiple types of strings can be identified from the first text at once using the multiple recognition rules included in the set, thereby improving the recognition efficiency of multiple types of strings and flexibly meeting different string recognition needs.
[0052] Figure 3 The illustration shows a structural diagram of a set of identification rules provided in at least one embodiment of the present disclosure.
[0053] like Figure 3 As shown, the set of recognition rules can include recognition rule 1, recognition rule 2, ..., recognition rule X, where X is an integer greater than 1. By combining recognition rule 1, recognition rule 2, ..., recognition rule X, strings of the type corresponding to recognition rule 1, recognition rule 2, ..., recognition rule X are identified in the first text.
[0054] Thus, when adding a new string type that needs to be recognized, only one recognition rule needs to be added, which is highly scalable. Furthermore, in the actual string recognition process, if the string recognition requirements change, the string types that need to be recognized can be updated simply by recombining the set of recognition rules. This supports uninterrupted rule updates in the production environment, ensuring business continuity.
[0055] An identification rule may include anchor matching rule 1, anchor matching rule 2, ..., anchor matching rule Y and extended matching rule 1, extended matching rule 2, ..., extended matching rule Z, where Y and Z are both integers greater than or equal to 1. Anchor matching is performed using anchor matching rule 1, anchor matching rule 2, ..., anchor matching rule Y, and extended matching is performed using extended matching rule 1, extended matching rule 2, ..., extended matching rule Z.
[0056] In the process of using the set of recognition rules to perform string recognition on the first text, the first text is traversed. In the process of traversing the first text, anchor characters are identified in the first text based on at least one first anchor matching rule and at least one second recognition rule, which respectively include anchor matching rules.
[0057] In other words, for multiple recognition rules, anchor character matching for all rules is completed in a single text traversal. After achieving unified anchor character matching, the subsequent extended matching process is then executed. Compared to the traditional method of "performing anchor matching and extended matching separately for each recognition rule," this eliminates the need for multiple text traversals of the first text, reducing the number of text traversals, minimizing computational resource consumption, and improving memory utilization efficiency.
[0058] The following describes the specific process of identifying whether a first text contains a string of the first type based on the first identification rule. The specific process of identifying whether a first text contains a string of the first type based on the first identification rule may include steps S2011 and S2012:
[0059] Step S2011: Identify the first anchor character in the first text based on at least one first anchor matching rule.
[0060] In one or more embodiments of this disclosure, during the string recognition process, at least one first anchor point matching rule in the first recognition rule is first used to perform anchor point matching to determine whether a first anchor point character exists in the first text.
[0061] In one or more embodiments of this disclosure, the anchor character can be a string feature that a specific type of string commonly satisfies, and the anchor matching rule describes a string feature that a specific type of string commonly satisfies. Thus, by using the anchor matching rule, it is possible to identify whether a string feature that a specific type of string commonly satisfies exists in the first text.
[0062] For example, for a string of email type, the anchor character can be "@"; for a string of ID type, the anchor character can be "user_id".
[0063] Since a string of a certain type can have one or more anchor characters, the identification rules can include one or more anchor matching rules. The anchor characters in the first text are searched using one or more anchor matching rules. If any anchor matching rule is successfully matched, it indicates that the anchor characters of that type of string exist in the first text.
[0064] For the first recognition rule, if no first anchor character corresponding to any first anchor matching rule is recognized in the first text, it indicates that there is no string feature that first type of strings commonly satisfy in the first text, and therefore, there will be no first type of strings in the first text. Therefore, the string recognition process can be stopped. If one or more first anchor characters corresponding to the first anchor matching rule are recognized in the first text, it indicates that there is a string feature that first type of strings commonly satisfy in the first text, and therefore, there may be first type of strings in the first text. Therefore, the string recognition process can continue.
[0065] Through the anchor matching process of at least one first anchor matching rule, the positions in the first text where strings of the first type may exist are located, so as to carry out targeted and efficient extended matching in the future.
[0066] The embodiments disclosed herein do not limit the implementation method of recognizing the first text using the first anchor point matching rule. For example, the AC automaton algorithm can be used for anchor point matching. Since the AC automaton algorithm is a non-backtracking algorithm, it can ensure that the anchor point matching process is completed in O(n) linear time, eliminating the risk of exponential complexity and improving the speed of anchor point matching.
[0067] One or more embodiments of this disclosure support first anchor matching rules in different modes, that is, the first anchor matching rules can identify the first anchor character in different ways. For example, the first anchor matching rule may include at least one of the following: a first anchor matching rule that identifies the first anchor character by matching a string, and a first anchor matching rule that identifies a finite number of first anchor characters corresponding to a string of a first type.
[0068] The first anchor matching rule that identifies the first anchor character by matching strings can also be called the first anchor matching rule of keyword pattern. That is, it uses the keywords that exist in the string features that the first type of strings satisfy to accurately match the first anchor character in the first text. For example, the first anchor matching rule that identifies the first anchor character by matching strings can be used to match the first anchor character "user_id".
[0069] The first anchor matching rule, which matches a finite number of first anchor characters corresponding to the first type of string, can also be called the first anchor matching rule of the scanner pattern. That is, since the first type of string corresponds to a finite number of first anchor characters, the first anchor matching rule exhaustively enumerates the finite number of anchor characters to cover all possible common string features that the first type of string can satisfy.
[0070] For example, when the first type of string is an IPv4 string, the first anchor matching rule can be used to match the first anchor characters, including: all possible first two segments of the IPv4 string such as "0.0.", "192.168.", "255.255.", etc.; when the first type of string is an IPv6 string, the first anchor matching rule can be used to match the first anchor characters, including: all possible first segments of the IPv6 string such as "2001:", "ffff:", "FFFF:", etc.; when the first type of string is a MAC address string, the first anchor matching rule can be used to match the first anchor characters, including: all possible first two segments of the MAC address string such as "0a:1e:", "8A:F3:", "0a-1e-", "8A-F3-", etc.
[0071] In this way, by flexibly selecting appropriate mode configurations for anchor point matching rules based on the different characteristics of different types of strings, the anchor point matching rules can be better adapted to the characteristics of the string types to be identified, thereby improving the efficiency and accuracy of string recognition.
[0072] Step S2012: In response to the identification of a first anchor character in the first text, starting from the first anchor character, identify a first type of string in the first text based on at least one first extended matching rule.
[0073] When the first anchor character is identified in the first text, it indicates that the first text contains strings of the first type that together satisfy the string characteristics, and the anchor matching is successful.
[0074] Furthermore, considering that there may be a need to exclude certain anchor characters in some string recognition scenarios, the first anchor matching rule may also include an anchor exclusion sub-rule. In this case, in response to the recognition of the first anchor character in the first text and the first anchor character not matching the anchor exclusion sub-rule, the first type of string is recognized in the first text based on at least one first extended matching rule, starting from the first anchor character.
[0075] In other words, if there is a first anchor character in the first text that matches the first anchor character matching rule, the first anchor character is additionally checked using the anchor exclusion sub-rule to determine whether the first anchor character is an anchor character that needs to be excluded. If the first anchor character is not an anchor character that needs to be excluded, that is, the first anchor character does not match the anchor exclusion sub-rule, the first anchor character is retained.
[0076] After locating the first anchor character from the first text, at least one of the first extended matching rules in the first recognition rules is used to start extended matching from the first anchor character to identify the first type of string.
[0077] It should be noted that one or more embodiments of this disclosure do not limit the number of first anchor characters. For example, when only one first anchor matching rule is included, the first anchor matching rule can also identify multiple first anchor characters in the first text; or, for example, when multiple first anchor matching rules are included, the multiple first anchor matching rules can identify multiple first anchor characters in the first text.
[0078] In cases involving multiple first anchor characters, during extended matching, multiple first anchor characters can be used as starting points to perform extended matching separately, thereby identifying multiple first-type strings in the first text.
[0079] In some possible implementations, starting from the first anchor character, identification is performed in the first text based on at least one first extended matching rule. In response to the identification of the first extended matching character in the first text, a string of the first type is obtained based on the first anchor character and the first extended matching character.
[0080] In one or more embodiments of this disclosure, a first extended matching rule can be used to identify a first extended matching character. The first extended matching character can be understood as a character belonging to a string of the first type. Extended matching can be understood as a matching process starting from a first anchor character. That is, the starting point can be understood as the position where extended matching begins. The next character along the matching direction from the starting point is taken as the first identified character for extended matching. For example, the first character identified in extended matching can be the character after the last character in the first anchor character, or it can be the character before the first character in the first anchor character.
[0081] Since the representation of strings of the first type can be quite complex, the first recognition rule can include one or more first extended matching rules. For example, multiple first extended matching rules can be used to jointly describe the characteristics of strings belonging to the first type, that is, multiple first extended matching rules can be used to jointly identify the first extended matching characters. Extended matching is initiated at the position of the first anchor character in the first text using one or more first extended matching rules. Only if all one or more first extended matching rules match successfully does it indicate that the continuous string adjacent to the first anchor character in the first text belongs to the first type of string, and the first extended matching character is identified, thus the extended matching is successful. If any first extended matching rule fails to match, it indicates that there is no string of the first type adjacent to the first anchor character in the first text, and the first extended matching character is not identified, thus the extended matching fails.
[0082] In some embodiments, continue as follows Figure 3As shown, at least one first extended matching rule may include at least one of the following: a first extended matching rule in a first matching direction and a first extended matching rule in a second matching direction. The first matching direction and the second matching direction are two different matching directions. For example, the first matching direction may be forward (i.e., matching backward) and the second matching direction may be reverse (i.e., matching forward).
[0083] In this case, the process of identifying a first type of string in the first text based on at least one first extended matching rule, starting from the first anchor character, may include at least one of the following: identifying a first type of string in the first text along the first matching direction based on the first extended matching rule in the first matching direction, starting from the first anchor character; and identifying a first type of string in the first text along the second matching direction based on the first extended matching rule in the second matching direction, starting from the first anchor character.
[0084] For example, when the first identification rule is used to identify the email type string, the first anchor character can be "@", the first extended matching rule in the first matching direction can be used to identify the email suffix (e.g., "xyz.com"), and the first extended matching rule in the second direction can be used to identify the email prefix (e.g., "username").
[0085] In other words, during the extended matching process, extended matching can be performed in different matching directions to achieve bidirectional extended matching, making the extended matching process more flexible and enabling the matching of rich and complex string types by configuring extended matching rules.
[0086] In some embodiments, at least one first extended matching rule may include at least two first extended matching rules in the same matching direction. In this case, starting from the first anchor character, the first type of string is identified in the first text according to the order of the at least two first extended matching rules in the same matching direction.
[0087] In other words, within the same matching direction, multiple first extended matching rules are sequentially used for ordered extended matching according to their order. For example, for two first extended matching rules with an order relationship in the same matching direction, the first extended matching rule that comes first in the order relationship is called rule A, and the first extended matching rule that comes later in the order relationship is called rule B. Rule A is used first, with the first anchor character as the first starting point for extended matching. If there is a string that matches rule A, that is, there is a first extended matching character corresponding to rule A, it means that rule A has matched successfully, and the second starting point is determined. Then rule B is used to start extended matching from the second starting point. If there is no string that matches rule A, that is, there is no first extended matching character corresponding to rule A, it means that rule A has not matched successfully, and there is no need to use rule B for extended matching, and the extended matching process can be ended.
[0088] For example, the first anchor character is the 4th to 7th character in the first text. Rule A and Rule B are both positive first expansion matching rules. Using Rule A, the 8th character of the first text is used as the first character for expansion matching, and the string matched by Rule A is the 8th to 15th character of the first text. Using Rule B, the 16th character of the first text is used as the first character for expansion matching, and the string matched by Rule B is the 16th to 18th character of the first text. Therefore, the expansion matching characters can be the 8th to 18th characters in the first text.
[0089] In this way, by using multiple first-order extended matching rules with sequential relationships, the first text can be extended and matched in multiple steps in sequence, without having to configure complex matching logic in a single extended matching rule, thus achieving ordered extended matching for complex types of strings.
[0090] In some embodiments, the first extended matching rule includes a second parameter, the value of which is used to indicate the length range of the first extended matching characters. For example, the value of the second parameter in rule A is used to indicate the length range of the first extended matching characters corresponding to rule A, and the value of the second parameter in rule B is used to indicate the length range of the first extended matching characters corresponding to rule B.
[0091] By configuring the parameter value of the second parameter, the length of each first extended matching character corresponding to the first extended matching rule is limited. A match is considered successful only if the length of the first extended matching character is within the length range indicated by the parameter value of the second parameter in the first extended matching rule; otherwise, the match fails.
[0092] For example, if the length range indicated by the second parameter is [0, 10], the first extended matching rule will be matched when the length of the first extended matching character is 0-10 characters; if the length range indicated by the second parameter is [5, 10], the first extended matching rule will be matched when the length of the first extended matching character is 5-10 characters.
[0093] In this case, the starting point of the latter first extended matching rule in at least two first extended matching rules in the same matching direction is: the last character of the first extended matching character identified based on the previous first extended matching rule, or the character in the first extended matching character identified based on the previous first extended matching rule that is located at the maximum length position indicated by the parameter value of the second parameter in the previous first extended matching rule.
[0094] In other words, when the length of the first extended matching character corresponding to the previous first extended matching rule meets the length range, the next character along the matching direction of the first extended matching character corresponding to the previous first extended matching rule is used as the first character for extended matching in the next first extended matching rule.
[0095] When the length of the first extended matching character corresponding to the previous first extended matching rule exceeds the maximum length, the length of the first extended matching character corresponding to the previous first extended matching rule is limited by the maximum length of the length range indicated by the parameter value of the second parameter. The character following the first extended matching character of the previous first extended matching rule at the maximum length position is used as the first character for extended matching in the next first extended matching rule.
[0096] For example, the first first extended matching rule is called rule A, and the second first extended matching rule is called rule B. The value of the second parameter in rule A indicates the length range of the first extended matching character corresponding to rule A, which is [5, 10]. When the first extended matching character corresponding to rule A is the 8th to 10th character in the first text, the length of the first extended matching character corresponding to rule A is 3, which satisfies the length range indicated by the value of the second parameter in rule A. Using rule B, extended matching starts from the 11th character in the second text. When the first extended matching character corresponding to rule A is the 8th to 19th character in the first text, the length of the first extended matching character corresponding to rule A is 12, which is greater than the length range indicated by the value of the second parameter in rule A. Using rule B, extended matching starts from the 18th character in the second text.
[0097] Thus, by configuring the second parameter, on the one hand, the extension length of the extended match is limited, allowing for more accurate extended matching; on the other hand, when multiple extended matching rules exist, the starting point of the next extended matching rule is accurately determined, avoiding errors in extended matching.
[0098] One or more embodiments of this disclosure support first anchor matching rules with different modes. For example, the first extended matching rule may include at least one of the following: a first extended matching rule that identifies first extended matching characters using a set of characters, a first extended matching rule that identifies first extended matching characters using regular expressions, and a first extended matching rule that determines whether to retain the first type of string by identifying characters in the first text that are adjacent to the first type of string.
[0099] The first extended matching rule for identifying the first extended matching character using a predefined character set can also be called the first extended matching rule of the character set pattern. That is, using a preset character set, it determines whether a character in the first text matches the first extended matching rule. If the currently identified character belongs to a character in the predefined character set, then that character matches the first extended matching rule and is considered a first extended matching character, until a character not belonging to the predefined character set is identified. For example, the predefined character set can include a set of letters (AZ), a set of numbers (0-9), a set of symbols ("-", ".", "_", "=", etc.), a set of multibyte characters (words such as "is", "ID", or emojis), etc.
[0100] The first extended matching rule for identifying the first extended matching character using regular expressions can also be called the first extended matching rule for regular expression patterns. That is, using regular expressions, we determine whether consecutive characters in the first text match the first extended matching rule. If the currently identified consecutive characters match the regular expression, then the consecutive characters match the first extended matching rule and belong to the first extended matching character.
[0101] The first extended matching rule for determining whether to retain the first type of string by identifying the characters adjacent to it in the first text can also be called the first extended matching rule of the boundary pattern. The first extended matching rule of the boundary pattern can be used to determine whether the first type of string ends at a suitable boundary. Therefore, the first extended matching rule of the boundary pattern can be used as the last first extended matching rule in the same matching direction.
[0102] For example, when performing string recognition on a string that starts with "139" and consists of 8 consecutive digits, the first anchor matching rule can be used to identify the first anchor character "139". The first extended matching rule can be used to identify 5 consecutive digits. The second extended matching rule can be a boundary pattern extended matching rule used to identify whether the next character after the first extended matching character corresponding to the first extended matching rule is a digit. If it is a digit, it indicates that the first extended matching character corresponding to the first extended matching rule is part of a long string of digits, rather than an independent string of a specific type that needs to be identified, and the extended matching fails. If it is not a digit, it indicates that the first extended matching character corresponding to the first extended matching rule may be an independent string of a specific type that needs to be identified, and the extended matching succeeds.
[0103] In this way, for different types of strings with different characteristics, the appropriate mode configuration corresponding to the first extended matching rule can be flexibly selected, and multiple first extended matching rules with different modes can be combined to form at least one first extended matching rule in the final first recognition rule. This makes the first extended matching rule more compatible with the characteristics of the string type to be recognized, thereby improving the efficiency and accuracy of string recognition.
[0104] Furthermore, considering that in some string recognition scenarios there may be a need to exclude certain extended matching characters, the first extended matching rule may include an extended exclusion sub-rule. In this case, in response to the recognition of the first extended matching character in the first text and the fact that the first extended matching character is not excluded by the extended exclusion sub-rule, a string of the first type is obtained based on the first anchor character and the first extended matching character.
[0105] In other words, if the first extended matching characters corresponding to each of the first extended matching rules exist in the first text, the first extended matching characters corresponding to each of the first extended matching rules are additionally checked using extended exclusion sub-rules to determine whether the first extended matching characters corresponding to each of the first extended matching rules are strings that need to be excluded. If the first extended matching characters corresponding to each of the first extended matching rules are not strings that need to be excluded, that is, the first extended matching characters corresponding to each of the first extended matching rules do not match the extended exclusion sub-rules, the first extended matching characters corresponding to each of the first extended matching rules are retained. If at least some of the first extended matching characters corresponding to each of the first extended matching rules are strings that need to be excluded, that is, at least some of the first extended matching characters corresponding to each of the first extended matching rules match the extended exclusion sub-rules, the part that matches the extended exclusion sub-rules is discarded, and the part that does not match the extended exclusion sub-rules is retained.
[0106] It is understandable that when the first extended matching rule includes multiple first extended matching rules in multiple matching directions, each first extended matching rule in multiple matching directions can include its own corresponding extended exclusion sub-rule. In the process of matching the first extended matching characters corresponding to each first extended matching rule with the extended exclusion sub-rule, the matching is performed according to their respective matching directions.
[0107] After completing anchor matching and extended matching, since both the first anchor character and the first extended matching character can be understood as content that conforms to the characteristics of a string of the first type, the string of the first type in the first text is determined based on the first anchor character and the first extended matching character.
[0108] Furthermore, considering that there may be a need to exclude certain recognition results in some string recognition scenarios, the first recognition rule may also include a recognition result exclusion rule. In this case, in response to the first type of string not matching the recognition result exclusion rule, the first type of string is retained, or in response to the first type of string matching the recognition result exclusion rule, the first type of string is discarded.
[0109] In other words, after obtaining the first type of string in the first text, the recognition result exclusion rules are used to further examine the first type of string in the first text to determine whether it is a recognition result that needs to be excluded. If the first type of string in the first text is not a recognition result that needs to be excluded, that is, the first type of string in the first text does not match the recognition result exclusion rules, the first type of string in the first text is retained. If at least part of the first type of string in the first text is a recognition result that needs to be excluded, that is, at least part of the first type of string in the first text matches the recognition result exclusion sub-rule, the part that matches the recognition result exclusion sub-rule is discarded, and the remaining part of the first type of string in the first text is taken as the final recognition result.
[0110] The anchor exclusion sub-rules, extended exclusion sub-rules, and recognition result exclusion rules mentioned above can also have different modes. For example, the anchor exclusion sub-rules, extended exclusion sub-rules, and recognition result exclusion rules can be in the inclusion mode, where the part being judged contains any substring in the set, and therefore needs to be excluded. Another example is the equality mode, where the part being judged is exactly equal to a string in the set, and therefore needs to be excluded. Yet another example is the regular expression mode, where the part being judged matches a regular expression, and therefore needs to be excluded. Finally, the anchor exclusion sub-rules, extended exclusion sub-rules, and recognition result exclusion rules can be in the suffix mode, where the part being judged uses any string in the set as a suffix, and therefore needs to be excluded.
[0111] In some embodiments, the first anchor matching rule and the first extended matching rule may include a first parameter, the value of which indicates whether the string of the first type includes an anchor character or an extended matching character. That is, the value of the first parameter in the first anchor matching rule indicates whether the string of the first type includes a first anchor matching character, and the value of the first parameter in the first extended matching rule indicates whether the string of the first type contains a first extended matching character.
[0112] In this case, based on the parameter value of the first parameter in at least one first anchor matching rule and the parameter value of the first parameter in at least one first extended matching rule, at least some characters in the first anchor character and the first extended matching character are concatenated to obtain a string of the first type.
[0113] In other words, the first anchor character matched by the first anchor matching rule and the first extended matching character matched by the first extended matching rule may not all appear in the final recognition result (i.e., the string of the first type). According to the actual string recognition needs, the matching content as the final recognition result can be flexibly selected by configuring the parameter value of the first parameter. In the string recognition process, the entire first text is used for comprehensive recognition to improve the accuracy of string recognition. When outputting the recognition result, some or all of the matching content that meets the characteristics of the string of the first type is selected to present the recognition result, which enhances flexibility.
[0114] In a specific example, when performing string recognition on a date type string, the first anchor matching rule matches the first anchor character as "date", the first extended matching rule matches the first extended matching character as "=", and the second extended matching rule matches the first extended matching character as "20251101". The parameter value of the first parameter in the first anchor matching rule can indicate that the first type of string does not include the anchor character, the parameter value of the first parameter in the first extended matching rule can indicate that the first type of string does not include the extended matching character, and the parameter value of the first parameter in the second extended matching rule can indicate that the first type of string includes the extended matching character. Therefore, the first type of string in the first text can be "20251101".
[0115] In another specific example, when performing string recognition on a string of email type, the first anchor matching rule matches the first anchor character "@", the positive first extended matching rule matches the first extended matching character "mail.com", and the negative first extended matching rule matches the first extended matching character "example". The parameter value of the first parameter in the first anchor matching rule can indicate that the first type of string includes the anchor character. The parameter values of the first parameter in both the positive and negative first extended matching rules can indicate that the first type of string includes the extended matching character. Therefore, the first type of string in the first text can be "example@mail.com".
[0116] In some possible implementations, the first identification rule described above can be presented in the form of a structure. For example, the first identification rule can be:
[0117] {
[0118] "enabled": true, / / Whether to enable
[0119] "rule_id": 178, / / Unique rule ID
[0120] "rule_version": 2, / / version number
[0121] "rule_name_en": "User Email Address", / / English name
[0122] "rule_name_zh": "email address", / / Chinese name
[0123] "sensitive_type": "email", / / Type identifier used to determine the anonymization method of the recognition result.
[0124] "anchor": { / / Anchor phase configuration
[0125] "finders": [...], / / List of anchor matching rules
[0126] "excluders": [...] / / Anchor point exclusion sub-rules
[0127] },
[0128] "forward": { / / Configuration for the extension phase of the first matching direction
[0129] "extenders": [...], / / List of extended matching rules for the first matching direction
[0130] "excluders": [...] / / Extended exclusion rules for the first matching direction
[0131] },
[0132] "backward": { / / Configuration for the extension phase of the second matching direction
[0133] "extenders": [...], / / List of extended matching rules for the second matching direction
[0134] "excluders": [...] / / Extended exclusion rules for the second matching direction
[0135] },
[0136] "value_excluders": [...] / / Rules for excluding recognition results
[0137] }
[0138] A first anchor point matching rule can be:
[0139] {
[0140] "mode": "word", / / The mode for anchor matching rules
[0141] "values": ["@", "a"], / / Matching logic of anchor point matching rules
[0142] "in_value": false, / / The value of the first parameter
[0143] "extra": {...} / / Extra parameters
[0144] }
[0145] A first-order extended matching rule can be:
[0146] {
[0147] "mode": "character_set", / / Mode for extended matching rules
[0148] "values": ["$numbers", ".-_"], / / Matching logic for extended matching rules
[0149] "min_length": 1, / / The value of the second parameter
[0150] "max_length": 10, / / The value of the second parameter
[0151] "in_value": true, / / The value of the first parameter
[0152] "extra": {...} / / Extra parameters
[0153] }
[0154] Anchor point exclusion sub-rules, extended exclusion sub-rules, and recognition result exclusion rules can be:
[0155] {
[0156] "mode": "contain", / / The mode for excluding rules
[0157] "values": ["abc"], / / Exclusion logic of the exclusion rule
[0158] }
[0159] Based on the string recognition method provided in at least one embodiment of this disclosure, at least one embodiment of this disclosure also provides a string recognition device. The following will be combined with... Figure 4 The string recognition device is described in detail.
[0160] Figure 4 The schematic diagram illustrates the structure of a string recognition device provided in at least one embodiment of the present disclosure.
[0161] like Figure 4As shown, the string recognition device 400 of this embodiment includes a recognition module 401. For example, the recognition module 401 can be implemented using a hardware (e.g., circuit) module or a software module; the following embodiments are similar and will not be repeated. For example, the recognition module 401 can be implemented using a central processing unit (CPU), a general-purpose graphics processing unit (GPGPU), a graphics processing unit (GPU), a tensor processor (TPU), a field-programmable gate array (FPGA), or other processing units with data processing capabilities and / or instruction execution capabilities, along with corresponding computer instructions.
[0162] The recognition module 401 is configured to: based on a first recognition rule, identify whether the first text contains a string of a first type, wherein the first recognition rule includes: at least one first anchor point matching rule and at least one first extended matching rule, and the first anchor point rule is used to identify a first anchor point character. For example, the recognition module 401 can be configured to execute step S201 described above; its specific implementation principle can be found in the relevant description of step S201, and will not be repeated here.
[0163] The recognition module 401 is further configured to: recognize the first anchor character in the first text based on the at least one first anchor matching rule; and, in response to recognizing the first anchor character in the first text, recognize the first type of string in the first text, starting from the first anchor character, based on the at least one first extended matching rule. For example, the recognition module 401 can be configured to execute steps S2011 to S2012 described above. The specific implementation principle can be found in the relevant descriptions of steps S2011 and S2012, and will not be repeated here.
[0164] In at least one embodiment of this disclosure, the recognition module 401 is further configured to: recognize the first text based on the first anchor character as the starting point and the at least one first extended matching rule; and, in response to recognizing the first extended matching character in the first text, obtain a string of the first type based on the first anchor character and the first extended matching character.
[0165] In at least one embodiment of this disclosure, the first anchor matching rule and the first extended matching rule include a first parameter, the value of which indicates whether the string of the first type includes an anchor character or an extended matching character. The recognition module 401 is further configured to concatenate at least some characters of the first anchor character and the first extended matching character according to the parameter value of the first parameter in the at least one first anchor matching rule and the parameter value of the first parameter in the at least one first extended matching rule to obtain the string of the first type.
[0166] In at least one embodiment of this disclosure, the at least one first extended matching rule includes at least one of the following: a first extended matching rule in a first matching direction and a first extended matching rule in a second matching direction. The recognition module 401 is further configured to: starting from the first anchor character, and based on the first extended matching rule in the first matching direction, recognize the string of the first type in the first text along the first matching direction; and starting from the first anchor character, and based on the first extended matching rule in the second matching direction, recognize the string of the first type in the first text along the second matching direction.
[0167] In at least one embodiment of this disclosure, the at least one first extended matching rule includes at least two first extended matching rules in the same matching direction, and the recognition module 401 is further configured to: take the first anchor character as the starting point and identify the first type of string in the first text according to the order relationship of the at least two first extended matching rules in the same matching direction.
[0168] In at least one embodiment of this disclosure, the first extended matching rule includes a second parameter, the value of which is used to indicate the length range of the first extended matching character. The starting point of the latter first extended matching rule in the at least two first extended matching rules in the same matching direction is: the last character of the first extended matching character identified based on the previous first extended matching rule, or the character in the first extended matching character identified based on the previous first extended matching rule that is located at the maximum length position indicated by the parameter value of the second parameter in the previous first extended matching rule.
[0169] In at least one embodiment of this disclosure, the first extended matching rule includes at least one of the following: a first extended matching rule that identifies a first extended matching character using a set of characters; a first extended matching rule that identifies a first extended matching character using a regular expression; and a first extended matching rule that determines whether to retain the first type of string by identifying characters in the first text that are adjacent to the first type of string.
[0170] In at least one embodiment of this disclosure, the first anchor matching rule includes an anchor exclusion sub-rule, and the recognition module 401 is further configured to: in response to recognizing the first anchor character in the first text and the first anchor character not being excluded by the anchor exclusion sub-rule, recognize the first type of string in the first text based on the first anchor character as the starting point and the at least one first extended matching rule.
[0171] In at least one embodiment of this disclosure, the first extended matching rule includes an extended exclusion sub-rule, and the identification module 401 is further configured to: in response to identifying a first extended matching character in the first text and the first extended matching character not being excluded by the extended exclusion sub-rule, obtain a string of the first type based on the first anchor character and the first extended matching character.
[0172] In at least one embodiment of this disclosure, the first identification rule further includes an identification result exclusion rule, and the identification module 401 is further configured to: retain the first type of string in response to the first type of string not matching the identification result exclusion rule; or discard the first type of string in response to the first type of string matching the identification result exclusion rule.
[0173] In at least one embodiment of this disclosure, the string recognition device 400 further includes a configuration module, which is configured to: configure a set of recognition rules, wherein the set of recognition rules includes a first recognition rule and at least one second recognition rule, the first recognition rule and the at least one second recognition rule being used to recognize different types of strings.
[0174] In at least one embodiment of this disclosure, the recognition module 401 is further configured to: based on the first recognition rule and the at least one second recognition rule, identify whether the first text contains strings of different types corresponding to the first recognition rule and the at least one second recognition rule, respectively.
[0175] In at least one embodiment of this disclosure, the recognition module 401 is further configured to: traverse the first text; and during the traversal of the first text, recognize anchor characters in the first text based on the anchor matching rules included in the at least one first anchor matching rule and the at least one second recognition rule of the first recognition rule.
[0176] It should be noted that, for clarity and brevity, at least one embodiment of this disclosure does not show all the constituent units of the string recognition device 400. To achieve the necessary functions of the string recognition device 400, those skilled in the art can provide or set other constituent units (not shown) according to specific needs, and one or more embodiments of this disclosure do not limit this.
[0177] At least one embodiment of this disclosure also provides an electronic device, including a processing device and a storage device, the storage device including one or more computer program modules; wherein the one or more computer program modules are stored in the storage device and configured to be executed by the processing device, the one or more computer program modules being used to implement the string recognition method provided in any embodiment of this disclosure.
[0178] For example, the processing device may be a processor, such as a central processing unit (CPU), digital signal processor (DSP), image processor (GPU), general-purpose graphics processor (GPGPU), or other form of processing unit with data processing capabilities and / or instruction execution capabilities. It may be a general-purpose processor or a dedicated processor and may control other components in the electronic device to perform the desired functions.
[0179] For example, the storage device may be a memory, which may include one or more computer program products. These computer program products may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may, for example, include random access memory (RAM) and / or cache memory. The non-volatile memory may, for example, include read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and a processing device may execute these program instructions to implement the functions (implemented by the processing device) in at least one embodiment of this disclosure and / or other desired functions. Various application programs and various data may also be stored in the computer-readable storage medium, which is not limited by one or more embodiments of this disclosure.
[0180] The following is for reference. Figure 5 The diagram illustrates a structural schematic of an electronic device (e.g., a terminal device or a server) 500 suitable for implementing at least one embodiment of the present disclosure. The terminal device in at least one embodiment of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 5 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of use of at least one embodiment of this disclosure.
[0181] like Figure 5 As shown, electronic device 500 may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 502 or a program loaded from storage device 508 into random access memory (RAM) 503. RAM 503 also stores various programs and data required for the operation of electronic device 500. Processing unit 501, ROM 502, and RAM 503 are interconnected via bus 504. Input / output (I / O) interface 505 is also connected to bus 504.
[0182] Typically, the following devices can be connected to I / O interface 505: input devices 506 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 507 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 508 including, for example, magnetic tapes, hard disks, etc.; and communication devices 509. Communication device 509 allows electronic device 500 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 5 An electronic device 500 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.
[0183] In particular, according to one or more embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, one or more embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 509, or installed from a storage device 508, or installed from a ROM 502. When the computer program is executed by the processing device 501, it performs the functions defined in the methods of at least one embodiment of this disclosure.
[0184] It should be noted that the computer-readable medium described in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0185] In some implementations, clients and servers can communicate using any currently known or future-developed network protocol such as HTTP (Hypertext Transfer Protocol) and can interconnect with digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include local area networks (“LANs”), wide area networks (“WANs”), the Internet (e.g., the Internet of Things), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future-developed networks.
[0186] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.
[0187] The aforementioned computer-readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to perform the aforementioned string recognition method.
[0188] Computer program code for performing the operations of this disclosure can be written in one or more programming languages or a combination thereof, including but not limited to object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0189] One or more embodiments of this disclosure also provide a computer program product comprising one or more computer instructions. When the computer instructions are loaded and executed on a computing device, all or part of the processes or functions described in any embodiment of this disclosure are generated.
[0190] The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, or data center to another website, computer, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means.
[0191] When the computer program product is executed by a computer, the computer performs any of the aforementioned string recognition methods. The computer program product can be a software installation package; when any of the aforementioned string recognition methods needs to be used, the computer program product can be downloaded and executed on the computer.
[0192] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0193] The units or modules described in at least one embodiment of this disclosure can be implemented in software or hardware. The names of the units or modules do not necessarily limit the specific unit or module itself.
[0194] The functions described above in this document can be performed at least in part by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), system-on-a-chip (SoCs), complex programmable logic devices (CPLDs), and so on.
[0195] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0196] According to one or more embodiments of this disclosure, Example 1 provides a string recognition method, including:
[0197] Based on a first recognition rule, it is determined whether the first text contains a string of a first type, wherein the first recognition rule includes at least one first anchor point matching rule and at least one first extended matching rule, and the first anchor point rule is used to identify the first anchor point character;
[0198] The step of identifying whether the first text contains a string of the first type includes:
[0199] Based on the at least one first anchor point matching rule, the first anchor point character is identified in the first text;
[0200] In response to the identification of the first anchor character in the first text, the first type of string is identified in the first text based on the first anchor character as the starting point and the at least one first extended matching rule.
[0201] According to one or more embodiments of this disclosure, Example 2 provides the method of identifying the first type of string in the first text based on the first anchor character as the starting point and the at least one first extended matching rule, as in Example 1, including:
[0202] Starting from the first anchor character, identification is performed in the first text based on the at least one first extended matching rule;
[0203] In response to the identification of a first extended matching character in the first text, a string of the first type is obtained based on the first anchor character and the first extended matching character.
[0204] According to one or more embodiments of this disclosure, Example 3 provides the first anchor matching rule and the first extended matching rule in Example 2, including a first parameter. The parameter value of the first parameter is used to indicate whether the string of the first type includes an anchor character or an extended matching character. The step of obtaining the string of the first type based on the first anchor character and the extended matching character includes:
[0205] Based on the parameter value of the first parameter in the at least one first anchor matching rule and the parameter value of the first parameter in the at least one first extended matching rule, at least some characters in the first anchor character and the first extended matching character are concatenated to obtain a string of the first type.
[0206] According to one or more embodiments of this disclosure, Example 4 provides at least one first extended matching rule from Example 1, including at least one of the following: a first extended matching rule in a first matching direction and a first extended matching rule in a second matching direction, wherein identifying the first type of string in the first text based on the first anchor character as the starting point and the at least one first extended matching rule includes at least one of the following:
[0207] Starting from the first anchor character, and based on the first extended matching rule of the first matching direction, the first type of string is identified in the first text along the first matching direction; and
[0208] Starting from the first anchor character, and based on the first extended matching rule of the second matching direction, the first type of string is identified in the first text along the second matching direction.
[0209] According to one or more embodiments of this disclosure, Example 5 provides at least one first extended matching rule from Example 1, including at least two first extended matching rules with the same matching direction. The step of identifying the first type of string in the first text based on the at least one first extended matching rule, starting from the first anchor character, includes:
[0210] Starting from the first anchor character, the first type of string is identified in the first text according to the order of at least two first extended matching rules in the same matching direction.
[0211] According to one or more embodiments of this disclosure, Example Six provides a first extended matching rule in Example Five that includes a second parameter, the value of which is used to indicate the length range of the first extended matching character. The starting point of the latter first extended matching rule in the at least two first extended matching rules in the same matching direction is: the last character of the first extended matching character identified based on the previous first extended matching rule, or the character in the first extended matching character identified based on the previous first extended matching rule that is located at the maximum length position indicated by the parameter value of the second parameter in the previous first extended matching rule.
[0212] According to one or more embodiments of this disclosure, Example 7 provides that the first extended matching rule in Example 1 includes at least one of the following:
[0213] The first extended matching rule for the first extended matching character is identified using a set of characters.
[0214] Using regular expressions to identify the first extended matching rule for the first extended matching character; and
[0215] By identifying characters in the first text that are adjacent to the first type of string, it is determined whether to retain the first extended matching rule of the first type of string.
[0216] According to one or more embodiments of this disclosure, Example 8 provides a first anchor matching rule from Example 1 including an anchor exclusion sub-rule, wherein in response to identifying the first anchor character in the first text, starting from the first anchor character, based on the at least one first extended matching rule, identifying the first type of string in the first text includes:
[0217] In response to the identification of the first anchor character in the first text and the fact that the first anchor character is not excluded by the anchor exclusion sub-rule, the first type of string is identified in the first text, starting from the first anchor character, based on the at least one first extended matching rule.
[0218] According to one or more embodiments of this disclosure, Example 9 provides a first extended matching rule in Example 2 including an extended exclusion sub-rule, wherein in response to recognizing a first extended matching character in the first text, obtaining a string of the first type based on the first anchor character and the first extended matching character includes:
[0219] In response to the identification of a first extended matching character in the first text and the fact that the first extended matching character is not excluded by the extended exclusion sub-rule, a string of the first type is obtained based on the first anchor character and the first extended matching character.
[0220] According to one or more embodiments of this disclosure, Example 10 provides that the first identification rule in Example 1 further includes an identification result exclusion rule, and the method further includes:
[0221] In response to the first type of string not matching the recognition result exclusion rule, the first type of string is retained; or
[0222] In response to the first type of string matching the recognition result exclusion rule, the first type of string is discarded.
[0223] According to one or more embodiments of this disclosure, Example 11 provides that, before identifying whether the first text contains a string of the first type based on the first identification rule, the method further includes:
[0224] Configure a set of recognition rules, wherein the set of recognition rules includes a first recognition rule and at least one second recognition rule, the first recognition rule and the at least one second recognition rule being used to recognize different types of strings.
[0225] According to one or more embodiments of this disclosure, Example Twelve provides the method of Example Eleven, further comprising:
[0226] Based on the first recognition rule and the at least one second recognition rule, identify whether the first text contains strings of different types corresponding to the first recognition rule and the at least one second recognition rule, respectively.
[0227] According to one or more embodiments of this disclosure, Example Thirteen provides the identification method of Example Twelve for identifying whether the first text contains strings of different types corresponding to the first identification rule and the at least one second identification rule, including:
[0228] Iterate through the first text;
[0229] During the process of traversing the first text, anchor characters are identified in the first text based on the anchor matching rules included in the at least one first anchor matching rule and the at least one second identification rule of the first identification rule.
[0230] According to one or more embodiments of this disclosure, Example Fourteen provides a string recognition device, comprising:
[0231] The recognition module is configured to: recognize whether the first text contains a string of a first type based on a first recognition rule, wherein the first recognition rule includes: at least one first anchor point matching rule and at least one first extended matching rule, and the first anchor point rule is used to recognize the first anchor point character;
[0232] The identification module is further configured as follows:
[0233] Based on the at least one first anchor point matching rule, the first anchor point character is identified in the first text;
[0234] In response to the identification of the first anchor character in the first text, the first type of string is identified in the first text based on the first anchor character as the starting point and the at least one first extended matching rule.
[0235] According to one or more embodiments of this disclosure, Example Fifteen provides an electronic device, including:
[0236] Processing device; and
[0237] Storage device, including one or more computer program instructions;
[0238] The one or more computer program instructions are executed by the processing device to perform the string recognition method provided in at least one embodiment of the present disclosure.
[0239] According to one or more embodiments of the present disclosure, Example Sixteen provides a computer-readable storage medium that non-transitory stores computer-readable instructions, wherein the computer-readable instructions, when executed by a processor, implement the string recognition method provided in at least one embodiment of the present disclosure.
[0240] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.
[0241] Furthermore, while the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.
[0242] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.
Claims
1. A string recognition method, comprising: recognizing whether a first type of string is contained in a first text based on a first recognition rule, wherein the first recognition rule comprises at least one first anchor point matching rule and at least one first extension matching rule, and the first anchor point rule is used to recognize a first anchor point character; wherein the recognizing whether the first type of string is contained in the first text comprises: recognizing the first anchor point character in the first text based on the at least one first anchor point matching rule; in response to recognizing the first anchor point character in the first text, recognizing the first type of string in the first text based on the at least one first extension matching rule, starting from the first anchor point character.
2. The method of claim 1, wherein, the recognizing the first type of string in the first text based on the at least one first extension matching rule, starting from the first anchor point character, comprises: recognizing in the first text based on the at least one first extension matching rule, starting from the first anchor point character; in response to recognizing a first extension matching character in the first text, obtaining the first type of string according to the first anchor point character and the first extension matching character.
3. The method of claim 2, wherein, the first anchor point matching rule and the first extension matching rule comprise a first parameter, and a parameter value of the first parameter is used to indicate whether an anchor point character or an extension matching character is included in the first type of string, the obtaining the first type of string according to the first anchor point character and the first extension matching character comprises: splicing at least part of characters in the first anchor point character and the first extension matching character according to the parameter value of the first parameter in the at least one first anchor point matching rule and the parameter value of the first parameter in the at least one first extension matching rule, to obtain the first type of string.
4. The method of claim 1, wherein, the at least one first extension matching rule comprises at least one of a first extension matching rule of a first matching direction and a first extension matching rule of a second matching direction, the recognizing the first type of string in the first text based on the at least one first extension matching rule, starting from the first anchor point character, comprises at least one of: recognizing the first type of string in the first text based on the first extension matching rule of the first matching direction, starting from the first anchor point character, along the first matching direction; and recognizing the first type of string in the first text based on the first extension matching rule of the second matching direction, starting from the first anchor point character, along the second matching direction.
5. The method of claim 1, wherein, the at least one first extension matching rule comprises at least two first extension matching rules of a same matching direction, the recognizing the first type of string in the first text based on the at least one first extension matching rule, starting from the first anchor point character, comprises: The first anchor character is taken as a starting point, and the first type of string is identified in the first text according to the sequence relationship of the at least two first extended matching rules in the same matching direction.
6. The method of claim 5, wherein, The first extended matching rule includes a second parameter, and a parameter value of the second parameter is used to indicate a length range of the first extended matching character, The starting point of a later first extended matching rule in the at least two first extended matching rules in the same matching direction is based on a last character of the first extended matching character identified based on a previous first extended matching rule, or a character in the first extended matching character identified based on the previous first extended matching rule and located at a maximum length position indicated by a parameter value of the second parameter in the previous first extended matching rule.
7. The method of claim 1, wherein, The first extended matching rule includes at least one of the following: A first extended matching rule for identifying a first extended matching character by using a set of configured characters; A first extended matching rule for identifying a first extended matching character by using a regular expression; and The first extended matching rule includes an extended exclusion sub-rule, The first anchor character is taken as a starting point, and the first type of string is identified in the first text according to the sequence relationship of the at least two first extended matching rules in the same matching direction.
8. The method of claim 1, wherein, The first anchor matching rule includes an anchor exclusion sub-rule, The first anchor character is taken as a starting point, and the first type of string is identified in the first text according to the sequence relationship of the at least two first extended matching rules in the same matching direction. The first extended matching rule includes an extended exclusion sub-rule, 9. The method of claim 2, wherein, The first anchor character is taken as a starting point, and the first type of string is identified in the first text according to the sequence relationship of the at least two first extended matching rules in the same matching direction. The first identification rule further includes an identification result exclusion rule, and the method further includes: In response to the first type of string not matching the identification result exclusion rule, the first type of string is retained; or 10. The method of claim 1, wherein, In response to the first type of string matching the identification result exclusion rule, the first type of string is discarded. Before the first type of string in the first text is identified based on the first identification rule, the method further includes: Configuring a set of identification rules, wherein the set of identification rules includes the first identification rule and at least one second identification rule, and the first identification rule and the at least one second identification rule are used to identify different types of strings.
11. The method according to any one of claims 1 to 10, wherein, 12. The method of claim 11, further comprising: identify whether the first text contains different types of strings corresponding to the first identification rule and the at least one second identification rule respectively based on the first identification rule and the at least one second identification rule.
13. The method of claim 12, wherein, The identifying whether the first text contains different types of strings corresponding to the first identification rule and the at least one second identification rule respectively includes: traversing the first text; during the traversing of the first text, identifying anchor characters in the first text based on anchor point matching rules included in the at least one first anchor point matching rule of the first identification rule and the at least one second identification rule respectively.
14. A string identification apparatus, comprising: an identification module configured to identify whether a first text contains a first type of string based on a first identification rule, wherein the first identification rule includes at least one first anchor point matching rule and at least one first extension matching rule, the first anchor point rule being used to identify first anchor characters; wherein the identification module is further configured to: identify the first anchor characters in the first text based on the at least one first anchor point matching rule; in response to identifying the first anchor characters in the first text, identify the first type of string in the first text based on the at least one first extension matching rule, with the first anchor characters as a starting point.
15. An electronic device, comprising: a processing apparatus; and a storage apparatus including one or more computer program instructions; wherein the one or more computer program instructions, when executed by the processing apparatus, perform the method of any one of claims 1 to 13.
16. A computer-readable storage medium, non-transitorily storing computer- readable instructions, wherein, The computer readable instructions, when executed by the processor, implement the method of any one of claims 1 to 13.
Citation Information
Patent Citations
Message text processing method and device, electronic equipment and storage medium
CN108062290A
Method and device for detecting batch registration mailboxes
CN110019818A
Sensitive information identification method and device, electronic equipment and storage medium
CN110209892A
Systems and methods for offline character recognition
US20150131912A1