A method, apparatus, electronic device, and storage medium for generating regular expressions.
By extracting and filtering example features, generating and combining regular expressions, the accuracy problem of existing tools in noisy examples is solved, and more efficient and accurate regular expression generation is achieved.
Patent Information
- Application Number
- CN202310542925.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-11
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2043-05-11
AI Technical Summary
Existing regular expression generation tools produce regular expressions with low accuracy when dealing with noisy examples, and cannot effectively handle abnormal examples in real-world application scenarios.
By extracting example features, filtering out abnormal examples, generating regular expressions using the same example features, and combining them to generate the final regular expression, the generation complexity is reduced and the accuracy is improved.
The generated regular expressions are more accurate and interpretable, more efficient, and can effectively cover all cases.
Smart Images

Figure CN116738253B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, specifically to a regular expression generation method, apparatus, electronic device, and storage medium. Background Technology
[0002] Regular expressions describe a pattern for matching strings and are widely used in various fields of computer science, such as programming languages, natural language processing, string manipulation, and databases.
[0003] Currently, commonly used regular expression generation tools assume that all input examples are correct when synthesizing regular expressions from multiple input examples. However, in real-world applications, the input examples often contain a few exceptions, and the presence of these exceptions can affect the accuracy of the generated regular expressions. Summary of the Invention
[0004] The purpose of this application is to provide a regular expression generation method, apparatus, electronic device, and storage medium to address the shortcomings of the prior art, and this purpose is achieved through the following technical solutions.
[0005] The first aspect of this application proposes a regular expression generation method, the method comprising:
[0006] Extract the instance features of each instance from the multiple received instances;
[0007] Based on the extracted example features, filter out abnormal examples from the multiple examples and delete the example features to which the abnormal examples belong;
[0008] A regular expression for the target example feature is generated using examples that belong to the same target example feature, and the target example feature belongs to the remaining example features among the extracted example features;
[0009] The regular expressions corresponding to the features of each target example are combined to generate a final regular expression.
[0010] A second aspect of this application provides a regular expression generation apparatus, the apparatus comprising:
[0011] The feature extraction module is used to extract example features from each of the multiple received examples;
[0012] An anomaly filtering module is used to filter out abnormal instances among the multiple instances based on the extracted instance features and delete the instance features to which the abnormal instances belong.
[0013] An expression generation module is used to generate a regular expression for the target example feature using examples that belong to the same target example feature, wherein the target example feature belongs to the remaining example features among the extracted example features;
[0014] The synthesis module is used to combine the regular expressions corresponding to the features of each target example to generate a final regular expression.
[0015] A third aspect of this application provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, the processor executing the program to perform the steps of the method as described in the first aspect above.
[0016] The fourth aspect of this application provides a computer-readable storage medium having a computer program stored thereon, the program being executed by a processor to perform the steps of the method as described in the first aspect above.
[0017] Based on the regular expression generation method and apparatus described in the first and second aspects above, this application has at least the following beneficial effects or advantages:
[0018] By extracting instance features from multiple examples and removing outliers based on these features, the accuracy of the generated regular expression is prevented from being affected. Regular expressions are generated using examples with the same instance feature, resulting in a simple regular expression for each instance feature. This is equivalent to clustering multiple examples using instance features to generate multiple simple regular expressions, which are then combined. This reduces the complexity of directly generating a single regular expression to cover all cases, resulting in higher generation efficiency. Furthermore, the final regular expression formed by combining multiple simple regular expressions is more interpretable. Attached Figure Description
[0019] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0020] Figure 1 This is a flowchart illustrating an embodiment of a regular expression generation method according to an exemplary embodiment;
[0021] Figure 2 This is a cumulative probability distribution diagram illustrated according to an exemplary embodiment;
[0022] Figure 3 This is a schematic diagram illustrating the composition of a longest common subsequence according to an exemplary embodiment;
[0023] Figure 4 This is a schematic diagram illustrating a variable slot format according to an exemplary embodiment;
[0024] Figure 5 This is a schematic diagram illustrating an abstract tree structure for characters according to an exemplary embodiment;
[0025] Figure 6 A logic graph for generating a sub-regular expression as illustrated in an exemplary embodiment;
[0026] Figure 7 This is a schematic diagram illustrating the structure of a regular expression generation apparatus according to an exemplary embodiment;
[0027] Figure 8 This is a schematic diagram of the hardware structure of an electronic device according to an exemplary embodiment;
[0028] Figure 9 This is a schematic diagram illustrating the structure of a storage medium according to an exemplary embodiment. Detailed Implementation
[0029] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0030] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used in this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.
[0031] It should be understood that although the terms first, second, third, etc., may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."
[0032] As mentioned earlier, regular expressions are widely used in various fields of computer science. For example, in cloud service scenarios, cloud services provide users with API (Application Programming Interface) debugging tools. Usually, users will only enter the API integration stage after successfully trying out the API. To improve the success rate of API trials, using regular expressions to validate the parameters input by users is the most direct and effective means. Therefore, how to generate accurate regular expressions using a large number of API call logs is crucial.
[0033] Currently used regular expression generation tools always assume that the input examples are correct. However, in real-world applications, the examples used to generate regular expressions are noisy, resulting in relatively low accuracy of the regular expressions generated by these tools.
[0034] To address the aforementioned technical issues, this application proposes a regular expression generation method. This method extracts instance features from multiple input examples and removes anomalous instances based on these features to prevent them from affecting the accuracy of the generated regular expression. Then, it generates a regular expression using instances sharing the same instance feature, resulting in a simple regular expression for each instance feature. Essentially, this method clusters multiple examples using instance features to generate multiple simple regular expressions, which are then combined. This reduces the complexity of directly generating a single regular expression to cover all cases, resulting in higher generation efficiency. Furthermore, the final regular expression formed by combining multiple simple regular expressions is more interpretable.
[0035] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.
[0036] Figure 1 The flowchart illustrates an embodiment of a regular expression generation method according to an exemplary embodiment, including the following steps:
[0037] Step 101: Extract the example features of each example from the received multiple examples.
[0038] The example feature represents the constituent elements of the example and their relative order. Each example has one example feature, and different examples may have the same or different example features due to differences in their specific content.
[0039] In an optional embodiment, for each example, each character in the example is converted into the corresponding abstract character based on a preset conversion table, and then the example feature of the example is obtained based on the converted example.
[0040] The conversion table records the mapping relationship between various types of characters and abstract characters. By converting characters of the same type into the same abstract characters, the expression can be simplified and common features can be abstracted.
[0041] As shown in Table 1 below, if the character is a Chinese character, it is converted to "z"; if the character is a lowercase English character, it is converted to "x"; if the character is an uppercase English character, it is converted to "X"; if the character is a number, it is converted to "d"; if the character is any other type (i.e., none of the above), it remains the same character after conversion. For example, the number 123 will be converted to ddd.
[0042] Abstract characters Example content description z Chinese characters x English lowercase characters X English uppercase characters d Numeric characters Character reservation Other types of characters
[0043] Table 1
[0044] It is understood that the information shown in Table 1 above is merely illustrative and does not constitute a limitation on the scope of protection of the present application.
[0045] Optionally, to further simplify the abstract expression, the repeated abstract characters in the transformed example can be converted into a single abstract character to obtain the example feature.
[0046] Referring to Table 1 above, assuming the example is SMS_123456, after conversion using Table 1, we get XXX_dddddd. After further deduplication, the example feature is X_d. That is, the example feature of SMS_123456 is X_d, indicating that the example consists of uppercase English characters, the underscore "_", and numeric characters, with the relative order of uppercase English characters + underscore "_" + numeric characters.
[0047] Based on the above description, by clustering multiple examples according to example features, a group of examples is divided under one example feature, which represents that these examples have the same constituent elements and the relative order of elements.
[0048] Step 102: Filter out abnormal instances from multiple instances based on the extracted instance features, and delete the instance features to which the abnormal instances belong.
[0049] Among them, abnormal examples are noise in the examples.
[0050] In one optional embodiment, the filtering process for anomalous examples involves determining the probability of occurrence of each example feature based on the number of examples belonging to that feature, and then filtering out anomalous examples from multiple examples based on the probability of occurrence of each example feature.
[0051] The probability of occurrence of an example feature can represent the frequency of its appearance in all examples. In other words, the higher the probability of occurrence, the higher the proportion of examples belonging to that example feature in all examples. Assuming the total number of examples is N and the number of examples belonging to example feature p is n, the probability of occurrence of example feature p is n*100% / N.
[0052] In one specific implementation, the cumulative probability distribution map of each example feature is determined by utilizing the occurrence probability of each example feature. Then, based on the cumulative probability distribution map, example features representing abnormal examples are determined among each example feature, thereby filtering out examples belonging to the determined example features from multiple examples.
[0053] The Cumulative Distribution Function (CDF) is the cumulative distribution of the probability of occurrence of example features. By using the CDF, the rate of change of the probability of occurrence can be reflected, so as to effectively filter out abnormal examples from a large number of examples.
[0054] In real-world applications, the number of abnormal instances is usually much smaller than the number of correct instances. Consequently, the probability of occurrence of the instance features to which abnormal instances belong is relatively low. Therefore, when filtering abnormal instances based on the cumulative probability distribution map, the goal is to filter out abnormal instances that belong to instance features with a relatively low probability of occurrence.
[0055] Specifically, the inflection point of the cumulative probability distribution map can be used to determine the example features that represent abnormal examples. This is because the inflection point represents the turning point where the cumulative probability change of the example features changes rapidly. That is, the cumulative probability of example features on one side of the inflection point changes rapidly, while the cumulative probability of example features on the other side of the inflection point changes slowly. The example features on the side where the cumulative probability change slows down are the example features with a relatively low probability of occurrence.
[0056] See Figure 2 The cumulative probability distribution plot shown is generated by sorting the example features in descending order of probability: X_d, x_d, X_xd, X_xx, X_dx, d, and then calculating the cumulative probability of each example feature sequentially from front to back. Figure 2It is clear that the inflection point occurs in X_xd, and the example features corresponding to the side with the slow rate of cumulative probability change are X_xx, X_dx, and d. In other words, example features X_xx, X_dx, and d are example features with low occurrence probability, and the examples corresponding to them are all abnormal examples.
[0057] Step 103: Generate a regular expression for the target example feature using examples that belong to the same target example feature. This target example feature belongs to the remaining example features among the extracted example features.
[0058] In other words, after deleting the instance features to which the abnormal instance belongs, the remaining instance features are all target instance features.
[0059] For examples of the same target feature, these examples share common characteristics, namely, the constituent elements and their relative order are identical. Therefore, the regular expressions generated using these examples have low complexity, high interpretability, and high generation efficiency. It can be understood that a regular expression for one example feature can cover all cases of a class of examples.
[0060] In one alternative embodiment, the regular expression generation process for a single example feature is implemented as follows:
[0061] First, determine the longest common subsequence of examples that belong to the same target example feature.
[0062] The longest common subsequence includes the common characters between variable slots and examples belonging to the same target example feature. The variable slots represent the positions of non-common characters in the longest common subsequence among examples belonging to the same target example feature. Referring to the longest common subsequence shown in Figure 3, the longest common subsequence obtained from examples SMS_173425840 and SMS_112954A0 is: SM S_1slot 4slot 0, where slot represents a variable slot, and both variable slots are located between non-contiguous common characters. "S", "M", "S", "_", "1", "4", and "0" are all common characters, which are characters present in both examples.
[0063] Then, from examples belonging to the same target example feature, obtain the substring corresponding to that variable slot.
[0064] Continuing with Figure 3, the substrings corresponding to the variable slots between the common characters “1” and “4” are “73” and “1295”; the substrings corresponding to the variable slots between the common characters “4” and “0” are “2584” and “A”.
[0065] Finally, a sub-regular expression is generated based on the obtained substring, and this sub-regular expression is added to the corresponding variable slot to obtain the regular expression of the target example feature.
[0066] Based on the above description, since examples belonging to the same example feature have certain common features, by determining the longest common subsequence of these examples, and representing the positions of non-common characters in the longest common subsequence with the corresponding non-common character sub-regular expressions, we can obtain a relatively accurate and simple regular expression that covers all cases of a class of examples.
[0067] In one optional embodiment, for the process of generating a sub-regular expression based on the obtained substring, the substring is first deduplicated, and each deduplicated substring is used to generate a coarse-grained regular expression. Then, a sub-regular expression is generated using each coarse-grained regular expression, and a quantifier is set for the sub-regular expression according to the length of each substring. Finally, characters indicating the matching pattern are added after the quantifier to obtain the final sub-regular expression.
[0068] Coarse-grained regular expressions simplify data by removing duplicate data from substrings. They are regular expressions that do not perform any operations on the substrings, but directly use them for matching. Specifically, coarse-grained regular expressions are generated by adding the special characters "[" and "]" to both sides of the substring.
[0069] Quantifiers specify how many times a given component of a regular expression must appear to satisfy a match. There are six quantifiers: "*", "+", "?", "{n}", "{n,}", and "{n, m}". For example, the regular expression `a{m, n}` searches for sequences of length `a` that are at least `m` and at most `n`. When setting quantifiers based on the length of a substring, you can follow the predefined rules for these six quantifiers. For instance, if there is a substring with a length of 0 (i.e., an empty string), the quantifier is set to "*".
[0070] The matching mode refers to whether the regular expression is a greedy or non-greedy match. For example, using the character "?" indicates a non-greedy match, while not setting the character indicates a greedy match.
[0071] See Figure 4 As shown, the format of a complete regular expression added in the variable slot consists of three parts: character + quantifier + matching mode. After generating a sub-regular expression from each coarse-grained regular expression, the content of the character part is obtained. Then, the quantifier and matching mode need to be set.
[0072] In one optional implementation, for the process of generating a sub-regular expression from various coarse-grained regular expressions, the coarse-grained regular expressions with more than a preset number of characters can first be abstracted to reduce the number of characters in the coarse-grained regular expressions to below the preset number. Then, the abstracted coarse-grained regular expressions are merged into a single regular expression, and the validity of the single regular expression is further judged. That is, if the number of characters in the single regular expression exceeds the preset number, the single regular expression is further abstracted to obtain a sub-regular expression. If the number of characters in the single regular expression does not exceed the preset number, the single regular expression is directly used as the sub-regular expression.
[0073] The single regular expression generated by merging various coarse-grained regular expressions may exceed the character length limit. Therefore, before merging, the coarse-grained regular expressions that exceed the character length limit are abstracted and processed. After merging, the single regular expressions that exceed the character length limit are abstracted and processed again to ensure that the character length of the final sub-regular expression meets the requirements, thereby improving the matching success rate of the sub-regular expression.
[0074] Optionally, the abstract processing mentioned above can be implemented by: determining the common parent node of each character in the input regular expression in the preset character abstract tree structure, and then replacing the string in the input regular expression with the string of the common parent node and outputting it.
[0075] The input regular expression can be either a coarse-grained regular expression or a single regular expression, and the common parent node is the common parent node of all the nodes containing the characters.
[0076] See Figure 5The character abstract tree structure shown illustrates how any digit from 0 to 9 is abstracted into a regular expression of [0-9]. Any uppercase letter in the uppercase English characters AZ is abstracted into a regular expression of [AZ]. Any lowercase letter in the lowercase English characters az is abstracted into a regular expression of [az]. Furthermore, the three nodes at the same level, [0-9], [AZ], and [az], are further abstracted upwards through pairwise merging into [0-9A-Z], [0-9a-z], and [A-Za-z]. These three nodes are then further abstracted upwards into \w. For any special character among various special symbols, such as "-", "_", "{", "}", "%", "<", and ">", they are abstracted upwards into a regular expression of [combination]. Combination refers to the combination of the matched special characters. For example, if there are two special characters "!" and "@", then they are abstracted upwards into [!]. @], and further, [combination] and any of the nodes in [0-9], [AZ], [az], [0-9A-Z], [0-9a-z], [A-Za-z], and \w on the left are abstracted as ".".
[0077] Assuming the input regular expression contains uppercase English characters and numeric characters, based on the above... Figure 5 Given the abstract tree structure of the characters shown, the common parent node of the nodes containing these characters is [0-9A-Z]. Therefore, the string "0-9A-Z" from the common parent node is used to replace the string in the input regular expression.
[0078] It is understandable that the above Figure 5 The character abstract tree structure shown is merely an illustrative example and does not constitute a limitation on the scope of protection of this application.
[0079] For the process of generating sub-regular expressions to fill variable slots, see [link to documentation]. Figure 6 The diagram shows the overall logic for generating sub-regular expressions, including a data processing module, a coarse-grained regular expression generation module, a valid judgment module, an abstraction module, a data merging module, a quantifier generation module, and a regular expression generation module.
[0080] The data processing module is used to deduplicate the input substrings and send the deduplicated substrings to the coarse-grained regular expression generation module. It is also used to calculate the length of each deduplicated substring and send the calculated length information to the quantifier generation module.
[0081] The coarse-grained regular expression generation module is used to add special characters "[" and "]" to both sides of the received substring to generate a coarse-grained regular expression, and then send the coarse-grained regular expression to the valid judgment module.
[0082] The valid judgment module limits the number of characters in the string of the regular expression. It is used to determine whether the number of characters in the received regular expression exceeds the preset number. Regular expressions with more than the preset number of characters are sent to the abstract module, while regular expressions with less than the preset number of characters are sent to the data merging module.
[0083] The abstract module is used to abstract and process regular expressions that do not meet the judgment conditions of the valid judgment module.
[0084] The data merging module is used to merge the received coarse-grained regular expressions into a single regular expression, and send it to the qualifier generation module when the number of characters in the single regular expression meets the judgment condition of the valid judgment module.
[0085] The quantifier generation module is used to set quantifiers after a single regular expression based on the length of the received substring and send it to the regular expression generation module.
[0086] The regular expression generation module is used to wrap the received regular expressions, such as adding characters to indicate the matching pattern after quantifiers, and adding escape characters "\" before special characters in the regular expression to mark them as literal characters, such as pi 3.14, which is represented as 3\.14 in the regular expression.
[0087] exist Figure 6In the input data processing module, the substrings "1212976", "XYZZX", and "" are deduplicated. The data processing module performs deduplication on "1212976", "XYZZX", and "", resulting in "12976", "XYZ", and "". Then, the length information of the three substrings, 5, 3, and 0 respectively, is sent to the qualifier generation module. The non-empty substrings "12976" and "XYZ" are sent to the coarse-grained regular expression generation module. The coarse-grained regular expression generation module adds special characters "[" and "]" to the received "12976" and "XYZ" respectively, resulting in coarse-grained regular expressions
[12976] and [XYZ], which are then sent to the validity judgment module for validity judgment. The judgment condition is that the number of characters is less than or equal to 4. Since the characters in
[12976] are less than or equal to 4, the validity judgment module will not be valid. Since the number exceeds 4, the abstract module abstracts
[12976] to obtain [0-9]. Because [0-9] satisfies the condition, it is sent to the data merging module. Similarly, because [XYZ] satisfies the condition, it is sent to the data merging module. The data merging module merges [XYZ] and [0-9] to generate [0-9XYZ] and sends it to the validity judgment module for validity assessment. Because [0-9XYZ] satisfies the condition, it is sent to the qualifier generation module. The qualifier generation module adds a qualifier "*" after [0-9XYZ] and sends it to the regular expression generation module. The regular expression generation module adds a matching pattern symbol "?" after [0-9XYZ]* and outputs the final sub-regular expression [0-9XYZ]*?.
[0088] Step 104: Combine the regular expressions corresponding to the features of each target example to generate a final regular expression.
[0089] Specifically, regular expressions are combined using combination operators to generate a single regular expression. For example, the Union operator can combine two or more results into a single result set.
[0090] Since the regular expressions for each target example feature are highly accurate and can cover all cases belonging to this type of target example feature, the regular expressions of each target example feature are combined to obtain a highly interpretable, accurate, and low-complexity regular expression to cover all cases.
[0091] This completes the above. Figure 1The illustrated regular expression generation process extracts example features from multiple examples and removes outlier examples based on these features, preventing them from affecting the accuracy of the generated regular expression. By generating regular expressions using examples with the same example features, each example feature corresponds to a simple regular expression. This is equivalent to clustering multiple examples using example features to generate multiple simple regular expressions, and then combining these simple regular expressions. This reduces the complexity of directly generating a single regular expression to cover all cases, resulting in higher generation efficiency. Furthermore, the final regular expression formed by combining multiple simple regular expressions is more interpretable.
[0092] Based on the above Figure 1 The regular expression generation scheme shown is evaluated for precision, recall, and F-score using four datasets. The evaluation strategy involves inputting a certain number of examples from the datasets into the scheme to obtain the corresponding regular expressions, then extracting a certain number of examples from the datasets and adding them to a document. The regular expressions are then used to perform matching and extraction in the document, and the number of extractions is counted. When a correct example is matched, the correct match count is incremented by 1. Thus, precision is the ratio of the number of correct matches to the number of extractions, recall is the ratio of the number of correct matches to the number of extracted examples, and the F-score is the harmonic mean of precision and recall.
[0093] As shown in Table 2 below, the four datasets are telephone number datasets, course name datasets, software name datasets, and URL address datasets. "Learning" indicates the number of examples used in the dataset to generate the regular expression, "Testing" indicates the number of examples extracted from the dataset and placed into the document, and "F-measure" represents the F-value. From the F-value metric, the proposed solution shows clear applicability to the scenarios described above. Specifically, the F-values for the telephone number dataset, software name dataset, and URL address dataset are all relatively good. However, the F-value for the course name dataset is significantly lower because the strings representing course names have a certain semantic meaning, while regular expressions do not possess semantic recognition capabilities. Therefore, if the examples are fixed characters, special characters, or information of a specific length, the regular expressions generated by the proposed solution are more accurate.
[0094]
[0095] Table 2
[0096] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0097] Corresponding to the aforementioned embodiments of the regular expression generation method, this application also provides embodiments of a regular expression generation apparatus.
[0098] Figure 7 This is a schematic diagram illustrating the structure of a regular expression generation apparatus according to an exemplary embodiment. This apparatus is used to execute the regular expression generation method provided in any of the above embodiments, such as... Figure 7 As shown, the regular expression generation device includes:
[0099] The feature extraction module 710 is used to extract example features from each of the multiple received examples;
[0100] Anomaly filtering module 720 is used to filter out abnormal examples among the multiple examples based on the extracted example features and delete the example features to which the abnormal examples belong.
[0101] The expression generation module 730 is used to generate a regular expression for the target example feature using examples that belong to the same target example feature, wherein the target example feature belongs to the remaining example features among the extracted example features;
[0102] The synthesis module 740 is used to combine the regular expressions corresponding to the features of each target example to generate a final regular expression.
[0103] The specific implementation process of the functions and roles of each unit in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0104] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this application according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0105] This application also provides an electronic device corresponding to the regular expression generation method provided in the foregoing embodiments, for executing the regular expression generation method described above.
[0106] Figure 8 The present invention illustrates a hardware structure diagram of an electronic device according to an exemplary embodiment. The electronic device includes a communication interface 601, a processor 602, a memory 603, and a bus 604. The communication interface 601, processor 602, and memory 603 communicate with each other via the bus 604. The processor 602 can execute the regular expression generation method described above by reading and executing machine-executable instructions corresponding to the control logic of the regular expression generation method in the memory 603. The specific content of this method is described in the above embodiment and will not be repeated here.
[0107] The memory 603 mentioned in this application can be any electronic, magnetic, optical, or other physical storage device, and can contain stored information such as executable instructions, data, etc. Specifically, the memory 603 can be RAM (Random Access Memory), flash memory, storage drive (such as hard disk drive), any type of storage disk (such as optical disc, DVD, etc.), or similar storage media, or combinations thereof. Communication between this system network element and at least one other network element is achieved through at least one communication interface 601 (which can be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc., can be used.
[0108] Bus 604 can be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. The memory 603 is used to store programs, and the processor 602 executes the programs after receiving execution instructions.
[0109] Processor 602 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 602 or by instructions in software form. The processor 602 can be a general-purpose processor, including a network processor (NP), digital signal processor (DSP), application-specific integrated circuit (ASIC), field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor.
[0110] The electronic device provided in this application embodiment and the regular expression generation method provided in this application embodiment are based on the same inventive concept and have the same beneficial effects as the methods they adopt, run or implement.
[0111] This application also provides a computer-readable storage medium corresponding to the regular expression generation method provided in the foregoing embodiments. Please refer to... Figure 9 As shown, the computer-readable storage medium is an optical disc 30, on which a computer program (i.e., a program product) is stored. When the computer program is run by a processor, it executes the regular expression generation method provided in any of the foregoing embodiments.
[0112] It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical and magnetic storage media, which will not be elaborated here.
[0113] The computer-readable storage medium provided in the above embodiments of this application and the regular expression generation method provided in the embodiments of this application are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by the applications stored therein.
[0114] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0115] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0116] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A method for generating regular expressions, characterized in that, The method includes: Extract the instance features of each instance from the multiple received instances; Based on the extracted example features, filter out abnormal examples from the multiple examples and delete the example features to which the abnormal examples belong; A regular expression for the target example feature is generated using examples that belong to the same target example feature, and the target example feature belongs to the remaining example features among the extracted example features; The regular expressions corresponding to the features of each target example are combined to generate a final regular expression.
2. The method according to claim 1, characterized in that, The extraction of example features from the received multiple examples includes: For each example in the multiple examples, each character in the example is converted into a corresponding abstract character based on a preset conversion table; the conversion table records the mapping relationship between various characters and abstract characters; Generate example features of the example based on the transformed example.
3. The method according to claim 1, characterized in that, The filtering of anomalous examples among the multiple examples based on extracted example features includes: For each example feature extracted from the example features, the probability of occurrence of the example feature is determined based on the number of examples belonging to the example feature; Filter out anomalous examples from the plurality of examples based on the probability of occurrence of each example feature.
4. The method according to claim 3, characterized in that, The filtering of anomalous examples among the multiple examples based on the occurrence probability of each example feature includes: The cumulative probability distribution of each example feature is determined by using the occurrence probability of each example feature; Based on the cumulative probability distribution map, the example features representing the abnormal examples are determined from the example features; Filter out examples that belong to a specific example feature from the multiple examples.
5. The method according to claim 1, characterized in that, The step of generating a regular expression for the target example feature using examples belonging to the same target example feature includes: Determine the longest common subsequence of examples belonging to the same target example feature. The longest common subsequence includes variable slots and common characters between examples belonging to the same target example feature. The variable slots are used to characterize the positions of non-common characters in the longest common subsequence among examples belonging to the same target example feature. Obtain the substring corresponding to the variable slot from examples belonging to the same target example feature; A sub-regular expression is generated based on the obtained substring, and the sub-regular expression is added to the variable slot to obtain the regular expression of the target example feature.
6. The method according to claim 5, characterized in that, The step of generating a sub-regular expression based on the obtained substring includes: The substrings are deduplicated, and each deduplicated substring is used to generate a coarse-grained regular expression. A sub-regular expression is generated using each of the aforementioned coarse-grained regular expressions; The sub-regular expression is configured with quantifiers based on the length of each substring, and characters indicating the matching pattern are added after the quantifiers to obtain the final sub-regular expression.
7. The method according to claim 6, characterized in that, The step of generating a sub-regular expression using each of the coarse-grained regular expressions includes: Abstraction processing is performed on each of the coarse-grained regular expressions in which the number of characters exceeds a preset number, so as to reduce the number of characters in the coarse-grained regular expressions in which the number of characters exceeds the preset number to below the preset number; The abstracted coarse-grained regular expressions are merged into a single regular expression; If the number of characters in the single regular expression exceeds a preset number, the single regular expression is abstracted to obtain a sub-regular expression. If the number of characters in the single regular expression does not exceed a preset number, the single regular expression is used as a sub-regular expression.
8. The method according to claim 7, characterized in that, The method also includes an abstraction process: Determine the common parent node of the nodes where each character in the input regular expression is located in the preset character abstract tree structure. The input regular expression includes coarse-grained regular expressions or single regular expressions. Replace the string in the input regular expression with the string of the common parent node and output it.
9. A regular expression generation device, characterized in that, The device includes: The feature extraction module is used to extract example features from each of the multiple received examples; An anomaly filtering module is used to filter out abnormal instances among the multiple instances based on the extracted instance features and delete the instance features to which the abnormal instances belong. An expression generation module is used to generate a regular expression for the target example feature using examples that belong to the same target example feature, wherein the target example feature belongs to the remaining example features among the extracted example features; The synthesis module is used to combine the regular expressions corresponding to the features of each target example to generate a final regular expression.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, The processor executes the program to implement the steps of the method as claimed in any one of claims 1-8.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that, The program is executed by a processor to implement the steps of the method as described in any one of claims 1-8.
Citation Information
Patent Citations
Method and device for excavating data regular expressions
CN103425771A
Text error correction method and device, medium and electronic equipment
CN112784581A