A rule expression matching method, device and computer readable storage medium

By performing syntax verification and simplification algorithms on the rule text string to convert it into the simplest rule expression, and combining predicate calculus and network merging, the problem of insufficient complexity and flexibility of rule expression patterns in existing technologies is solved, and efficient feature matching is achieved.

CN116089663BActive Publication Date: 2025-12-16CHINA UNIONPAY
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211515709.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-29
Publication Date
2025-12-16
Estimated Expiration
2042-11-29

AI Technical Summary

Technical Problem

Existing matching devices cannot be configured with complex rule expression patterns, have low scalability and flexibility, and cannot perform completeness verification on rule expression patterns, thus affecting matching efficiency.

Method used

The method employs a regular expression matching approach. It receives a regular text string and performs syntax verification. It uses a cyclic binary code simplification algorithm to losslessly convert the regular expression into the simplest regular expression. Based on the predicate calculus algorithm, it is equivalently transformed into a regular expression matching tree and merged into a merged matching network. Common rule fragments are then identified for feature matching.

Benefits of technology

It significantly improves the matching efficiency of regular expressions, can handle complex regular expression patterns, and ensures the completeness and flexibility of matching.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116089663B_ABST
    Figure CN116089663B_ABST
Patent Text Reader

Abstract

The application provides a rule expression matching method, device and computer readable storage medium, the method comprises the following steps: receiving a rule text string, performing syntax checking on the rule text string, and outputting a rule expression; based on a cyclic binary code simplification algorithm, the rule expression is losslessly converted into a simplest rule expression; based on a predicate calculus algorithm, the simplest rule expression is equivalently converted into a rule expression matching tree; a plurality of rule expression matching trees are merged into a merged matching network, and a common rule segment is identified; and the merged matching network and the common rule segment are used for feature matching on to-be-matched data. By using the above method, the matching efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the field of feature matching, and particularly relates to a rule expression matching method and device and a computer readable storage medium. BACKGROUND

[0002] This section is intended to provide background or context to the embodiments of the application recited in the claims. The description herein does not constitute admission that the prior art is prior art nor does it constitute an admission of any description in this section as prior art to an application described herein and / or in another application also owned by the applicant of the present application.

[0003] Some of the prior art matching devices use a line list method, which cannot configure a relatively complex rule expression mode, and have low expansibility and flexibility. Another part of the devices uses a rule expression method, but whether the rule expression meets the established syntax is often checked by a text character parsing hard coding method or a regular matching method (the regular matching algorithm is based on a finite state machine and cannot operate on an infinite number of calculation elements). These checking methods are only suitable for simple scenarios and cannot perform complete checking on all combination scenarios of the rule expression mode. For the rule expression configured by the business, there is a lack of effective equivalent predicate operation, the rule expression configured by the user is simplified into the simplest expression, and there is a lack of identification of the public segment of the rule expression, which affects the subsequent matching efficiency.

[0004] Therefore, how to improve the matching efficiency is a problem to be solved. SUMMARY

[0005] In view of the problems in the prior art, a rule expression matching method, device and computer readable storage medium are provided, which can solve the above problems.

[0006] The present application provides the following solutions.

[0007] In a first aspect, a rule expression matching method is provided, including: receiving a rule text string, performing syntax checking on the rule text string, and outputting a rule expression; based on a simplification algorithm of a cyclic binary code, losslessly converting the rule expression into a simplest rule expression; based on a predicate calculus algorithm, equivalently converting the simplest rule expression into a rule expression matching tree; merging a plurality of rule expression matching trees into a merged matching network, and identifying a public rule segment; and using the merged matching network and the public rule segment to perform feature matching on to-be-matched data.

[0008] In an embodiment, the lossless conversion of the rule expression into a minimal rule expression based on a cyclic binary code simplification algorithm further comprises: obtaining all key elements in the rule expression, generating all combinations of the key elements based on positive and negative values of each key element; obtaining a combination value range that makes the rule expression true from all combinations, and obtaining a binary code combination of the combination value range; performing cyclic binary code merging on the binary codes in the binary code combination to obtain a simplified binary code combination; and converting each binary bit in the simplified binary code combination back to the key elements, and outputting the minimal rule expression.

[0009] In an embodiment, the cyclic binary code merging comprises: comparing the binary codes in the binary code combination two by two, and merging to generate new binary codes; comparing the new binary codes and the original binary codes that failed to be merged two by two, merging to generate new binary codes and removing duplicate binary codes; and repeating the above merging steps until no new binary code can be generated.

[0010] In an embodiment, the cyclic binary code merging further comprises: when there is only one different binary bit between two binary codes, setting the different binary bit as a set symbol, and keeping the remaining same binary bits unchanged as a new binary code.

[0011] In an embodiment, the conversion of each binary bit in the simplified binary code combination back to the key elements comprises: for each binary code in the simplified binary code combination, converting the binary bit to the corresponding key element according to the position of the binary bit; performing a not operation or no not operation on the key element according to the value of each binary bit; and if the binary code includes a binary bit with the set symbol value, ignoring the corresponding key element.

[0012] In an embodiment, the syntax checking of the rule text string further comprises: using a context-free grammar and a recursive descent algorithm to perform a complete syntax check of the rule text string.

[0013] In an embodiment, the syntax checking of the rule text string further comprises: reading in the rule text string, splitting the rule text string according to a predetermined delimiter to obtain multiple morphemes; sorting each morpheme according to the order of the morphemes in the rule text string to generate a lexical unit sequence; and traversing the lexical unit sequence to check the syntax of the rule text string.

[0014] In an embodiment, the morphemes are classified into key element types and logical operation types.

[0015] In an embodiment, the minimal rule expression is converted into a rule expression matching tree; further comprising: repeatedly performing one or more of the following predicate inference algorithms until stable, to obtain the rule expression matching tree: obtaining a rule tree corresponding to the minimal rule expression; if there are multiple non-operation child nodes of the rule tree, pushing down the non-operation into the child nodes and exchanging the and operator and the or operator; if the current operator of the minimal rule expression is consistent with the parent node operator, moving up the child nodes of the current operator and deleting the current operator; for the same layer leaf nodes, sorting according to the unique attributes of the nodes.

[0016] In an embodiment, a plurality of the rule expression matching trees are merged into a merged matching network, and common rule fragments are identified, comprising: selecting one rule expression matching tree for up-down transposition, taking the rule expression matching tree square rule as the root node, as the initial state of the merged matching network; traversing other rule expression matching trees one by one for up-down transposition, and merging them one by one into the merged matching network; after traversal, forming a complete merged matching network, and extracting common rule fragments.

[0017] In an embodiment, merging into the merged matching network one by one further comprises: for an element node in a single rule expression matching tree, adding or reusing an element node in the merged matching network; and / or, for a logical symbol node in a single rule expression matching tree, adding or reusing a logical symbol node in the merged matching network; and / or, for completely coinciding logical symbol nodes, the common rule fragments and their corresponding rule expression matching trees can be extracted through reverse search; and / or, for partially coinciding logical symbol nodes, splitting the logical symbol nodes in the merged matching network.

[0018] In an embodiment, using the merged matching network and the common rule fragments to perform feature matching on the to-be-matched data, comprising: pre-sorting the priority of each rule identifier in the merged matching network; sequentially matching the element set involved by each rule identifier in the merged matching network with the to-be-matched data according to the priority, until matching is successful or ends.

[0019] In an embodiment, using the merged matching network and the common rule fragments to perform feature matching on the to-be-matched data, comprising one or more of the following operations: matching the to-be-matched data with the element node set of the rule expression matching tree involved by each rule identifier, entering from the entrance of the merged matching network, if the element node of the rule expression matching tree is matched, caching the element matching result.

[0020] In an embodiment, the feature matching of the to-be-matched data by using the merged matching network and the common rule fragment further comprises: if a logical node of the rule expression matching tree is matched, then inquiring in a cache whether a parent element node of the logical node has been hit, wherein: if there is no cache result, then taking a next element node from the element node set and matching with the to-be-matched data; if there is a cache result, then directly taking the cache result to perform logical operation; and if the logical node belongs to the common rule fragment, then caching a logical matching result.

[0021] In an embodiment, the feature matching of the to-be-matched data by using the merged matching network and the common rule fragment further comprises: if a rule identification node of the rule expression matching tree is matched, then returning a hit rule identification.

[0022] In a second aspect, a rule expression matching apparatus is provided, which is configured to perform the method of any one of claims 1-13, and comprises: a syntax verifier configured to receive a rule text string, perform syntax verification on the rule text string, and output a rule expression; a feature converter configured to convert the rule expression into a simplest rule expression based on a simplification algorithm of a cyclic binary code; a predicate operator configured to equivalently transform the simplest rule expression into a rule expression matching tree based on a predicate algorithm; a network merger configured to merge a plurality of rule expression matching trees into a merged matching network, and identify a common rule fragment; and a feature matcher configured to perform feature matching of to-be-matched data by using the merged matching network and the common rule fragment.

[0023] In a third aspect, a rule expression matching apparatus is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method of the first aspect.

[0024] In a fourth aspect, a computer readable storage medium is provided, which stores a program, and when the program is executed by a multi-core processor, the multi-core processor performs the method of the first aspect.

[0025] One of the advantages of the above embodiments is that the matching efficiency can be significantly improved.

[0026] Other advantages of the present application will be illustrated in more detail in conjunction with the following description and drawings.

[0027] It should be understood that the above description is only a summary of the technical solutions of the present application, so as to enable a clearer understanding of the technical means of the present application, and thus the content of the specification can be implemented. In order to make the above and other objects, features and advantages of the present application more apparent and comprehensible, the specific embodiments of the present application are described below. BRIEF DESCRIPTION OF DRAWINGS

[0028] The advantages and benefits described herein, as well as other advantages and benefits, will be apparent to those of ordinary skill in the art upon reading the following detailed description of exemplary embodiments. The drawings are for purposes of illustration only and are not considered a limitation of the present application. Moreover, in the drawings, like reference numerals designate like parts throughout the various figures. In the drawings:

[0029] Figure 1 Structure diagram of a rule expression matching device according to an embodiment of the present application;

[0030] Figure 2 Flow diagram of a rule expression matching method according to an embodiment of the present application;

[0031] Figure 3 Rule tree diagram of a rule expression according to an embodiment of the present application;

[0032] Figure 4 Rule tree conversion diagram according to an embodiment of the present application;

[0033] Figure 5 Rule tree conversion diagram according to an embodiment of the present application;

[0034] Figure 6 Rule tree inversion diagram according to an embodiment of the present application;

[0035] Figure 7 Rule tree merging diagram according to an embodiment of the present application;

[0036] Figure 8 Rule tree merging diagram according to another embodiment of the present application;

[0037] Figure 9 Rule tree diagram according to an embodiment of the present application;

[0038] Figure 10 Rule tree merging diagram according to an embodiment of the present application.

[0039] In the drawings, the same or corresponding reference numerals designate the same or corresponding parts. DETAILED DESCRIPTION

[0040] Exemplary embodiments of the present disclosure will be described more fully hereinafter with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it is to be understood that the present disclosure can be embodied in various forms without being limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the present disclosure to those skilled in the art.

[0041] In the description of embodiments of the present application, it is to be understood that terms such as "including" or "having," etc., are intended to indicate the presence of the features, numbers, steps, actions, components, parts, or combinations thereof disclosed in the specification, and do not exclude the possibility that one or more other features, numbers, steps, actions, components, parts, or combinations thereof exist.

[0042] Unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" herein is only a description of the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B, which means that there are three cases of A alone, A and B together, and B alone.

[0043] The terms "first", "second", and the like are only for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined with "first", "second", and the like can explicitly or implicitly include one or more features. In the description of embodiments of the present application, unless otherwise specified, the meaning of "multiple" is two or more.

[0044] Figure 1 An exemplary rule expression matching device is shown, which includes a syntax checker 110 for receiving a rule text string, performing syntax checking on the rule text string, outputting a rule expression, and ensuring the rationality of the matching rule expression; a feature converter 120 for losslessly converting the rule expression into a minimal rule expression based on a simplification algorithm of a cyclic binary code; a predicate operator 130 for equivalently converting the minimal rule expression into a rule expression matching tree based on a predicate calculus algorithm, and preparing for subsequent identification of common fragments; a network merger 140 for merging multiple rule expression matching trees into a merged matching network, and identifying common rule fragments; and a feature matcher 150 for performing feature matching on to-be-matched data using the merged matching network and the common rule fragments. In this way, through a series of simplification steps, the matching efficiency can be significantly improved.

[0045] Figure 2A flowchart for performing a rule expression matching method according to an embodiment of the present disclosure is shown. It should be understood that the method 200 can also include additional blocks not shown and / or can omit blocks shown, and the scope of the present disclosure is not limited in this regard.

[0046] At step 210, a rule text string is received, and the rule text string is syntax checked, and a rule expression is outputted.

[0047] In an embodiment, the rule text string is subjected to complete syntax checking using a context-free grammar and a recursive descent algorithm.

[0048] In an embodiment, to implement the syntax checking of the rule text string, the following steps can also be specifically performed: reading in the rule text string, splitting the rule text string according to a predetermined delimiter to obtain a plurality of morphemes, wherein the morphemes can be classified into a key element type and a logical operation type; sorting each morpheme according to the order of the morphemes in the rule text string to generate a lexical unit sequence; and traversing the lexical unit sequence to check the syntax of the rule text string.

[0049] Specifically, each applicable rule can be configured as a corresponding text string, i.e., a rule text string. For example, assuming that there are the following two rule text strings at present:

[0050]

[0051] The electronic device can receive rule text strings configured by developers, etc., and can split the rule text string according to a predetermined delimiter for each received rule text string, and remove redundant spaces and line breaks to obtain individual morphemes. For example, splitting according to a comma “,” can obtain individual morphemes, and querying a lexical unit attribute table can obtain morpheme attribute information of each morpheme:

[0052]

[0053] The morphemes are classified into a key element type and a logical operation type: the logical operation type mainly includes and “&”, or “|”, not “!”, and parentheses “()”; the key element type is related to the meaning of a specific business scenario, such as an external card used internally, a non-banking institution, etc.

[0054] Each morpheme can be sorted according to the order of the morphemes in the rule text string. For ease of description, the sorted morphemes are referred to as a lexical unit sequence. A model created based on a context-free grammar can be referred to as a production model G=(N,∑,P,S).

[0055] Exemplarily, the following shows a production model diagram provided by some embodiments, which can be based on a production model created according to a context-free grammar conforming to an Extended Backus-Naur Form (EBNF) to perform syntax analysis on a rule text string and generate a rule tree corresponding to the rule text string.

[0056]

[0057] Exemplarily, when performing syntax analysis on a rule text string based on a production model created according to a context-free grammar, each morpheme in a sequence of lexical units corresponding to the rule text string can be read in sequence, and a top-down recursive descent algorithm can be used, and each time one symbol is looked ahead, and the looked-ahead symbol is used to guide the selection of a syntax rule (analysis function) to determine an analysis function applicable to each morpheme. Exemplarily, there are five analysis functions in total, which are respectively an expression analysis function expr(), an or analysis function or(), an and left analysis function andLeftCond(), an and right analysis function andRightCond(), and a not analysis function notCond(). Each analysis function can be processed according to a conventional recursive descent algorithm. Subsequently, the sequence of lexical units that have been parsed is traversed once to check the syntax of the rule expression, and a rule tree corresponding to the rule text string is generated.

[0058] Specifically, the process of establishing a rule tree corresponding to a rule text string can include:

[0059] Each key element contained in the rule text string is taken as a node contained in the rule tree corresponding to the rule text string, respectively, and a logical operator in the rule text string is also taken as a node contained in the rule tree, respectively, and nodes having an association relationship in the rule text string can be connected, thereby establishing the rule tree corresponding to the rule text string.

[0060] In a possible implementation, when establishing a rule tree corresponding to a rule text string, if an analysis function applicable to a morpheme in a sequence of lexical units of the rule text string is an or analysis function or(), an and right analysis function andLeftCond(), a not analysis function notCond(), or the like, a newly-added matching intermediate node or (or), and (and), or (or), or the like can be established in the rule tree simultaneously, respectively, and if the morpheme (element) in the sequence of lexical units of the rule text string is a terminal symbol (TOK_COND), a corresponding leaf node can be newly added in a lower layer of the associated intermediate node. After all lexical units are traversed, if the syntax is satisfied, the rule tree shown in FIG. 8 is established simultaneously. Figure 3

[0061] ​In this embodiment, a complete grammar checking method suitable for logical operation of rule expression is created. The method uses recursive descent algorithm to complete the syntax checking of rule expression by only one traversal, and can check the syntax of infinite logical operation combination.

[0062] In step 220, the rule expression is losslessly converted into a simplest rule expression based on a simplification algorithm of cyclic binary code.

[0063] In one embodiment, the step 220 can further include:

[0064] In step 221, all key elements in the rule expression are obtained, and all combinations of the key elements are generated based on the positive and negative values of each key element.

[0065] For example, based on the rule expression output in the step 210:

[0066] F=(!A&C&D)|(!A&!C&D)|(A&!B&D)|(A&!B&!D)|(A&!B&C&D)

[0067] wherein the key elements are A, B, C and D, the value of each key element is 0 or 1, and it is assumed that a key element represents 1, and the value of the key element (negation) is 0. The value range of the key element is 2^N=2^4=16 (2 to the power of N, N is the number of key elements), and the binary string format is 0000, 0001, 0010, 0011, 0100,..., 1111. The corresponding relationship is as follows:!A!B!C!D=0000,!A!B!CD=0001,!A!BC!D=0010,..., ABCD=1111.

[0068] The binary string is expressed in decimal, i.e.

[0069] !A!B!C!D=0000=0,!A!B!CD=0001=1,!A!BC!D=0010=2,..., ABCD=1111=15.

[0070] In step 222, the combination value range that makes the rule expression true is obtained from all combinations, and the binary code combination of the combination value range is obtained.

[0071] For example, the value range that can make the original rule expression true is taken from all combinations, i.e.

[0072]

[0073] The decimal representation is as follows:

[0074]

[0075] Step 223, performing parity-cyclic binary code merging on the plurality of binary codes in the binary code combination to obtain a simplified binary code combination;

[0076] In an embodiment, the step 223 can specifically include:

[0077] (1) comparing the binary codes in the binary code combination two by two, and merging to generate new binary codes;

[0078] More specifically, when there is only one different binary bit between two binary codes, the different binary bit is set as the set symbol, and the remaining identical binary bits are kept unchanged as new binary codes. For example, for "0000" and "0010", there is 1-bit difference, which can be merged into "00*0", where "*" is the set symbol.

[0079] (2) comparing the new binary codes and the original binary codes that failed to be merged two by two, merging to generate new binary codes and removing duplicate binary codes;

[0080] Repeating the above merging steps (1) and (2) until new binary codes can no longer be generated.

[0081] Alternatively, other parity-cyclic binary code merging methods can also be used, which are not specifically limited in the present application.

[0082] Step 224, converting each binary bit in the simplified binary code combination back to the key elements, and outputting the simplest rule expression.

[0083] In an embodiment, the step 224 can specifically include one or more of the following operations:

[0084] (1) for each binary code in the simplified binary code combination, converting according to the position of the binary bit to the corresponding key element;

[0085] (2) performing a not operation or no not operation on the key element according to the value of each binary bit; and,

[0086] (3) if the binary code includes a binary bit with the set symbol value, the corresponding key element is ignored.

[0087] For example, "0000" is converted to "!A!B!C!D", "0011" is converted to "!A!BCD", "11*1" is converted to "ABD", and so on.

[0088] Exemplarily, the merging process is as follows:

[0089]

[0090] That is, the original rule expression can be equivalently simplified:

[0091] The original rule expression: F = (!A&C&D) | (!A&!C&D) | (A&!B&D) | (A&!B&!D) | (A&!B&C&D)

[0092] The simplest rule expression: F = (!AD) | (A!B)

[0093] In this embodiment, by using the above simplification algorithm based on the cyclic binary code, the rule expression configured by the user is simplified, redundant rule expression fragments are automatically removed and simplified, lossless conversion to the simplest rule expression is performed, and a matching tree is generated based on the simplified rule expression.

[0094] In this embodiment, by using the lossless conversion of the simplest expression, the text rule configured by the user is losslessly simplified into the simplest rule expression, which greatly simplifies the subsequent matching process and improves the matching efficiency.

[0095] Step 230, equivalently converting the simplest rule expression into a rule expression matching tree based on a predicate calculus algorithm;

[0096] In an embodiment, the above step 230 can specifically include: first, obtaining a rule tree corresponding to the simplest rule expression, and then repeatedly performing one or more predicate deduction algorithms until stability is obtained, to obtain the rule expression matching tree:

[0097] (1) If the non-operation has multiple child nodes, the non-operation is pushed down to the child nodes, and the AND operator and the OR operator are exchanged;

[0098] For example, referring to Figure 4 If the non-operation has multiple child nodes, the non-operation is pushed down to the child nodes, the AND operator “&” and the OR operator “|” are exchanged, and a bracket is added after the pushing down.

[0099] (2) If the current operator of the simplest rule expression is consistent with the parent node operator, the child nodes of the current operator are moved up, and the current operator is deleted;

[0100] For example, referring to Figure 5 When the current operator is consistent with the parent node operator, the child nodes of the current operator are moved up, and the current operator is deleted.

[0101] (3) For the same layer of leaf nodes, the nodes are sorted according to the unique attribute.

[0102] For example, the in-node ordering: the same layer leaf nodes are sorted by the unique attribute of the node, such as the field ID in ascending or descending order, and the same layer non-leaf nodes are arranged behind. The unique attribute of the non-leaf node is composed of the unique attributes of the child nodes, and therefore, the same layer non-leaf nodes are also sorted by the unique attribute.

[0103] Step 240, merging the multiple rule expression matching trees into a merged matching network, and identifying the common rule fragments;

[0104] In an embodiment, the above step 240 can further include:

[0105] (1) selecting one rule expression matching tree for up-down transposition, taking the rule expression matching tree as the root node, and taking the rule expression matching tree as the initial state of the merged matching network;

[0106] For example, referring to Figure 6 , selecting one rule network for up-down transposition, taking the original leaf node as the entry point, and taking the rule for the final matching hit as the terminal point, and the network is the initial state of the merged network. After up-down transposition, the element nodes are in the uppermost layer.

[0107] (2) traversing other rule expression matching trees one by one for up-down transposition, and merging them one by one into the merged matching network;

[0108] Further, in order to merge them one by one into the merged matching network, it further includes: for the element nodes in a single rule expression matching tree, adding or reusing the element nodes in the merged matching network; and / or, for the logical symbol nodes in a single rule expression matching tree, adding or reusing the logical symbol nodes in the merged matching network; and / or, for the completely coincident logical symbol nodes, the common rule fragment and the rule expression matching tree to which it belongs can be extracted through reverse search, for example, referring to Figure 7 , wherein "condition 5 & condition 6" is a common fragment, and rules 1 and 2 are shared; and / or, for the partially coincident logical symbol nodes, the logical symbol nodes in the merged matching network are split, for example, referring to Figure 8 .

[0109] (3) after the traversal is completed, a complete merged matching network is formed, and the common rule fragment and the rule to which it belongs are extracted, and the single element or derived element set of each rule is recorded.

[0110] For example, merging Figure 9 to generate the merged matching network shown in Figure 10 , wherein the elements in the dashed box are common rule fragments, and the element set involved in each rule identification (rule 1 and rule 2) is recorded.

[0111] Step 250, performing feature matching on the to-be-matched data by using the merged matching network and the common rule fragment.

[0112] In one embodiment, the priority of each rule identifier in the merged matching network can be pre-ordered; and the element set involved in each rule identifier in the merged matching network is sequentially matched with the to-be-matched data according to the priority until the matching is successful or ends.

[0113] In one embodiment, performing feature matching on the to-be-matched data by using the merged matching network and the common rule fragment comprises:

[0114] (1) Element matching, according to the element node set of the rule expression matching tree involved in each rule identifier, entering from the entrance of the merged matching network, matching the element set with the to-be-matched data, and caching the element matching result.

[0115] (2) Logic matching, if a logic node is matched, querying whether the cache of the parent node has been hit; the result can be further divided into two cases: if i) there is no cache result, then taking the next element node from the element node set to match with the to-be-matched data; ii) if there is a cache result, then directly taking the cache result to perform logic operation; and if the logic node belongs to the common rule fragment, then caching the logic matching result. Otherwise, no caching is needed to save space.

[0116] (3) If a final node is matched, returning the hit rule identifier; if the return is not met halfway, then continuing to match the next rule according to the priority order.

[0117] It should be noted that the steps not described in detail in the present embodiment can refer to the description of the related steps in the embodiments shown in Figure 1 and will not be described here again.

[0118] In the description of the present specification, the description of the terms "some possible embodiments", "some embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present application. In the present specification, the illustrative description of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any appropriate manner in any one or more embodiments or examples. In addition, the skilled in the art can combine and combine the different embodiments or examples described in the present specification and the features of the different embodiments or examples without contradiction.

[0119] With respect to the method flowcharts of the embodiments of the present application, certain operations are described as distinct steps in a sequence. Such flowcharts are illustrative and not limiting. Certain steps described herein can be grouped together and performed in a single operation, certain steps can be split into multiple sub-steps, and certain steps can be performed in an order different from that shown herein. The individual steps shown in the flowcharts can be implemented in any manner by any circuitry structure and / or tangible mechanism (e.g., by software running on a computer device, hardware (e.g., a processor or a chip-implemented logic function), etc., and / or any combination thereof).

[0120] It should be noted that the apparatus in the embodiments of the present application can implement each process of the embodiments of the foregoing method, and achieve the same effects and functions, which will not be described here.

[0121] According to some embodiments of the present application, a non-volatile computer storage medium of a rule expression matching method is provided, and computer executable instructions are stored on the non-volatile computer storage medium, and the computer executable instructions are set to execute the method described in the above embodiments when run by a processor.

[0122] Each of the embodiments of the present application is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment mainly describes the difference from other embodiments. In particular, for the apparatus, device and computer readable storage medium embodiments, since they are basically similar to the method embodiments, their description is simplified, and the relevant parts can be referred to the part of the method embodiments.

[0123] The apparatus, device and computer readable storage medium provided by the embodiments of the present application are one-to-one corresponding to the method, and therefore, the apparatus, device and computer readable storage medium also have the similar beneficial technical effects as the method. Since the beneficial technical effects of the method have been described in detail above, the beneficial technical effects of the apparatus, device and computer readable storage medium will not be described here.

[0124] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, an apparatus (device or system), or a computer readable storage medium. Therefore, the present application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer readable storage medium implemented on one or more computer readable storage media containing computer usable program code (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.).

[0125] The computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 one or more flowcharts and / or blocks in the flowcharts and / or combination thereof. Figure 1 one or more flowcharts and / or blocks in the flowcharts and / or combination thereof.

[0126] The computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 one or more flowcharts and / or blocks in the flowcharts and / or combination thereof. Figure 1 one or more flowcharts and / or blocks in the flowcharts and / or combination thereof.

[0127] The computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 one or more flowcharts and / or blocks in the flowcharts and / or combination thereof. ​ one or more flowcharts and / or blocks in the flowcharts and / or combination thereof.

[0128] In one typical configuration, the computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0129] The memory can include non-persistent memory and / or volatile memory, such as random access memory (RAM) and / or cache memory, non-volatile memory, such as read-only memory (ROM), EPROM, and / or flash memory. The memory is an example of computer-readable media.

[0130] Computer-readable media includes permanent and non-permanent, movable and non-movable media that can be implemented by any method or technology for storing information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media 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 memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible by a computing device. In addition, although the operations of the method of the present application are described in a particular order in the accompanying drawings, this does not require or imply that the operations must be performed in that particular order, or that all of the shown operations must be performed to achieve the desired result. Additionally or alternatively, certain steps can be omitted, a plurality of steps can be combined into one step, and / or one step can be divided into a plurality of steps.

[0131] Although the spirit and principles of the present application have been described with reference to several specific embodiments, it should be understood that the present application is not limited to the disclosed specific embodiments, and the division of aspects does not mean that the features in these aspects cannot be combined to benefit. This division is only for the convenience of expression. The present application is intended to cover various modifications and equivalent arrangements included in the spirit and scope of the appended claims.

Claims

1. A method for matching regular expressions, characterized in that, include: Receive a rule text string, perform syntax validation on the rule text string, and output the rule expression; A simplification algorithm based on cyclic binary code is used to losslessly convert the regular expression into the simplest regular expression. The simplest rule expression is equivalently transformed into a rule expression matching tree based on the predicate calculus algorithm. Multiple rule expression matching trees are merged into a merged matching network, and common rule fragments are identified. The merged matching network and common rule fragments are used to perform feature matching on the data to be matched; The simplification algorithm based on cyclic binary code, which losslessly converts the regular expression into its simplest regular expression, also includes: Obtain all key elements in the rule expression, and generate all combinations of all key elements based on the positive and negative values ​​of each key element; Obtain the range of values ​​for the combination that makes the rule expression true from all combinations, and obtain the binary code combination of the range of values. By performing cyclic binary code merging on multiple binary codes in the binary code combination, a simplified binary code combination is obtained. Each binary bit in the simplified binary code combination is converted back to the key element, and the simplest rule expression is output.

2. The method according to claim 1, characterized in that, Performing cyclic binary code merging on the multiple binary codes includes: The binary codes in the binary code combination are compared pairwise and merged to generate a new binary code; The new binary code is compared pairwise with the original binary code that failed to be merged, and the new binary code is generated by merging them and removing duplicate binary codes. Repeat the above merging steps until it is no longer possible to merge and generate a new binary number.

3. The method according to claim 1, characterized in that, The merging of cyclic binary codes also includes: When two binary codes differ by only one bit, that different bit is set as the setting symbol, and the remaining identical bits are kept unchanged as the new binary code.

4. The method according to claim 3, characterized in that, Each binary bit in the simplified binary code combination is converted back to the key element, including: For each binary code in the simplified binary code combination, it is converted into the corresponding key element according to the position of the binary bits; The key element is either NOT operated on or not NOT operated on based on the value of each binary bit; and, If the binary code includes binary bits that take the value of the set symbol, then the corresponding key element is ignored.

5. The method according to claim 1, characterized in that, The syntax verification of the rule text string also includes: performing a completeness syntax verification on the rule text string using a context-free grammar and a recursive descent algorithm.

6. The method according to claim 1, characterized in that, The syntax validation of the rule text string also includes: Read the rule text string, and split the rule text string according to a predetermined delimiter to obtain multiple morphemes; According to the word order in the text string, each word is sorted to generate a lexical unit sequence; Traverse the sequence of lexical units to verify the syntax of the rule text string.

7. The method according to claim 6, characterized in that, The morphemes are divided into key element type and logical operation type.

8. The method according to claim 1, characterized in that, The simplest rule expression is equivalently transformed into a rule expression matching tree; it also includes: Repeat one or more of the following predicate derivation algorithms until stable to obtain the matching tree of the regular expression: Obtain the rule tree corresponding to the simplest rule expression; If there are multiple child nodes of the NOT operation in the rule tree, the NOT operation is pushed down to the child node and interchanged with the operator and OR operator; If the current operator of the simplest regular expression is the same as the parent node operator, then move the child node of the current operator up and delete the current operator; For leaf nodes at the same level, sort them according to their unique attributes.

9. The method according to claim 1, characterized in that, Multiple rule expression matching trees are merged into a merged matching network, and common rule fragments are identified, including: Select a regular expression matching tree and transpose it vertically. Mark the regular expression matching tree rule as the root node, which serves as the initial state of the merged matching network. The other rule expression matching trees are traversed one by one, transposed vertically, and then merged into the merged matching network. After the traversal is complete, a complete merging and matching network is formed, and common rule fragments are extracted.

10. The method according to claim 1, characterized in that, The method further includes integrating each component into the merging and matching network, and also includes: For a feature node in a single rule expression matching tree, add or reuse the feature node in the merged matching network; and / or, For a logical character node in a single regular expression matching tree, add or reuse logical character nodes from the merged matching network; and / or, For completely overlapping logical sign nodes, the common rule fragment and its corresponding rule expression matching tree can be extracted through reverse search; and / or, For partially overlapping logical symbol nodes, the logical symbol nodes in the merged matching network are split.

11. The method according to claim 1, characterized in that, The feature matching of the data to be matched is performed using the merged matching network and common rule fragments, including: Prioritize and sort the rule identifiers in the merged matching network in advance; According to the priority, the set of elements involved in each rule identifier in the merging matching network is matched with the data to be matched in sequence until the match is successful or the matching ends.

12. The method according to claim 1, characterized in that, The feature matching of the data to be matched using the merged matching network and common rule fragments includes one or more of the following operations: The data to be matched is matched with the set of feature nodes in the rule expression matching tree involved in each rule identifier. The matching is entered from the entrance of the merged matching network. If a feature node in the rule expression matching tree is matched, the feature matching result is cached.

13. The method according to claim 1, characterized in that, The method of performing feature matching on the data to be matched using the merging matching network and common rule fragments also includes: If a logical node in the matching tree of the rule expression is matched, then the cache is queried to see if the parent element node of the logical node has been matched, where: If there is no cached result, the next feature node is taken from the feature node set and matched with the data to be matched; If there are cached results, the cached results are directly used for logical operations; and if the logical node belongs to a common rule fragment, the logical matching result is cached.

14. The method according to claim 1, characterized in that, The method of performing feature matching on the data to be matched using the merging matching network and common rule fragments also includes: If a rule identifier node in the rule expression matching tree is matched, the matched rule identifier is returned.

15. A regular expression matching device, characterized in that, The apparatus, configured to perform the method as described in any one of claims 1-14, comprises: A syntax validator is used to receive a rule text string, perform syntax validation on the rule text string, and output a rule expression. A feature converter is used in a simplification algorithm based on cyclic binary code to losslessly convert the regular expression into the simplest regular expression; A predicate calculus is used to convert the simplest rule expression into a rule expression matching tree based on a predicate calculus algorithm. A network merger is used to merge multiple rule expression matching trees into a merged matching network and identify common rule fragments. A feature matcher is used to perform feature matching on the data to be matched using the merged matching network and common rule fragments.

16. A regular expression matching device, characterized in that, include: At least one processor; And a memory communicatively connected to at least one processor; wherein the memory stores instructions executable by at least one processor, the instructions being executed by at least one processor to enable at least one processor to perform: the method as described in any one of claims 1-14.

17. A computer-readable storage medium storing a program that, when executed by a multi-core processor, causes the multi-core processor to perform the method as described in any one of claims 1-14.

Citation Information

Patent Citations

  • Feature matching rule construction method and device, feature matching method and device, equipment and medium

    CN114564624A