CN114879965A - Data settlement method, device, equipment and storage medium - Google Patents

Data settlement method, device, equipment and storage medium Download PDF

Info

Publication number
CN114879965A
CN114879965A CN202210369911.6A CN202210369911A CN114879965A CN 114879965 A CN114879965 A CN 114879965A CN 202210369911 A CN202210369911 A CN 202210369911A CN 114879965 A CN114879965 A CN 114879965A
Authority
CN
China
Prior art keywords
data
reduction
grammar
lexical
executable
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
Application number
CN202210369911.6A
Other languages
Chinese (zh)
Inventor
钱克金
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Tuanxing Information Technology Co ltd
Original Assignee
Hangzhou Tuanxing Information Technology Co ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Hangzhou Tuanxing Information Technology Co ltd filed Critical Hangzhou Tuanxing Information Technology Co ltd
Priority to CN202210369911.6A priority Critical patent/CN114879965A/en
Publication of CN114879965A publication Critical patent/CN114879965A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/253Grammatical analysis; Style critique
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/279Recognition of textual entities
    • G06F40/284Lexical analysis, e.g. tokenisation or collocates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/279Recognition of textual entities
    • G06F40/289Phrasal analysis, e.g. finite state techniques or chunking
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/425Lexical analysis

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Software Systems (AREA)
  • Character Discrimination (AREA)

Abstract

The embodiment of the application discloses a data settlement method, a device, equipment and a storage medium, wherein the method comprises the following steps: when a data settlement event is detected, acquiring data to be calculated, and performing lexical analysis on the data to be calculated to generate a lexical analysis result; adopting grammar analysis based on computational grammar to the lexical analysis result to obtain an executable grammar tree; and calculating the data to be calculated according to the executable syntax tree to obtain a data settlement result. According to the scheme, the data calculation efficiency is remarkably improved, the expandability is strong, and the safety is higher.

Description

Data settlement method, device, equipment and storage medium
Technical Field
The embodiment of the application relates to the technical field of computers, in particular to a data settlement method, a data settlement device, data settlement equipment and a storage medium.
Background
With the development and diversity demands of services, the demand for settlement of data related to the services is increasingly highlighted. Taking a logistics scene as an example, uniform logistics cost calculation needs to be performed on various settlement rules of different logistics head courses, clearance courses and tail courses, so how to perform efficient calculation becomes a current main subject.
In the related art, compared with a traditional manual processing mode, the execution of data settlement by using a written scripting language can obviously save labor cost, but for most existing scripts, the execution efficiency is too low on a platform, for example, the execution speed of a Groovy script is less than one tenth of that of a java native language, and in the case of a complex data settlement scene, a general scripting language cannot meet the business requirement of real-time cost settlement, and meanwhile, certain defects exist in the safety.
Disclosure of Invention
The embodiment of the application provides a data settlement method, a data settlement device, data settlement equipment and a storage medium, data calculation efficiency is remarkably improved, expandability is strong, and safety is higher.
In a first aspect, an embodiment of the present application provides a data settlement method, where the method includes:
when a data settlement event is detected, acquiring data to be calculated, and performing lexical analysis on the data to be calculated to generate a lexical analysis result;
adopting grammar analysis based on computational grammar to the lexical analysis result to obtain an executable grammar tree;
and calculating the data to be calculated according to the executable syntax tree to obtain a data settlement result.
In a second aspect, an embodiment of the present application further provides a data settlement apparatus, including:
the data acquisition module is configured to acquire data to be calculated when a data settlement event is detected;
the lexical analysis module is configured to perform lexical analysis on the data to be calculated to generate a lexical analysis result;
a syntax analysis module configured to obtain an executable syntax tree by using syntax analysis based on computational syntax on the lexical analysis result;
and the calculation module is configured to calculate the data to be calculated according to the executable syntax tree to obtain a data settlement result.
In a third aspect, an embodiment of the present application further provides a data settlement device, where the device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor; when the processor executes the computer program, the data settlement method according to the embodiment of the application is realized.
In a fourth aspect, the present application further provides a storage medium storing computer-executable instructions, which when executed by a computer processor, are used to perform the data settlement method according to the present application.
In a fifth aspect, the present application further provides a computer program product, where the computer program product includes a computer program, the computer program is stored in a computer-readable storage medium, and at least one processor of the device reads from the computer-readable storage medium and executes the computer program, so that the device executes the data settlement method described in the present application.
In the embodiment of the application, when a data settlement event is detected, to-be-calculated data is obtained, lexical analysis is performed on the to-be-calculated data to generate a lexical analysis result, syntax analysis based on computational grammar is performed on the lexical analysis result to obtain an executable grammar tree, and the to-be-calculated data is calculated according to the executable grammar tree to obtain a data settlement result.
Drawings
Fig. 1 is a flowchart of a data settlement method provided in an embodiment of the present application;
FIG. 2 is a flow chart of another data settlement method provided by the embodiment of the present application;
FIG. 3 is a diagram illustrating an executable syntax tree according to an embodiment of the present application;
FIG. 4 is a flow chart of another data settlement method provided by the embodiment of the present application;
FIG. 5 is a flow chart of another data settlement method provided by the embodiment of the present application;
FIG. 6 is a flow chart of another data settlement method provided in the embodiments of the present application
Fig. 7 is a block diagram of a data settlement apparatus according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of a data settlement device according to an embodiment of the present application.
Detailed Description
The embodiments of the present application will be described in further detail with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of and not restrictive on the broad embodiments of the present application. It should be further noted that, for convenience of description, only some structures related to the embodiments of the present application are shown in the drawings, not all of the structures are shown.
The terms first, second and the like in the description and in the claims of the present application are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It will be appreciated that the data so used may be interchanged under appropriate circumstances such that embodiments of the application may be practiced in sequences other than those illustrated or described herein, and that the terms "first," "second," and the like are generally used herein in a generic sense and do not limit the number of terms, e.g., the first term can be one or more than one. In addition, "and/or" in the specification and claims means at least one of connected objects, a character "/" generally means that a preceding and succeeding related objects are in an "or" relationship.
The embodiments of the present application will be further explained with reference to the drawings.
Fig. 1 is a flowchart of a data settlement method provided in an embodiment of the present application, which can be used for data settlement in a plurality of different scenarios, and the method can be executed by a computing device related to data settlement, such as a server, an intelligent terminal, a notebook computer, a tablet computer, and the like, and specifically includes the following steps:
step S101, when a data settlement event is detected, acquiring data to be calculated, and performing lexical analysis on the data to be calculated to generate a lexical analysis result.
The data settlement event is a specific event triggering data settlement. Illustratively, it may be a click event for a data settlement button displayed in the display screen, or an event triggered by other associated program runtime.
The data to be calculated is data which needs to be operated to obtain a corresponding data settlement result. For example, the data to be calculated may be text data composed of character strings. Alternatively, the character string may be a character string composed of characters constituting one or more expressions. In one embodiment, the characters are divided into numeric characters, common characters, and operators.
The lexical analysis refers to performing word segmentation and analysis on the character strings, and parsing and stipulating the text of the character strings into words. In one embodiment, the data to be computed includes script text data. Fig. 2 is a specific flowchart for performing lexical analysis according to an embodiment of the present application, and shows a specific process for performing lexical analysis on data to be calculated, as shown in fig. 2, including:
and step S1011, identifying characters in the script text data.
In one embodiment, the lexical analysis is performed by identifying characters in the data to be calculated for word segmentation. Optionally, in the specific character recognition process, the characters to be recognized may be respectively compared with a plurality of different character lists, and if the comparison is successful, the successfully compared characters are determined to be recognized. For example, if the currently extracted character is "+", and the character comparison result is consistent with the operator "+" set in the list, it is determined that the operator "+" is recognized, and the specific comparison process may be comparison for performing corresponding machine coding on the character.
Step S1012, based on the recognition result of the characters in the script text data and the set lexical reduction rule, performing word segmentation to obtain a lexical analysis result, where the lexical reduction rule includes corresponding lexical reduction modes in different character types and different lexical pre-reduction states.
In one embodiment, after an operator and a non-operator are identified in a word segmentation mode with operator priority, word segmentation is performed based on a set lexical reduction rule to obtain a lexical analysis result. The word segmentation result may be a word array composed of word strings obtained by segmenting a plurality of words.
In one embodiment, corresponding lexical reduction modes are set for different character types and different lexical pre-reduction states. The character types comprise operators and non-operators, the non-operators can be further classified into numbers and common characters, and the lexical pre-reduction states comprise a starting state, an operator reduction state and a variable reduction state. Specifically, the state machine of the lexical reduction rule is shown in the following table:
Figure BDA0003587831450000041
exemplary, different word types and exemplary examples obtained by lexical analysis conventions are as follows:
Figure BDA0003587831450000042
Figure BDA0003587831450000051
and S102, obtaining an executable syntax tree by adopting syntax analysis based on computational grammar on the lexical analysis result.
In one embodiment, the lexical analysis result is obtained and then further analyzed by syntax analysis, specifically, a syntax analysis mode based on computational grammar is adopted for analysis. In the scheme, a lexical analysis result is taken as a word array, namely a plurality of words comprising divided words are taken as an example, the syntactic analysis refers to semantic analysis of the words, and a word sequence is reduced into an abstract syntactic tree in an operator priority analysis mode. For example, assuming that the expression is E ═ a + B) × C + D, the multiplication and division are calculated first and then the addition and subtraction are calculated according to the operator priority, if there is a bracket, the bracket is calculated first, that is, the executable syntax tree obtained through syntax analysis is shown in fig. 3, and fig. 3 is a schematic diagram of the executable syntax tree provided in the embodiment of the present application.
In one embodiment, the specific process of generating the executable syntax tree may be: and on the basis of the set grammar reduction rule, reducing each word in the word array to obtain an executable grammar tree. The grammar reduction rule is determined according to the operation priority sequence, and comprises different word types and corresponding grammar reduction modes in different grammar prepositive reduction states. Optionally, the word types include single character operators, multiple character operators, left brackets, right brackets, function declarations, parameter lists, and variables, the pre-reduction states include a start state, a reduction state for single character operators, a reduction state for binocular character operators, a reduction state for bracket conventions, a reduction state for function conventions, and a reduction state for list conventions, and the reduction modes for syntax conventions include a reduction mode for single character operators, a reduction mode for binocular character operators, a reduction mode for bracket conventions, a reduction mode for function conventions, and a reduction mode for list conventions. An exemplary analysis state machine for the partial grammar specification rule is shown in the following table:
Figure BDA0003587831450000061
specifically, in the above-mentioned syntax reduction mode, the specification of the binocular operator is about the specification of the binocular operator, such as the specification of the summation symbol as an example; the monocular operator specification is a specification made for a monocular operator, illustratively a specification for bitwise negating symbols; in the bracket reduction mode, recursive re-reduction is carried out on clause contents in brackets; the function specification mode is a specification of the content of a function name plus a bracket expression, such as max (a, b); parameter list conventions are for conventions of comma-signed expressions, such as (a, b, c).
And step S103, calculating the data to be calculated according to the executable syntax tree to obtain a data settlement result.
The executable syntax tree is a data structure which can be executed by a computer, namely, a result obtained by performing lexical analysis and syntax analysis on data to be calculated and performing reduction on the data to be calculated. Each node in the executable syntax tree represents a variable or an operator, a variable corresponding to a parent node is obtained by operating the variables and operators of the child nodes, and the final root node of the executable syntax tree is reduced to be a variable. For example, the variables may include expressions and parameters, the parameters include constant parameters and variable parameters, the expressions include unary expressions, binary expressions, function expressions, bracket expressions, and the like, wherein each expression may be further divided into a plurality of child nodes; the operators include monocular operators, binocular operators, function operators, placeholders, and the like.
In one embodiment, the executable syntax tree is obtained and then the final data settlement result is obtained by performing traversal operation on each node of the executable syntax tree. Optionally, the method includes inputting parameter values of corresponding variables in the data to be calculated into the executable syntax tree, and outputting a data settlement result.
Illustratively, taking a logistics scenario as an example, each calculation item and the corresponding expression are shown in the following table (for ease of understanding, a column of related description is added):
Figure BDA0003587831450000071
according to the scheme, when a data settlement event is detected, the data to be calculated is obtained, lexical analysis is carried out on the data to be calculated to generate a lexical analysis result, syntax analysis based on computational grammar is adopted for the lexical analysis result to obtain an executable grammar tree, and the data to be calculated is calculated according to the executable grammar tree to obtain a data settlement result, so that the data settlement calculation mode realizes flexible configuration of complex settlement rules, can realize large-scale real-time settlement and has high expansibility; the data to be calculated is converted into an executable grammar tree through the set lexical method and grammar analysis rules, word segmentation is carried out by utilizing operator priority in the specification process, and the grammar analysis of the computational grammar is adopted without other grammar analysis and word segmentation modes, so that the generation process of the executable grammar tree is safer and more reliable.
In a specific test process, taking a script XT00025N + XT00026N XT00027N as an example for testing, 2744 milliseconds are consumed for ten thousand times of calculation by adopting a traditional script Groovy, and 12 milliseconds are consumed for ten thousand times of calculation by adopting the calculation method, wherein 89 milliseconds are consumed for ten thousand times of compiling when an executable syntax tree is generated, 35 milliseconds are consumed for ten thousand times of lexical analysis, and 4 milliseconds are consumed for ten thousand times of syntactic analysis, which is obviously due to the prior art.
Fig. 4 is a flowchart of another data settlement method provided in the embodiment of the present application, which shows a specific process for performing word segmentation to obtain lexical analysis results, and as shown in fig. 4, the process includes:
step S201, when a data settlement event is detected, script text data is obtained, character-by-character recognition is carried out on the script text data in a stack structure mode, a lexical reduction mode of a current character is determined according to the character type obtained through recognition and the determined lexical pre-reduction state, and corresponding reduction processing is carried out to obtain a lexical analysis result.
In one embodiment, in the process of lexical analysis to realize specification processing, script text data is stored in a stack data structure, when the specification processing is performed, the stack is sequentially popped of characters, the popped characters are identified and subjected to specification processing, until all the characters are popped, lexical analysis is judged to be finished, and a lexical analysis result is returned.
Optionally, the type of the character is identified for the popped character, if the character is a common character or a number, the character is correspondingly added into the operator stack, until the character of the operator type is identified, a specification of the operator stack is executed, for example, a variable specification of the operator stack is executed, a non-operator specification in the operator stack is a variable, and meanwhile, an operator specification is further executed for the operator, the specification being a monocular operator, a binocular operator, and the like.
Specifically, taking the calculation content of XT00025N + XT00026N × XT00027N as an example, character recognition is performed sequentially from the first X from the beginning, common characters and numeric characters are recognized before "N" in XT00025N, an operator stack of "XT 00025N" is entered, when "+" is recognized, an operator "+" is detected, at this time, the character type is changed from a non-operator to an operator, that is, a state change of the character type occurs, a variable specification of the operator stack is executed, a variable word of "XT 00025N" is obtained, when "+" is determined, when a second "X" is recognized, the character type is changed from the operator to a common character, at this time, an operator specification is executed, an operator word of "+" is obtained, at this time, an operator stack is executed for the second "X", and subsequent words of XT000 00026N, × 000 00027N, and others are obtained by performing lexical analysis sequentially.
And S202, obtaining an executable syntax tree by adopting syntax analysis based on computational grammar on the lexical analysis result.
And step S203, calculating the data to be calculated according to the executable syntax tree to obtain a data settlement result.
According to the method, the lexical analysis mode with operator preference is adopted, the data to be calculated are segmented through the identification of the operator, the method is suitable for the data settlement, particularly the logistics data settlement scene, the extensible and flexible segmentation can be performed according to different data to be calculated, and the overall data settlement efficiency is improved.
Fig. 5 is a flowchart of another data settlement method according to an embodiment of the present application, which shows a specific process of performing word segmentation to obtain a syntax analysis result, and as shown in fig. 5, the process includes:
step S301, when a data settlement event is detected, acquiring data to be calculated, and performing lexical analysis on the data to be calculated to generate a word array.
Step S302, carrying out type recognition on the word arrays one by one in a stack structure mode, determining a grammar specification mode of the current word according to the word type obtained by recognition and the determined word preposed specification state, and carrying out corresponding specification processing to obtain an executable grammar tree.
In one embodiment, the word groups are stored in a stack data structure, the stack popping operation of the words is sequentially carried out, the word types are identified, and if the words are words of variable types, the words are input into a word stack to be subjected to protocol reduction; if the current word type is the operational character, the priority of the pre-operational character is determined, if the priority of the pre-operational character is high, the grammar reduction rule of the pre-operational character is executed, otherwise, the operational character is put into a stack to be reduced of the word and is reduced until the word in the stack data structure is empty, and after the stack to be reduced of the word is empty, the root node of the grammar tree can be executed by returning to the abstract grammar tree for data settlement.
And step S303, calculating the data to be calculated according to the executable syntax tree to obtain a data settlement result.
According to the method, words are approximately in a tree structure according to the custom language and the rules through syntactic analysis, the process of the rules is in accordance with operator priority sequencing, the method is suitable for the scenes of data settlement, particularly logistics data settlement, extensible and flexible word segmentation can be performed according to different data to be calculated, and the overall data settlement efficiency is improved.
On the basis of the technical scheme, the method further comprises a step of checking the legality of the grammar while performing lexical analysis and syntactic analysis so as to prohibit illegal grammars from participating in calculation, wherein the specific illegal grammars can be correspondingly configured in a grammar analysis specification rule, such as records in the state machine table. Therefore, the reasonability and the accuracy of the calculation result are ensured, and meanwhile, a prompt can be given in time aiming at the illegal condition.
Fig. 6 is a flowchart of another data settlement method provided in an embodiment of the present application, and illustrates a method for caching an executable syntax tree and performing data settlement based on the cached executable syntax tree, as shown in fig. 6, including:
step S401, when a data settlement event is detected, script text data are obtained, character-by-character recognition is carried out on the script text data in a stack structure mode, a lexical reduction mode of a current character is determined according to the character type obtained through recognition and the determined lexical pre-reduction state, and corresponding reduction processing is carried out to generate a word array.
Step S402, carrying out type identification of words one by one on the word array in a stack structure form, determining a grammar specification mode of the current word according to the word type obtained by identification and the determined word preposed specification state, and carrying out corresponding specification processing to obtain an executable grammar tree.
And S403, calculating the data to be calculated according to the executable syntax tree to obtain a data settlement result.
And step S404, caching the executable syntax tree for subsequent data settlement processing.
In one embodiment, the executable syntax tree is cached after it is obtained. Optionally, for different data settlement processes in different scenes, after the executable syntax trees are generated, the executable syntax trees are cached. In the subsequent data settlement process, whether the corresponding executable syntax tree is hit or not is firstly searched from the cache, if yes, calculation is directly carried out, otherwise, calculation is carried out after the executable syntax tree is generated.
Therefore, after the data settlement result is obtained by calculating the data to be calculated according to the executable syntax tree, the executable syntax tree is cached for subsequent data settlement processing, the processing efficiency of data settlement can be further remarkably improved, and the same executable syntax tree does not need to be repeatedly generated.
Fig. 7 is a block diagram of a data settlement apparatus according to an embodiment of the present application, where the apparatus is configured to execute the data settlement method according to the embodiment, and has functional modules and beneficial effects corresponding to the execution method. As shown in fig. 7, the apparatus specifically includes: a data acquisition module 101, a lexical analysis module 102, a syntax analysis module 103, and a computation module 104, wherein,
a data acquisition module 101 configured to acquire data to be calculated when a data settlement event is detected;
the lexical analysis module 102 is configured to perform lexical analysis on the data to be calculated to generate a lexical analysis result;
a syntax analysis module 103 configured to obtain an executable syntax tree from the lexical analysis result by using syntax analysis based on computational syntax;
the calculation module 104 is configured to perform calculation on the data to be calculated according to the executable syntax tree to obtain a data settlement result.
According to the scheme, when a data settlement event is detected, the data to be calculated is obtained, lexical analysis is carried out on the data to be calculated to generate a lexical analysis result, grammar analysis based on computational grammar is adopted for the lexical analysis result to obtain an executable grammar tree, and the data settlement result is obtained by computing the data to be calculated according to the executable grammar tree. The functions executed by the modules can be selected as follows:
in a possible embodiment, the data to be calculated includes script text data, and performing lexical analysis on the data to be calculated to generate a lexical analysis result includes:
identifying characters in the script text data;
and performing word segmentation to obtain a lexical analysis result based on the recognition result of the characters in the script text data and the set lexical reduction rule, wherein the lexical reduction rule comprises corresponding lexical reduction modes in different character types and different lexical pre-reduction states.
In one possible embodiment, the character types include operators, numbers, and common characters, the lexical pre-reduction state includes a start state, an operator reduction state, and a variable reduction state, and the lexical reduction patterns include operator reductions and variable reductions.
In a possible embodiment, the recognizing characters in the script text data, and performing word segmentation based on the recognition result of the characters in the script text data and a set lexical reduction rule to obtain a lexical analysis result includes:
carrying out character-by-character recognition on the script text data in a stack structure form;
and determining a lexical reduction mode of the current character according to the character type obtained by recognition and the determined lexical pre-reduction state, and performing corresponding reduction processing.
In one possible embodiment, the lexical analysis results include an array of words, and the parsing using computational grammar based syntax to obtain an executable syntax tree includes:
and on the basis of the set grammar reduction rule, reducing each word in the word array to obtain an executable grammar tree, wherein the grammar reduction rule is determined according to operation priority sequencing, and comprises different word types and corresponding grammar reduction modes under different grammar leading reduction states.
In one possible embodiment, the word types include single-character operators, multi-character operators, left brackets, right brackets, function declarations, parameter lists, and variables, the syntactical pre-reduction states include a start state, a single-character operator reduction state, a binocular operator reduction state, a bracket reduction state, a function reduction state, and a list reduction state, and the syntactical reduction modes include a single-character operator reduction mode, a binocular operator reduction mode, a bracket reduction mode, a function reduction mode, and a list reduction mode.
In one possible embodiment, the specifying each word in the word array based on the set grammar specification rule to obtain an executable grammar tree includes:
carrying out type recognition on the word arrays one by one in a stack structure mode;
determining a grammar reduction mode of a current word according to the recognized word type and the determined word preposed reduction state, and performing corresponding reduction processing to obtain an executable grammar tree, wherein if the current word type is an operator, the priority of the preposed operator is determined, and if the priority of the preposed operator is high, the grammar reduction rule of the preposed operator is executed.
In one possible embodiment, the syntax root node of the executable syntax tree is a variable, the executable syntax tree is composed of variables and operators, the variables include expressions and parameters, and the calculating of the data to be calculated according to the executable syntax tree obtains a data settlement result, including:
and inputting the parameter values of the corresponding variables in the data to be calculated into the executable syntax tree, and outputting a data settlement result.
In a possible embodiment, after the parsing result of the lexical analysis uses a syntax analysis based on computational grammar to obtain an executable syntax tree, the method further includes:
and caching the executable syntax tree for subsequent data settlement processing.
Fig. 8 is a schematic structural diagram of a data settlement apparatus provided in an embodiment of the present application, and as shown in fig. 8, the apparatus includes a processor 201, a memory 202, an information transceiver 203, and an output device 204; the number of the processors 201 in the device may be one or more, and one processor 201 is taken as an example in the figure; the processor 201, the memory 202 and the information transceiver 203 in the device may be connected by a bus or other means, and the bus connection is taken as an example in the figure. The memory 202 is a computer-readable storage medium, and can be used for storing software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the data settlement method in the embodiment of the present application. The processor 201 executes various functional applications of the device and data processing by executing software programs, instructions, and modules stored in the memory 202, that is, implements the above-described data settlement method. An information transceiver 203 for receiving information of numerals or characters for input and transmitting the processed output information. The output device 204 may include a display device such as a display screen.
An embodiment of the present application further provides a storage medium containing computer-executable instructions, where the computer-executable instructions are executed by a computer processor to perform the above data settlement method, and specifically includes:
when a data settlement event is detected, acquiring data to be calculated, and performing lexical analysis on the data to be calculated to generate a lexical analysis result; adopting grammar analysis based on computational grammar to the lexical analysis result to obtain an executable grammar tree; and calculating the data to be calculated according to the executable syntax tree to obtain a data settlement result.
It should be noted that, in the embodiment of the video gear selection device, the units and modules included in the embodiment are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be implemented; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the embodiments of the present application.
In some possible embodiments, various aspects of the methods provided by the present application may also be implemented in the form of a program product including program code for causing a computer device to perform the steps of the methods according to various exemplary embodiments of the present application described above in this specification when the program product is run on the computer device, for example, the computer device may perform the data settlement method described in the embodiments of the present application. The program product may be implemented using any combination of one or more readable media.

Claims (13)

1. A data settlement method, comprising:
when a data settlement event is detected, acquiring data to be calculated, and performing lexical analysis on the data to be calculated to generate a lexical analysis result;
adopting grammar analysis based on computational grammar to the lexical analysis result to obtain an executable grammar tree;
and calculating the data to be calculated according to the executable syntax tree to obtain a data settlement result.
2. The data settlement method according to claim 1, wherein the data to be calculated includes script text data, and the performing lexical analysis on the data to be calculated to generate lexical analysis results includes:
identifying characters in the script text data;
based on the recognition result of the characters in the script text data and the set lexical reduction rule, performing word segmentation to obtain a lexical analysis result, wherein the lexical reduction rule comprises corresponding lexical reduction modes in different character types and different lexical prepositive reduction states.
3. The data settlement method of claim 2, wherein the character types include operators, numbers and common characters, the lexical pre-reduction states include a start state, an operator reduction state and a variable reduction state, and the lexical reduction patterns include operator reductions and variable reductions.
4. The data settlement method according to claim 2, wherein the recognizing characters in the script text data and performing word segmentation based on the recognition results of the characters in the script text data and the set lexical reduction rule to obtain lexical analysis results comprises:
carrying out character-by-character recognition on the script text data in a stack structure form;
and determining a lexical reduction mode of the current character according to the character type obtained by recognition and the determined lexical pre-reduction state, and performing corresponding reduction processing.
5. The data settlement method of claim 1, wherein the lexical analysis results include an array of words, and wherein using computational grammar based grammar analysis on the lexical analysis results to obtain an executable grammar tree comprises:
and on the basis of the set grammar reduction rule, reducing each word in the word array to obtain an executable grammar tree, wherein the grammar reduction rule is determined according to operation priority sequencing, and comprises different word types and corresponding grammar reduction modes under different grammar leading reduction states.
6. The data settlement method of claim 5, wherein the word types include single-character operators, multi-character operators, left brackets, right brackets, function declarations, parameter lists, and variables, the syntactical pre-reduction states include a start state, a single-character operator reduction state, a binocular operator reduction state, a bracket reduction state, a function reduction state, and a list reduction state, and the syntactical reduction modes include a single-character operator reduction mode, a binocular operator reduction mode, a bracket reduction mode, a function reduction mode, and a list reduction mode.
7. The data settlement method of claim 5, wherein the stipulating each word in the word array based on the set grammar stipulation rule to obtain an executable grammar tree, comprises:
carrying out type recognition on the word arrays one by one in a stack structure mode;
and determining a grammar reduction mode of the current word according to the recognized word type and the determined word prepositive reduction state, and performing corresponding reduction processing to obtain an executable grammar tree, wherein if the current word type is an operator, the priority of the prepositive operator is determined, and if the priority of the prepositive operator is high, the grammar reduction rule of the prepositive operator is executed.
8. The data settlement method according to claim 1, wherein the syntax root node of the executable syntax tree is a variable, the executable syntax tree is composed of variables and operators, the variables include expressions and parameters, and the calculating of the data to be calculated according to the executable syntax tree obtains a data settlement result, and the calculating includes:
and inputting the parameter values of the corresponding variables in the data to be calculated into the executable syntax tree, and outputting a data settlement result.
9. The data settlement method according to any one of claims 1 to 8, further comprising, after obtaining an executable syntax tree using computational syntax-based syntax analysis on the lexical analysis result:
and caching the executable syntax tree for subsequent data settlement processing.
10. A data settlement apparatus, characterized by comprising:
the data acquisition module is configured to acquire data to be calculated when a data settlement event is detected;
the lexical analysis module is configured to perform lexical analysis on the data to be calculated to generate a lexical analysis result;
a syntax analysis module configured to obtain an executable syntax tree by using syntax analysis based on computational syntax on the lexical analysis result;
and the calculation module is configured to calculate the data to be calculated according to the executable syntax tree to obtain a data settlement result.
11. A data settlement device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the data settlement method of any one of claims 1 to 9 when executing the computer program.
12. A storage medium storing computer-executable instructions for performing the data settlement method of any one of claims 1 to 9 when executed by a computer processor.
13. A computer program product comprising a computer program, characterized in that the computer program realizes the data settlement method of any one of claims 1-9 when executed by a processor.
CN202210369911.6A 2022-04-08 2022-04-08 Data settlement method, device, equipment and storage medium Pending CN114879965A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210369911.6A CN114879965A (en) 2022-04-08 2022-04-08 Data settlement method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210369911.6A CN114879965A (en) 2022-04-08 2022-04-08 Data settlement method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114879965A true CN114879965A (en) 2022-08-09

Family

ID=82669684

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210369911.6A Pending CN114879965A (en) 2022-04-08 2022-04-08 Data settlement method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114879965A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115438653A (en) * 2022-09-17 2022-12-06 南京捷崎信息科技有限公司 Telemetry data analysis expression repeated calculation method and system

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115438653A (en) * 2022-09-17 2022-12-06 南京捷崎信息科技有限公司 Telemetry data analysis expression repeated calculation method and system

Similar Documents

Publication Publication Date Title
US10776567B2 (en) Method for compiling page data, method, device and storage medium for page rendering
CN108388425B (en) Method for automatically completing codes based on LSTM
EP3336721B1 (en) Method and system for generating a parser and parsing complex data
EP3891599B1 (en) Code completion of method parameters with machine learning
CN111736840A (en) Compiling method and running method of applet, storage medium and electronic equipment
CN115328756A (en) Test case generation method, device and equipment
CN110096599B (en) Knowledge graph generation method and device
CN110688121A (en) Code completion method, device, computer device and storage medium
CN111158663B (en) Method and system for handling references to variables in program code
CN114879965A (en) Data settlement method, device, equipment and storage medium
CN116028028A (en) Request function generation method, device, equipment and storage medium
CN113419721B (en) Web-based expression editing method, device, equipment and storage medium
CN117555720B (en) Code repairing method, device, equipment and medium
CN114398138A (en) Interface generation method and device, computer equipment and storage medium
CN112506503B (en) Programming method, device, terminal equipment and storage medium
CN109033082B (en) Learning training method and device of semantic model and computer readable storage medium
CN113987405A (en) AST-based mathematical expression calculation algorithm
CN116560666B (en) AI front end unified computing method, device and medium based on multi-level code generation
CN112416533A (en) Method and device for running application program on browser and electronic equipment
CN110362317B (en) Code conversion method, device and storage medium
CN114564195B (en) B/S architecture-based secondary development method for cloud CAD platform
JP7352640B2 (en) Search item rewriting method, device, equipment and storage medium
CN114911541A (en) Configuration information processing method and device, electronic equipment and storage medium
CN114115872A (en) Method and device for realizing service expression generation and analysis tool
CN110489124B (en) Source code execution method, source code execution device, storage medium and computer equipment

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