Data processing method, device and storage medium

文档序号:1952864 发布日期:2021-12-10 浏览:24次 中文

阅读说明:本技术 一种数据处理的方法、装置和存储介质 (Data processing method, device and storage medium ) 是由 周涛 于 2020-11-04 设计创作,主要内容包括:本申请公开了一种数据处理的方法、装置和存储介质,具体为获取输入字符串,利用获取到的输入字符串,生成与输入字符串对应的运算符字符串,其中,运算符字符串包含输入字符串中的运算符、以及输入字符串中的实际变量参数被呈现为第一数据格式的字符项,在已注册的运算符中匹配运算符字符串中的运算符,当匹配到已注册的运算符时,调用为指定运算符创建的运算符函数处理运算符字符串中的字符项,其中,运算符函数为与注册后的该运算符函数对应的运算符的功能相匹配的功能函数。本申请实施例通过增加自定义的运算符语法,支持封装各种自定义运算符逻辑和自定义运算符函数名称,提升运算符的逻辑顺序可读性。(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.)

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.

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 }".

For operator string ofThe abstract structure of the operator of (1) is as follows:

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.

26页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种基于知识图谱的非结构化电网数据处理方法及装置

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!