Computers have become highly integrated in the workforce, in the home, in mobile devices, and many other places. Computers can process massive amounts of information quickly and efficiently. Software applications designed to run on computer systems allow users to perform a wide variety of functions including business applications, schoolwork, entertainment and more. Software applications are often designed to perform specific tasks, such as word processor applications for drafting documents, or email programs for sending, receiving and organizing email.
In some cases, software applications may be designed to parse the text of documents, emails or other strings of characters. In such cases, regular expressions may be used to identify words, phrases or certain characters within the text. For instance, spam filters may use regular expressions to scan for certain words or phrases in email messages that are commonly associated with unwanted spam messages. In other cases, regular expressions may scan for strings of numbers or other characters. These regular expressions, however, may be very large and complicated. Processing these complicated regular expressions may consume considerable amounts of processing resources.
Embodiments described herein are directed to techniques to transform regular expressions. In one embodiment, for example, an apparatus may comprise a processor circuit and a key terms identifying module operative on the processor circuit to generate a set of one or more regular expression key terms from enabled features of a regular expression based on a set of configuration parameters, and filter one or more electronic messages using the set of regular expression key terms.
Embodiments are further described herein that are directed to conditionally executing regular expressions and to simplifying regular expressions by canonicalizing regular expression terms. In one embodiment, a computer system accesses identified regular expression key terms that are to appear in a selected portion of text. The regular expression key terms are identified from terms in a selected regular expression. The computer system determines whether the identified regular expression key terms appear in the selected portion of text. The computer system also, upon determining that none of the identified regular expression key terms appears in the selected portion of text, prevents execution of the regular expression. Upon determining that at least one of the identified regular expression key terms appears in the selected portion of text, the computer system executes the regular expression.
In another embodiment, a computer system accesses regular expression terms in a regular expression. The regular expression is configured for finding desired characters sets in a document. The computer system determines that some of the regular expression terms are to be canonicalized. Based on the determination, the computer system canonicalizes the regular expression terms, so that at least one previously uncanonicalized regular expression term is simplified into a single, canonicalized term.
This Summary is provided to introduce a selection of concepts in a simplified form that are further described below in the Detailed Description. This Summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used as an aid in determining the scope of the claimed subject matter.
Additional features and advantages will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the teachings herein. Features and advantages of the embodiments may be realized and obtained by means of the instruments and combinations particularly pointed out in the appended claims. Features of the present embodiments will become more fully apparent from the following description and appended claims, or may be learned by the practice of the embodiments as set forth hereinafter.
To further clarify the above and other advantages and features of various embodiments, a more particular description of some embodiments will be rendered by reference to the appended drawings. It is appreciated that these drawings depict only typical embodiments and are therefore not to be considered limiting of its scope. The embodiments will be described and explained with additional specificity and detail through the use of the accompanying drawings in which:
Embodiments described herein are directed to techniques to transform regular expressions into keyword terms (and phrases) in a robust, efficient and effective manner. The resulting keyword terms may be used for any number of use scenarios. In one embodiment, for example, the keyword terms may be used for a given application, such as filtering of electronic messages. In one embodiment, for example, the keyword terms may be used for indexing complex regular expressions to facilitate searches. In one embodiment, for example, the keyword terms may be used to automatically build text based data sets for generating test data for various test scenarios, such as test email messages for testing an “anti-spam” filter. In one embodiment, for example, the keyword terms may be used to automatically and dynamically construct conditional regular expressions. In one embodiment, for example, the keyword terms may be used to automatically and dynamically generate recommendations to refine authoring of regular expressions. Other capabilities and uses for the keyword terms are described in more detail below.
Embodiments further described herein are directed to conditionally executing regular expressions and to simplifying regular expressions by canonicalizing regular expression terms. In one embodiment, a computer system accesses identified regular expression key terms that are to appear in a selected portion of text. The regular expression key terms are identified from terms in a selected regular expression. The computer system determines whether the identified regular expression key terms appear in the selected portion of text. The computer system also, upon determining that none of the identified regular expression key terms appears in the selected portion of text, prevents execution of the regular expression. Upon determining that at least one of the identified regular expression key terms appears in the selected portion of text, the computer system executes the regular expression.
In another embodiment, a computer system accesses regular expression terms in a regular expression. The regular expression is configured for finding desired characters sets in a document. The computer system determines that some of the regular expression terms are to be canonicalized. Based on the determination, the computer system canonicalizes the regular expression terms, so that at least one previously uncanonicalized regular expression term is simplified into a single, canonicalized term.
The following discussion now refers to a number of methods and method acts that may be performed. It should be noted, that although the method acts may be discussed in a certain order or illustrated in a flow chart as occurring in a particular order, no particular ordering is necessarily required unless specifically stated, or required because an act is dependent on another act being completed prior to the act being performed.
Embodiments may comprise or utilize a special purpose or general-purpose computer including computer hardware, such as, for example, one or more processors and system memory, as discussed in greater detail below. Embodiments may also include physical and other computer-readable media for carrying or storing computer-executable instructions and/or data structures. Such computer-readable media can be any available media that can be accessed by a general purpose or special purpose computer system. Computer-readable media that store computer-executable instructions are computer storage media. Computer-readable media that carry computer-executable instructions are transmission media. Thus, by way of example, and not limitation, embodiments can comprise at least two distinctly different kinds of computer-readable media: computer storage media and transmission media.
Computer storage media includes RAM, ROM, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store desired program code means in the form of computer-executable instructions or data structures and which can be accessed by a general purpose or special purpose computer.
A “network” is defined as one or more data links that enable the transport of electronic data between computer systems and/or modules and/or other electronic devices. When information is transferred or provided over a network or another communications connection (either hardwired, wireless, or a combination of hardwired or wireless) to a computer, the computer properly views the connection as a transmission medium. Transmissions media can include a network and/or data links which can be used to carry or desired program code means in the form of computer-executable instructions or data structures and which can be accessed by a general purpose or special purpose computer. Combinations of the above should also be included within the scope of computer-readable media.
Further, upon reaching various computer system components, program code means in the form of computer-executable instructions or data structures can be transferred automatically from transmission media to computer storage media (or vice versa). For example, computer-executable instructions or data structures received over a network or data link can be buffered in RAM within a network interface module (e.g., a “NIC”), and then eventually transferred to computer system RAM and/or to less volatile computer storage media at a computer system. Thus, it should be understood that computer storage media can be included in computer system components that also (or even primarily) utilize transmission media.
Computer-executable instructions comprise, for example, instructions and data which cause a general purpose computer, special purpose computer, or special purpose processing device to perform a certain function or group of functions. The computer executable instructions may be, for example, binaries, intermediate format instructions such as assembly language, or even source code. Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the described features or acts described above. Rather, the described features and acts are disclosed as example forms of implementing the claims.
Those skilled in the art will appreciate that the embodiments may be practiced in network computing environments with many types of computer system configurations, including, personal computers, desktop computers, laptop computers, message processors, hand-held devices, multi-processor systems, microprocessor-based or programmable consumer electronics, network PCs, minicomputers, mainframe computers, mobile telephones, PDAs, pagers, routers, switches, and the like. The embodiments may also be practiced in distributed system environments where local and remote computer systems, which are linked (either by hardwired data links, wireless data links, or by a combination of hardwired and wireless data links) through a network, both perform tasks. In a distributed system environment, program modules may be located in both local and remote memory storage devices.
Regular expressions (e.g. 105) may include substantially any number of terms or special characters. Key terms identifying module 110 may be used to identify one or more regular expression key terms 111 in the regular expression. Key terms, as used herein, may include regular expression terms that are fundamental to that regular expression. In other words, without that key term or terms, the regular expression will not match and the rest of the regular expression does not need to be applied. Accordingly, in the example mentioned above, if a regular expression is designed to look for “Credit Card” (e.g. “Credit Card:.*?\d{16}” with key term {“Credit Card”}), if the word “Credit Card” was not found in the text, the regular expression would not match. Moreover, because the regular expression did not match, the text would not need to be searched for the other information.
Key term evaluating module 115 may access text portion 116, which may be an email, document, web page or any other file or item that includes text. Module 115 may evaluate the text portion to determine whether it has any of the regular expression key terms 111 of the regular expression that is being used (105). Determination 117 indicates that the identified key terms were either present in the text portion, or were not present in the text portion. Based on this determination, regular expression execution module 120 may either prevent execution in cases where the key terms were not present in the text portion, or may initiate execution in cases where the key terms were present in the text portion. In cases where the regular expression was executed, the execution results 121 may be sent to a user, computer system, software application or other entity.
Canonicalization module 435 may access a portion of text 416 and an indication of characters that are to be canonicalized 430. This indication may be received from a user, computer system, software application or other entity. Based on the indication, module 435 may canonicalize the characters as instructed and output the text with canonicalized characters 436. This text with canonicalized characters may be sent to the key term evaluating module 415 to determine whether the text includes any of the identified key terms. Additionally or alternatively, the text with canonicalized characters may be sent to regular expression execution module 420 to be analyzed by a regular expression.
In this manner, regular expressions may be statically analyzed to extract key terms, and then conditionally executed if those key terms are present. This enables very complex regular expressions to be used. As long as part of the regular expression may be found to require any of a set of key terms to match, the rest of the regular expression may be highly sophisticated. This allows existing corpuses of regular expressions to be used, some of which may be very complex.
Preprocessing of regular expressions may be used to generate a conditional regular expression. In some cases, preprocessing may be performed once on each regular expression in the corpus. The results may be saved and then consumed during the execution stage. Preprocessing is designed to extract terms from a regular expression, in order to speed up the execution stage. Canonicalization may be performed during preprocessing.
In some embodiments, alternation or operators which may result in multiple matches result in multiple generated terms. For instance, “this|that” results in the terms ‘this’ and ‘that’. If an operator cannot be turned into a term (or would result in too many terms), groups of terms may be created. For example, “this \w* that” may result in the term group {‘this’, ‘that’ } (\w* does not generate any finite set of terms). Groups may be parsed separately, and then merged with the remaining results. For instance, “Test (stuff|data) text” results in {‘stuff’, data’} being produced from the contained group, then being merged into the parent group, to produce { ‘Test stuff text’, ‘Test data text’}.
The following examples are for illustration purposes only and should not be read as limiting the scope of the embodiments. In these examples, the following terminology will apply: Given n regular expressions and i|0≦i≦n, let Ri be the ith regular expression. A target document on which regular expressions are to be executed is D. Characters which (after canonicalization) are useful in key terms are aggregated and combined into the set Si. Si includes groups of terms Each generated Si is grouped into T (e.g. T={Si|0≦i≦n}). If the regular expression could not be parsed, or resulted in too many terms, Si is empty (meaning Ri would always be executed).
When executing on a document, all terms within a document D are searched (e.g. any member of any of the groups S) using a searching algorithm such as Aho-Corasick, which can match any of the terms in T in one pass (e.g. can find the set of all terms in any Si which occurred in D). Ri may match if Si matches, and never matches if Si does not match. Si matches if any group of terms g under it matches or it is empty. “g” matches if each of the terms in g occurred in D.
When Si did not match, the regular expression did not match. This may occur in many scenarios (for regular expressions detecting credit cards, for example, most documents do not contain credit cards, and so the regular expressions will usually not match). When Si does match, one of the following may happen: 1) The regular expression was fully processed while extracting key terms. Then Ri matched if and only if Si matched, 2) The regular expression was partially processed, start and end lengths are known. Then, searches may be performed within a constrained range within D for Or 3) The regular expression was partially processed, and start and end lengths are not known. Then Ri on D will be run. If Si was empty (couldn't be generated), Ri is executed on D. Thus, Ri is conditionally executed through use of Si.
Performance gains may be significant for parsed regular expressions. “n” regular expressions run on a document of length m in O(n*m) time, while n (successfully preprocessed) conditional regular expressions can run in O(m) time (in the case where either the regular expressions were fully processed, or did not match the document). For many cases, like data leakage protection and anti-spam, most regular expressions do not match any given document, and thus processing for many regular expressions may be avoided.
Canonicalization, as mentioned above, is the process of converting a set of characters to a single character during document processing. The choice of which characters to canonicalize may vary heavily based on implementation. The conversion may be performed both while processing the regular expression (at which point a match of any character in the set instead matches the single character), and while searching for terms within the document (at which point any character in the set is converted). This process can broaden the number of regular expressions which can be successfully converted into conditional regular expressions. Moreover, the preprocessed regular expressions can be executed significantly faster than normal regular expressions.
In some cases, data leakage protection regular expressions are very heavily number oriented. Canonicalizing based on numbers can significantly increase the number of regular expressions which can be preprocessed. For instance, when reading a document, any Arabic number (0 through 9) might be treated as a 0. When this is done, it collapses the number of terms needed to match a regular expression substantially. For instance, [0-9]{3} generates a large number of terms before canonicalization (and a primitive regular expression to match social security numbers, like [0-9]{3}-[0-9]{2}-[0-9]{4}, generates many more). After canonicalization, these become 000 and 000-00-0000, respectively. As most documents do not have such strings of numbers, most regular expressions searching for such strings do not match any given document.
Other examples of where term canonicalization may be useful include numbers, consecutive whitespace characters, languages (Unicode code blocks), alphabetical characters (for example a-z), symbols (canonicalize common textual symbols, like $%^), case (make everything lowercase), or any well-defined set of characters (e.g. abcdef may map to 0, for regular expressions where finding hexadecimal numbers is important). Terms that use canonicalization may not fully parse regular expressions; thus, if the term set matches, Ri will need to be executed.
Extracting terms from the regular expressions happens by processing the regular expression itself. When a character is encountered which is matchable within a relatively small set of characters (the size of this may be customizable) (for example, [0-9] can be any of 10 possibilities, in an ASCII regular expression, \w can be 26 or 52 (depending on if the match is case insensitive), and in a Unicode regular expression, \w can be several thousand characters. Consecutive matchable characters may be aggregated into a set of terms, until an item which cannot be added into a term is encountered (for example, \w*). The next matchable character begins a new set of terms. Grouping operators also cause term-sets to be grouped.
Groups are first processed individually, and then merged into the higher-level results. In processing “a(b(c|d)){2}”: “(c|d)” would be processed (producing {‘c’, ‘d’}), then “(b|(c|d)” would be processed (producing {‘bc’, ‘bd’}) and finally, the top level group would be processed, producing a final result of {‘abcbc’, ‘abcbd’, ‘abdbc’, ‘abdbd’}.
Once parsing is complete, a list of sets of terms is produced. Each set is then combined—if the number of terms becomes too large at any point, then the set is discarded. The combined sets are placed into groups (with another discard step when there are too many possibilities). The resultant set of groups of terms form Si. The examples below provide indications of how this is done.
Canonicalization: none, Regular expression: This example.*text. After processing this, we find the following term-sets: ‘This’, ‘example’, ‘text’. These are combined into a single group {‘This’, ‘example’, ‘text’}. The start and end points of this regular expression are known (‘this’ and ‘text’), and so if Si matches, Ri the regular expression can be run with a predefined start and ending point which is a subset of D (from the start of where ‘this’ was matched, to the end of where ‘text’ was matched).
Canonicalization: lowercase, Regular expression: The example.*text. After processing this, the following term-sets are found: ‘the’, ‘example’, ‘text’. There are combined into a single group {‘the’, ‘example’, ‘text’}. The start and end points of this regular expression are known (‘the’ and ‘text’), and so if Si matches, Ri can be run with a predefined start and ending point which is a subset of D.
Canonicalization: none, Regular expression: where (is|are) the (people|person). After processing this, the following term-sets are found: ‘where’, {‘is’, ‘are’}, ‘the’, {‘people’, ‘person’}. These are combined and joined to form four terms: “where is the people”, “where is the person”, “where are the people”, “where are the person”. The regular expression was fully converted to terms. As such, the regular expression does not need to be executed, since the regular expression matched if and only if one of the terms matched.
Canonicalization: lowercase, Regular expression: where ([Ii]s|are) the ([Pp]eople|[Pp]ersons?). After processing this, the following term-sets are found: ‘where’, {‘is’, ‘are’}, ‘the’, {‘people’, ‘person’, ‘persons’}. These are combined and joined to form six terms: “where is the people”, “where is the person”, “where is the persons”, “where are the people”, “where are the person”, “where are the persons”. The regular expression was fully converted to terms, but because of the canonicalization, this is not sufficient to ensure the regular expression matched. The regular expression needs to be executed to check if a match exists, but has given start and end points.
Canonicalization: numbers, Regular expression: \w* who (will (go|\d)|\d{2})\w* test. The deepest group (go|\d) is analyzed to produce ‘go’ and ‘0’, the next group up is analyzed to produce {‘will’, {‘go’, ‘0’}}, ‘00’}. Finally, the top level group is analyzed. The \w* is ignored as no terms can be built out of it. Once terms are combined, the following groups are produced: {‘who will go’, ‘test’}, {‘who will 0’, ‘test’}, and {‘who 00’, ‘test’}. The regular expression was not fully converted to terms, and the start point is not known. Thus, if the terms match, the regular expression would need to be run on the entire document to verify a match.
Canonicalization: none, Regular expression: (\w+\s+){3}\w+. The regular expression matches any four consecutive words, but none of this regular expression is able to be analyzed, and so no terms are produced. In this example, the regular expression needs to be executed to check for a match.
Canonicalization: none, Regular expression: “\w*\s*Some Text.*(?!invalid).*” where positive key terms include {“Some Text”} and negative key terms include {“invalid”}. Negative key terms, as used herein, include terms that, if found, mean that the regular expression cannot match. Thus, in this example, if the term “invalid” is found in the text, the regular expression will not match. These and other concepts will be explained in greater detail below with regard to methods 200 and 300 of
In view of the systems and architectures described above, methodologies that may be implemented in accordance with the disclosed subject matter will be better appreciated with reference to the flow charts of
Method 200 includes an act of accessing one or more identified regular expression key terms that are to appear in a selected portion of text, wherein the regular expression key terms are identified from terms in a selected regular expression (act 210). For example, key term evaluating module 115 may access regular expression key terms 111 that are to appear in a selected portion of text (e.g. text 116). The regular expression key terms 111 may be identified by key terms identifying module 110. The regular expression from which the key terms may be identified (e.g. regular expression 105) may include multiple different regular expression terms and regular expression special characters. The key terms may include fundamental terms that, without which, prevent the regular expression from being matched to the selected portion of text. Accordingly, as explained above, if the key terms of the regular expression are not found in the document, then the rest of the regular expression does not need to be executed, as the key terms must be present in the document for a match to occur.
In some cases, identifying regular expression key terms may include parsing only a portion of the regular expression 105 to identify the regular expression key terms 111, without parsing the entire regular expression. This may save processing resources by avoiding parsing the entire regular expression. Additionally or alternatively, identifying regular expression key terms may include identifying a group of key terms that, without each key term in the group, prevents the regular expression from being matched to the selected portion of text. In other cases involving groups of terms, if any key term in the group of key terms is matched to the selected portion of text, the match may cause the regular expression to be executed. In such cases, policy may determine matching with groups of terms.
Method 200 includes an act of determining whether the one or more identified regular expression key terms appear in the selected portion of text (act 220). For example, key term evaluating module 115 may determine whether one or more regular expression key terms 111 appears in the text portion 116. In some cases, the identified key terms may be identified without parsing the entire regular expression. In such cases, the regular expression 105 may be executed using a bounded execution. A bounded execution may execute only portions of the regular expression, based on where the key terms were identified in the regular expression. Data such as metadata may be stored, identifying where in the regular expression each key term was found. Based on this information, regular expression execution module 120 may perform a bounded execution on the regular expression. During such a bounded execution, the execution may start and stop based on where in the regular expression the key terms were found.
In some embodiments, regular expression terms may be canonicalized in the regular expression. As explained above, canonicalizing may reduce the number of terms in the regular expression by converting certain a set of characters to a single character during the processing of a document. In some cases, a user may be able to specify which characters are to be canonicalized in given portion of text or perform other regular expression optimizations.
Method 200 includes, upon determining that none of the identified regular expression key terms appears in the selected portion of text, an act of preventing execution of the regular expression (act 230). For example, if none of the regular expression key terms 111 appears in the selected portion of text 116, regular expression execution module 120 may prevent execution of the regular expression. On the other hand, if one or more of the regular expression key terms does appear in the text, execution module 120 may execute the regular expression as planned (act 240). In this manner, execution of a regular expression with no matching key terms may be avoided. Moreover, when key terms do match, the regular expression may be executed as it normally would be.
Method 300 includes an act of accessing one or more regular expression terms in a regular expression, the regular expression being configured for finding desired characters sets in a document (act 310). For example, canonicalization module 435 may access regular expression terms in regular expression 105. In some cases, a user may indicate which regular expression terms are to be canonicalized (e.g. in indication 430). Additionally or alternatively, a software program or other entity may determine which regular expression terms are to be canonicalized for a given regular expression.
Method 300 includes an act of determining that one or more of the regular expression terms are to be canonicalized (act 320). For example, canonicalization module 435 (or another user or software program) may determine that certain regular expression terms are to be canonicalized, or converted from a set of terms to a single term.
Method 300 includes, based on the determination, an act of canonicalizing the regular expression terms, such that at least one previously uncanonicalized regular expression term is simplified into a single, canonicalized term (act 330). Thus, canonicalization module 435 may canonicalize the specified regular expression terms (as specified in indication 430) so that at least one previously uncanonicalized regular expression term is simplified into a single, canonicalized term. The resulting text with canonicalized characters 436 may be sent to key term evaluating module 415 to evaluate key terms in the regular expression and/or may be sent to regular expression execution module 420 for execution of the regular expression that includes the canonicalized terms.
In some cases, the regular expression terms may be canonicalized while the regular expression terms are being identified as key terms. Moreover, in some cases, the regular expression terms may be canonicalized while canonicalized terms are being searched for in the associated text (i.e. in text 416). Thereafter, upon determining that at least one of the searched for canonicalized terms was found in the associated text, the full regular expression may be executed.
Accordingly, systems, methods and computer program products are provided which conditionally execute regular expressions. Moreover, systems, methods and computer program products are provided which simplify regular expressions by canonicalizing regular expression terms.
Regular Expression Transformation
As previously described with reference to
The key terms identifying module 110 may be arranged for execution on a processor, such as a processor circuit, to generate a set of one or more regular expression key terms 111 from various enabled features of a regular expression 105 based on a set of configuration parameters. The regular expression key terms 111 may be suited for any number of use scenarios, such as an anti-spam filter arranged to filter one or more electronic messages (e.g., email messages) using the set of regular expression key terms 111. The use of regular expression key terms 111, which are typically an array of strings, is much more efficient to filter electronic messages relative to applying hundreds if not thousands of potentially very complex regular expressions 105 to each electronic message.
Method 500 may retrieve a set of one or more configuration parameters arranged to control expansion of features of the regular expression at block 504. For example, the key terms identifying module 110 may retrieve a set of one or more configuration parameters from a configuration profile, with each configuration parameter 504 arranged to control expansion of one or more features of the selected regular expression 105.
A feature of a regular expression 105 may comprise a defined syntactical element of a regular expression 105. As previously described, a regular expression 105 provides a concise and flexible means for matching (e.g., specifying and recognizing) strings of text, such as particular characters, words or patterns of characters. Depending on a particular type of regular expression, a regular expression 105 may follow a defined syntax, such as use of Boolean operators such as a vertical bar (e.g., “gray|grey”) to separate alternatives, grouping operators such as parentheses to define scope and precedence of operators (e.g., “gr(a|e)y”), quantification operators such as a quantifier for repeating elements (e.g., a “?” to indicate zero or one of a preceding element), and so forth. A grouping is a collection of regular expression terms, which can be extended by using alternation or repetition operators. A repetition operator defines a set of constraints on how many subsequent matches of an expression need to be made. For example, “a?” states that the character “a” should occur between 0 and 1 times. These and other constructions are features that can be combined to form arbitrarily complex expressions. Examples of features may include without limitation normal characters (e.g., letters, numbers, etc.), special characters, meta characters, operators, delimiters, terms, groups, classes, variables, and so forth. Other features exist, and the embodiments are not limited to these examples.
The configuration parameters may be defined to control performance of the regular expression expansion algorithm when expanding out a regular expression 105 into one or more regular expression key terms 111 for a given application. A regular expression 105 may have varying levels of complexity, which in some cases can generate a relatively large number of regular expression key terms 111 when fully processed. The configuration parameters may constrain expansion operations to accommodate regular expressions 105 of varying levels of complexity for a given application. For instance, a regular expression 105 may potentially generate thousands of regular expression key terms 111, which may consume more resources in terms of storage and compute cycles than use of the regular expression 105 itself. The configuration parameters can comprise integer values placing limits on a particular feature for a regular expression 105, thereby providing a fine level of control and granularity for the regular expression expansion algorithm.
In various embodiments, the key terms identifying module 110 may retrieve a configuration parameter comprising an integer value to constrain expansion of a feature of a regular expression 105. In one embodiment, an integer value of zero may indicate that the feature should not be expanded. In one embodiment, an integer value of greater than zero may indicate a number of occurrences of the feature allowed before limiting expansion. For example, assume a configuration parameter for an alternation feature is stored in a configuration profile in the following format:
<FeatureName=“Alternation”value=“3”/>
As previously described, an alternation applies an operand to a grouping of regular expressions until a match is made or until no further conditions applies. In this case, if a regular expression 105 has an alternation that occurs greater than three (3) times, the regular expression expansion algorithm will not attempt to expand that feature for the regular expression 105. Such constraints may be needed since any feature detected within a regular expression 105 may result in 2n new keyword phrases, with the exception of features using repetition operators of greater than one (1).
Method 500 may identify a set of one or more features within the regular expression enabled by the set of configuration parameters at block 506. For instance, the key terms identifying module 110 may identify a set of one or more features within the regular expression 105 enabled by the set of configuration parameters.
In one embodiment, the key terms identifying module 110 may identify a set of one or more features within the regular expression enabled by the set of configuration parameters, the one or more features comprising a grouping feature, a class feature, or an operator feature. A grouping feature represents grouping operators such as parentheses to define scope and precedence of operators (e.g., “gr(a|e)y”). A class feature represents a class or category of characters, such as alphanumeric characters, non-word characters, word boundaries, control characters, digits, non-digits, visible characters, punctuation characters, whitespace characters, non-whitespace characters, uppercase letters, lowercase characters, hexadecimal digits, a short class, and so forth. A short class is a syntax that is a short form of a class of characters. For example, the symbol “\w” represents a class of characters that include “a-z—0-9,” the symbol “\d” represents “0-9” and so forth. An operator feature represents an operator denoted as a symbol or function representing a mathematical operation.
Using this exemplary set of feature types, the key terms identifying module 110 may retrieve configuration parameters for each feature type, determine whether a feature type is enabled or disabled, and scan a regular expression 105 to identify a presence of the grouping, class or operator feature within the regular expression 105 as enabled by the set of configuration parameters. When a grouping, class or operator feature is found in the regular expression 105, the key terms identifying module 110 may evaluate the grouping, class or operator feature to determine whether expansion of that feature is permitted or not. In our previous example, a feature such as an alternation with more than 3 terms would not be expanded.
Method 500 may generate a set of one or more identified regular expression key terms from the enabled features of the regular expression based on the set of configuration parameters at block 508. For example, the key terms identifying module 110 may generate a set of one or more identified regular expression key terms 111 from the enabled features of the regular expression 105 based on the set of configuration parameters.
To begin generating the identified regular expression key terms 111, the key terms identifying module 110 may enumerate each of the identified features. Once enumerated, the key terms identifying module 110 may replace each of the identified features with a literal representation to generate the identified regular expression key term 111. The literal representations are stored in a hashed set of strings to avoid duplication.
The key terms identifying module 110 may apply an order of operations to the identified features in the regular expression 105. In one embodiment, an exemplary order of operations may comprise: (1) single characters followed by a repetition operator; (2) groupings followed by a repetition operator; and (3) groupings with alternations. If any groupings with no operands exist, the key terms identifying module 110 may remove the grouping syntax. The key terms identifying module 110 may convert any short classes without a repetition operator to literal representations.
As shown in method 600, relevant software components are loaded at diamond 602. For instance, a configuration profile with a set of one or more configuration parameters 604 is loaded into memory at block 602 in preparation of executing the regular expression expansion algorithm. The set of one or more configuration parameters 604 may be arranged to control expansion of certain defined features of a regular expression 105. Further, the regular expression expansion algorithm is loaded into memory at block 602, and execution of the regular expression expansion algorithm begins at block 606.
Method 600 may check constraints implemented by the configuration parameters 604 at diamond 606. For instance, the key terms identifying module 110 may retrieve a set of one or more configuration parameters 604 arranged to control expansion of features of for a set of regular expressions to determine which features of the regular expressions can be expanded or not. Some constraints may cause a bypass or “short circuit” in the regular expression expansion algorithm resulting in passing one or more regular expressions 105 on without any transformations, as indicated by regular expression 628. Assuming the configuration parameters 604 do not indicate a bypass state, control is passed to block 608.
Method 600 may select a regular expression from a set of regular expressions used to identify a text portion of a message at block 608. For instance, the key terms identifying module 110 may select a regular expression 105 from a set of regular expressions used to identify a text portion 116 of an electronic message, such as an email message, chat message, instant message, short messaging service (SMS) message, a multimedia messaging service (MMS) message, a social networking system (SNS) message, a speech-to-text (STT) message, and other types of messages.
Method 600 may convert any short classes to literal expressions at block 610. For instance, the key terms identifying module 110 may convert regular expression short classes to literal representations, such as converting a “\s” and “\x20” to a literal space. Further, the key terms identifying module 110 may perform “unescaping” operations for special characters at this point. For instance, the key terms identifying module 110 may convert “hello\ !” into “hello!”. Any special characters that are escaped are meant to target the literal value.
Method 600 may attempt to validate the regular expression 105 at diamond 612. For instance, the key terms identifying module 110 may validate the regular expression 105 by passing it into a .NET regular expression object. If there are any syntax issues, an exception is thrown and the regular expression object will not be created. If the regular expression 105 does not pass validation then the regular expression is ignored at diamond 614 and the regular expression expansion algorithm skips to the end.
Once the regular expression 105 is validated at diamond 612, method 600 may check a configuration parameter 604 to determine whether to expand or optimize the regular expression 105. If the configuration parameter 604 is set to TRUE, the regular expression expansion algorithm will attempt to expand (or optimize) the regular expression 105. If the configuration parameter 604 is set to FALSE, the regular expression 105 will remain as is, and the algorithm will end.
When expansion is enabled for the regular expression 105, method 600 may attempt to detect whether the regular expression 618 is expandable at diamond 618. For example, the key terms identifying module 110 may analyze the regular expression 105 to make an initial determination as to whether it is a good candidate for producing regular expression key terms 111 from the regular expression 105 prior to attempting to perform expansion operations. For instance, when the regular expression 105 is composed of only special characters, without any normal characters (e.g., “a-z0-9”), it is likely not a good candidate for expansion.
When the regular expression 105 is not initially determined to be a good candidate for expansion at diamond 618, method 600 may analyze the regular expression 105 to detect whether it is intended to target specific domains or uniform resource locators (URLs) at diamond 620.
When the regular expression 105 is not intended for a specific domain at diamond 620, method 600 may analyze the regular expression 105 to determine if a word boundary (e.g., “\b”) is leading or following or both at diamond 622. If TRUE, the key terms identifying module 110 may convert the word boundary into a feature within another external application, such as a spam engine for a messaging application, for example.
If FALSE at diamond 622, the key terms identifying module 110 may attempt to parse keywords for a conditional regular expression as previously described with reference to
If any of the tests for diamonds 618, 620 or 622 are TRUE, method 600 initiates expansion operations for the regular expression 105 at diamond 624. The key terms identifying module 110 may perform expansion operations using a defined order of operations, such as optional single characters, optional groupings, groupings with alternation, redundant non-capture groupings, and so forth.
In one embodiment, for example, method 600 may perform various expansion operations at diamond 624 by first extracting single characters with repetition operators from the regular expression 105. Method 600 may next extract groupings with repetition operators from the regular expression 105. Method 600 may then extract groupings with alternations from the regular expression 105. Finally, method 600 may remove redundant groupings from the regular expression 105. Each of these operations may be demonstrated using the various expansion scenarios detailed below.
A first expansion scenario provides an example of a regular expression 105 having a single character with a repetition operator. Assume the key terms identifying module 110 receives a regular expression 105 as follows:
“buy?(?:from)?our store”
This example contains the following features: (1) an optional character; and (2) an optional grouping. Assuming configuration parameters enable expansion of these two features, the key terms identifying module 110 may use the previously defined order of operations to expand out the single character by splitting it into two new string values: (1) “buy (?:from)? our store”; and (2) “bu (?:from)? our store”. The key terms identifying module 110 then expands out the optional grouping by splitting into four new strings: (1) “buy from our store”; (2) “bu from our store”; (3) “buy our store”; and (4) “bu our store”. An array of four new strings may be stored as identified regular expression key terms 111 in a data store for the regular expression 105. It is worthy to note that in this example, there are no redundant groupings to remove, and further, there are no short classes or syntax in the example to convert.
A second expansion scenario provides an example of a regular expression 105 having an alternation with a repetition operator. Assume the key terms identifying module 110 receives a regular expression 105 as follows:
“buy(?:(?:any|every)thing)?from our store”
This example contains the following features: (1) an optional grouping that is non-capturing “(?:(?:any|every)thing)?”; and (2) a grouping with an alternation that is non-capturing “(?:any|every)”. Note there are no single characters or short classes in this example. Assuming configuration parameters enable expansion of these two features, the key terms identifying module 110 may use the previously defined order of operations to expand out the repetition grouping by splitting it into two new string values since the operator is a “?”: (1) “buy from our store”; and (2) “buy (?:(?:any|every)thing) from our store”. The key terms identifying module 110 may expand out the remaining alternation as follows: (1) “buy (?:anything) from our store”; and (2) “buy (?:everything) from our store”. The key terms identifying module 110 may then remove any groupings that do not have an operand (e.g., a redundant grouping). There are three strings as a result of the previous expansion operation, including: (1) “buy from our store”; (2) “buy (?:anything) from our store”; and (3) “buy (?:everything) from our store”. Note there are two redundant groupings of “(?anything)” and “(?everything)” that are artifacts from the expansion. The key terms identifying module 110 may remove the redundant grouping syntax to produce the following strings: (1) “buy from our store”; (2) “buy anything from our store”; and (3) “buy everything from our store”. An array of three new strings may be stored as identified regular expression key terms 111 in a data store for the regular expression 105. The key terms identifying module 110 may stop processing the regular expression 105 at this point since there are no short classes or syntax in the example to convert.
A third expansion scenario provides an example of a regular expression 105 having a short class. Assume the key terms identifying module 110 receives a regular expression 105 as follows:
“\bbuy\sfrom\sour\sstore”
This example contains the following features: (1) a word boundary denoted by “\b”; and (2) a short class denoted by “\s”. A word boundary is a character that is not “a-z0-9” that is followed or preceded by a character that is “a-z0-9”. Note this example does not contain any single characters, groupings with repetition operators, groupings with alternations, or redundant groupings. Assuming configuration parameters enable expansion of these two features, the key terms identifying module 110 may use the previously defined order of operations to convert any short classes to literal values, which includes: (1) convert “\s” to a literal space such as “\bbuy from our store”; and (2) convert “\b” to a word boundary feature defined by another application, such as a spam filter, for example.
A fourth expansion scenario provides an example of a regular expression 105 having a conditional regular expression. Assume the key terms identifying module 110 receives a regular expression 105 as follows:
“hello.*world\!”
Special characters are escaped to indicate a literal match. In parsing keyword patterns, escaped characters are identified and include them in keyword parsing operations. This example contains a wildcard feature with a repetition operator for zero (0) to any number of iterations. The regular expression expansion algorithm executed by the key terms identifying module 110 immediately detects the special characters “.*” and does not attempt to expand the wildcard feature. The key terms identifying module 110 attempts to extract keyword values and build a conditional regular expression. For instance, the key terms identifying module 110 may parse for characters until a regular expression syntax character is detected, which in this case is “.”. The term that is parsed is “hello”. The key terms identifying module 110 then parses for characters after the regular expression syntax until the end of the string or until other regular expression syntax characters are found. In this example the key term parsed is “world!”. The key terms identifying module 110 generates a conditional regular expression rule using the found key terms. Thus, if either of the terms “hello” or “world!” are present within the text portion 116 of an electronic message (e.g., email message), then the key terms identifying module 110 executes the regular expression 105, otherwise the key terms identifying module 110 does not execute the regular expression 105.
A fifth expansion scenario provides an example of a regular expression 105 having a conditional regular expression with a grouping feature commonly referred to as a “lookaround.” A lookaround is a grouping that asserts or rejects a term at a position within the regular expression 105. A lookaround can be negative or positive and can assert or reject text values in front of a current position or behind the current position. For example, “out of (?!office)” will match any text containing the term “out of” except when followed by the term “office”, which is described in more detail below. This type of lookahead is referred to as a negative lookahead.
By way of further example, assume the key terms identifying module 110 receives a regular expression 105 as follows:
“out of(?!office)”
This example contains a negative lookahead (NLA) grouping feature, and a corresponding configuration parameter 604 that indicates any NLA grouping features are disabled. The key terms identifying module 110 may attempt to extract keyword values by parsing for characters until some regular expression syntax is detected, which in this case results in the key term “out of”. The key terms identifying module 110 identifies “(?!office)” as a NLA grouping feature, and therefore does not extract out a key term “office” based on the associated configuration parameter. The key terms identifying module 110 will not execute the regular expression 105 against an electronic message unless the phrase “out of” is present in a text portion 116 of the electronic message.
Regular expressions 105 can be syntactically complex and require expertise to craft. Often, when presented with a regular expression, it takes time and understanding to determine what phrases are targeted by the rule. As such, regular expressions are typically authored by a team of knowledge engineers specialized in a particular application. For instance, if a particular application is an email messaging application, knowledge engineers intimately familiar with email messaging applications and use scenarios may design regular expressions specifically constructed for email messaging applications. This may include regular expressions designed to identify and filter out unsolicited, malicious, bulk or commercial electronic messages, informally referred to as “spam” messages.
As shown in
The recommend module 706 is arranged to automatically recommend modifications to the regular expression 105 based on the set of regular expression key terms 111 generated by the key terms identifying module 110. At a first level, the recommend module 706 organizes and presents the regular expression key terms 111 to the regular expression author 702. The regular expression author 702 may then evaluate and analyze the regular expression key terms 111 to determine whether they are the intended result of the draft of the regular expression 105, and if not, modify the regular expression 105 accordingly. At a second level, the recommend module 706 may evaluate and analyze the draft of the regular expression 105 based on a set of authoring rules, and automatically generate one or more regular expression recommendations 708 to modify or correct the draft of the regular expression 105 to provide enhanced results. In both cases, the recommend module 706 provides a way for the regular expression author 702 to “debug” a draft of a regular expression 105 based on hard results rather than conjecture as to what potential phrases could be matched.
By way of example of dynamic rule feedback for the regular expression author 702, assume a knowledge engineer (KE) receives a spam complaint from a customer and opens a tool to author a new regular expression 105. The KE submits the regular expression 105 into a regular expression editor via an input device of the device 704, which forwards the regular expression 105 to the key terms identifying module 110. The key terms identifying module 110 executes the regular expression expansion algorithm to generate a set of regular expression key terms 111, which is used as input to the recommend module 706. The recommend module 706 generates a regular expression recommendation 708, which is sent to the regular expression editor for presentation to the regular expression author 702 via a user interface of an output device (e.g., display) for the device 704. The KE can further modify keywords or other properties of the regular expression 105 based on the surfaced regular expression recommendation 708. For instance, assume the regular expression author 105 submits a regular expression 105 as follows:
“(?:what|this)(?:is)?spam”
Further assume the regular expression 105 produced a few keywords that the regular expression author 702 did not mean to target. For instance, the key terms identifying module 110 may return a set of four regular expression key terms 111 that includes: (1) “what is spam”; (2) “this is spam”, (3) “what spam”; and (4) “this spam”. In this example, assume the recommend module 706 merely returns the set of four regular expression key terms 111 as a regular expression recommendation 708. Once surfaced by the user interface, the regular expression author 702 discovers that the keyword “this spam” is not intended and it was an unforeseen consequence of the regular expression 105. This is typical since regular expressions can potentially be very complex. This feedback allows the regular expression author 702 to modify the regular expression 105 in a way that avoids producing the term “this spam”. Alternatively, the regular expression author 702 may selectively remove the term “this spam” from the set of regular expression key terms 111, thereby reducing the set of four regular expression key terms 111 to three regular expression key terms 111.
Additionally or alternatively to returning a regular expression recommendation 708 comprising the four regular expression key terms 111, the recommend module 706 may automatically return suggestions to modify or correct the regular expression 105 to avoid producing the term “this spam”, or eliminating it from the set of regular expression key terms 111.
In either case, the key terms identifying module 110 and the recommend module 706 provides feedback useful for developing or refining regular expressions 105, which otherwise may have gone unnoticed until a false positive was reported from a customer. In this manner, instead of manually adding in hundreds of keywords, the KE can simply write one regular expression 105 to produce the same output within the regular expression authoring tool.
In addition to the regular expression key terms 111, the recommend module 706 may provide regular expression recommendations 708 based on test results from various simulations performed using the regular expression key terms 111. Referring again to
As shown in
In one embodiment, for example, the test data generator module 802 may dynamically generate a corpus for test purposes. For instance, the key terms identification module 110 may expand one or more regular expressions 105 into regular expression key terms 111, and store the regular expression key terms 111 in a database, such as data store 730. The test data generator module 802 may dynamically construct test data, such as test email messages, using a rule target property. The test data generator module 802 may select a couple of random subject rules and populate a subject field of test email messages based off of the regular expression key terms 111. The test data generator module 802 may select several rules targeted at a body for test email messages and populate the body based on the regular expression key terms 111. This process can be repeated for all desired properties of a test email message. The test data generator module 802 may then generate a corpus of test data 732 with a configurable amount of volume.
Once the test data 732 is generated, a test (or profiling) machine may be loaded with all the regular expressions 105 used to generate the test data 732. An example of a test machine may include the spam engine 710, among others. The test machine runs against the corpus at regular intervals. Any new rules or change to an existing rule can generate an alert event. These alerts can be used as functional tests. Additionally, when making code or design changes to software, this scenario can complement integration and functional testing. This model may also provide a state mechanism that can detect small changes in rule behavior.
The computer architecture 900 provides a way to enhance searches for particular regular expressions 105 within a set of regular expressions 105, thereby allowing a set of rules for a given application to be refined at a much faster pace. As shown in
The index module 902 and the search module 906 provide a KE the capability to perform quick and accurate searches based on keywords to find application rules that were previously in regular expression form. The index module 902 and the search module 906 further provide the capability to show rules that have similar keywords, thereby allowing a KE to potentially reduce or remove any redundant rules. The ability to automatically generate text based search indices 904 based on keyword terms (e.g., regular expression key terms 111) extracted from regular expressions 105 provide more accurate results with a high degree of performance
The present embodiments may be embodied in other specific forms without departing from its spirit or essential characteristics. The described embodiments are to be considered in all respects only as illustrative and not restrictive. The scope of the embodiments is, therefore, indicated by the appended claims rather than by the foregoing description. All changes which come within the meaning and range of equivalency of the claims are to be embraced within their scope.
This commonly owned application is a continuation-in-part of, and claims priority to, U.S. patent application Ser. No. 12/938,895 titled “Conditional Execution Of Regular Expressions” filed Nov. 3, 2010, the entirety of which is hereby incorporated by reference.
Number | Name | Date | Kind |
---|---|---|---|
7685271 | Schneider et al. | Mar 2010 | B1 |
7779049 | Phillips | Aug 2010 | B1 |
7916510 | Starovoitov et al. | Mar 2011 | B1 |
7945528 | Cytron et al. | May 2011 | B2 |
8413124 | Wang | Apr 2013 | B2 |
20020042794 | Konaka | Apr 2002 | A1 |
20020194172 | Schreiber | Dec 2002 | A1 |
20050278781 | Zhao et al. | Dec 2005 | A1 |
20060085389 | Flanagan et al. | Apr 2006 | A1 |
20090089278 | Poola et al. | Apr 2009 | A1 |
20090276506 | Tiwari et al. | Nov 2009 | A1 |
20100131935 | Wang | May 2010 | A1 |
20100174770 | Pandya | Jul 2010 | A1 |
20110093496 | Bando et al. | Apr 2011 | A1 |
20110119440 | Pandya | May 2011 | A1 |
20120005184 | Thilagar et al. | Jan 2012 | A1 |
20120240185 | Kapoor et al. | Sep 2012 | A1 |
Entry |
---|
Eguro, Ken, “Automated Dynamic Reconfiguration for High-Performance Regular Expression Searching”, Retrieved at <<http://research.microsoft.com/pubs/141496/TechReport.pdf>>, International Conference on Field-Programmable Technology (FPT), Dec. 9, 2009, pp. 8. |
Mat Nor, Hairul Anuar, “Improving Antispam Techniques by Embracing Pattern-based Filtering”, Retrieved at <<http://eprints.utm.my/10003/1/HairulAnuarMatMFSKSM2009.pdf>>, Apr. 2009, pp. 87. |
Lin, et al., “High-Speed Detection of Unsolicited Bulk Emails”, Retrieved at <<http://www.cse.wustl.edu/ANCS/2007/papers/p175.pdf>>, Proceedings of the 3rd ACM/IEEE Symposium on Architecture for networking and communications systems (ANCS), Dec. 3-4, 2007, pp. 175-184. |
Tseng, et al., “Deterministic High-Speed Root-Hashing Automaton Matching Coprocessor for Embedded Network Processor”, Retrieved at <<http://140.113.88.160/˜ydlin/deterministic—root—hashing.pdf>>, ACM SIGARCH Computer Architecture News, vol. 35, No. 3, Jun. 2007, pp. 36-43. |
Number | Date | Country | |
---|---|---|---|
20120124064 A1 | May 2012 | US |
Number | Date | Country | |
---|---|---|---|
Parent | 12938895 | Nov 2010 | US |
Child | 13359975 | US |