A regular parsing method and system for representing complex functions
By splitting function expressions into atomic functions and ordinary calculation formulas through regular expression parsing, and combining them with custom functions, the problem of efficient development of complex business scenarios in existing technologies is solved, realizing fast logical calculation and low-cost function calls.
Patent Information
- Application Number
- CN202210085978.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-25
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2042-01-25
AI Technical Summary
When dealing with complex business scenarios, existing technologies cannot meet specific and independent business needs with general calculation methods and function processing, resulting in high and scattered R&D costs.
The function expression is split into atomic functions and atomic ordinary calculations by using regular expression parsing. By combining the custom function and ordinary calculations, a custom calculation expression is generated, and fast logical calculation is achieved through a callback interface.
It improves the system's development efficiency and computing speed in complex business scenarios, reduces R&D costs, and enables rapid function calls and nested combinations.
Smart Images

Figure CN114489869B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method and system for representing complex functions using regular expressions. Background Technology
[0002] As computer programs evolve, some scenarios may require processing raw data using logic based on certain rules. After processing the raw data and obtaining new results, further processing can then proceed. Current technologies typically employ general computational methods and functions to achieve this. However, these methods have the following technical limitations: as the complexity of the system increases, unique and independent business scenarios arise. These general computational methods and functions cannot solve these problems, requiring significant R&D investment to implement separate and decentralized processing logic for these scenarios. Summary of the Invention
[0003] One of the objectives of this invention is to provide a method and system for representing complex functions using regular expressions. This method and system use regular expression features to separate function calculations and ordinary mathematical calculations in function expressions, thereby enabling the rapid combination of function calculations and ordinary mathematical calculations in scenario logic calculations. This allows for the rapid definition and computation of business functions, improving the efficiency of system business development.
[0004] Another objective of this invention is to provide a method and system for parsing complex function representations using regular expressions. After splitting the function expression, the method and system can perform hierarchical and sequential calculations, enabling rapid parsing and invocation of functions as the complexity of system business increases, thereby improving the development efficiency of complex business processes.
[0005] Another objective of this invention is to provide a method and system for parsing complex function representations using regular expressions. This method and system can generate custom function expressions by nesting custom functions and ordinary operations according to scenario requirements.
[0006] To achieve at least one of the above-mentioned objectives, the present invention further provides a method for representing complex functions using regular expressions, the method comprising the following steps:
[0007] Define the supported function types and number on the server side, register the supported functions, and generate callback interfaces for the defined functions;
[0008] Generate custom calculation expressions based on the supported function types, number of functions, and scenario calculation logic;
[0009] The custom computational expression is parsed using general regular expressions to generate atomic functions and / or atomic general computational expressions;
[0010] The general logic is invoked to execute the calculations of the atomic functions and / or atomic general calculation formulas, generate the calculation results, determine the data type of the results, and return the calculation results and data type.
[0011] According to a preferred embodiment of the present invention, the callback interface is a SignCalculateFunction interface, and the SignCalculateFunction interface includes the @FunctionalInterface annotation, and the scene calculation logic is implemented through the callback interface.
[0012] According to another preferred embodiment of the present invention, a list of functions and ordinary calculation expressions is generated based on the function types and number supported by the server definition, and a calculation expression that satisfies the scenario logic calculation is generated based on the generated list of functions and ordinary calculation expressions.
[0013] According to another preferred embodiment of the present invention, the method for generating the computational expression includes: selecting functions and / or ordinary computational expressions from a list of ordinary computational expressions, combining and nesting them to generate a text-type computational expression that satisfies the scene logic calculation.
[0014] According to another preferred embodiment of the present invention, the SignCalculateFunction interface receives a String type array and verifies whether the number and type of parameters of the String type array meet the requirements. If the String type array meets the verification, it returns CalculateResult; otherwise, it returns CalculateException.
[0015] According to another preferred embodiment of the present invention, after obtaining the calculation expression, a Calculator object is instantiated, and the calculation expression attribute and the functionality of the custom function are passed into the signCalculateFunctionMap attribute. By calling the regular expression parsing function in execute, the calculation expression is recursively parsed to generate atomic functions and atomic ordinary calculation formulas.
[0016] According to another preferred embodiment of the present invention, after obtaining the parsed atomic function and atomic general calculation formula, the atomic general calculation formula is operated on by calling the general logic processingRoutineCalculate, and the atomic function is operated on by calling the processingFunctionCalculate method.
[0017] According to another preferred embodiment of the present invention, after receiving the String type array and completing the verification of the String type array, the String type array is converted into data of the corresponding type, wherein the converted data types include Bigdecimal, Bool, String, Int and Timestamp, and the calculation result of the corresponding data type is output after logical calculation.
[0018] To achieve at least one of the above-mentioned objectives, the present invention further provides a system for representing complex functions using regular parsing, wherein the system executes the method for representing complex functions using regular parsing.
[0019] The present invention further provides a computer-readable storage medium storing a computer program, the computer program being executable by a processor to represent the method for parsing complex functions using regular expressions. Attached Figure Description
[0020] Figure 1 The diagram shown is a flowchart of a method for representing complex functions using regular expressions according to the present invention. Detailed Implementation
[0021] The following description is intended to disclose the present invention and enable those skilled in the art to implement it. The preferred embodiments described below are merely examples, and other obvious variations will occur to those skilled in the art. The basic principles of the invention defined in the following description can be applied to other embodiments, modifications, improvements, equivalents, and other technical solutions that do not depart from the spirit and scope of the invention.
[0022] It is understood that the term "a" should be understood as "at least one" or "one or more", that is, in one embodiment, the number of an element can be one, while in another embodiment, the number of the element can be multiple, and the term "a" should not be understood as a limitation on the number.
[0023] Please combine Figure 1 This invention discloses a method and system for representing complex functions using regular expressions. The method includes: firstly, predefining supported function types, common calculation types, and their numbers on the server side. The method supports commonly used function types and calculation types by default, and also allows for the setting of custom function types on the server side. The supported function types and common mathematical calculations are then registered. Simultaneously, a callback interface for the function is established, through which logical calculations for the scenario can be implemented.
[0024] Specifically, the callback interface is set to the SignCalculateFunction interface. It should be noted that the SignCalculateFunction interface includes the @FunctionalInterface annotation, through which methods can be called to obtain the calculation results. The SignCalculateFunction interface can receive a String array. Since all parameter types can be abstracted as String arrays, the parameters obtained through the SignCalculateFunction interface can be considered as String arrays. The method for receiving String arrays implemented through the SignCalculateFunction interface includes the following steps: First, the parameter types and number of parameters that meet the receiving conditions need to be preset. For example, the parameter types can be preset as Bigdecimal, Bool, String, Int, Timestamp, and the present invention can also preset the number of parameters that can be received. If the number and type of parameters in the received String array both meet the preset standards, it means that the input String array has passed verification.
[0025] Once the input String array passes validation, it needs to be converted into data of the corresponding parameter type. For example, if the String array contains an Int parameter, the data at the corresponding position in the String array needs to be converted into an Int parameter. Then, logical operations are performed based on the Int parameter in the specific scenario. The String array can also be converted into Bigdecimal, Bool, and Timestamp data. It should be noted that the above-mentioned conversions between different data types are existing technologies, and this invention will not describe them in detail.
[0026] The present invention further performs corresponding calculation logic based on the converted Bigdecimal, Bool and Timestamp data logic and outputs corresponding logical results, wherein the output logical results include the corresponding data types.
[0027] Once the client program runs, the server retrieves the calculation expression configured by the client and obtains the expression result by instantiating a Calculator object. Specifically, this involves passing in registered expression attributes, including but not limited to global, ignore, multiline, and input validation patterns, as well as passing the function corresponding to the custom function to the signCalculateFunctionMap property. It should be noted that the uploaded expression attributes and custom functions are constructed according to the needs of the scenario, and this invention will not describe them in detail. The `execute` method is further invoked. This method utilizes its regular expression parsing capabilities to recursively parse the expression. This recursive parsing involves obtaining the function header and the parentheses of the expression, and configuring the calculation priority for different parenthesis positions according to conventional calculation principles. The expression is recursively decomposed into atomic functions and atomic calculations using the function header and parenthesis priority. For example, if the server defines the `SUBSTR` and `MAX` functions, and the client inputs the calculation expression `SUBSTR("text001",1,MAX(1,3+1))`, the `execute` method recursively decomposes the expression into the following parts: `3+1`; `MAX(1,4)`; `SUBSTR("text001",1,4)`. Further calculations are performed on each atomic function according to the registered functions or ordinary calculations: the calculation results include: `3+1=4`; `MAX(1,4)=4`; `SUBSTR("text001",1,4)="text"`. The final calculation result of the above expression is "text", and this result is returned, along with the type of the calculation result based on the parameter type.
[0028] It's worth noting that the atomic functions and atomic general calculations invoke different logical processes. Atomic general calculations require calling the general logic `processingRoutineCalculate` to perform operations on each general computer according to the general calculation rules of multiplication and division followed by addition and subtraction. For atomic functions, the `processingFunctionCalculate` logic is called to perform complex function calculations. When a complex function calculation includes general calculations, the general calculations are performed first, and then, according to the configuration of the parentheses, general calculations and / or function calculations are performed sequentially. Function calculations include server-side built-in functions and system-defined business functions. Built-in functions directly execute logic to obtain the result, while system-defined business functions obtain the corresponding result through the callback interface `SignCalculateFunction`.
[0029] In particular, according to embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication component, and / or installed from a removable medium. When the computer program is executed by a central processing unit (CPU), it performs the functions defined in the methods of this application. It should be noted that the computer-readable medium described above in this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wire segments, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in connection with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on a computer-readable medium may be transmitted using any suitable medium, including but not limited to: wireless segments, wire segments, optical fibers, RF, etc., or any suitable combination thereof.
[0030] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0031] Those skilled in the art should understand that the embodiments of the present invention described above and shown in the accompanying drawings are merely examples and do not limit the present invention. The purpose of the present invention has been fully and effectively achieved. The functions and structural principles of the present invention have been shown and explained in the embodiments. Without departing from the stated principles, the implementation of the present invention may have any variations or modifications.
Claims
1. A method for representing complex functions using regular parsing, characterized in that, The method includes the following steps: Define the supported function types and number on the server side, register the supported functions, and generate callback interfaces for the defined functions; Generate custom calculation expressions based on the supported function types, number of functions, and scenario calculation logic; The custom calculation expression is parsed using general regular expressions to generate atomic functions and atomic general calculation formulas. Specifically, after obtaining the calculation expression, a Calculator object is instantiated, and the calculation expression attribute and the functionality of the custom function are passed to the signCalculateFunctionMap attribute. The calculation expression is recursively parsed by calling the regular expression parsing function in execute to generate atomic functions and atomic general calculation formulas. The general logic is invoked to execute the calculations of the atomic functions and atomic general calculations, generate calculation results, determine the data type of the results, and return the calculation results and data type. Specifically, after obtaining the parsed atomic functions and atomic general calculations, the general logic processingRoutineCalculate is invoked to perform calculations on the atomic general calculations, and the processingFunctionCalculate method is invoked to perform calculations on the atomic functions. The callback interface is the SignCalculateFunction interface, which includes the @FunctionalInterface annotation. The callback interface implements the scenario's calculation logic. The SignCalculateFunction interface receives a String array and verifies whether the number and type of parameters in the String array meet the requirements. If the String array meets the verification, it returns CalculateResult; otherwise, it returns CalculateException. After verifying the String array, it converts the String array to data of the corresponding type, including Bigdecimal, Bool, String, Int, and Timestamp. After performing logical calculations, it outputs the calculation result of the corresponding data type.
2. The method for representing complex functions using regular parsing according to claim 1, characterized in that, Based on the function types and number supported by the server definition, a list of functions and common calculation expressions is generated, and a calculation expression that satisfies the scenario logic calculation is generated based on the generated list of functions and common calculation expressions.
3. The method for representing complex functions using regular parsing according to claim 1, characterized in that, The method for generating the computational expression includes: selecting functions and / or ordinary computational expressions from the list of ordinary computational expressions, combining and nesting them to generate a text-type computational expression that satisfies the scene logic calculation.
4. A regular analytic complex function representation system, characterized in that, The system executes a regular parsing complex function representation method according to any one of claims 1-3.
5. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that can be executed by a processor according to any one of claims 1-3, a method for representing complex functions using regular expressions.
Citation Information
Patent Citations
Standardized description method for spacecraft telemetering processing algorithm
CN113468470A