CN113779311A - Data processing method, device and storage medium - Google Patents
Data processing method, device and storage medium Download PDFInfo
- Publication number
- CN113779311A CN113779311A CN202011214884.2A CN202011214884A CN113779311A CN 113779311 A CN113779311 A CN 113779311A CN 202011214884 A CN202011214884 A CN 202011214884A CN 113779311 A CN113779311 A CN 113779311A
- Authority
- CN
- China
- Prior art keywords
- operator
- character string
- function
- character
- data format
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000003672 processing method Methods 0.000 title abstract description 13
- 238000000034 method Methods 0.000 claims abstract description 52
- 238000012545 processing Methods 0.000 claims abstract description 17
- 238000013507 mapping Methods 0.000 claims description 10
- 238000012216 screening Methods 0.000 claims description 5
- 238000001914 filtration Methods 0.000 claims description 2
- 238000005538 encapsulation Methods 0.000 abstract description 4
- 230000006870 function Effects 0.000 description 116
- 238000010586 diagram Methods 0.000 description 12
- 238000004590 computer program Methods 0.000 description 5
- 238000013461 design Methods 0.000 description 5
- 238000006243 chemical reaction Methods 0.000 description 3
- 238000011160 research Methods 0.000 description 3
- 238000004364 calculation method Methods 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 238000011161 development Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000004088 simulation Methods 0.000 description 1
- 125000006850 spacer group Chemical group 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/80—Information retrieval; Database structures therefor; File system structures therefor of semi-structured data, e.g. markup language structured data such as SGML, XML or HTML
- G06F16/81—Indexing, e.g. XML tags; Data structures therefor; Storage structures
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/80—Information retrieval; Database structures therefor; File system structures therefor of semi-structured data, e.g. markup language structured data such as SGML, XML or HTML
- G06F16/83—Querying
- G06F16/835—Query processing
- G06F16/8358—Query translation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/80—Information retrieval; Database structures therefor; File system structures therefor of semi-structured data, e.g. markup language structured data such as SGML, XML or HTML
- G06F16/84—Mapping; Conversion
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Stored Programmes (AREA)
Abstract
The application discloses a data processing method, a data processing device and a data processing storage medium, and particularly relates to a method for acquiring an input character string, generating an operator character string corresponding to the input character string by using the acquired input character string, wherein the operator character string comprises operators in the input character string and actual variable parameters in the input character string are presented as character items in a first data format, matching operators in the operator character string in a registered operator, and calling an operator function established for a specified operator to process the character items in the operator character string when the operator character string is matched with the registered operator, wherein the operator function is a function matched with the function of the operator corresponding to the operator function. The embodiment of the application supports encapsulation of various custom operator logics and custom operator function names by adding custom operator grammars, and improves the readability of the logic sequence of operators.
Description
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for data processing, and a storage medium.
Background
Operators are common in programming languages, and typically each language provides several built-in supported operators, such as "+, -,! And the like. However, the operators provided by each language are not completely different, such as the ". multidot" operator supported by Swift, Javascript is not supported. Because Javascript does not support custom operator functionality, it is not feasible to use the ".." operator in Javascript.
In this case, the same effect can be achieved by creating a function in Javascript that has the same function as the ".." operator. For example, a range (1,100) can be defined, which is the same as the result of the 1..100 calculation in Swift, and is an array of values from 1 to 100, i.e., [1,2,4, …,100 ]. But the logical order readability of the syntax of the function is less clear than the operators using the function versus the operators. Like the (1. <100). count..1000 expression in Swift, the range (1,100). length),1000 is used in Javascript using function simulation, and it can be seen that since the function can only pass parameters in parentheses, there is no clear operator in the readability of the logical sequence of the sentence, especially for longer sentences. In addition, the semantics of operators is often a special calculation or logic judgment, and the existing Javascript functions can only be named by characters supported by the specification (letters, Chinese, underlines and dollar symbols), so that the functions cannot be named by special characters and have no specificity.
Disclosure of Invention
The embodiment of the application provides a data processing method, and the problem that a user-defined operator cannot be used in Javascript language is solved.
The method comprises the following steps:
acquiring an input character string;
generating an operator character string corresponding to the input character string by using the acquired input character string, wherein the operator character string comprises an operator in the input character string and actual variable parameters in the input character string are presented as character items in a first data format;
matching the operator in the operator string among the registered operators;
and when the registered operator is matched, calling the operator function created for the specified operator to process the character item in the operator character string, wherein the operator function is a function matched with the function of the operator corresponding to the registered operator function.
Optionally, for each operator, taking the function matched with the function of the operator as the corresponding operator function, and creating a key-value pair containing a function name of the operator function and an operator name of the operator;
and storing the created mapping relation between the key value pairs.
Optionally, analyzing the input character string through an operator execution function, generating a first character string array after the actual variable parameters are removed, and taking each actual variable parameter in the input character string extracted in sequence as a second character string array;
and circulating the first character string array, and adding character items in the first data format at positions corresponding to the actual variable parameters of the first character string array, wherein x is added with 1 from 0 to the first character string array in each circulation until the first character string circulation is finished, so as to generate the operator character string corresponding to the input character string.
Optionally, an operator abstract structure with the operator character string as a first index value is searched in an operator abstract structure library, and when the corresponding operator abstract structure is not found, the operator abstract structure is created for the operator character string, and the operator character string is stored in the operator abstract structure library as the first index value.
Optionally, in the operator character string, screening out character items in the first data format, which are directly connected with the operator, except for a first character item in the first data format, and adding a spacing symbol between the operator and the character items in the first data format;
screening out a structural character string consisting of the operator containing the interval symbols and the character item in the first data format from the operator character string, and taking the operator name corresponding to the operator contained in the structural character string as the name attribute of the structural character string;
and storing the x in the character item of the first data format of each structural character string as a second index value of the actual variable parameter.
Optionally, it is determined whether the leftmost side of the first character item in the first data format is a non-empty character, and when the left-most character item is not a non-empty character, the multivariate operator identifier is added to the operator abstract structure, where the multivariate operator identifier is an index value of the actual variable parameter corresponding to x in the first character item in the first data format.
Optionally, when the matched operator abstract structure does not carry the multi-element operator identifier, obtaining the structure character string in the operator abstract structure, and obtaining a corresponding operator function in the mapping relationship between the key-value pairs based on the name attribute of the structure character string;
based on the second index value contained in each structure character string in the operator abstract structure, searching the corresponding actual variable parameter in the second character string array, and placing the actual variable parameter according to the position of the corresponding character item in the first data format;
and circularly executing the operator function containing the actual variable parameter, and taking the operation result of the previous operator function as the first parameter in the next operator function.
Optionally, when the matched operator abstract structure carries the multiple operator identifier, obtaining the structure character string in the operator abstract structure, and obtaining a corresponding operator function in the mapping relationship between the key-value pairs based on the name attribute of the structure character string;
searching the corresponding actual variable parameter in the second character string array based on the multi-element operator identifier, and taking the actual variable parameter as a first parameter of a first operator function;
based on the second index value contained in each structure character string in the operator abstract structure, searching the corresponding actual variable parameter in the second character string array, and placing the actual variable parameter according to the position of the corresponding character item in the first data format;
and circularly executing the operator function containing the actual variable parameter, and taking the operation result of the previous operator function as the first parameter in the next operator function.
Optionally, the running result of the last operator function is output as the running result corresponding to the input character string.
Optionally, the first data format is $ { x } format.
In another embodiment of the present invention, there is provided an apparatus for data processing, the apparatus including:
the acquisition module is used for acquiring an input character string;
the generating module is used for generating an operator character string corresponding to the input character string by using the acquired input character string, wherein the operator character string contains the operator in the input character string and actual variable parameters in the input character string are presented as character items in a first data format;
a matching module for matching the operator in the operator character string among the registered operators;
and the calling module is used for calling the operator function created for the specified operator to process the character item in the operator character string when the registered operator is matched, wherein the operator function is a function matched with the function of the operator corresponding to the registered operator function.
In another embodiment of the invention, a non-transitory computer readable storage medium is provided, storing instructions that, when executed by a processor, cause the processor to perform the steps of one of the above-described methods of data processing.
In another embodiment of the present invention, a terminal device is provided, which includes a processor configured to execute the steps of a data processing method as described above.
Based on the above embodiment, an input character string is first obtained, an operator character string corresponding to the input character string is generated by using the obtained input character string, where the operator character string includes operators in the input character string and character items of actual variable parameters in the input character string in a first data format, an operator in the operator character string is matched in a registered operator, and when the registered operator is matched, an operator function created for a specified operator is called to process the character items in the operator character string, where the operator function is a function matched with a function of the registered operator corresponding to the operator function. The embodiment of the application supports encapsulation of various custom operator logics and custom operator function names by adding custom operator grammars, and improves the readability of the logic sequence of operators.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained from the drawings without inventive effort.
Fig. 1 is a flow chart illustrating a method of data processing provided in an embodiment 100 of the present application;
fig. 2 is a schematic diagram illustrating a specific flow of a registration operator provided in an embodiment 200 of the present application;
FIG. 3 is a diagram illustrating a detailed flow provided in an embodiment 300 of the present application for creating an operator abstract structure;
fig. 4 is a schematic diagram illustrating a specific flow of a method for data processing according to an embodiment 400 of the present application;
fig. 5 is a schematic diagram illustrating an apparatus for data processing according to an embodiment 500 of the present application;
fig. 6 shows a schematic diagram of a terminal device provided in embodiment 600 of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims, as well as in the drawings, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are, for example, capable of operation in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprising" and "having," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements explicitly listed, but may include other steps or elements not explicitly listed or inherent to such process, method, article, or apparatus.
Based on the problems in the prior art, the embodiment of the application provides a data processing method, which is mainly applicable to the technical field of computers. By utilizing the self-research design based on the existing Tagged Templates grammar of the Javascript, the new custom operator grammar is added, the encapsulation of various custom operator logics is supported, the necessary characteristics of parameter nesting, mixed operation with a common Javascript operator and the like are supported, and the whole body conforms to the readability of the logic sequence similar to the common operator, so that the data processing method is realized. Several of the following embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments. The application scene of the embodiment of the application is mainly a JavaScript-based language environment. JavaScript (JS) is a lightweight, interpreted or just-in-time high-level programming language with function priority, is the main programming language of the front-end development technology, and has wide application. Fig. 1 is a schematic flow chart of a data processing method according to an embodiment 100 of the present application. The first data format in the embodiment of the present application is $ { x } format. The method comprises the following detailed steps:
in step S11, an input character string is acquired.
In this step, after the function matched with the function of at least one operator is registered as the corresponding operator function, an input character string to be operated is composed of the operator and the actual variable parameter. The operators in the input character string can be registered custom operators or common operators in Javascript language.
Step S12, generating an operator character string corresponding to the input character string by using the acquired input character string, where the operator character string includes an operator in the input character string and an actual variable parameter in the input character string is presented as a character item in the first data format.
In this step, the operator execution function is used to perform initial processing on the input string. Specifically, an operator is reserved by filtering out and removing the actual variable parameter in the input character string, and the actual variable parameter is replaced by a character item in the first data format. Wherein, the initial value of x in the first data is 0, and 1 is added circularly according to the number of operators. Further, the character string including the operator and the character item in the first data format subjected to the aforementioned processing is determined as an operator character string corresponding to the input character string. The first data format in the embodiment of the present application is $ { x } format.
In step S13, operators in the operator character string are matched among the registered operators.
In this step, based on the generated operator character string, if the character string contains a user-defined operator, the operator needs to be matched with the registered operator to determine the operation logic of the operator, and the operator in the operator character string is processed by using an operator function corresponding to the operator.
Step S14, when the registered operator is matched, calling an operator function created for the specified operator to process the character item in the operator character string, where the operator function is a function matched with the function of the operator corresponding to the registered operator function.
In this step, before the input character string is acquired, the function matched with the function of at least one operator is registered as a corresponding operator function. Further, when the operator execution function is matched with the registered operator, the operator function is called, corresponding actual variable parameters are extracted, character items in the operator character string are processed according to the nesting logic of the operators in the operator character string, and an operation result is generated.
As described above, based on the above embodiment, specifically, an input character string is first obtained, an operator character string corresponding to the input character string is generated by using the obtained input character string, where the operator character string includes an operator in the input character string, and an actual variable parameter in the input character string is presented as a character item in a first data format, an operator in the operator character string is matched in a registered operator, and when the registered operator is matched, an operator function created for a specified operator is called to process the character item in the operator character string, where the operator function is a function matched with a function of the operator corresponding to the registered operator function. The embodiment of the application supports encapsulation of various custom operator logics and custom operator function names by adding custom operator grammars, and improves the readability of the logic sequence of operators.
For convenience of description, the usage of the operator in the embodiments of the present application in various scenarios is explained first:
(1) the most commonly used binary operator:
(2) the right binary operator containing a number of parameters:
(3) nested scenarios:
the nested execution is provided by default for Tagged Templates syntax and does not need to be realized by oneself. With nesting, a wide variety of syntax logic can be implemented with very strong adaptability, for example:
o ' $ { o {1} - < ($ { o ' $ {100} -. $ o ' $ 100} - $ 200} -. length } -). length } -. $ 1000} -; in addition, the o function can also support the mixed use with the ordinary operator of Javascript:
o`${100}..${200}`.length+100*2>=1000
(4) scenario with unary operator:
(5) mixed execution with common Javascript operators:
o`${o`${1}..<${100}`.length}..${1000}`;
further, in the embodiment of the present application, a user-defined operator is first registered, as shown in fig. 2, which is a schematic diagram of a specific flow of the registration operator provided in the embodiment 200 of the present application. Wherein, the detailed process of the specific flow is as follows:
s201, writing a function as an operator function.
Here, for each operator, a function matching the function of the operator is taken as the corresponding operator function. Specifically, the operator function may be written using a Javascript function, such as the ". lam" operator in o' $ {1}. $ 10}, which may be written as the following function:
the function name of the operator function and the operator name of the operator can be written arbitrarily.
S202, register an operator function using a register operator method.
Here, each operator is substantially a Javascript function, and a custom operator function is globally registered using a registereopertor method, as follows:
function registerOperator(operatorName,operatorFunc){
OperatorMap[operatorName]=operatorFunc;
}
it is used for operator registration:
register operator ('.
S203, storing the mapping relation between the created key value pairs.
Here, a key-value pair is created that contains the function name of the operator function and the operator name of the operator. Specifically, the operator Map in step S202 is an operator function Map, which is a global Javascript object structure and can be used to store the mapping relationship between the registered operator function and the key-value pair:
the embodiment of the application completes the specific flow of the registration operator based on the steps.
In addition, the step of creating a corresponding operator abstract structure for an operator character string is shown in fig. 3, which is a schematic diagram of a specific flow for creating an operator abstract structure provided in embodiment 300 of the present application. Wherein, the detailed process of the specific flow is as follows:
s301, an operator character string is transmitted and initialized.
Here, if the operator string isInitializing an AST object for the operator string with a Javascript empty object: constast ast { }.
S302, generating an expression containing the structural character string.
Here, in the operator character string, character items in the first data format directly connected to the operator except for the first character item in the first data format are screened out, and a space symbol is added between the operator and the character items in the first data format. The operator character string is processed to generate a structural character string in a format of 'xxx ($ { x })'. Specifically, the "$ { x }" string "$ {0 }" to the leftmost side of the operator string is extracted. Note that it cannot have non-null characters on its left, extractedThe character string isFurther, all character strings in the format of "xxx $ { x }" are extracted by a regular expression, and an array [ ', $ {1} ', '.<${2}']. Adding a spacer such as a small bracket outside "$ { x }" of all the items in the array, and then filling back the stringThereby generating an expression containing the structural string.
S303, screening out the structural character strings.
Here, in the operator character string, a structure character string composed of an operator including an interval symbol and a character item in the first data format is selected. Specifically, all the structural character strings of 'xxx ($ { x })' are extracted by using a regular expression, and the result is an array
S304, judging whether a multi-element operator mark is added or not.
In this step, it is determined whether the leftmost side of the first character item in the first data format is a non-empty character, and when the left side of the first character item in the first data format is not a non-empty character, a multivariate operator identifier is added to the operator abstract structure, wherein the multivariate operator identifier is an index value of an actual variable parameter corresponding to x in the first character item in the first data format. The multivariate operator identifier is used to indicate whether the operator string contains a multivariate operator.
The embodiment of the application can support unary operators besides conventional binary operators, and the operator character string is exemplified as follows:
in the above exampleI.e., unary operator, which is located to the left of the parameter when used. After conversion into an operator abstract structure, each parameter is described as:
the unary operator is typically set to the left-most side of the operator execution function, as exemplified below:
further, whether "$ { x }" can be extracted at the leftmost side of the operator character string is checked, and if yes, the first operator is determined to be a binary operator; otherwise the first operator is a unary operator.
This example is "$ { x }", with a non-null character on the left-most side: at this time, the multivariate operator mark is not added to the operator abstract structure. If the first operator is a binary operator, a multivariate operator mark is added at the outermost layer of the operator abstract structure, wherein the value of x is "$ { x }" and the meaning is parameter number:
const ast={
argIndex:0
}
s305, setting the name attribute of the structural character string.
In this step, the operator name corresponding to the operator included in the structural character string is used as the name attribute of the structural character string. Specifically, an operators array structure is created in an operator abstract structure, an operator object structure is created in the array for each structure character string, and non-parenthesized parts are extracted from each 'xxx ($ { x })' and then front and rear spaces are removed to be operator names:
s306, storing x in the character item of the first data format of each structural character string as a second index value of the actual variable parameter.
Here, each operator generally has at least 1 actual variable parameter, usually 2, i.e. 2 on the left and right of the binary operator (hereinafter startTime and endTime are parameters):
the operator in the embodiment of the present application may also have 3 rd and more actual variable parameters, and then a small bracket needs to be added on the right side of the operator:
the operator function parameters are also changed to 3:
further, whether commas exist in small brackets or not is checked in each structural character string, and if commas exist, the right side of the operator contains a plurality of actual variable parameters; without comma, there is only one actual variable parameter to the right of the operator. If a plurality of parameters exist on the right side of the operator, each parameter object is separated and analyzed by commas, then a plurality of parameter objects are placed in a params array in the structure of the operator object, and a second index value is set, wherein the value is x of "$ { x }".
if there is only one actual variable parameter on the right side of the operator, there is only one parameter object in the params array of each operator object structure, and the AST is changed as follows:
the following example operator string is again:
after conversion into an operator abstract structure, each parameter is described as:
taking another example of the multi-parameter operator, when the operator transmits multiple parameters to the right side, a small bracket is required to be added:
after conversion into an operator abstract structure, each parameter is described as:
the embodiment of the application completes the concrete flow of creating the operator abstract structure based on the steps.
Further, the operator execution function processes the input string. Fig. 4 is a schematic diagram illustrating a specific flow of a data processing method according to an embodiment 400 of the present application. Wherein, the detailed process of the specific flow is as follows:
s401, inputting a first character string array and a second character string array of the character string to be input into an operator execution function.
After the input character string is obtained, the input character string is analyzed through an operator execution function, a first character string array with actual variable parameters removed is generated, and each actual variable parameter in the input character string extracted in sequence is used as a second character string array. Specifically, the operator execution function is implemented based on Javascript's Tagged Templates syntax. The mode of use is as follows:
wherein, the o function is defined once in the whole situation, and the function is executed for the operator. Its parameter definition structure follows the specification of the Tagged Templates syntax:
function o(operatorExprs,...args){
}
the operatorExprs is a first character string array, and the value is the character string array corresponding to the character string to be input after the actual variable parameter is removed:
args is a second character string array, and the value is an actual variable parameter corresponding to each first data extracted in sequence: [ startTime, endTime ].
S402, generating an operator character string corresponding to the input character string.
Here, the first character string array is looped, and character items in the first data format are added at positions corresponding to the actual variable parameters of the first character string array, wherein x is added by 1 from 0 to the end of the first character string loop after each loop item, so as to generate an operator character string corresponding to the input character string. Specifically, an operator character string corresponding to the input character string is generated using a first character string array operatorExprs of an o function, which is a character string execution function. For example, for the first string array operatorExprsThe generated operator character string isThe first character string array operatorExprs is circulated, character items in a first data format are added at the position of each actual variable parameter (x is increased by 1 from 0 in each circulation), and the character items are not added when the last item is judged, so that an operator character string containing the operator in the input character string and the character items in the first data format of the actual variable parameters in the input character string are generated.
S403, searching an operator abstract structure which takes the operator character string as a first index value in the operator abstract structure library.
Here, the operator abstract structure is an Abstract Syntax Tree (AST) method after parsing of an operator character string. AST is a tree-like representation of the abstract syntax structure of the source code, with each node on the tree representing a structure in the source code. If the operator character string generates the corresponding operator abstract structure, a mapping relation is established between the operator character string as the first index value and the corresponding operator abstract structure, and searching is facilitated. Specifically, when the o function (operator execution function) is executed, if the same operator character string is analyzed into an operator abstract structure each time, repeated operation may occur, which reduces the operation efficiency. Therefore, an operator abstract structure library is established, and the operator character strings which are converted into the operator abstract structure are cached. The AST Map object can be globally created to serve as an operator abstract structure library for storage, and the first index value can be obtained by using an operator character string. Such as:
further, the operator abstraction structure is used directly when looking up.
S404, when the operator character string is not found, a corresponding operator abstract structure is created for the operator character string.
When the corresponding operator abstract structure is not found, the operator abstract structure is created for the operator character string, and the operator character string is used as a first index value to be stored in the operator abstract structure library. The steps for creating an operator abstract structure are described in embodiment 300.
S405, judging whether the operator abstract structure carries a multivariate operator identifier.
Here, the multivariate operator is used to indicate whether the operator abstract structure contains a multivariate operator. Specifically, whether the leftmost side of the character item in the first data format is a non-null character is judged in the operator abstract structure, and when the character item is not a non-null character, a multivariate operator identifier is added to the operator abstract structure, wherein the multivariate operator identifier is an index value of an actual variable parameter corresponding to x in the character item in the first data format. Further, the process of adding the multivariate operator is added when creating a corresponding operator abstraction structure for the operator string.
S406, obtaining an operator function corresponding to the operator abstract structure.
In this step, when the matched operator abstract structure does not carry a multi-element operator identifier, a structural character string is obtained in the operator abstract structure, and a corresponding operator function is obtained in a mapping relation between key-value pairs based on the name attribute of the structural character string.
S407, acquiring actual variable parameters corresponding to the operator abstract structure.
And searching a corresponding actual variable parameter in the second character string array based on a second index value contained in each structure character string in the operator abstract structure, and placing the actual variable parameter at the position of the character item of the corresponding first data format.
S408, judging whether the current operator function is the last operator function of the input character string.
Here, the loop executes an operator function containing an actual variable parameter, and takes the operation result of the previous operator function as the first parameter in the subsequent operator function. If not, the process returns to continue the steps S406 to S408.
And S409, acquiring actual variable parameters corresponding to the multi-element operation identifier.
Here, when the matched operator abstract structure carries a multi-element operator identifier, a corresponding actual variable parameter is searched in the second character string array based on the multi-element operator identifier, and the actual variable parameter is used as a first parameter of a first operator function. Specifically, if the operator is determined to be a binary operator, that is, there is a first operation result, after the step of obtaining an operator function corresponding to the operator abstract structure, first, the step of using the multivariate operation identifier argIndex to take out a corresponding parameter from the second string array args array according to an index value is performed, and the corresponding parameter is placed in a first parameter of the first operator function. And this step is performed only once. Further, the step of obtaining the actual variable parameter corresponding to the operator abstract structure and the subsequent steps are executed.
And S410, outputting the operation result of the last operator function as the operation result corresponding to the input character string.
The application realizes the data processing method based on the steps.
The embodiment of the application provides a feasible implementation scheme for the Javascript user-defined operator function. Based on the existing Tagged Templates grammar implementation of Javascript, the readability of the logical sequence of the grammar of the operator can be kept. As in swift, (1. <100). count..1000 can be written as o' $ {1}. < $ {100}. length }. $ {1000 }. Meanwhile, the hybrid use of various common Javascript operators is supported, and the grammar can be adapted to various complex scenes, such as o ' $ { startTime +1000} ($ { endTime-1000}, $ { o ' sqrt $ {2500} ' -1000 }).
In addition, the operator in the embodiment of the present application may also process multiple actual variable parameters, and support the nested use of operators in the parameters, and the writing method may be: o' $ {1}>...<($ {100}, $ { o $ {50}. $ {10 }) "). And operators support naming with various types of special characters, e.g., emoJi icons and the like can be used. E.g. the number of milliseconds elapsed between the start time and the end time, can be written as: (As operator):
the operator grammar design scheme adopted in the embodiment of the application is a good enhancement scheme for Javascript grammar, and is characterized in that a new user-defined operator grammar is added by self-research design on the basis of the existing Tagged Templates grammar of Javascript, the package of various user-defined operator logics is supported, the necessary characteristics of parameter nesting, mixed operation with common Javascript operators and the like are supported, the whole readability of logic sequence similar to common operators is met. The adopted implementation scheme of the user-defined operator is self-research design, namely, the AST flow for creating and caching a special generated character string abstract structure, the design of each attribute of the AST, the implementation logic of a final operator execution function and the like are included.
In addition, the operator adopted in the embodiment of the application is also unique to the processing scheme of the execution sequence priority, and the priority rule of the operator is mainly as follows: the operation sequence of a plurality of operators is from left to right, if one of the operators is to be operated first, the operators can be nested by using "$ { }", and the operation is very convenient. Such as:
1. default left to right operation
2. Let the right side run first
3. Let the left run first (e.g., left-side solve operator result and then need to superimpose other operations)
Based on the same inventive concept, the embodiment 500 of the present application further provides an apparatus for data processing, where as shown in fig. 5, the apparatus includes:
an obtaining module 51, configured to obtain an input character string;
the generating module 52 is configured to generate an operator character string corresponding to the input character string by using the obtained input character string, where the operator character string includes an operator in the input character string and an actual variable parameter in the input character string is presented as a character item in a first data format;
a matching module 53 for matching operators in the operator character string among the registered operators;
and the calling module 54 is configured to, when the registered operator is matched, call an operator function created for the specified operator to process a character item in the operator character string, where the operator function is a function matched with a function of the operator corresponding to the registered operator function.
In this embodiment, specific functions and interaction manners of the obtaining module 51, the generating module 52, the matching module 53 and the calling module 54 can be referred to the record of the embodiment corresponding to fig. 1, and are not described herein again.
As shown in fig. 6, another embodiment 600 of the present application further provides a terminal device, which includes a processor 601, where the processor 601 is configured to execute the steps of the data processing method. As can also be seen from fig. 6, the terminal device provided by the above embodiment further includes a non-transitory computer readable storage medium 602, the non-transitory computer readable storage medium 602 has a computer program stored thereon, and the computer program is executed by the processor 601 to perform the steps of the above-mentioned data processing method. In practice, the terminal device may be one or more computers, as long as the computer-readable medium and the processor are included.
In particular, the storage medium can be a general-purpose storage medium, such as a removable disk, a hard disk, a FLASH, and the like, and when the computer program on the storage medium is executed, the computer program can execute the steps of the data processing method. In practical applications, the computer readable medium may be included in the apparatus/device/system described in the above embodiments, or may exist alone without being assembled into the apparatus/device/system. The computer-readable storage medium carries one or more programs which, when executed, enable performance of the steps of a method of data processing as described above.
According to embodiments disclosed herein, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example and without limitation: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing, without limiting the scope of the present disclosure. In the embodiments disclosed herein, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The flowchart and block diagrams in the figures of the present application illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments disclosed herein. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that various combinations and/or combinations of features recited in the various embodiments and/or claims of the present disclosure can be made, even if such combinations or combinations are not explicitly recited in the present application. In particular, the features recited in the various embodiments and/or claims of the present application may be combined and/or coupled in various ways, all of which fall within the scope of the present disclosure, without departing from the spirit and teachings of the present application.
Finally, it should be noted that: the above-mentioned embodiments are only specific embodiments of the present application, and are used for illustrating the technical solutions of the present application, but not limiting the same, and the scope of the present application is not limited thereto, and although the present application is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can still change or easily conceive of the technical solutions described in the foregoing embodiments or equivalent replacement of some technical features thereof within the technical scope disclosed in the present application; such changes, variations and substitutions do not depart from the spirit and scope of the exemplary embodiments of the present application and are intended to be covered by the appended claims. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims (13)
1. A method of data processing, the method comprising:
acquiring an input character string;
generating an operator character string corresponding to the input character string by using the acquired input character string, wherein the operator character string comprises an operator in the input character string and actual variable parameters in the input character string are presented as character items in a first data format;
matching the operator in the operator string among the registered operators;
and when the registered operator is matched, calling an operator function created for the specified operator to process the character item in the operator character string, wherein the operator function is a function matched with the function of the operator corresponding to the registered operator function.
2. The method of claim 1, wherein the step of registering a function matching a function of at least one operator as a corresponding operator function comprises:
for each operator, taking the function matched with the function of the operator as the corresponding operator function, and creating a key-value pair containing the function name of the operator function and the operator name of the operator;
and storing the created mapping relation between the key value pairs.
3. The method of claim 2, wherein the step of generating an operator string corresponding to the input string comprises:
analyzing the input character string through an operator execution function, generating a first character string array after the actual variable parameters are removed, and taking each actual variable parameter in the input character string extracted in sequence as a second character string array;
and circulating the first character string array, and adding character items in the first data format at positions corresponding to the actual variable parameters of the first character string array, wherein x is added with 1 from 0 to the first character string array in each circulation until the first character string circulation is finished, so as to generate the operator character string corresponding to the input character string.
4. The method of claim 3, wherein the step of matching the operator in the operator string among the registered operators comprises:
and searching an operator abstract structure which takes the operator character string as a first index value in an operator abstract structure library, creating the operator abstract structure for the operator character string when the corresponding operator abstract structure is not found, and storing the operator abstract structure into the operator abstract structure library by taking the operator character string as the first index value.
5. The method of claim 4, wherein the step of creating the operator abstraction structure for the operator string comprises:
screening out character items in the first data format, which are directly connected with the operator, except for the first character item in the first data format in the operator character string, and adding interval symbols between the operator and the character items in the first data format;
screening out a structural character string consisting of the operator containing the interval symbols and the character item in the first data format from the operator character string, and taking the operator name corresponding to the operator contained in the structural character string as the name attribute of the structural character string;
and storing the x in the character item of the first data format of each structural character string as a second index value of the actual variable parameter.
6. The method of claim 5, wherein before the step of filtering out character items of the first data format that are directly connected to the operator except for a first character item of the first data format, the method further comprises:
judging whether the leftmost side of the first character item in the first data format is a non-empty character, and adding the multivariate operator mark to the operator abstract structure when the leftmost side of the first character item in the first data format is not the non-empty character, wherein the multivariate operator mark is an index value of the actual variable parameter corresponding to the x in the first character item in the first data format.
7. The method of claim 6, wherein the step of invoking the operator function created for a given operator to process the character term in the operator string comprises:
when the matched operator abstract structure does not carry the multivariate operator mark, acquiring the structure character string in the operator abstract structure, and acquiring the corresponding operator function in the mapping relation between the key-value pairs based on the name attribute of the structure character string;
based on the second index value contained in each structure character string in the operator abstract structure, searching the corresponding actual variable parameter in the second character string array, and placing the actual variable parameter according to the position of the corresponding character item in the first data format;
and circularly executing the operator function containing the actual variable parameter, and taking the operation result of the previous operator function as the first parameter in the next operator function.
8. The method of claim 6, wherein the step of invoking the operator function created for a given operator to process the character term in the operator string further comprises:
when the matched operator abstract structure carries the multivariate operator identifier, acquiring the structure character string in the operator abstract structure, and acquiring the corresponding operator function in the mapping relation between the key-value pairs based on the name attribute of the structure character string;
searching the corresponding actual variable parameter in the second character string array based on the multi-element operator identifier, and taking the actual variable parameter as a first parameter of a first operator function;
based on the second index value contained in each structure character string in the operator abstract structure, searching the corresponding actual variable parameter in the second character string array, and placing the actual variable parameter according to the position of the corresponding character item in the first data format;
and circularly executing the operator function containing the actual variable parameter, and taking the operation result of the previous operator function as the first parameter in the next operator function.
9. The method of claim 7 or 8, wherein after the step of invoking the operator function created for a specified operator to process the character item in the operator string, the method further comprises:
and outputting the operation result of the last operator function as the operation result corresponding to the input character string.
10. The method of claim 1, wherein the first data format is $ { x } format.
11. An apparatus for data processing, the apparatus comprising:
the acquisition module is used for acquiring an input character string;
the generating module is used for generating an operator character string corresponding to the input character string by using the acquired input character string, wherein the operator character string contains the operator in the input character string and actual variable parameters in the input character string are presented as character items in a first data format;
a matching module for matching the operator in the operator character string among the registered operators;
and the calling module is used for calling the operator function created for the specified operator to process the character item in the operator character string when the registered operator is matched, wherein the operator function is a function matched with the function of the operator corresponding to the registered operator function.
12. A non-transitory computer readable storage medium storing instructions which, when executed by a processor, cause the processor to perform the steps of a method of data processing according to any one of claims 1 to 10.
13. A terminal device, comprising a processor configured to perform the steps of a method of data processing according to any one of claims 1 to 10.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011214884.2A CN113779311A (en) | 2020-11-04 | 2020-11-04 | Data processing method, device and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011214884.2A CN113779311A (en) | 2020-11-04 | 2020-11-04 | Data processing method, device and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN113779311A true CN113779311A (en) | 2021-12-10 |
Family
ID=78835155
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202011214884.2A Pending CN113779311A (en) | 2020-11-04 | 2020-11-04 | Data processing method, device and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113779311A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115935698A (en) * | 2022-12-30 | 2023-04-07 | 南京维拓科技股份有限公司 | Calculation method for design parameters in industrial design process |
Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
GB1522518A (en) * | 1974-12-04 | 1978-08-23 | Anvar | Data comparison system |
CN101739439A (en) * | 2009-11-30 | 2010-06-16 | 中兴通讯股份有限公司 | Method and system for dynamically customizing statistical object based on template |
CN107832271A (en) * | 2017-10-31 | 2018-03-23 | 广州视睿电子科技有限公司 | Function image drawing method, device, equipment and computer storage medium |
EP3349108A1 (en) * | 2017-01-13 | 2018-07-18 | Omron Corporation | Character string input apparatus, input character string inference method, and input character string presumption program |
CN110210212A (en) * | 2019-03-14 | 2019-09-06 | 腾讯科技(深圳)有限公司 | A kind of data processing method, device and relevant device |
CN110413284A (en) * | 2019-08-06 | 2019-11-05 | 腾讯科技(深圳)有限公司 | Morphology analysis methods, device, computer equipment and storage medium |
CN111310114A (en) * | 2019-12-20 | 2020-06-19 | 上海金融期货信息技术有限公司 | Self-analysis custom column calculation method and system |
CN111858576A (en) * | 2019-04-25 | 2020-10-30 | 北京京东尚科信息技术有限公司 | Real-time message processing method, system, device, storage medium and electronic equipment |
-
2020
- 2020-11-04 CN CN202011214884.2A patent/CN113779311A/en active Pending
Patent Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
GB1522518A (en) * | 1974-12-04 | 1978-08-23 | Anvar | Data comparison system |
CN101739439A (en) * | 2009-11-30 | 2010-06-16 | 中兴通讯股份有限公司 | Method and system for dynamically customizing statistical object based on template |
EP3349108A1 (en) * | 2017-01-13 | 2018-07-18 | Omron Corporation | Character string input apparatus, input character string inference method, and input character string presumption program |
CN107832271A (en) * | 2017-10-31 | 2018-03-23 | 广州视睿电子科技有限公司 | Function image drawing method, device, equipment and computer storage medium |
CN110210212A (en) * | 2019-03-14 | 2019-09-06 | 腾讯科技(深圳)有限公司 | A kind of data processing method, device and relevant device |
CN111858576A (en) * | 2019-04-25 | 2020-10-30 | 北京京东尚科信息技术有限公司 | Real-time message processing method, system, device, storage medium and electronic equipment |
CN110413284A (en) * | 2019-08-06 | 2019-11-05 | 腾讯科技(深圳)有限公司 | Morphology analysis methods, device, computer equipment and storage medium |
CN111310114A (en) * | 2019-12-20 | 2020-06-19 | 上海金融期货信息技术有限公司 | Self-analysis custom column calculation method and system |
Non-Patent Citations (2)
Title |
---|
牟江涛;: "基于递归的通用表达式解析器设计", 软件导刊, no. 09, 30 September 2010 (2010-09-30), pages 1 - 3 * |
颜昌学: "对计算机学科字符使用规范的几点建议", 编辑学报, no. 06, 30 December 2001 (2001-12-30) * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115935698A (en) * | 2022-12-30 | 2023-04-07 | 南京维拓科技股份有限公司 | Calculation method for design parameters in industrial design process |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10169471B2 (en) | Generating and executing query language statements from natural language | |
CN107506181A (en) | Business processing, data processing method, device and electronic equipment | |
CN109710260B (en) | Multi-platform-based applet code conversion method | |
CN109491658A (en) | The generation method and device of computer-executable code data | |
CN111488155B (en) | Coloring language translation method | |
CN108549535B (en) | Efficient program analysis method and system based on file dependency relationship | |
US10592304B2 (en) | Suggesting application programming interfaces based on feature and context analysis | |
CN112346730B (en) | Intermediate representation generation method, computer equipment and storage medium | |
US8701086B2 (en) | Simplifying analysis of software code used in software systems | |
CN109669678A (en) | Template engine integration method, device, electronic equipment and storage medium | |
CN108170661B (en) | Method and system for managing rule text | |
CN115982416A (en) | Data processing method and device, readable storage medium and electronic equipment | |
CN113779311A (en) | Data processing method, device and storage medium | |
CN108920179A (en) | Java reflects implementation method, device and system | |
CN112148746B (en) | Method, device, electronic device and storage medium for generating database table structure document | |
GB2539898B (en) | A data handling method | |
JP2009163662A (en) | Information processor, control method of information processor, and control program of information processor | |
EP3113038B1 (en) | A data handling method | |
US11609893B1 (en) | Systems and methods for generating and modifying a pattern for pattern matching utilizing a hierarchical structure that stores one or more values | |
CN116414494A (en) | Service processing method, device, equipment and storage medium | |
CN109725932B (en) | Method and device for generating description document of application component | |
US10684781B1 (en) | Big data read-write reduction | |
KR101673151B1 (en) | Method and Apparatus for Analyzing Relationship Change of Program Source and DB Schema | |
CN113031952A (en) | Method and device for determining execution code of deep learning model and storage medium | |
CN114579137B (en) | Page rendering method and device, computer equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |