Logic expression structure comparison method and device, equipment and storage medium
Patent Information
- Application Number
- CN202211711444.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-29
- Publication Date
- 2026-09-04
- Estimated Expiration
- 2042-12-29
AI Technical Summary
[0003]传统的逻辑表达式比对方法一般仅能够获取两个逻辑表达式之间的字符差异,对于字符不同但逻辑结构相同的场景无法精准获取比对结果
Smart Images

Figure CN116050351B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer data processing technology, and in particular to a method, apparatus, device, and storage medium for comparing the structure of logical expressions. Background Technology
[0002] A logical expression is a meaningful expression obtained by concatenating relational expressions or logical quantities using logical operators.
[0003] Traditional logical expression comparison methods can generally only capture the character differences between two logical expressions. They cannot accurately obtain comparison results for scenarios where characters differ but the logical structure is the same. To compare the logical structure of logical expressions, manual comparison is required. However, for logical expressions with complex logical structures, manual comparison is not only time-consuming but also cannot guarantee the accuracy of the comparison results. Summary of the Invention
[0004] This invention provides a method, apparatus, device, and storage medium for structural comparison of logical expressions, which can replace traditional manual comparison methods and perform rapid comparison of complex logical expressions.
[0005] According to one aspect of the present invention, a method for comparing the structure of logical expressions is provided, comprising:
[0006] The first logical expression and the second logical expression are parsed respectively to generate basic element groups that match the first logical expression and the second logical expression respectively.
[0007] If each group of basic elements contains the same basic elements, then a simplified multi-way tree is generated that matches the first logical expression and the second logical expression, respectively.
[0008] Based on the hierarchical layout relationship and the total number of tree nodes in each simplified multi-way tree, generate the node code of each tree node in each simplified multi-way tree;
[0009] Based on the logical relationships between different tree nodes in each simplified multi-way tree and the node encoding of each tree node, the logical values of each simplified multi-way tree are generated, and the comparison results of the first logical expression and the second logical expression are generated based on each logical value.
[0010] According to another aspect of the present invention, a structure comparison device for logical expressions is provided, characterized in that it comprises:
[0011] The basic element group generation module is used to parse the first logical expression and the second logical expression respectively, and generate basic element groups that match the first logical expression and the second logical expression respectively.
[0012] A simplified multi-way tree generation module is used to generate simplified multi-way trees that match the first logical expression and the second logical expression respectively if each group of basic elements contains the same basic elements.
[0013] The node encoding generation module is used to generate the node encoding of each tree node in each simplified multi-way tree based on the hierarchical layout relationship and the total number of tree nodes in each simplified multi-way tree.
[0014] The comparison result generation module is used to generate logical values for each simplified multi-way tree based on the logical relationships between different tree nodes and the node encoding of each tree node, and to generate comparison results for the first logical expression and the second logical expression based on each logical value.
[0015] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0016] At least one processor; and
[0017] A memory communicatively connected to the at least one processor; wherein,
[0018] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the structure comparison method of logical expressions according to any embodiment of the present invention.
[0019] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the structure comparison method of logical expressions according to any embodiment of the present invention.
[0020] The technical solution of this invention obtains the basic element group of a logical expression, generates a simplified multi-way tree and node codes of each tree node in the simplified multi-way tree for logical expressions with the same basic element group, and then generates the logical value of the simplified multi-way tree. By comparing the logical value of the simplified multi-way tree, the comparison result of the logical expression can be obtained. This method can achieve rapid comparison of complex logical expressions with high accuracy, thereby reducing manual comparison and lowering labor and time costs.
[0021] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0022] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 This is a flowchart of a logical expression structure comparison method provided in Embodiment 1 of the present invention;
[0024] Figure 2 This is a flowchart of another logical expression structure comparison method provided in Embodiment 2 of the present invention;
[0025] Figure 3 This is a schematic diagram of a logical expression structure comparison device provided in Embodiment 3 of the present invention;
[0026] Figure 4 This is a schematic diagram of the structure of an electronic device that implements the structure comparison method of logical expressions in the embodiments of the present invention. Detailed Implementation
[0027] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0028] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0029] This invention is applicable to any type of logical expression. In order to better illustrate the technical solution of this invention, an investment monitoring expression is used as an example in the embodiments of this invention.
[0030] Example 1
[0031] Figure 1 This is a flowchart of a logical expression structure comparison method provided in Embodiment 1 of the present invention. This embodiment is applicable to generating simplified multi-way trees and node codes for each tree node in a simplified multi-way tree based on logical expressions with the same basic element group, thereby generating logical values for the simplified multi-way tree, comparing the logical values of the simplified multi-way tree, and obtaining the comparison result of the logical expression. This method can be executed by a logical expression structure comparison device, which can be implemented in hardware and / or software, and is generally configured in a computer or processor with data processing capabilities. Figure 1 As shown, the method includes:
[0032] S110. Parse the first logical expression and the second logical expression respectively, and generate basic element groups that match the first logical expression and the second logical expression respectively.
[0033] A meaningful expression obtained by concatenating relational expressions or logical quantities using logical operators is called a logical expression. Logical operators can include logical AND, logical OR, logical NOT, and other operators. Relational expressions and logical quantities are the other elements in a logical expression besides logical operators.
[0034] In a specific example, when the investment supervision expression is “[Security Class in {Depositary Receipts}]and[Market Code in {Shanghai Stock Exchange, Shenzhen Stock Exchange, Beijing Stock Exchange}]”, “and” is a logical operator, and [Security Class in {Depositary Receipts}] and [Market Code in {Shanghai Stock Exchange, Shenzhen Stock Exchange, Beijing Stock Exchange}] are two different logical quantities.
[0035] In this example, the first logical expression and the second logical expression are two expressions used for comparison. The terms "first" and "second" are merely for distinguishing between the two logical expressions and do not restrict their order. In the example of the investment supervision expression used in this embodiment, the first logical expression can refer to a logical expression manually composed by business personnel after interpreting the investment supervision rule text. The second logical expression can refer to a logical expression automatically generated using a template library. This template library is compiled by business personnel based on past experience and can provide a comparison and verification function when writing new expressions. Both manually composed and template-generated logical expressions may contain errors. Therefore, by comparing the two logical expressions, differences can be quickly identified when they differ, allowing business personnel to conduct targeted checks. This improves both the accuracy and efficiency of logical expression generation.
[0036] The basic element group is a set of elements decomposed from a logical expression. Continuing the previous example, [market code in{Shanghai Stock Exchange, Shenzhen Stock Exchange, Beijing Stock Exchange}] can be decomposed into three elements, including: market code in Shanghai Stock Exchange, market code in Shenzhen Stock Exchange, and market code in Beijing Stock Exchange.
[0037] S120. If each group of basic elements contains the same basic elements, then generate a simplified multi-way tree that matches the first logical expression and the second logical expression, respectively.
[0038] In a specific example, when the first logical expression is [Security Class in {Depositary Receipts}]and([Market Code in {Shanghai Stock Exchange, Shenzhen Stock Exchange, Beijing Stock Exchange}]or [Security Class in {Depositary Receipts}]), the basic element group that the first logical expression can parse contains the following basic elements:
[0039] a. Securities Category in Depositary Receipts
[0040] b. Market code in Shanghai Stock Exchange
[0041] c. Market code in Shenzhen Stock Exchange
[0042] d. Market code in Beijing Stock Exchange
[0043] When the second logical expression is [Security Class in {Depositary Receipts}] and [Market Code in {Shanghai Stock Exchange, Shenzhen Stock Exchange, Beijing Stock Exchange}], the basic element group that the second logical expression can parse contains the following basic elements:
[0044] a. Securities Category in Depositary Receipts
[0045] b. Market code in Shanghai Stock Exchange
[0046] c. Market code in Shenzhen Stock Exchange
[0047] d. Market code in Beijing Stock Exchange
[0048] It can be seen that although the first and second logical expressions have different forms, all the basic elements in the two parsed basic element groups are the same. However, this does not necessarily mean that the two logical expressions have the same logical structure. In other words, although the basic element groups derived from the two logical expressions are the same, the meanings expressed by the two logical expressions may be different. Therefore, this invention creatively proposes generating a simplified multi-way tree based on the logical expression, and further obtaining the comparison results between the two logical expressions through analysis of the simplified multi-way tree.
[0049] Optionally, a binary tree matching the first and second logical expressions can be generated based on the first and second logical expressions respectively. The binary tree can be converted into a multi-way tree using a preset conversion rule, and the multi-way tree can be simplified to obtain a simplified multi-way tree matching the two logical expressions respectively.
[0050] Continuing the previous example, when the second logical expression is [Security Class in {Depositary Receipts}] and [Market Code in {Shanghai Stock Exchange, Shenzhen Stock Exchange, Beijing Stock Exchange}], its simplified multi-way tree is as follows:
[0051]
[0052] It is easy to see that the element "Securities Classification in Depositary Receipts" is missing in the simplified multi-branch tree of the second logical expression. One possible reason is that the multi-branch tree of the first logical expression has an element with the same logic as this element. By simplifying the process, this element in both logical expression multi-branch trees is eliminated simultaneously, and finally a simplified multi-branch tree as shown above is obtained.
[0053] S130. Based on the hierarchical layout relationship and the total number of tree nodes in each simplified multi-branch tree, generate the node code of each tree node in each simplified multi-branch tree.
[0054] It is understood that in the actual application of this invention, the simplified multi-way tree of the logical expression can generally have multiple tree nodes. This invention encodes each tree node in the simplified multi-way tree, so that the logical value of the simplified multi-way tree can be further calculated through the encoding of each tree node.
[0055] Optionally, the encoding of a tree node can be determined based on the total number of tree nodes in the simplified multi-way tree. For example, for a simplified multi-way tree with three tree nodes, the encodings of the three tree nodes can be 1110100, 1101010, and 1011001, respectively. It should be noted that the encoding consists of consecutive numbers; the grouping here is to illustrate the encoding construction method. Specifically, for a simplified multi-way tree with three tree nodes, the encoding of each tree node can be divided into... as well as Three sets, for the tree node encoded as 1110100, its For 1, For 110, As shown by the value 100, the three codes... All are the same, fixed at 1, three codes and They are all different.
[0056] S140. Based on the logical relationships between different tree nodes in each simplified multi-way tree and the node encoding of each tree node, generate the logical values of each simplified multi-way tree, and generate the comparison results of the first logical expression and the second logical expression based on each logical value.
[0057] It is understandable that after encoding each tree node, the simplified multi-way tree can be equivalent to being composed of encoding and logical operators. The encoding is calculated according to the operation logic of the logical operators, and finally the logical value of the simplified multi-way tree can be obtained.
[0058] In a specific example, continuing from the previous example, if the three tree nodes with codes 1110100, 1101010 and 1011001 are tree nodes under the same AND logic, then the final calculated logical value of these three tree nodes is 1000000. From this, the logical value of the simplified multi-way tree can be deduced layer by layer.
[0059] It is understandable that if the simplified multi-way trees of two logical expressions have the same logical value and the elements in their basic element groups are the same, then the two logical expressions represent the same meaning; if the elements in the basic element groups of two logical expressions are the same, but the logical values of their simplified multi-way trees are different, then the tree nodes with different meanings can be found by encoding each tree node in the simplified multi-way tree.
[0060] One way to obtain tree nodes with different meanings is to compare the two simplified multi-branch trees layer by layer, determine the logical value at each level, and if the logical values are the same, temporarily remove the current level and proceed to the next level to determine the logical value. Continue until two levels with different logical values are obtained, and at least one of these two levels cannot be removed to obtain a new level. In this case, output these two levels as the parts where the two logical expressions differ.
[0061] Optionally, the comparison result of the first logical expression and the second logical expression can be that the two logical expressions are the same or that the two logical expressions are different, and the parts of the logical expressions that are different are obtained.
[0062] The technical solution of this invention obtains the basic element group of a logical expression, generates a simplified multi-way tree and node codes of each tree node in the simplified multi-way tree for logical expressions with the same basic element group, and then generates the logical value of the simplified multi-way tree. By comparing the logical value of the simplified multi-way tree, the comparison result of the logical expression can be obtained. This method can achieve rapid comparison of complex logical expressions with high accuracy, thereby reducing manual comparison and lowering labor and time costs.
[0063] Example 2
[0064] Figure 2This is a flowchart illustrating another method for structural comparison of logical expressions provided in Embodiment 2 of the present invention. Based on the above embodiments, this embodiment specifically describes a method for structural comparison of logical expressions. For example... Figure 2 As shown, the method includes:
[0065] S210. Obtain the logical operation characters and element characters in the logical expression.
[0066] Optionally, logical operator characters can be characters such as and, any, or, used to represent logical relationships, and element characters can be text elements such as market codes or Shenzhen Stock Exchange.
[0067] S220. Based on the logical operation characters and element characters, split the element characters in the logical expression that have a merging relationship, and generate multiple basic elements based on the splitting results.
[0068] In a specific example, [market code in {Shanghai Stock Exchange, Shenzhen Stock Exchange, Beijing Stock Exchange}] can be broken down into three basic elements: market code in Shanghai Stock Exchange, market code in Shenzhen Stock Exchange, and market code in Beijing Stock Exchange.
[0069] The specific splitting method depends on the meaning of the logical operator characters; this is just an example.
[0070] S230. Use basic elements to form a basic element group that matches the logical expression.
[0071] S240. If each group of basic elements contains the same basic elements, then generate a simplified multi-way tree that matches the first logical expression and the second logical expression, respectively.
[0072] Specifically, generating simplified multi-way trees that match the first and second logical expressions can include:
[0073] Generate binary trees that match the first logical expression and the second logical expression respectively, according to the preset binary tree generation rules;
[0074] According to the preset multi-way tree conversion rules, the binary tree is converted into a multi-way tree, and the converted multi-way tree is simplified to obtain a simplified multi-way tree.
[0075] Continuing with the previous example, when the logical expression is [Security Class in {Depositary Receipts}] and [Market Code in {Shanghai Stock Exchange, Shenzhen Stock Exchange, Beijing Stock Exchange}], the matching binary tree form is as follows:
[0076]
[0077] Furthermore, after converting the above binary tree into a multi-way tree, the multi-way tree takes the following form:
[0078]
[0079] Although the binary trees and multi-way trees mentioned above have different forms, they represent the same meaning.
[0080] The simplification of the converted multi-way tree may include at least one of the following:
[0081] If there are identical first tree nodes under the first operation logic in the multi-way tree, then keep one first tree node and delete the rest.
[0082] If the second operation logic of each multi-way tree contains the same second tree node, then delete the second tree node in each multi-way tree;
[0083] If there are multiple third tree nodes that satisfy the merging condition under the third operation logic of each multi-way tree, and the third tree nodes of each multi-way tree are the same, then merge the multiple third tree nodes in each multi-way tree to generate a fourth tree node with the same logical meaning as the multiple third tree nodes.
[0084] Simplifying a multi-way tree can include simplification within the multi-way tree and simplification between multi-way trees. Simply put, we can first simplify redundant elements within the multi-way tree. After there are no redundant elements in the multi-way tree, we compare the multi-way trees after removing redundancy from the two logical expressions, delete tree nodes in the two multi-way trees that are identical in both logic and element, and finally merge multiple tree nodes that can be represented by merging into one tree node for representation, thus completing the simplification process of the multi-way tree.
[0085] In a specific example, the multi-way tree matching the first logical expression is as follows:
[0086]
[0087] The multi-way tree that matches the second logical expression is as follows:
[0088]
[0089] At this point, we can delete one of the security categories in the second logical expression, namely "depositary receipts," to complete the tree simplification of the second logical expression. Since both multi-way trees have the element "depositary receipts" under the "all" logic, we can delete the "depositary receipts" element from both multi-way trees simultaneously. It can be seen that the market codes "Shanghai Stock Exchange," "Shenzhen Stock Exchange," and "Beijing Stock Exchange" under the "any" logic can be logically merged. Therefore, we can use the element ([market code in Shenzhen Stock Exchange] - [market code in Beijing Stock Exchange] - [market code in Shanghai Stock Exchange]) to replace the above three elements. The simplified multi-way tree of the first logical expression can be represented as:
[0090]
[0091] The simplified multi-way tree of the second logical expression can be represented as:
[0092]
[0093] Optionally, if there are different basic elements among the basic element groups that match the first logical expression and the second logical expression respectively, then the structure comparison result of the logical expression is generated based on the different basic elements.
[0094] In a specific example, if the basic element group of the first logical expression is a. security type in depositary receipts b. market code in Shanghai Stock Exchange c. market code in Shenzhen Stock Exchange d. market code in Beijing Stock Exchange, and the basic element group of the second logical expression is a. security type in depositary receipts b. market code in Shanghai Stock Exchange c. market code in Shenzhen Stock Exchange d. market code in New York Stock Exchange, then the d-term of the two basic element groups are two different basic elements, and the market code in Beijing Stock Exchange and the market code in New York Stock Exchange can be output as the structure comparison result.
[0095] S250. Sort the tree nodes in the current simplified multi-branch tree according to the hierarchical layout relationship of the current simplified multi-branch tree.
[0096] S260. Based on the total number of tree nodes in the current simplified multi-way tree, determine the encoding template with a set encoding length that matches the current simplified multi-way tree. The encoding template includes at least one fixed encoding region and at least one variable encoding region.
[0097] Continuing the previous example, for a simplified multi-way tree with three tree nodes, the encoding of each tree node can be divided into... as well as Three sets, and the encoding length in each set is a preset length, for example, There is only one code in it. and There is a three-digit code that can be used to... Set as a fixed encoding region, for all tree nodes Both are 1, which can be and Set it to a variable encoding region, as long as the encoding in the variable encoding region of each tree node is different.
[0098] S270. According to the preset encoding rules, fill the fixed encoding area with fixed encoding values, and according to the sorting results of each tree node in the current simplified multi-way tree, fill the variable encoding area with variable encoding values respectively, forming a node encoding corresponding to each tree node in the current simplified multi-way tree.
[0099] S280. Based on the logical relationships between different tree nodes in each simplified multi-way tree and the node encoding of each tree node, generate the logical values of each simplified multi-way tree, and generate the comparison results of the first logical expression and the second logical expression based on each logical value.
[0100] Specifically, generating a comparison result between the first and second logical expressions based on each logical value can include:
[0101] Check whether the first logical value and the second logical value corresponding to the first logical expression and the second logical expression are consistent;
[0102] If not, then in the first logical expression and the second logical expression, the first logical sub-value and the second logical sub-value corresponding to the current comparison level of each simplified multi-way tree are parsed, and the current comparison level is initialized to the last level of the simplified multi-way tree;
[0103] Compare whether the first logical subvalue and the second logical subvalue are consistent;
[0104] If so, after decrementing the current alignment level by one, return to the operation of parsing the first and second logical sub-values corresponding to the current alignment level of each simplified multi-way tree, until the processing of all levels in the simplified multi-way tree is completed;
[0105] If not, when the total number of tree nodes included in the current comparison level is not unique, the first logical sub-value and the second logical sub-value will be resolved into the last logical sub-value corresponding to each tree node respectively.
[0106] Identify the target tree nodes with different last logical sub-values, and use them as the comparison results of the first logical expression and the second logical expression;
[0107] When the total number of tree nodes included in the current comparison level is unique, the unique tree node in the current comparison level is taken as the comparison result of the first logical expression and the second logical expression.
[0108] The technical solution of this invention can effectively reduce the amount of subsequent calculations and improve the calculation speed by simplifying the multi-way tree of the logical expression. By generating the comparison result of the logical expression based on the logical value of the simplified multi-way tree, the difference part of the logical expression can be quickly located, thus improving the comparison efficiency of the logical expression.
[0109] Example 3
[0110] Figure 3 This is a schematic diagram of a logical expression structure comparison device provided in Embodiment 3 of the present invention. Figure 3 As shown, the device includes: a basic element group generation module 310, a simplified multi-branch tree generation module 320, a node encoding generation module 330, and a comparison result generation module 340.
[0111] The basic element group generation module 310 is used to parse the first logical expression and the second logical expression respectively, and generate basic element groups that match the first logical expression and the second logical expression respectively.
[0112] The simplified multi-way tree generation module 320 is used to generate a simplified multi-way tree that matches the first logical expression and the second logical expression respectively if each group of basic elements contains the same basic elements.
[0113] The node encoding generation module 330 is used to generate the node encoding of each tree node in each simplified multi-branch tree based on the hierarchical layout relationship and the total number of tree nodes in each simplified multi-branch tree.
[0114] The comparison result generation module 340 is used to generate logical values for each simplified multi-way tree based on the logical relationships between different tree nodes and the node codes of each tree node, and to generate comparison results for the first logical expression and the second logical expression based on each logical value.
[0115] The technical solution of this invention obtains the basic element group of a logical expression, generates a simplified multi-way tree and node codes of each tree node in the simplified multi-way tree for logical expressions with the same basic element group, and then generates the logical value of the simplified multi-way tree. By comparing the logical value of the simplified multi-way tree, the comparison result of the logical expression can be obtained. This method can achieve rapid comparison of complex logical expressions with high accuracy, thereby reducing manual comparison and lowering labor and time costs.
[0116] Based on the above embodiments, the basic element group generation module 310 can be specifically used for:
[0117] Retrieves logical operation characters and element characters from a logical expression;
[0118] Based on logical operation characters and element characters, the element characters in the logical expression that have a merging relationship are split, and multiple basic elements are generated based on the splitting results;
[0119] Use basic elements to construct a group of basic elements that matches a logical expression.
[0120] Based on the above embodiments, a basic element result generation module may also be included, specifically used for:
[0121] If there are different basic elements among the basic element groups that match the first and second logical expressions respectively, then the structure comparison result of the logical expression is generated based on the different basic elements.
[0122] Based on the above embodiments, the simplified multi-branch tree generation module 320 may include:
[0123] The binary tree generation unit is used to generate binary trees that match the first logical expression and the second logical expression respectively, according to the preset binary tree generation rules.
[0124] The multi-way tree simplification element is used to convert a binary tree into a multi-way tree according to a preset multi-way tree conversion rule, and then simplify the converted multi-way tree to obtain a simplified multi-way tree.
[0125] Based on the above embodiments, the multi-branch tree-based simple element can be specifically used for:
[0126] If there are identical first tree nodes under the first operation logic in the multi-way tree, then keep one first tree node and delete the rest.
[0127] If the second operation logic of each multi-way tree contains the same second tree node, then delete the second tree node in each multi-way tree;
[0128] If there are multiple third tree nodes that satisfy the merging condition under the third operation logic of each multi-way tree, and the third tree nodes of each multi-way tree are the same, then merge the multiple third tree nodes in each multi-way tree to generate a fourth tree node with the same logical meaning as the multiple third tree nodes.
[0129] Based on the above embodiments, the node encoding generation module 330 can be specifically used for:
[0130] Based on the hierarchical layout of the current simplified multi-way tree, sort the tree nodes in the current simplified multi-way tree;
[0131] Based on the total number of tree nodes in the current simplified multi-way tree, determine the encoding template with a set encoding length that matches in the current simplified multi-way tree. The encoding template includes at least one fixed encoding region and at least one variable encoding region.
[0132] According to the preset encoding rules, fixed encoding values are filled in the fixed encoding area, and variable encoding values are filled in the variable encoding area according to the sorting results of each tree node in the current simplified multi-way tree, forming a node encoding corresponding to each tree node in the current simplified multi-way tree.
[0133] Based on the above embodiments, the comparison result generation module 340 can be specifically used for:
[0134] Check whether the first logical value and the second logical value corresponding to the first logical expression and the second logical expression are consistent;
[0135] If not, then in the first logical expression and the second logical expression, parse the first logical sub-value and the second logical sub-value corresponding to the current comparison level of each simplified multi-way tree, and initialize the current comparison level to the last level of the simplified multi-way tree;
[0136] Compare whether the first logical subvalue and the second logical subvalue are consistent;
[0137] If so, after decrementing the current alignment level by one, return to the operation of parsing the first and second logical sub-values corresponding to the current alignment level of each simplified multi-way tree, until the processing of all levels in the simplified multi-way tree is completed;
[0138] If not, when the total number of tree nodes included in the current comparison level is not unique, the first logical sub-value and the second logical sub-value will be resolved into the last logical sub-value corresponding to each tree node respectively.
[0139] Identify the target tree nodes with different last logical sub-values, and use them as the comparison results of the first logical expression and the second logical expression;
[0140] When the total number of tree nodes included in the current comparison level is unique, the unique tree node in the current comparison level is taken as the comparison result of the first logical expression and the second logical expression.
[0141] The logical expression structure comparison device provided in the embodiments of the present invention can execute the logical expression structure comparison method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0142] Example 4
[0143] Figure 4 A schematic diagram of an electronic device 10 that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0144] like Figure 4 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0145] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0146] Processor 11 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, central processing unit (CPU), graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as the structure comparison method of logical expressions as described in embodiments of the present invention. That is:
[0147] The first logical expression and the second logical expression are parsed respectively to generate basic element groups that match the first logical expression and the second logical expression respectively.
[0148] If each group of basic elements contains the same basic elements, then a simplified multi-way tree is generated that matches the first logical expression and the second logical expression, respectively.
[0149] Based on the hierarchical layout relationship and the total number of tree nodes in each simplified multi-way tree, generate the node code of each tree node in each simplified multi-way tree;
[0150] Based on the logical relationships between different tree nodes in each simplified multi-way tree and the node encoding of each tree node, the logical values of each simplified multi-way tree are generated, and the comparison results of the first logical expression and the second logical expression are generated based on each logical value.
[0151] In some embodiments, the logical expression structure comparison method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the logical expression structure comparison method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform the logical expression structure comparison method by any other suitable means (e.g., by means of firmware).
[0152] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0153] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0154] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0155] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0156] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0157] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0158] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0159] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for comparing the structure of logical expressions, characterized in that, include: The first logical expression and the second logical expression are parsed respectively to generate basic element groups that match the first logical expression and the second logical expression respectively; wherein, the first logical expression refers to the logical expression manually spelled out by business personnel after interpreting the investment supervision rule text; the second logical expression refers to the logical expression automatically generated using the template library; If each of the basic element groups contains the same basic elements, then a simplified multi-way tree is generated that matches the first logical expression and the second logical expression, respectively. Based on the hierarchical layout relationship and the total number of tree nodes in each simplified multi-way tree, generate the node code of each tree node in each simplified multi-way tree; Based on the logical relationships between different tree nodes in each simplified multi-way tree and the node encoding of each tree node, generate the logical values of each simplified multi-way tree, and generate the comparison results of the first logical expression and the second logical expression based on each logical value. Generate simplified multi-way trees that match the first logical expression and the second logical expression, respectively, including: Generate binary trees that match the first logical expression and the second logical expression respectively, according to the preset binary tree generation rules; According to the preset multi-way tree conversion rules, the binary tree is converted into a multi-way tree, and the converted multi-way tree is simplified to obtain a simplified multi-way tree. The transformed multi-way tree is simplified, including at least one of the following: If there are identical first tree nodes under the first operation logic in the multi-way tree, then keep one first tree node and delete the rest. If the second operation logic of each multi-way tree contains the same second tree node, then delete the second tree node in each multi-way tree; If there are multiple third tree nodes that satisfy the merging condition under the third operation logic of each multi-way tree, and the third tree nodes of each multi-way tree are the same, then merge the multiple third tree nodes in each multi-way tree to generate a fourth tree node with the same logical meaning as the multiple third tree nodes.
2. The method according to claim 1, characterized in that, The first logical expression and the second logical expression are parsed respectively to generate basic element groups that match the first logical expression and the second logical expression respectively, including: Obtain the logical operation characters and element characters in the logical expression; based on the logical operation characters and element characters, split the element characters in the logical expression that have a merging relationship, and generate multiple basic elements based on the splitting results; use the basic elements to form a basic element group that matches the logical expression.
3. The method according to claim 2, characterized in that, After generating the basic element groups that match the first logical expression and the second logical expression respectively, the method further includes: if there are different basic elements among the basic element groups that match the first logical expression and the second logical expression respectively, then generating a structural comparison result of the logical expression based on the different basic elements.
4. The method according to claim 1, characterized in that, Based on the hierarchical layout of each simplified multi-way tree and the total number of tree nodes, generate the node code for each tree node in each simplified multi-way tree, including: Based on the hierarchical layout of the current simplified multi-way tree, sort the tree nodes in the current simplified multi-way tree; Based on the total number of tree nodes in the current simplified multi-way tree, determine the encoding template with a set encoding length that matches the current simplified multi-way tree. The encoding template includes at least one fixed encoding region and at least one variable encoding region. According to the preset encoding rules, fixed encoding values are filled in the fixed encoding area, and variable encoding values are filled in the variable encoding area according to the sorting results of each tree node in the current simplified multi-branch tree, forming a node encoding corresponding to each tree node in the current simplified multi-branch tree.
5. The method according to claim 4, characterized in that, Based on each logical value, a comparison result is generated between the first logical expression and the second logical expression, including: Check whether the first logical value and the second logical value corresponding to the first logical expression and the second logical expression are consistent; If not, then in the first logical expression and the second logical expression, the first logical sub-value and the second logical sub-value corresponding to the current comparison level of each simplified multi-way tree are parsed, and the current comparison level is initialized to the last level of the simplified multi-way tree; Compare whether the first logical subvalue and the second logical subvalue are consistent; If so, after decrementing the current alignment level by one, return to the operation of parsing the first and second logical sub-values corresponding to the current alignment level of each simplified multi-way tree, until the processing of all levels in the simplified multi-way tree is completed; If not, when the total number of tree nodes included in the current comparison level is not unique, the first logical sub-value and the second logical sub-value will be resolved into the last logical sub-value corresponding to each tree node respectively. Identify the target tree nodes with different last logical sub-values, and use them as the comparison results of the first logical expression and the second logical expression; When the total number of tree nodes included in the current comparison level is unique, the unique tree node in the current comparison level is taken as the comparison result of the first logical expression and the second logical expression.
6. A structure comparison device for logical expressions, characterized in that, include: The basic element group generation module is used to parse the first logical expression and the second logical expression respectively, and generate basic element groups that match the first logical expression and the second logical expression respectively; wherein, the first logical expression refers to the logical expression manually spelled out by business personnel after interpreting the investment supervision rule text; the second logical expression refers to the logical expression automatically generated using the template library; A simplified multi-way tree generation module is used to generate a simplified multi-way tree that matches the first logical expression and the second logical expression respectively if each group of basic elements includes the same basic elements. The node encoding generation module is used to generate the node encoding of each tree node in each simplified multi-way tree based on the hierarchical layout relationship and the total number of tree nodes in each simplified multi-way tree. The comparison result generation module is used to generate logical values for each simplified multi-way tree based on the logical relationships between different tree nodes and the node encoding of each tree node, and to generate comparison results for the first logical expression and the second logical expression based on each logical value. A simplified multi-way tree generation module, including: The binary tree generation unit is used to generate binary trees that match the first logical expression and the second logical expression respectively, according to the preset binary tree generation rules. The multi-way tree simplification element is used to convert a binary tree into a multi-way tree according to a preset multi-way tree conversion rule, and then simplify the converted multi-way tree to obtain a simplified multi-way tree. The multi-branch tree-based simple element is specifically used for: If there are identical first tree nodes under the first operation logic in the multi-way tree, then keep one first tree node and delete the rest. If the second operation logic of each multi-way tree contains the same second tree node, then delete the second tree node in each multi-way tree; If there are multiple third tree nodes that satisfy the merging condition under the third operation logic of each multi-way tree, and the third tree nodes of each multi-way tree are the same, then merge the multiple third tree nodes in each multi-way tree to generate a fourth tree node with the same logical meaning as the multiple third tree nodes.
7. An electronic device characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the structure comparison method of the logical expression according to any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the structure comparison method of the logical expression according to any one of claims 1-5.
Citation Information
Patent Citations
Logic expression analysis method and apparatus
CN105404497A
Rule logic diagram comparison method and device, medium and electronic equipment
CN111563178A