Custom logic expression analysis method, electronic equipment and storage medium
Through character-by-character traversal and stack mechanism, the problem of fewer custom logical expression parsing tools in the existing technology is solved, improving analysis efficiency and reducing R&D costs.
Patent Information
- Application Number
- CN202411674903.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2044-11-21
AI Technical Summary
In the prior art, Java open source tool classes rarely support the parsing of custom logical expressions, resulting in high R&D costs and time.
By traversing custom logical expressions by character-by-character, creating logical rule objects, and using the stack mechanism to track the hierarchy of expressions, segmenting and storing parsable structural units, and finally combining to obtain parsable custom logical expressions.
It improves the parsing efficiency of custom logical expressions, reduces R&D costs and time, and simplifies the project R&D process.
Smart Images

Figure CN119690393A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the computer field, and more specifically, to a method for parsing a custom logic expression in the computer field, an electronic device and a storage medium. Background Art
[0002] In project development, business requirements often require the configuration of many rules. Related businesses need to use the rule engine to determine whether the custom logic expression returns True or False, and then proceed with related business process processing.
[0003] However, in the related technologies, Java open source tool classes support more parsing of mathematical, Boolean, and functional expressions, but there are fewer parsing tools that can well support custom logical expressions, which may lead to more R&D costs and time spent on parsing custom logical expressions. Therefore, how to facilitate the parsing of custom logical expressions to improve the efficiency of project R&D and save project R&D costs has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] The present application provides a method for parsing a custom logical expression, an electronic device and a storage medium. The method can facilitate the parsing of the custom logical expression, thereby improving the efficiency of project development and saving project development costs.
[0005] In a first aspect, a method for parsing a custom logical expression is provided, the method comprising: traversing each character in the custom logical expression to be parsed in turn; if it is determined based on the traversed characters that a preset creation condition is met, creating a logic rule object, and pushing the logic rule object into a pre-created stack; during the traversal process, segmenting the custom logical expression according to the traversed characters to obtain parseable structural units, and storing the structural units in the logic rule object; after traversing all characters in the custom logical expression to be parsed, popping the logic rule object from the stack; combining the structural units stored in the popped-up logic rule object to obtain a parseable custom logical expression.
[0006] The above technical solution, by traversing the custom logic expression to be parsed character by character, is conducive to accurately identifying the meaning of each character, thereby accurately segmenting the custom logic expression. By creating a logic rule object and using a stack mechanism to push the logic rule object into the stack, it is conducive to tracking the hierarchical structure of the custom logic expression to be parsed through the stack, making the parsing of the custom logic expression clearer and easier to maintain. During the traversal process, the parsable structural units obtained by segmentation are stored in the logic rule object to ensure that each parsable structural unit can be stored completely and orderly. The stack is a data structure with a first-in-last-out feature, and the logic rule objects in the stack store parsable structural units. Therefore, after traversing all characters, the logic rule objects are orderly popped out from the stack, and the structural units stored in the popped-out logic rule objects are combined to facilitate the acquisition of a parsable custom logic expression. In the process of project development, for the custom logic expressions involved, the custom logic expressions can be gradually parsed by the above method without spending other workload, which is conducive to improving the efficiency of project development and saving project development costs.
[0007] In combination with the first aspect, in some possible implementations, if it is determined based on the traversed characters that a preset creation condition is met, a logical rule object is created, including: if the currently traversed character belongs to a starting separator and the starting separator is the first character in the custom logical expression to be parsed, then a logical rule object is created; or, if the currently traversed character belongs to a logical operator and the logical rule object at the top of the stack already has a left sub-expression and a right sub-expression stored in it, then a logical rule object is created.
[0008] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the structural unit includes a sub-expression; the custom logical expression is segmented according to the traversed characters to obtain a parsable structural unit, and the structural unit is stored in the logical rule object, including: determining a start delimiter and an end delimiter matching the start delimiter among the traversed characters, and determining the characters between the start delimiter and the end delimiter as a sub-expression; obtaining the logical rule object at the top of the stack, and storing the sub-expression in the logical rule object at the top of the stack.
[0009] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the storing the sub-expression in the logic rule object at the top of the stack includes: if the left sub-expression is not stored in the logic rule object at the top of the stack, then the sub-expression is used as the left sub-expression and the left sub-expression is stored in the logic rule object at the top of the stack; if the left sub-expression is stored in the logic rule object at the top of the stack, then the sub-expression is used as the right sub-expression and the right sub-expression is stored in the logic rule object at the top of the stack.
[0010] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the structural unit also includes: a logical operator; after storing the left sub-expression in the logical rule object at the top of the stack and before storing the right sub-expression in the logical rule object at the top of the stack, the method also includes: if the currently traversed character belongs to the logical operator and the previously traversed character belongs to the end delimiter, then the currently traversed logical operator is stored in the logical rule object at the top of the stack.
[0011] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the sub-expression also includes: a third sub-expression; after storing the right sub-expression in the logic rule object at the top of the stack, the method also includes: if the currently traversed character belongs to a logical operator and it is determined that the left sub-expression and the right sub-expression are already stored in the logic rule object at the top of the stack, then the logical operator is used as the logical operator between the logic rule object at the top of the stack and the third sub-expression; the logical operator between the left sub-expression and the third sub-expression is stored in the logic rule object at the top of the stack; wherein the third sub-expression is a sub-expression identified after the right sub-expression.
[0012] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the structural units stored in the popped-out logic rule object are combined to obtain a resolvable custom logic expression, including: if the stack includes multiple logic rule objects, then in accordance with the popping order, a parent-child relationship is established for two adjacent logic rule objects that are popped out successively to obtain a parent logic rule object and a child logic rule object; wherein, the logic rule object that is popped out first among the two adjacent logic rule objects is the child logic rule object, and the logic rule object that is popped out later is the parent logic rule object; according to the parent-child relationship, the structural units stored in the parent logic rule object and the structural units stored in the child logic rule object are combined to obtain a resolvable custom logic expression.
[0013] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, after combining the structural units stored in the pop-up logic rule object to obtain a resolvable custom logic expression, the method also includes: obtaining business data; bringing the business data into the resolvable custom logic expression, and calculating the Boolean value of the custom logic expression.
[0014] In a second aspect, a parsing device for a custom logical expression is provided, the parsing device comprising: a traversal module, for traversing each character in the custom logical expression to be parsed in turn; a creation module, for creating a logic rule object if it is determined based on the traversed characters that a preset creation condition is met, and pushing the logic rule object into a pre-created stack; a segmentation and storage module, for segmenting the custom logical expression according to the traversed characters during the traversal process to obtain parseable structural units, and storing the structural units in the logic rule object; a popping module, for popping the logic rule object from the stack after traversing all the characters in the custom logical expression to be parsed; and a combining module, for combining the structural units stored in the popped-out logic rule object to obtain a parseable custom logical expression.
[0015] In a third aspect, an electronic device is provided, comprising a memory for storing executable program code; and a processor for calling and running the executable program code from the memory, so that the electronic device executes the method in the above-mentioned first aspect or any possible implementation manner of the first aspect.
[0016] In a fourth aspect, a computer program product is provided, comprising: a computer program code, which, when executed on a computer, enables the computer to execute the method in the first aspect or any possible implementation of the first aspect.
[0017] In a fifth aspect, a computer-readable storage medium is provided, which stores a computer program code. When the computer program code runs on a computer, the computer executes the method in the above-mentioned first aspect or any possible implementation manner of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 It is a schematic flow chart of a method for parsing a custom logical expression provided in an embodiment of the present application;
[0019] Figure 2 It is a schematic diagram of establishing a parent-child relationship between a parent logic rule object and a child logic rule object provided by an embodiment of the present application;
[0020] Figure 3 It is a structural schematic diagram of a device for parsing a custom logical expression provided in an embodiment of the present application;
[0021] Figure 4 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0022] The technical solution in the present application will be described clearly and in detail below in conjunction with the accompanying drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B: "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.
[0023] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.
[0024] In project development, business requirements often require the configuration of many rules. Related businesses need to use the rule engine to determine whether the custom logic expression returns True or False, and then proceed with related business process processing.
[0025] However, in the related technologies, Java open source tool classes support more parsing of mathematical, Boolean, and functional expressions, but there are fewer parsing tools that can well support custom logical expressions, which may lead to more R&D costs and time spent on parsing custom logical expressions. Therefore, how to facilitate the parsing of custom logical expressions to improve the efficiency of project R&D and save project R&D costs has become a technical problem that needs to be solved urgently.
[0026] In order to at least solve the above-mentioned technical problems, an embodiment of the present application provides a method for parsing a custom logical expression, which is applied to an electronic device. A custom logical expression parsing tool can be installed in the electronic device, so that the custom logical expression to be parsed can be parsed by the custom logical expression parsing tool, thereby improving the efficiency of project research and development and saving project research and development costs.
[0027] A custom logic expression is an expression that is defined according to specific requirements and rules, and is used for logical judgment and conditional control. Custom logic expressions are usually composed of different types of characters, including variables, constants, logical operators, comparison operators, start delimiters, and end delimiters. These characters are combined to implement complex logical judgments. The purpose of custom logic expressions is to flexibly represent and process various logical conditions in the program, thereby implementing more complex functions and decision-making processes. The following introduces the different types of characters mentioned above:
[0028] Variables are characters that store data, for example, x, y, GWM_FEATURE_HW_CO_DRIVER_SCREEN_SUPPORT, GWM_FEATURE_HW_CEILING_SCREEN_SUPPORT, etc.
[0029] Constants are fixed values, such as numbers (42), strings ("hello"), Boolean values (True, False), etc.
[0030] Logical operators are characters used to perform logical operations, including AND ("&"), OR ("|"), XOR ("^"), etc.
[0031] Comparison operators are characters used to perform comparison operations, including: greater than (">"), less than ("<"), equal to ("=="), not equal to ("!="), greater than or equal to ("≥"), less than or equal to ("≤"), etc.
[0032] The starting separator is the starting identifier of a subexpression, such as the left bracket "(".
[0033] End delimiter, the end identifier of the subexpression, such as the right bracket ")".
[0034] Figure 1 It is a schematic flowchart of a method for parsing a custom logical expression provided in an embodiment of the present application.
[0035] For example, Figure 1 As shown, the parsing method of the custom logical expression includes:
[0036] Step 101: traverse each character in the user-defined logical expression to be parsed in sequence.
[0037] Step 102: If it is determined based on the traversed characters that the preset creation condition is met, a logic rule object is created and pushed into a pre-created stack.
[0038] Step 103: During the traversal process, the user-defined logical expression is segmented according to the traversed characters to obtain parsable structural units, and the structural units are stored in the logical rule object.
[0039] Step 104: After traversing all characters in the user-defined logical expression to be parsed, pop the logical rule object from the stack.
[0040] Step 105: Combine the structural units stored in the pop-up logic rule object to obtain a resolvable custom logic expression.
[0041] exist Figure 1 In the embodiment shown, by traversing the custom logic expression to be parsed character by character, it is beneficial to accurately identify the meaning of each character, so as to accurately segment the custom logic expression. By creating a logic rule object and using a stack mechanism to push the logic rule object into the stack, it is beneficial to track the hierarchical structure of the custom logic expression to be parsed through the stack, so that the parsing of the custom logic expression is clearer and easier to maintain. During the traversal process, the parsable structural units obtained by segmentation are stored in the logic rule object to ensure that each parsable structural unit can be stored completely and orderly. The stack is a data structure with a first-in-last-out feature, and the logic rule objects in the stack store parsable structural units. Therefore, after traversing all characters, the logic rule objects are orderly popped out from the stack, and the structural units stored in the popped-out logic rule objects are combined to facilitate the parsable custom logic expression. In the process of project development, for the custom logic expressions involved, the custom logic expressions can be gradually parsed by the above method without spending other workload, which is beneficial to improve the efficiency of project development and save project development costs.
[0042] Below Figure 1 The specific implementation of each step in the embodiment shown is described as follows:
[0043] In step 101, the custom logic expression to be parsed can be input into the custom logic expression parsing tool, and then the custom logic expression parsing tool can traverse each character in the custom logic expression to be parsed from left to right, and identify the type of the traversed character. Combined with the above description, the type of the traversed character may be any one of the following: variable, constant, logical operator, comparison operator, start delimiter and end delimiter, etc.
[0044] For example, before traversal, line breaks in the input custom logical expression to be parsed may be removed to ensure that no errors are generated during the parsing process due to line breaks.
[0045] In step 102, the stack can be a JAVA stack, and the JAVA stack is an object of the Stack class. In programming, a logic rule object is an instance of a class, is a basic building block in object-oriented programming (OOP), and can be used to encapsulate data. In an embodiment of the present application, the logic rule object is used to store the parseable structural units obtained by segmenting from a custom logic expression. The parseable structural units include: a left sub-expression, a right sub-expression, and a logical operator. When the complexity of the custom logic expression is high, the parseable structural units may also include: a third sub-expression. Wherein, the left sub-expression refers to the sub-expression on the left side of the logical operator, the right sub-expression refers to the sub-expression on the right side of the logical operator, and the third sub-expression is a sub-expression other than the left sub-expression and the right sub-expression. The above-mentioned left sub-expression, right sub-expression, and the third sub-expression all belong to sub-expressions.
[0046] For example, assume that the custom logic expression to be parsed is the following expression 1:
[0047] (GWM_FEATURE_HW_CEILING_SCREEN_SUPPORT==true)|(GWM_FEAT URE_HW_CO_DRIVER_SCREEN_SUPPORT==true)(Expression 1)
[0048] The parsable structural units obtained by splitting expression 1 include: left sub-expression, right sub-expression and logical operator. The left sub-expression is: (GWM_FEATURE_HW_CEILING_SCREEN_SUPPORT==true), the logical operator is: |, and the right sub-expression is: (GWM_FEATURE_HW_CO_DRIVER_SCREEN_SUPPORT==true)
[0049] For example, assume that the custom logic expression to be parsed is the following expression 2:
[0050] (GWM_FEATURE_HW_CEILING_SCREEN_SUPPORT==true)|(GWM_FEAT URE_HW_CO_DRIVER_SCREEN_SUPPORT==true)&(GWM_FEATURE_HW_NON_DRIVING_MODE_SUPPORT==true)(Expression 2)
[0051] The parsable structural units obtained by splitting expression 2 include: a left sub-expression, a right sub-expression, a logical operator and a third sub-expression. The left sub-expression is: (GWM_FEATURE_HW_CEILING_SCREEN_SUPPORT==true), the right sub-expression is: (GWM_FEATURE_HW_CO_DRIVER_SCREEN_SUPPORT==true), and the third sub-expression is: (GWM_FEATURE_HW_NON_DRIVING_MODE_SUPPORT==true).
[0052] Exemplarily, a logic rule object may include multiple member variables, and different member variables are used to store different structural units. The multiple member variables may include: a first member variable for storing a left sub-expression, a second member variable for storing a right sub-expression, a third member variable for storing a position identifier, a fourth member variable for storing a logical operator, etc. Among them, the position identifier represents the position of the character in the custom logic expression to be parsed. For example, each character in the custom logic expression to be parsed is usually numbered in order from left to right to uniquely identify the position of each character in the custom logic expression.
[0053] It is understandable that in order to store the parseable structural units obtained by segmentation in the logic rule object during the traversal process, the logic rule object needs to be created in advance. Based on this, in this embodiment, if it is determined based on the traversed characters that the preset creation conditions are met, the logic rule object is created and pushed into the pre-created stack.
[0054] If the preset creation condition is determined to be met based on the traversed characters, it means that a logic rule object needs to be created at present. The logic rule object created here may be the first logic rule object created in the traversal process, or it may be the nth logic rule object, where n is greater than 1. In other words, during the traversal process, it may be detected more than once that the preset creation condition is met. Each time it is determined that the preset creation condition is met, a logic rule object will be created, and each time a logic rule object is created, the logic rule object will be pushed into the pre-created stack.
[0055] Each time a structural unit needs to be stored in a logical rule object, the structural unit is stored in the logical rule object at the top of the stack, and the logical rule object at the top of the stack is the most recently created logical rule object.
[0056] In one possible implementation, if it is determined based on the traversed characters that a preset creation condition is met, a logical rule object is created, including: if the currently traversed character is a starting separator and the starting separator is the first character in the custom logical expression to be parsed, a logical rule object is created.
[0057] That is to say, the creation condition includes: the character currently traversed is the start delimiter and the start delimiter is the first character in the custom logic expression to be parsed. For example, if the start delimiter is "(", then if the first character traversed is "(", a logic rule object is created, and the logic rule object created at this time is the first logic rule object.
[0058] It can be understood that the character currently traversed belongs to the starting separator and the starting separator is the first character in the custom logical expression to be parsed, which means that the next traversed character is a key component of the sub-expression. In this case, creating a logical rule object in time is conducive to establishing basic conditions for storing sub-expressions and facilitating the storage of complete sub-expressions.
[0059] Exemplarily, after the first logic rule object is created, the position identifier of the start delimiter currently traversed can be stored in the created logic rule object. In combination with the above description, the logic rule object includes a third member variable for storing the position identifier, and the position identifier of the start delimiter can be stored in the third member variable.
[0060] In one possible implementation, if it is determined based on the traversed characters that a preset creation condition is met, a logical rule object is created, including: if the currently traversed characters belong to a logical operator and the logical rule object at the top of the stack already has a left sub-expression and a right sub-expression stored in it, then a logical rule object is created.
[0061] That is, the creation condition includes: the currently traversed character belongs to a logical operator and the left sub-expression and the right sub-expression are stored in the logical rule object at the top of the stack.
[0062] It can be understood that if the character currently traversed belongs to a logical operator, it means that there are other sub-expressions after the currently traversed character. At the same time, if the left sub-expression and the right sub-expression are already stored in the logical rule object at the top of the stack, it means that there is no space in the logical rule object at the top of the stack to continue to store other sub-expressions, that is, the other sub-expression is the third sub-expression. At this time, in order to store the third sub-expression, a logical rule object is created. The logical rule object created at this time is not the first logical rule object, but the nth logical rule object, where n is greater than 1.
[0063] In step 103, during the traversal process, the user-defined logical expression is segmented according to the traversed characters to obtain parseable structural units. Each time a parseable structural unit is obtained, the logic rule object at the top of the stack can be obtained and the parseable structural unit can be stored in the logic rule object at the top of the stack.
[0064] Exemplarily, the parseable structural units include: sub-expressions; the above-mentioned segmentation of the custom logical expression according to the traversed characters to obtain the parseable structural units, and storing the structural units in the logical rule object, including: determining the starting delimiter and the ending delimiter matching the starting delimiter in the traversed characters, and determining the characters between the starting delimiter and the ending delimiter as sub-expressions; obtaining the logical rule object at the top of the stack, and storing the sub-expressions in the logical rule object at the top of the stack.
[0065] Specifically, if the character currently traversed belongs to the start delimiter, the position identifier of the start delimiter is stored in the logic rule object at the top of the stack, for example, in the third member variable of the logic rule object at the top of the stack. Then, continue to traverse the characters after the start delimiter. If the traversed character is not the end delimiter that matches the above start delimiter, continue to traverse the next character. If the character currently traversed belongs to the end delimiter that matches the start delimiter, then according to the position identifier of the end delimiter and the position identifier of the above start delimiter, the character string composed of the characters between the start delimiter and the end delimiter is determined as a sub-expression. The sub-expression is stored in the logic rule object at the top of the stack.
[0066] Exemplarily, the above-mentioned storing of the sub-expression in the logic rule object at the top of the stack includes: if the left sub-expression is not stored in the logic rule object at the top of the stack, then the sub-expression is used as the left sub-expression and the left sub-expression is stored in the logic rule object at the top of the stack; if the left sub-expression is stored in the logic rule object at the top of the stack, then the sub-expression is used as the right sub-expression and the right sub-expression is stored in the logic rule object at the top of the stack.
[0067] In combination with the above, the logic rule object may include a first member variable for storing a left sub-expression and a second member variable for storing a right sub-expression.
[0068] If the corresponding value of the first member variable of the logic rule object at the top of the stack is empty, it can be determined that the left sub-expression is not stored in the logic rule object at the top of the stack, and further indicates that the sub-expression currently determined is a left sub-expression. Therefore, the sub-expression is stored as a left sub-expression in the logic rule object at the top of the stack. Specifically, the sub-expression can be stored as a left sub-expression in the first member variable of the logic rule object at the top of the stack, so that the first member variable of the logic rule object at the top of the stack has a corresponding value.
[0069] If the corresponding value of the first member variable of the logic rule object at the top of the stack is not empty, it can be determined that a left sub-expression is stored in the logic rule object at the top of the stack, which further indicates that the sub-expression currently determined is not a left sub-expression, but a right sub-expression. Therefore, the sub-expression is stored as a right sub-expression in the logic rule object at the top of the stack. Specifically, the sub-expression can be stored as a right sub-expression in the second member variable of the logic rule object at the top of the stack, so that the second member variable of the logic rule object at the top of the stack has a corresponding value.
[0070] In this embodiment, it is considered that in the process of traversing each character in the custom logic expression from left to right, the characters related to the left sub-expression are usually traversed first, and then the characters related to the right sub-expression are traversed. Therefore, after determining a sub-expression, by judging whether the left sub-expression has been stored in the logic rule object at the top of the stack, it can be clearly determined whether the currently obtained sub-expression belongs to the left sub-expression or the right sub-expression, thereby ensuring the accuracy of storage.
[0071] Exemplarily, the structural unit also includes: a logical operator; after storing the left sub-expression in the logical rule object at the top of the stack and before storing the right sub-expression in the logical rule object at the top of the stack, it also includes: if the currently traversed character belongs to the logical operator and the previously traversed character belongs to the end delimiter, then the currently traversed logical operator is stored in the logical rule object at the top of the stack.
[0072] It can be understood that after the left sub-expression is stored in the logic rule object at the top of the stack and before the right sub-expression is stored in the logic rule object at the top of the stack, if the character currently traversed belongs to the logical operator and the character last traversed belongs to the end delimiter, it means that the logical operator currently traversed belongs to the logical operator between the left sub-expression and the right sub-expression, and the end delimiter last traversed is the end identifier of the left sub-expression. At this time, the logical operator is stored in the logic rule object at the top of the stack. Since the logic rule object includes a fourth member variable for storing the logical operator, the logical operator can be stored in the fourth member variable of the logic rule object at the top of the stack.
[0073] In the above example, the current traversal to the logical operator occurs before the right sub-expression is stored in the logical rule object at the top of the stack. This means that when the logical operator is traversed at this time, the right sub-expression has not yet been stored in the logical rule object at the top of the stack. The logical operator traversed at this time is a logical operator between the left sub-expression and the right sub-expression.
[0074] Exemplarily, the sub-expression also includes: a third sub-expression. After storing the right sub-expression in the logic rule object at the top of the stack, it also includes: if the currently traversed character belongs to a logical operator and it is determined that the left sub-expression and the right sub-expression are stored in the logic rule object at the top of the stack, then the logical operator is used as the logical operator between the logic rule object at the top of the stack and the third sub-expression; the logical operator between the left sub-expression and the third sub-expression is stored in the logic rule object at the top of the stack; wherein the third sub-expression is a sub-expression identified after the right sub-expression.
[0075] It can be understood that after the right sub-expression is stored in the logic rule object at the top of the stack, if the character currently traversed belongs to a logical operator and it is determined that the left sub-expression and the right sub-expression are already stored in the logic rule object at the top of the stack, it means that the logical operator traversed at this time is not the logical operator between the left sub-expression and the right sub-expression, but the logical operator between the other sub-expressions before the third sub-expression and the third sub-expression. The other sub-expressions before the third sub-expression include the left sub-expression and the right sub-expression that have been stored in the logic rule object at the top of the stack, so the logical operator traversed at this time can be used as the logical operator between the logic rule object at the top of the stack and the third sub-expression, and the logical operator between the third sub-expression and the third sub-expression is stored in the logic rule object at the top of the stack.
[0076] In a specific implementation, the logic rule object may further include a fifth member variable, and the fifth member variable is used for the logic operator between the third sub-expression. The fourth member variable is specifically used to store the logic operator between the left sub-expression and the right sub-expression. Based on this, the logic operator between the third sub-expression can be stored in the fifth member variable of the logic rule object at the top of the stack.
[0077] Combined with the above description, it can be known that the character currently traversed belongs to a logical operator and the left sub-expression and the right sub-expression are already stored in the logical rule object at the top of the stack, which also belongs to one of the creation conditions. That is, if the character currently traversed belongs to a logical operator and the left sub-expression and the right sub-expression are already stored in the logical rule object at the top of the stack, the step of creating a logical rule object will be executed. In this embodiment, if the character currently traversed belongs to a logical operator and the left sub-expression and the right sub-expression are already stored in the logical rule object at the top of the stack, the logical operator can be first used as the logical operator between the logical rule object at the top of the stack and the third sub-expression, and the logical operator between the third sub-expression is stored in the logical rule object at the top of the stack, and then the step of creating a logical rule object is executed to create a new logical rule object. In other words, the logical operator between the third sub-expression is stored in the previously created logical rule object, rather than in the newly created logical rule object.
[0078] In step 104, after all characters in the custom logic expression to be parsed are traversed, it means that all parseable structural units in the custom logic expression have been segmented, and each structural unit is also stored in the corresponding logic rule object. At this time, the logic rule object is popped from the stack, that is, the logic rule object in the control stack is popped out. Since the stack is a data structure with a first-in, last-out feature, the logic rule object pushed into the stack later will be popped out first when popping the stack.
[0079] In step 105, if there is only one logic rule object in the stack, the parsable structural units stored in the popped logic rule object are directly combined to obtain a parsable custom logic expression. The parsable custom logic expression has a hierarchical structure, which clarifies the definition of each structural unit and the logical relationship between each structural unit.
[0080] Combined with the above description, the logic rule object includes multiple member variables, each of which has its own definition. For example, the first member variable is defined as: used to store the left sub-expression, the second member variable is defined as: used to store the right sub-expression, and the fourth member variable is defined as: used to store the logical operator. Based on this, the structural units stored in each member variable can be combined according to the definition of each member variable in the logic rule object to obtain a resolvable custom logic expression.
[0081] In one possible implementation, if there is only one logic rule object in the stack, the form of the custom logic expression that can be parsed is as follows:
[0082] (The corresponding value of the first member variable) The corresponding value of the fourth member variable (The corresponding value of the second member variable) Wherein, the corresponding value of the first member variable is the structural unit stored by the first member variable, that is, the left sub-expression. The corresponding value of the second member variable is the structural unit stored by the second member variable, that is, the right sub-expression. The corresponding value of the fourth member variable is the structural unit stored by the fourth member variable, that is, the logical operator.
[0083] In another possible implementation, the stack includes multiple logic rule objects. In this case, the structural units stored in the popped-out logic rule objects are combined to obtain a resolvable custom logic expression, including: establishing a parent-child relationship between two adjacent logic rule objects that are popped out in sequence to obtain a parent logic rule object and a child logic rule object; and combining the structural units stored in the parent logic rule object and the structural units stored in the child logic rule object according to the parent-child relationship to obtain a resolvable custom logic expression.
[0084] Among them, the logical rule object that is popped out first of two adjacent logical rule objects is the child logical rule object, and the logical rule object that is popped out later is the parent logical rule object. The order of popping multiple logical rule objects is exactly the opposite of the order of stacking, that is, the first logical rule object that is stacked is popped out last, and the last logical rule object that is stacked is popped out first. By establishing a parent-child relationship for two adjacent logical rule objects that are popped out one after another, the hierarchical relationship between different logical rule objects can be sorted out, so that the structural units stored in the multiple logical rule objects that are popped out can be combined according to the parent-child relationship to obtain a clearly hierarchical and accurate custom logical expression that can be parsed.
[0085] In a possible implementation, if the stack includes two logic rule objects and the logic rule object at the top of the stack stores a left sub-expression but does not store a right sub-expression, the form of the resolvable custom logic expression may be as follows:
[0086] (The corresponding value of the first member variable of the parent logic rule object) The corresponding value of the fourth member variable (The corresponding value of the second member variable of the parent logic rule object) The corresponding value of the fifth member variable (The corresponding value of the first member variable of the child logic rule object)
[0087] Among them, the corresponding value of the first member variable of the parent logic rule object is the structural unit stored in the first member variable of the parent logic rule object, that is, the left sub-expression. The corresponding value of the second member variable of the parent logic rule object is the structural unit stored in the second member variable of the parent logic rule object, that is, the right sub-expression. The corresponding value of the fourth member variable is the structural unit stored in the fourth member variable, that is, the logical operator between the left sub-expression and the right sub-expression in the parent logic rule object. The corresponding value of the fifth member variable is the structural unit stored in the fifth member variable of the parent logic rule object, that is, the logical operator between the third sub-expression. The corresponding value of the first member variable of the child logic rule object is the structural unit stored in the first member variable of the child logic rule object, that is, the left sub-expression. In the above-mentioned form of the entire parseable custom logic expression, the left sub-expression stored in the child logic rule object can be understood as the third sub-expression.
[0088] In a possible implementation, after combining the structural units stored in the pop-up logic rule object to obtain a resolvable custom logic expression, it also includes: obtaining business data; bringing the business data into the resolvable custom logic expression, and calculating the Boolean value of the custom logic expression.
[0089] Specifically, the resolvable custom logical expression can be converted into a Boolean logical expression according to actual business data, and then the Boolean logical expression of the Boolean value can be calculated to obtain the Boolean value of the custom logical expression. For example, each sub-expression in the resolvable custom logical expression can be converted into a Boolean value according to actual business data, and then the converted Boolean values of each sub-expression are combined in combination with the logical operators in the resolvable custom logical expression to obtain the Boolean logical expression.
[0090] To facilitate understanding, the following example is used to illustrate the following custom logic expressions that can be parsed:
[0091] (the corresponding value of the first member variable) the corresponding value of the fourth member variable (the corresponding value of the second member variable), then the corresponding value of the first member variable, that is, the left sub-expression, can be converted into the first Boolean value according to the business data, and the corresponding value of the second member variable, that is, the right sub-expression, can be converted into the second Boolean value, thereby obtaining the logical expression of the Boolean value. If the first Boolean value is true, the second Boolean value is false, and the corresponding value of the fourth member variable is &, then the logical expression of the Boolean value is: true&false, and the Boolean value of the custom logical expression obtained by calculating the logical expression of the Boolean value is false.
[0092] To further facilitate the understanding of the embodiments of the present application, the parsing method in the embodiments of the present application is described below by taking the parsing of the following custom logical expression (Expression 2 in the above text) as an example:
[0093] (GWM_FEATURE_HW_CEILING_SCREEN_SUPPORT==true)|(GWM_FEATURE_HW_CO_DRIVER_SCREEN_SUPPORT==true)&(GWM_FEATURE_HW_NON_DRIVING_MODE_SUPPORT==true) (Expression 2) In order to analyze the above expression 2, it can be implemented by the following S1 to S15:
[0094] S1. Traverse each character in the above expression 2 from left to right, traverse to the starting separator "(", and "(" is the first character of expression 2, then create a logic rule object 1. The position identifier of the character "(" in expression 2 is stored by logic rule object 1, and logic rule object 1 is pushed into the JAVA stack.
[0095] S2. Continue traversing. If the traversed character is not the ending delimiter ")" that matches the starting delimiter "(" in S1, continue traversing backwards.
[0096] S3. If the traversal finds a ")" that matches the start delimiter "(" in S1, then according to the position identifier of the "(" in S1 in expression 2 stored in logic rule object 1 and the position identifier of the currently traversed ")" in expression 2, the string consisting of the characters between "(" and ")" is used as the left sub-expression. The left sub-expression is stored in logic rule object 1. The form of the left sub-expression is as follows:
[0097] GWM_FEATURE_HW_CEILING_SCREEN_SUPPORT==true
[0098] S4. Continue traversing. If the logical operator "|" is traversed, determine whether the previous character is ")". If the current traversal is a logical operator and the previous character is ")", obtain the top logical rule object 1 from the JAVA stack and store the logical operator "|" in the logical rule object 1.
[0099] S5. Continue traversing. If the starting separator "(" is traversed, and the "(" traversed at this time is not the first character of expression 2, then the position identifier of the currently traversed character "(" in expression 2 is stored in logic rule object 1.
[0100] S6. Continue traversing. If the traversed character is not the ending delimiter ")" that matches the starting delimiter "(" in S5, continue traversing backward.
[0101] S7. If the end delimiter ")" that matches the start delimiter "(" in S5 is traversed, then according to the position identifier of the start delimiter "(" in S5 in expression 2 stored in logic rule object 1 and the position identifier of the currently traversed ")" in expression 2, the string consisting of the characters between "(" and ")" is used as the right sub-expression. The right sub-expression is stored in logic rule object 1. The form of the right sub-expression is as follows:
[0102] GWM_FEATURE_HW_CO_DRIVER_SCREEN_SUPPORT==true
[0103] S8. Continue traversing. If the logical operator "&" is traversed and the left sub-expression and the right sub-expression are already stored in the logical rule object 1 at the top of the JAVA stack, then obtain the logical rule object 1 and store "&" in the logical rule object 1 as the logical operator of the third sub-logical expression. Then, recreate the logical rule object 2 and push it into the JAVA stack. At this time, the logical rule object 2 becomes the logical rule object at the top of the stack.
[0104] S9. Continue traversing. If the starting separator "(" is traversed, the position identifier of the currently traversed character "(" in expression 2 is stored in logic rule object 2.
[0105] S10. Continue traversing. If the traversed character is not the ending delimiter ")" that matches the starting delimiter "(" in S9, continue traversing backward.
[0106] S11. If the end delimiter ")" that matches the start delimiter "(" in S9 is traversed, then according to the position identifier of the start delimiter "(" in S9 in expression 2 stored in logic rule object 2 and the position identifier of the currently traversed ")" in expression 2, the string consisting of the characters between "(" and ")" is used as the left sub-expression (that is, the third sub-expression). The left sub-expression is stored in logic rule object 2. The form of the left sub-expression is as follows:
[0107] GWM_FEATURE_HW_NON_DRIVING_MODE_SUPPORT==true
[0108] S12, after traversing all characters in expression 2, pop each logic rule object from the JAVA stack. According to the order of popping, establish a parent-child relationship between the two logic rule objects popped from the JAVA stack, set the logic rule object 2 that is popped first as the child logic rule object, and the logic rule object 1 that is popped later as the parent logic rule object.
[0109] S13. According to the parent-child relationship, the structural units stored in the parent logic rule object and the structural units stored in the child logic rule object are combined to obtain a resolvable custom logic expression.
[0110] For example, a schematic diagram of establishing a parent-child relationship between a parent logic rule object and a child logic rule object can be found in Figure 2 .
[0111] pass Figure 2It can be seen that the member variables of parent:LogicalRule (parent logical rule object) include: a member variable for storing the left sub-expression (schematically shown in the figure as leftSingleRule), a member variable for storing the right sub-expression (schematically shown in the figure as rightSingleRule), a member variable for storing the logical operator between the left sub-expression and the right sub-expression (schematically shown in the figure as logicalConnective), a member variable for storing the logical operator with the third sub-expression (schematically shown in the figure as otherLogicalConnective), and a member variable for storing sub-logical rule objects (schematically shown in the figure as otherLogicalRule).
[0112] The corresponding value of leftSingleRule in the parent logic rule object, that is, the stored structural unit is: GWM_FEATURE_HW_CEILING_SCREEN_SUPPORT==true.
[0113] The corresponding value of rightSingleRule in the parent logic rule object, that is, the stored structural unit is: GWM_FEATURE_HW_CO_DRIVER_SCREEN_SUPPORT==true.
[0114] The corresponding value of logicalConnective in the parent logic rule object, that is, the storage structure unit is: |.
[0115] The corresponding value of otherLogicalConnective in the parent logical rule object, that is, the storage structure unit is: &.
[0116] The corresponding value of otherLogicalRule in the parent logical rule object is: child.
[0117] Child: The member variables of LogicalRule (child logical rule object) include: a member variable for storing the left child expression (schematically shown as leftSingleRule in the figure).
[0118] The corresponding value of leftSingleRule in the sub-logical rule object, that is, the stored structural unit, is: GWM_FEATURE_HW_NON_DRIVING_MODE_SUPPORT==true.
[0119] Through Figure 2The structural units stored in the parent logic rule object and the structural units stored in the child logic rule object are combined to obtain a parsable custom logic expression which can be expressed as follows:
[0120] (the corresponding value of leftSingleRule of the parent logic rule object) | (the corresponding value of rightSingleRule of the parent logic rule object) & (the corresponding value of leftSingleRule of the child logic rule object)
[0121] S14. According to the actual business, the corresponding value of leftSingleRule of the parent logic rule object is converted into a first Boolean value, the corresponding value of rightSingleRule of the parent logic rule object is converted into a second Boolean value, and the corresponding value of leftSingleRule of the child logic rule object is converted into a third Boolean value, to obtain a logical expression of the Boolean value: (first Boolean value) | (second Boolean value) & (third Boolean value).
[0122] GWM_FEATURE_HW_CEILING_SCREEN_SUPPORT==true may indicate that the ceiling screen support feature is enabled. If the ceiling screen support feature is enabled according to actual service data, the first Boolean value is true. If the ceiling screen support feature is disabled according to actual service data, the first Boolean value is false.
[0123] GWM_FEATURE_HW_CO_DRIVER_SCREEN_SUPPORT==true may indicate that the co-pilot screen support feature is enabled. If the co-pilot screen support feature is enabled according to actual business data, the second Boolean value is true. If the co-pilot screen support feature is disabled according to actual business data, the second Boolean value is false.
[0124] GWM_FEATURE_HW_NON_DRIVING_MODE_SUPPORT==true may indicate that the non-driving mode support feature is enabled. If the non-driving mode support feature is enabled according to actual business data, the third Boolean value is true. If the non-driving mode support feature is disabled according to actual business data, the third Boolean value is false.
[0125] S15. Calculate the Boolean value logical expression to obtain the Boolean value of the custom logical expression.
[0126] Combined with the above example, if the first Boolean value in the Boolean value logical expression is ture, the second Boolean value is false, and the third Boolean value is true, then the Boolean value logical expression is: ture|false&ture, so the Boolean value of the custom logical expression is ture|false&ture, which is the calculation result of the expression ture.
[0127] It should be noted that in the above example, the custom logic expression to be parsed is actually split into three sub-expressions, the first two sub-expressions are stored in logic rule object 1, and the last sub-expression is stored in logic rule object 2. After popping the stack, a pair of logic rule objects with a parent-child relationship are obtained. In a specific implementation, each logic rule object can store up to two sub-expressions. If the custom logic expression to be parsed is split into more sub-expressions, the number of logic rule objects created will also be more, so that multiple pairs of logic rule objects with a parent-child relationship may be obtained after popping the stack.
[0128] For example, if 5 sub-expressions are obtained by segmentation, 3 logic rule objects need to be created to store them. Assuming that the 3 logic rule objects pushed into the stack are: logic rule object 1 (storing the first two sub-expressions), logic rule object 2 (storing the third and fourth sub-expressions) and logic rule object 3 (storing the fifth sub-expression), then two pairs of logic rule objects with parent-child relationships can be obtained according to the order of popping out of the stack. Logic rule object 3 and logic rule object 2 form a pair of parent-child object 1, and logic rule object 2 and logic rule object 1 form a pair of parent-child object 2. In parent-child object 1, logic rule object 3 is a child logic rule object, and logic rule object 2 is a parent logic rule object. In parent-child object 2, logic rule object 2 is a child logic rule object, and logic rule object 1 is a parent logic rule object.
[0129] In the embodiment of the present application, the above-mentioned parsing method can be used to implement the parsing of different custom logic expressions according to different business needs, and then complete the result calculation of the custom logic expression. If the R&D personnel encounter a custom logic expression that needs to be parsed, they can directly use the custom logic expression parsing tool in this embodiment to return the result corresponding to the custom logic expression to the R&D business as true or false, thereby improving the efficiency of project R&D and saving project R&D costs.
[0130] Figure 3 It is a structural diagram of a device for parsing a custom logical expression provided in an embodiment of the present application.
[0131] For example, Figure 3 As shown, the parsing device 300 includes:
[0132] A traversal module 301 is used to sequentially traverse each character in the custom logical expression to be parsed;
[0133] A creation module 302, for creating a logic rule object if it is determined based on the traversed characters that a preset creation condition is met, and pushing the logic rule object into a pre-created stack;
[0134] The segmentation and storage module 303 is used to segment the user-defined logic expression according to the traversed characters during the traversal process to obtain parseable structural units, and store the structural units in the logic rule object;
[0135] A pop module 304 is used to pop the logic rule object from the stack after traversing all characters in the custom logic expression to be parsed;
[0136] The combining module 305 combines the structural units stored in the popped-up logic rule object to obtain a resolvable custom logic expression.
[0137] In one possible implementation, the creation module 302 is specifically used to: if the character currently traversed belongs to the starting separator and the starting separator is the first character in the custom logical expression to be parsed, then create a logical rule object; or, if the character currently traversed belongs to a logical operator and the logical rule object at the top of the stack already stores a left sub-expression and a right sub-expression, then create a logical rule object.
[0138] In one possible implementation, the structural unit includes a sub-expression; a segmentation and storage module 303 is specifically used to: determine a start delimiter and an end delimiter matching the start delimiter among the traversed characters, and determine the characters between the start delimiter and the end delimiter as a sub-expression; obtain a logic rule object at the top of the stack, and store the sub-expression in the logic rule object at the top of the stack.
[0139] In one possible implementation, the splitting and storage module 303 is specifically used to: if the left sub-expression is not stored in the logic rule object at the top of the stack, then the sub-expression is used as the left sub-expression and the left sub-expression is stored in the logic rule object at the top of the stack; if the left sub-expression is stored in the logic rule object at the top of the stack, then the sub-expression is used as the right sub-expression and the right sub-expression is stored in the logic rule object at the top of the stack.
[0140] In a possible implementation, the structural unit also includes: a logical operator; a splitting and storage module 303, which is specifically used to: after storing the left sub-expression in the logical rule object at the top of the stack and before storing the right sub-expression in the logical rule object at the top of the stack, if the currently traversed character belongs to the logical operator and the last traversed character belongs to the end delimiter, then the currently traversed logical operator is stored in the logical rule object at the top of the stack.
[0141] In a possible implementation, the sub-expression also includes: a third sub-expression; the segmentation and storage module 303 is also used for: after the right sub-expression is stored in the logic rule object at the top of the stack, if the currently traversed character belongs to a logical operator and it is determined that the left sub-expression and the right sub-expression are already stored in the logic rule object at the top of the stack, then the logical operator is used as the logical operator between the logic rule object at the top of the stack and the third sub-expression; the logical operator between the left sub-expression and the third sub-expression is stored in the logic rule object at the top of the stack; wherein the third sub-expression is a sub-expression identified after the right sub-expression.
[0142] In a possible implementation, the combination module 305 is specifically used to establish a parent-child relationship between two adjacent logic rule objects that are popped out of the stack in sequence, if the stack includes multiple logic rule objects, to obtain a parent logic rule object and a child logic rule object; wherein, the logic rule object that is popped out first among the two adjacent logic rule objects is the child logic rule object, and the logic rule object that is popped out later is the parent logic rule object; according to the parent-child relationship, the structural units stored in the parent logic rule object and the structural units stored in the child logic rule object are combined to obtain a resolvable custom logical expression.
[0143] In a possible implementation, the parsing device 300 also includes: a calculation module, which is used to obtain business data after combining the structural units stored in the pop-up logic rule object to obtain a resolvable custom logic expression; bringing the business data into the resolvable custom logic expression to calculate the Boolean value of the custom logic expression.
[0144] Figure 4 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application.
[0145] For example, Figure 4As shown, the electronic device 400 includes: a memory 401 and a processor 402, wherein the memory 401 stores an executable program code 4011, and the processor 402 is used to call and execute the executable program code 4011 to perform a method for parsing a user-defined logical expression.
[0146] In addition, an embodiment of the present application also protects a device, which may include a memory and a processor, wherein the memory stores executable program code, and the processor is used to call and execute the executable program code to execute a method for parsing a custom logical expression provided in an embodiment of the present application.
[0147] In this embodiment, the functional modules of the device can be divided according to the above method example. For example, each functional module can be corresponded, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware. It should be noted that the division of modules in this embodiment is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0148] In the case of dividing each functional module according to each function, the device may also include a traversal module, a creation module, a segmentation and storage module, a stacking module, a combination module, etc. It should be noted that all relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module, which will not be repeated here.
[0149] It should be understood that the device provided in this embodiment is used to execute the above-mentioned method for parsing a custom logical expression, and thus can achieve the same effect as the above-mentioned implementation method.
[0150] In the case of an integrated unit, the device may include a processing module and a storage module. When the device is applied to an electronic device, the processing module may be used to control and manage the actions of the electronic device. The storage module may be used to support the electronic device in executing related program codes, etc.
[0151] The processing module may be a processor or a controller, which may implement or execute various exemplary logic blocks, modules and circuits shown in conjunction with the disclosure of the present application. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc. The storage module may be a memory.
[0152] In addition, the device provided in the embodiments of the present application may specifically be a chip, component or module, and the chip may include a connected processor and memory; wherein the memory is used to store instructions, and when the processor calls and executes the instructions, the chip can execute a method for parsing a custom logical expression provided in the above embodiments.
[0153] This embodiment also provides a computer-readable storage medium, in which a computer program code is stored. When the computer program code is executed on a computer, the computer executes the above-mentioned related method steps to implement a method for parsing a custom logical expression provided in the above embodiment.
[0154] This embodiment also provides a computer program product. When the computer program product runs on a computer, it enables the computer to execute the above-mentioned related steps to implement a method for parsing a user-defined logical expression provided in the above embodiment.
[0155] Among them, the device, computer-readable storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be repeated here.
[0156] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0157] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0158] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for parsing a custom logical expression, characterized in that: The method comprises: Traverse each character in the custom logical expression to be parsed in turn; If it is determined based on the traversed characters that the preset creation condition is met, a logic rule object is created and the logic rule object is pushed into a pre-created stack; During the traversal process, the user-defined logical expression is segmented according to the traversed characters to obtain parseable structural units, and the structural units are stored in the logical rule object; After traversing all characters in the user-defined logical expression to be parsed, popping the logical rule object from the stack; The structural units stored in the pop-up logic rule object are combined to obtain a resolvable custom logic expression.
2. The method according to claim 1, characterized in that If it is determined based on the traversed characters that a preset creation condition is met, then a logic rule object is created, including: If the currently traversed character is a start delimiter and the start delimiter is the first character in the custom logic expression to be parsed, a logic rule object is created; or, If the currently traversed character belongs to a logical operator and the logical rule object at the top of the stack has stored a left sub-expression and a right sub-expression, a logical rule object is created.
3. The method according to claim 1, characterized in that The structural unit includes a sub-expression; The step of segmenting the custom logic expression according to the traversed characters to obtain parseable structural units, and storing the structural units in the logic rule object includes: Determine a start delimiter and an end delimiter matching the start delimiter from among the traversed characters, and determine the characters between the start delimiter and the end delimiter as a sub-expression; The logic rule object at the top of the stack is obtained, and the sub-expression is stored in the logic rule object at the top of the stack.
4. The method according to claim 3, characterized in that The storing the sub-expression in the logic rule object at the top of the stack includes: If the left sub-expression is not stored in the logic rule object at the top of the stack, the sub-expression is used as the left sub-expression, and the left sub-expression is stored in the logic rule object at the top of the stack; If the left sub-expression is stored in the logic rule object at the top of the stack, the sub-expression is used as the right sub-expression, and the right sub-expression is stored in the logic rule object at the top of the stack.
5. The method according to claim 4, characterized in that The structural unit also includes: a logical operator; After storing the left sub-expression in the logic rule object at the top of the stack and before storing the right sub-expression in the logic rule object at the top of the stack, the method further includes: If the currently traversed character belongs to a logical operator and the last traversed character belongs to an end delimiter, the currently traversed logical operator is stored in the logical rule object at the top of the stack.
6. The method according to claim 4, characterized in that The sub-expression also includes: a third sub-expression; After storing the right sub-expression in the logic rule object at the top of the stack, the method further includes: If the currently traversed character belongs to a logical operator and it is determined that the left sub-expression and the right sub-expression are already stored in the logical rule object at the top of the stack, the logical operator is used as the logical operator between the logical rule object at the top of the stack and the third sub-expression; The logical operator between the third sub-expression and the right sub-expression is stored in the logic rule object at the top of the stack; wherein the third sub-expression is a sub-expression identified after the right sub-expression.
7. The method according to claim 1, characterized in that The combining of the structural units stored in the pop-up logic rule object to obtain a resolvable custom logic expression includes: If the stack includes multiple logic rule objects, a parent-child relationship is established for two adjacent logic rule objects that are popped out of the stack in sequence, to obtain a parent logic rule object and a child logic rule object; wherein the logic rule object that is popped out of the stack first is the child logic rule object, and the logic rule object that is popped out of the stack later is the parent logic rule object; According to the parent-child relationship, the structural units stored in the parent logic rule object and the structural units stored in the child logic rule object are combined to obtain a resolvable custom logic expression.
8. The method according to any one of claims 1 to 7, characterized in that: After combining the structural units stored in the pop-up logic rule object to obtain a resolvable custom logic expression, the method further includes: Get business data; The business data is introduced into the resolvable custom logic expression, and a Boolean value of the custom logic expression is calculated.
9. An electronic device, characterized in that: The electronic device comprises: A memory for storing executable program codes; A processor, configured to call and run the executable program code from the memory, so that the electronic device executes the method according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
An automatic structuring and parsing method and system of command line interface command
CN101079737A
Method for verifying five-prevention logic expression through reverse Polish notation
CN105677528A
Rule configuration analysis-based association parameter automatic interpretation method and system
CN109445306A
Method for analyzing logic expression into general query statement
CN111008020A
Combined geometric neutron transport processing method and device based on characteristic line method
CN112329267A