Disclosure of Invention
The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the present invention proposes a user-friendly method of custom generating expressions.
In a first aspect, one embodiment of the present invention provides a: a method of customizing a generated expression, comprising:
generating the expression in a clicking or dragging mode according to an expression customization rule, wherein the expression customization rule comprises the following steps: initializing an expression, editing an expression element, adding the expression element, and converting the expression into a generation;
extracting the expression to debug the expression, and adjusting the expression according to the expression customization rule until a target expression passing verification is obtained;
and displaying the generated target expression.
Further, the initializing of the expression specifically includes:
generating an initial expression passing verification, wherein the initial expression comprises only one expression element;
the initial expression is converted into an expression tree structure.
Further, the converting the initial expression into an expression tree structure specifically includes:
and converting the initial expression into an abstract syntax tree, and traversing the abstract syntax tree to obtain the expression tree structure.
Further, the expression element editing specifically includes: editing operations including copying the expression element, pasting the expression element, and replacing the expression element are performed on the expression element.
Further, the expression element addition specifically includes:
the expression element is used as the first parameter of the additional operation function, and the original expression element position is replaced by the additional operation function.
Further, the converting the expression into the generation specifically includes: the expression tree structure is converted into an expression using a preface traversal recursion algorithm.
Further, the expression debugging specifically includes:
converting the expression into an abstract syntax tree;
extracting expression variables by traversing the abstract syntax tree;
inputting the variable value of the expression variable, performing expression debugging operation, and comparing the execution result obtained by the operation with the expected value corresponding to the variable value to obtain a debugging result.
In a second aspect, one embodiment of the present invention provides B: a custom generated expression system, comprising:
an expression customization module: for generating an expression in a click or drag manner according to an expression customization rule comprising: initializing an expression, editing an expression element, adding the expression element, and converting the expression into a generation;
expression debugging module: extracting the expression to debug the expression, and adjusting the expression according to the expression customization rule until a target expression passing verification is obtained;
the expression display module: for displaying the generated target expression.
In a third aspect, the present invention provides an apparatus for custom generating an expression, comprising:
at least one processor, and a memory communicatively coupled to the at least one processor;
wherein the processor is adapted to perform the method according to any of the first aspects by invoking a computer program stored in the memory.
In a fourth aspect, the present invention provides a computer-readable storage medium storing computer-executable instructions for causing a computer to perform the method of any one of the first aspects.
The beneficial effects of the invention are as follows:
the method comprises the steps of generating the expression in a clicking or dragging mode according to an expression customization rule comprising expression initialization, expression element editing, expression element adding, expression conversion generation and the like, extracting the generated expression to perform expression debugging, performing expression adjustment according to the expression customization rule until a verified target expression is obtained, and displaying the generated target expression. The method has the advantages that the expression is generated according to the expression customization rule through an intuitive clicking or dragging mode, then online debugging is carried out on the generated expression, accuracy of the customized expression is guaranteed, the expression mode is intuitive, difficulty of customizing the expression is reduced, user friendliness is improved, and time spent on customizing the expression is shortened on the premise that flexibility of the generation process is guaranteed.
Can be widely applied to the field of expression generation.
Detailed Description
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following description will explain the specific embodiments of the present invention with reference to the accompanying drawings. It is evident that the drawings in the following description are only examples of the invention, from which other drawings and other embodiments can be obtained by a person skilled in the art without inventive effort.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
Embodiment one:
an embodiment of the present invention provides a method for customizing a generated expression, and fig. 1 is a flowchart of an implementation of the method for customizing a generated expression provided by the embodiment of the present invention, as shown in fig. 1, where the method includes the following steps:
s1: the expression is generated in a click or drag manner according to the expression customization rules.
In this embodiment, the generating process of the expression is obtained by clicking or dragging, after clicking the element editing the expression, the operation result is visually displayed, and according to the sequence of the expression elements to be customized and generated, the selection elements are clicked or dragged in sequence, where the expression elements include the following: variables, constants, literal quantities, function return values.
For example, the expression to be customized is "(variable one+5) ×2.2", and then click or drag in turn: left brackets, variable one, plus sign, five, right brackets, two, point, two.
S2: extracting the expression to debug the expression, and adjusting the expression according to the expression customization rule until the target expression passing the verification is obtained.
S3: the generated target expression is displayed.
In a specific step S1, the expression customization rule includes: expression initialization, expression element editing, expression element addition, expression conversion generation, and the rules are described in detail below, respectively.
1) The expression initialization specifically includes:
s111: if the expression is a new expression, firstly generating an initial expression passing verification, wherein the initial expression is simple enough and only comprises one expression element, so that a user can be guided to generate the expression conveniently.
S112: the initial expression is converted into an expression tree structure, so that the display in the interface is facilitated. The converting the initial expression into the expression tree structure specifically comprises the following steps: converting the initial expression into an abstract syntax tree, and traversing the abstract syntax tree to obtain an expression tree structure.
In this embodiment, the logical expression which can be written directly by the code is stored in the tree structure through the expression tree structure, so that the tree can be parsed during running and then executed, and dynamic editing and code execution are realized.
Wherein the abstract syntax tree (abstract syntax code, AST) is a tree representation of the abstract syntax structure of the source code, each node on the tree representing a structure in the source code, which is abstract because the abstract syntax tree does not represent every detail of the actual syntax appearance, for example nested brackets are implicit in the tree structure and not presented in the form of nodes.
As shown in fig. 2, which is a schematic diagram of an expression tree structure in this embodiment, assuming that the current expression is 1+3 (4-1) +2, each element is represented as a node of the tree by traversing the expression tree structure.
2) The expression element editing specifically includes:
editing operations including copying the expression element, pasting the expression element, and replacing the expression element are performed on the expression element.
Wherein replication means placing the current expression element into a clipboard; pasting means that the expression element in the cut-off plate is overlaid with the current expression element; changing an expression element refers to modifying the current expression element into one of a variable, a constant, a literal quantity, and a function return value.
3) The expression element addition specifically includes:
since the append operation function requires at least one parameter, the expression element is used as the first parameter of the append operation function, and the position of the original expression element is replaced by the append operation function.
4) The conversion of the expression into the generation specifically includes: the expression tree structure is converted into an expression using a preface traversal recursion algorithm.
When the editing of the expression element and the addition of the expression element are completed, the expression tree structure needs to be converted into the expression by utilizing a preface traversal recursion algorithm.
After the expression is generated in step S1, the expression needs to be debugged to generate a customized target expression, and the expression debugging process in step S2 specifically includes:
s21: converting the expression into an abstract syntax tree;
s22: extracting expression variables by traversing the abstract syntax tree;
since the input parameters of different expressions are different, it is necessary to parse the user-defined expression tree structure and extract the expression variables for expression debugging.
S23: inputting the variable value of the expression variable, binding the expression variable to be debugged to an execution engine, performing expression debugging operation, and comparing the execution result obtained by the operation with an expected value corresponding to the variable value to obtain a debugging result.
In step S23, the optional user fills in the input variable value on the visual interface, after clicking operation, binds the input value with the expression variable and operates to obtain an execution result, and then the user determines whether the definition of the expression is correct according to the comparison result between the execution result and the expected value, for example, if the execution result is consistent with the expected value, the interface displays "/", and if not, displays "×".
And then judging whether the expression adjustment is needed according to the expression customization rule according to the debugging result, and repeating for a plurality of times until a target expression passing the verification is obtained.
Unlike the method of generating the expression in the prior art, which is usually performed on the database table, according to the one-dimensional table, the two-dimensional table, the multidimensional table and the correlation coefficient, the expression in the embodiment is not performed on a specific service component, the application range is wider, and all the systems requiring custom expression can be used. The target expression of the embodiment does not need to convert the description formula into the definition formula and then develop the definition formula with the multidimensional table to form the analysis consensus, but can directly analyze the running expression.
Embodiment two:
the present embodiment provides a custom generated expression system for performing the method according to the first embodiment, as shown in fig. 3, which is a structural block diagram of the custom generated expression system of the present embodiment, including:
expression customization module 100: for generating an expression in a click or drag manner according to an expression customization rule, the expression customization rule comprising: initializing an expression, editing an expression element, adding the expression element, and converting the expression into a generation;
expression debug module 200: the method comprises the steps of extracting an expression for expression debugging, and adjusting the expression according to an expression customization rule until a target expression passing verification is obtained;
expression display module 300: for displaying the generated target expression.
The specific details of each module of the custom generated expression system in the foregoing description have been described in detail in the method for customizing the generated expression corresponding to the embodiment, so that the details are not repeated here.
The process of custom generating an expression of the present embodiment is described below in one implementation scenario. For example, the wind control is used for judging that the house is Shenzhen and annual income is more than 20 ten thousand, and the input variables are the house and the month income.
1) Step 1: the expression variable "house hold place" is selected.
As shown in fig. 4, in the process of customizing and generating an expression in this embodiment, step 1 is to select an expression variable schematic diagram, click an edit icon in an expression customizing module, and select an expression variable "residence".
After the selection is completed, the expression is "= $_. User parameter. User location", as shown in fig. 5, the expression variable diagram is selected for step 1.
2) Step 2: the selection function is "equal".
Clicking a plus sign icon behind a 'house place' in the expression customizing module, performing additional operation, and then selecting 'equal' under a 'comparison function';
after the selection is completed, the expression "=equal ($_. User parameter. User location," hello ")", as shown in fig. 6, is the display interface of step 2.
3) Step 3: the modified contrast value is "Shenzhen city", and the "Shenzhen city" is input by the input box at the back, as shown in fig. 7, which is the display interface of step 3.
The expression at this time is "=equals ($_. User parameter. User location," Shenzhen city ")".
4) Step 4: the function "and" is selected, and by clicking on the last plus icon, the "and" under "logical operation" is selected, as shown in fig. 8, as the display interface of step 4.
The expression at this time is "=equals ($_. User parameter. User location," Shenzhen city ")".
5) Step 5: add and condition one and condition is added by clicking the plus sign under "House located" as shown in FIG. 9, the display interface of step 5.
At this time, the expression "=every (equal ($_. User parameter. House location," Shenzhen city "), equal ($_. User parameter. House location," Shenzhen city ")".
6) Step 6: the second condition is modified to be "month income", and the "month income" under the "variable" is selected by clicking on the last modified icon of the second condition, as shown in fig. 10, which is the display interface of step 6.
The expression at this time is "=every (equal ($_. User parameter. User place," Shenzhen city "), equal ($_. User parameter. Month income)".
7) Step 7: selecting 'multiplication', and clicking a plus sign icon after 'month income', so as to carry out additional operation. The "multiplication" under the "arithmetic function" is selected, as shown in fig. 11, as the display interface of step 7.
At this time, the expression "=every (equal ($_. User parameter. User place," Shenzhen city "), equal ($_. User parameter. Month income," hello ")".
8) Step 8: the number of months is modified as a numerical value input box, and the numerical value under the word size is selected to modify by clicking the modification icon after the number of months, and the default numerical value is 100, as shown in fig. 12, and is the display interface of step 8.
The expression at this time is "=every (equal ($_. User parameter. User place," Shenzhen city "), equal ($_. User parameter. Month income," 100 ")".
9) Step 9: the number of modified months is 12.
The expression at this time is "=every (equal ($_. User parameter. User place," Shenzhen city "), equal ($_. User parameter. Month income," 12 ")".
10 Step 10): the "greater than" operation is added, and by clicking the plus icon behind the second condition, the additional operation is performed, and the "greater than" under the "comparison function" is selected for modification, as shown in fig. 13, which is the display interface of step 10.
At this time, the expression "=every (equal ($_. User parameter. User place," Shenzhen city "), GREATER (multiple ($_. User parameter. Month income," 12 ")," hello "))".
11 Step 11): the comparison value type of annual income is modified, the "numerical value" under the "literal quantity" is selected by clicking the modification icon after annual income, and 100 of the default numerical value of the input box is modified to 200000, as shown in fig. 14, and the display interface of step 11 is provided.
To this end, the expression definition is completed.
At this time, the expression is "=every (equal ($. User parameter. User place of mouth," Shenzhen city "), GREATER (multiple ($. User parameter. Month income, 12), 200000))";
the process of performing expression debugging is as follows.
In the expression debugging, clicking a plus icon after the operation result, adding two test scene cases into three test scenes, as shown in fig. 15, which is a test result of a group of test data, clicking operation to obtain an operation result, and obtaining a customized target expression if the operation result is consistent with an expected result according to the test result.
Further, for a simple target expression, the present embodiment also provides a simple mode, including:
in the simple mode, the interface comprises three parts
The second expression display module 400: for displaying the expression, editing of the expression is what is seen and obtained. After the other region selects an element of the expression, this region will display the result of the operation.
The number and symbol selection module 500: comprising the following expression elements: the numbers 0-9, add, subtract, multiply, divide, greater than, less than, greater than or equal to, less than or equal to, left bracket, right bracket, decimal point, and, or, not, etc.
Variable selection module 600: including variables in the system that can be used for the expression, a list of variables is provided by the system.
The following describes the use method of the simple mode by way of an example:
input:
and clicking or dragging the selection elements in sequence according to the element sequence of the target expression. For example, the expression to be customized is "(variable one+5) ×2.2", and then click or drag in turn: left brackets, variable one, plus sign, five, right brackets, two, dot, two.
The target expression can be modified through positioning and rollback, a simple expression provides a cursor positioning function, and cursor positioning can be performed by clicking between expression elements in the expression display area through a mouse. By keyboard rollback keys, expression elements before the cursor may be deleted.
The expression definition of the common operation can be completed in the simple mode of the embodiment, and the method is friendly to users.
In addition, the invention also provides custom generated expression equipment, which comprises:
at least one processor, and a memory communicatively coupled to the at least one processor;
wherein the processor is configured to perform the method according to embodiment one by invoking a computer program stored in the memory. Computer program, i.e. program code, for causing a custom generated expression device to perform the steps in the custom generated expression method described in the above-described embodiments of the present specification when the program code is run on the custom generated expression device.
In addition, the invention also provides a computer readable storage medium, wherein the computer readable storage medium stores computer executable instructions for causing a computer to execute the method according to the first embodiment.
The method comprises the steps of generating the expression in a clicking or dragging mode according to an expression customization rule comprising expression initialization, expression element editing, expression element adding, expression conversion generation and the like, extracting the generated expression to perform expression debugging, performing expression adjustment according to the expression customization rule until a verified target expression is obtained, and displaying the generated target expression. The method has the advantages that the expression is generated according to the expression customization rule through an intuitive clicking or dragging mode, then online debugging is carried out on the generated expression, accuracy of the customized expression is guaranteed, the expression mode is intuitive, difficulty of customizing the expression is reduced, user friendliness is improved, and time spent on customizing the expression is shortened on the premise that flexibility of the generation process is guaranteed.
The above embodiments are only for illustrating the technical solution of the present invention, not for limiting the same, and although the present invention has been described in detail with reference to the above embodiments, it should be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some or all of the technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit of the invention, and are intended to be included within the scope of the appended claims and description.