A code generation method, apparatus, device, and computer readable storage medium

By constructing a target syntax tree through data transformation and syntax rules, and automatically generating code using preset code templates, the problem of low efficiency and poor quality of manual code writing is solved, achieving efficient and intelligent code generation.

CN114691143BActive Publication Date: 2026-03-27TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-31
Publication Date
2026-03-27

AI Technical Summary

Technical Problem

Manual coding is inefficient, and it is difficult to guarantee code quality and execution accuracy.

Method used

By acquiring the data to be processed for the target business, performing data transformation and syntax rule transformation, determining keywords, entities and operations, constructing the target syntax tree, and automatically generating target code using preset code templates.

Benefits of technology

It improves the efficiency and accuracy of code generation, realizes the automation and intelligence of code, reduces repetitive work of manual writing, and ensures the quality and execution efficiency of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114691143B_ABST
    Figure CN114691143B_ABST
Patent Text Reader

Abstract

The application discloses a code generation method, device and equipment and a computer readable storage medium. The method comprises the following steps: obtaining to-be-processed data of a target service; performing data conversion on the to-be-processed data to obtain target processing data conforming to a preset syntax rule; determining a keyword, an entity and an operation corresponding to the preset syntax rule; performing word segmentation on the target processing data according to the corresponding keyword, entity and operation to obtain at least one character string, and determining the type of each character string in the at least one character string; wherein the type of the character string is one of the keyword, entity and operation; constructing the at least one character string into a target syntax tree according to the type of the at least one character string, wherein the target syntax tree represents the association relationship between the to-be-processed data of the target service; obtaining a preset code template matched with the target service; and generating a target code based on the preset code template and the target syntax tree. The technical scheme provided in the application can automatically generate a code.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, and in particular to a code generation method and device, equipment and computer readable storage medium. BACKGROUND

[0002] With the development of computer technology and the rapid growth of data, people store a large amount of business data in the software system of the computer, so as to facilitate the storage and processing of data. In the case of needing to perform business operations on the data of the business, the related technical personnel obtain the target code of the executable business operation by manually writing the code.

[0003] However, since there is much repetitive content in the manually written code, the related technical personnel need to do repetitive work in the process of writing the code, which leads to low efficiency of code generation. In addition, the quality of the code and the correctness of the code in executing the business operation depend on the ability of the related technical personnel in writing the code, which leads to the fact that the quality of the code and the correctness cannot be guaranteed. SUMMARY

[0004] The present application provides a code generation method, device, equipment and computer readable storage medium, which can at least solve the technical problems of low efficiency, poor code quality and low correctness in code execution caused by manually writing the code in the related art.

[0005] In one aspect, the present application provides a code generation method, which comprises:

[0006] obtaining the to-be-processed data of the target business;

[0007] performing data conversion on the to-be-processed data to obtain target processing data conforming to a preset syntax rule;

[0008] determining the keywords, entities and operations corresponding to the preset syntax rule;

[0009] performing word segmentation on the target processing data according to the corresponding keywords, entities and operations to obtain at least one string, and determining the type of each string in the at least one string; wherein the type of the string is one of the keywords, entities and operations;

[0010] constructing the at least one string into the target syntax tree according to the type of the at least one string, the target syntax tree representing the association relationship between the to-be-processed data of the target business;

[0011] obtaining a preset code template matched with the target business;

[0012] generating target code based on the preset code template and the target syntax tree.

[0013] Another aspect provides a code generation apparatus, the apparatus comprising:

[0014] a first obtaining module configured to obtain to-be-processed data of a target service;

[0015] a data conversion module configured to perform data conversion on the to-be-processed data to obtain target processing data conforming to a preset syntax rule;

[0016] a determining module configured to determine keywords, entities and operations corresponding to the preset syntax rule;

[0017] an analyzing module configured to perform word segmentation on the target processing data according to the corresponding keywords, entities and operations to obtain at least one string, and determine a type of each string in the at least one string; wherein the type of the string is one of the keywords, the entities and the operations;

[0018] a constructing module configured to construct the at least one string into the target syntax tree according to the type of the at least one string, the target syntax tree representing an association relationship between the to-be-processed data of the target service;

[0019] a second obtaining module configured to obtain a preset code template matching the target service;

[0020] a generating module configured to generate target code based on the preset code template and the target syntax tree.

[0021] Another aspect provides a code generation device, the device comprising a processor and a memory, the memory storing at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the foregoing code generation method.

[0022] Another aspect provides a computer-readable storage medium, the storage medium storing at least one instruction, at least one program, a code set or an instruction set, the at least one instruction, the at least one program, the code set or the instruction set being loaded and executed by a processor to implement the code generation method as described above.

[0023] The code generation method, apparatus, device and computer-readable storage medium provided by the present application have the following technical effects:

[0024] The code generation method provided by the application utilizes preset syntax rules to convert the obtained to-be-processed data into target processing data that is beneficial to processing and conforms to the preset syntax rules, analyzes the target processing data according to keywords, entities and operations corresponding to the preset syntax rules, obtains at least one string, determines the type of each string in the at least one string, constructs the at least one string into the target syntax tree according to the type of the at least one string, and automatically generates target code by utilizing the target syntax tree and a preset code template, so that the automation and intelligence of data processing can be greatly improved, the efficiency of generated code and the correctness of code can be improved compared with manually writing audit code, and the execution efficiency of code can be further improved. BRIEF DESCRIPTION OF DRAWINGS

[0025] In order to more clearly illustrate the technical solutions in the embodiments of the application or the prior art, and the advantages thereof, a brief introduction will be given to the drawings needed in the embodiments or the prior art description. Obviously, the drawings in the following description only show some embodiments of the application, and for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0026] Figure 1 is a flowchart of a code generation method provided by an embodiment of the application;

[0027] Figure 2 is a flowchart of a method for obtaining target processing data in the code generation method provided by an embodiment of the application;

[0028] Figure 3 is a flowchart of a method for obtaining a target code template in the code generation method provided by an embodiment of the application;

[0029] Figure 4 is a flowchart of a method for generating target code in the code generation method provided by an embodiment of the application;

[0030] Figure 5 is a flowchart of another code generation method provided by an embodiment of the application;

[0031] Figure 6 is a structural diagram of a code generation device provided by an embodiment of the application;

[0032] Figure 7 is a structural diagram of another code generation device provided by an embodiment of the application;

[0033] Figure 8 is a syntax structure diagram of a preset syntax rule provided by an embodiment of the application;

[0034] Figure 9is a structural schematic diagram of a target syntax tree provided by an embodiment of the present application;

[0035] Figure 10 is a structural schematic diagram of a server provided by an embodiment of the present application. DETAILED DESCRIPTION

[0036] 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. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative effort belong to the scope of protection of the present application.

[0037] It should be noted that the terms "first", "second", and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product, or server including a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to the process, method, product, or device.

[0038] The present application aims to provide a code generation method, which automatically generates a code that can be used to perform a business operation of a target business, so as to solve the technical problems of low code generation efficiency, poor code quality, and low code execution accuracy caused by manual code writing in the related art.

[0039] It should be noted that the term "software system" referred to in the embodiments of the present application refers to a computer software system composed of system software, support software, and application software, i.e., the part of the computer system composed of software; "consistency" refers to the characteristic of keeping unchanged during the transmission of data in the software system; "consistency audit" refers to auditing the consistency of data in the software system; "consistency constraint" refers to verifying whether the data in the software system meets the requirement of consistency; and "consistency audit code" refers to the code used to audit the consistency of data.

[0040] The following introduces a code generation method of the present application, Figure 1is a flowchart of a code generation method provided by an embodiment of the present application. The present specification provides method operation steps as described in the embodiments or flowcharts, but more or fewer operation steps can be included based on conventional or non-creative labor. The order of steps listed in the embodiments is only one of the many step execution orders, and does not represent the only execution order. In actual system or server product execution, the method order shown in the embodiments or the drawings can be executed in sequence or in parallel (for example, in a parallel processor or multi-threaded processing environment). Specifically, as shown in Figure 1 The method can include:

[0041] S101: Obtain to-be-processed data of a target service.

[0042] In order to facilitate the storage and processing of service data, the service in the embodiment of the present application is executed by a corresponding software system, that is, a service system of the service. Correspondingly, the data of the service can be stored in the corresponding service system. In an embodiment, the data of the service can be stored in the database of the corresponding service system.

[0043] In a specific embodiment, the to-be-processed data can include data required for performing a service operation of the target service.

[0044] In actual application, in order to perform a service operation on the data in the target service, it is necessary to determine the field to which the data belongs. Therefore, in a specific embodiment, the implementation form of the to-be-processed data can be a field that distinguishes data.

[0045] In a specific embodiment, the target service can include one service, and the service operation can include a consistency audit operation on the data in the service system, so as to ensure that the data stored in different positions of the service system and belonging to the same field can meet the consistency.

[0046] In an optional embodiment, the target service can include at least two services, and the service operation of the target service can include a consistency audit operation on the data stored in different service systems, so as to ensure that the data stored in different service systems and belonging to the same field can meet the consistency.

[0047] In a specific embodiment, the obtaining of the to-be-processed data of the target service includes two obtaining modes:

[0048] First, in actual application, a terminal for users can be provided, and correspondingly, the user can input to-be-processed data through an obtaining module or an obtaining device of the terminal.

[0049] Secondly, the to-be-processed data of the target service is stored in a corresponding storage unit in advance, and after a control instruction of a user is acquired, the to-be-processed data is acquired from the storage unit according to the control instruction.

[0050] Taking the target service as a business management service and the business operation of the business management service as a consistency audit operation as an example:

[0051] In actual application, if an auditor wants to perform consistency audit on at least one kind of data in the business management service and the merchant multi-institution account application form, the to-be-processed data can be input through a user-oriented terminal, including the field of the "merchant multi-institution account application form" and at least one attribute of the field, and the at least one attribute can include "merchant multi-institution account application form (Identity Document, ID)", "application form ID" and "institution type".

[0052] Alternatively, the field of the "merchant multi-institution account application form" and at least one attribute of the field are stored in a corresponding storage unit in advance, and after a control instruction of a user is acquired, data in the storage unit is read according to the control instruction.

[0053] In the above embodiment, by acquiring the to-be-processed data of the target service, execution of the business operation of the target service can be ensured, and a condition for automatically generating a code for executing the business operation is provided.

[0054] S102: Data conversion is performed on the to-be-processed data to obtain target processing data conforming to a preset syntax rule.

[0055] In actual application, the original to-be-processed data often does not conform to the syntax rule of the code, and accordingly, in the embodiment of the present application, the to-be-processed data can be converted into target processing data conforming to the syntax rule of the code (for example, a preset syntax rule), so as to generate a target code based on the target processing data.

[0056] In order to obtain the target processing data, in a specific embodiment, before the data conversion is performed on the to-be-processed data to obtain the target processing data conforming to the preset syntax rule, the method further includes: acquiring the preset syntax rule.

[0057] Correspondingly, in the embodiment of the present application, the to-be-processed data can be converted according to the preset syntax rule to obtain the target processing data conforming to the preset syntax rule.

[0058] In a specific embodiment, the preset syntax rule includes keywords, entities, and operations, and syntax structure relationships between the keywords, entities, and operations; in a specific embodiment, the syntax rule can be set by using existing characters or character strings in natural languages, machine languages, and programming languages.

[0059] It can be understood that the preset syntax rule defines a domain specified language (DSL) of the target business, and the original to-be-processed data is formatted by using the DSL of the target business.

[0060] In a specific embodiment, taking the business operation of the target business as an example, the business operation includes auditing data consistency of the target business, the preset syntax rule can be presented according to an implementation manner shown in Table 1. The keywords include but are not limited to a syntax tree root and an entity; the entity includes but is not limited to an entity 1 and an entity 2; and the operation includes but is not limited to a union operation and a join operation. In addition, the syntax structure relationship between the keywords, entities, and operations can be identified by at least one character, and the at least one character includes “(”, “)”, “|”, “'”, “{”, and the like.

[0061] Specifically, the interpretation of the preset syntax rule can refer to Table 1.

[0062] Table 1: A preset syntax rule

[0063]

[0064]

[0065] Based on the preset syntax rule, in a specific embodiment as shown in FIG. 1, the data conversion on the to-be-processed data to obtain target processing data conforming to the preset syntax rule includes the following steps. Figure 2

[0066] S201: Format the to-be-processed data according to the preset syntax rule.

[0067] S202: Take the formatted to-be-processed data as the target processing data.

[0068] In the embodiment of the application, the to-be-processed data can be formatted according to the keywords, entities, operations, and syntax structure relationships between them defined in the preset syntax rule in Table 1.

[0069] ​The following application scenarios are combined with the business management business as an example. At least one field in the business management business can include a "merchant multi-institution account application form", a "scan code login session", and a "merchant landing whitelist". At least one attribute of the "commodity multi-institution application form" field can include: commodity multi-institution application form ID, application form ID, and institution type; at least one attribute of the "scan code login session" field can include: scan code login session ID, application form ID, and employee account; the "merchant landing whitelist" field can include whitelist key, whitelist type, and whitelist attribute. Where int32 indicates that the data type is a 32-bit integer, and string indicates that the data type is a string. Specifically, the statement for defining the foregoing entity is as follows:

[0070]

[0071] Next, based on the definition of the operation in the preset syntax rule, define the joint entity 1 (T_unionName): filter the data in the entity "T_MchInstitutionApplyment" where the merchant multi-institution application form ID (a) > 3, filter the data in the entity "T_ApplvmentWhitelist" where the whitelist key (a) > 3, and the data obtained by performing a joint operation (union) on the foregoing two kinds of data is the joint entity 1. Where the joint operation type (union_type) is union all, which means taking the union of the data of the two sets and retaining the duplicate data. Where b of the entity "T_MchInstitutionApplyment" part refers to the application form ID, and c refers to the institution type;

[0072] Where b of the entity "T_ApplvmentWhitelist" part refers to the whitelist type, and c refers to the whitelist attribute. Specifically, the statement for defining the joint entity 1 is as follows:

[0073]

[0074] Next, based on the definition of the operation in the preset syntax rule, define the join entity 1 (T_joinName): filter the data in the entity "T_MchInstitutionApplyment" with the merchant multi-institution application ID (a)>3, filter the data in the entity "T_ApplvmentWhitelist" with the whitelist key (a)>3, and perform a join operation on the two sets of data to obtain the data as the join entity 1. The join operation type (join_type) is all join, which means taking the intersection of the two sets of data, retaining the matched data, and retaining the unmatched data as a "null" string. In the entity "T_MchInstitutionApplyment", b refers to the application ID, and c refers to the institution type. In the entity "T_ApplvmentWhitelist", b refers to the whitelist type, and c refers to the whitelist attribute. Specifically, the statement for defining the join entity 1 is as follows:

[0075]

[0076]

[0077] Next, define at least one audit item "audit_items". Specifically, the type of the audit item 1 is audit consistency, which audits the data in the joint entity T_MchInstitutionApplyment with a>3 and the data in the joint entity T_TmpName2 with a>3 for consistency, and audits whether the b and c of the two entities are consistent. Specifically, the statement for defining the audit item is as follows:

[0078]

[0079] In the above embodiment, based on the preset syntax rule, the to-be-processed data that does not conform to the syntax rule of the code is formatted to obtain target processing data that conforms to the preset syntax rule. Through analysis of the target processing data in the subsequent processing process, the target code can be generated.

[0080] It can be understood that the above embodiment realizes the conversion of to-be-processed data that does not conform to the syntax rule of the code into target processing data that conforms to the syntax rule of the code (preset syntax rule).

[0081] In the embodiment of the application, the analysis of the target processing data based on the preset syntax rule includes lexical analysis and syntax analysis.

[0082] The part of the above lexical analysis can include:

[0083] S103: Determine the keywords, entities and operations corresponding to the preset syntax rule;

[0084] S104: According to the corresponding keywords, entities and operations, the target processing data is segmented, at least one string is obtained, and the type of each string in the at least one string is determined; wherein the type of the string is one of the keywords, entities and operations.

[0085] In the embodiment of the application, the preset syntax rule includes the definition of the keywords, entities and operations; accordingly, the keywords, entities and operations corresponding to the preset syntax rule include the keywords, entities and operations defined in the syntax rule.

[0086] Specifically, according to the corresponding keywords, entities and operations, the target processing data is segmented to obtain at least one string, and the type of each string in the at least one string is determined, including: according to the keywords, entities and operations defined in the syntax rule, the keywords, entities and operations existing in the target processing data are identified, and then according to the existing keywords, entities and operations, the string defined as a keyword, entity or operation is identified.

[0087] Therefore, the embodiment of the application can realize the segmentation of the target processing data to obtain the at least one string, and can also realize the identification of the type of the at least one string.

[0088] In some embodiments, the content and type of each string are recorded correspondingly. In order to facilitate storage and subsequent processing, the implementation of the corresponding record is preferably: the corresponding record is made according to the token data type.

[0089] The part of the syntax analysis includes:

[0090] S105: According to the type of the at least one string, the at least one string is constructed into the target syntax tree, and the target syntax tree represents the association relationship between the to-be-processed data of the target business.

[0091] It can be understood that, in order to construct the target syntax tree, it is necessary to determine at least one node of the target syntax tree. Among them, the node type of the at least one node includes a root node, a parent node and a child node, and the node relationship of the at least one node includes a parent-child node relationship. Based on this, it is necessary to determine which string in the at least one string can be used as a root node, which string(s) can be used as a parent node, which string(s) can be used as a child node, and which strings have a parent-child node relationship, so that the target syntax tree can be constructed by using at least one string.

[0092] Specifically, the at least one string is constructed into the target syntax tree according to the type of the at least one string, including:

[0093] A1: determining the syntax structure relationship between the corresponding keywords, entities and operations;

[0094] A2: determining the node type and the node relationship of the at least one string according to the syntax structure relationship and the type of the at least one string;

[0095] A3: constructing at least one string into the target syntax tree according to the node type and the node relationship of the at least one string.

[0096] In the embodiment of the application, in the process of setting the preset syntax rule, the keywords, entities and operations are defined, and the syntax structure relationship between the keywords, entities and operations is also defined. According to the syntax structure relationship between the keywords, entities and operations, it can be determined which field of which string (for example, root) can be used as a root node, which field of which string (for example, entity and audit item) can be used as a child node of the root node, which string can be used as a child node of a child node of the root node, and so on.

[0097] As Figure 8 shown, a syntax structure relationship of a preset syntax rule provided in the above embodiment. According to the preset syntax rule, the target processing data is analyzed, and the obtained target syntax tree can be as Figure 9 shown.

[0098] In the above embodiment, at least one string in the target processing data can be recognized by performing lexical analysis and syntax analysis on the target processing data, and the at least one string is constructed into a target syntax tree, so as to parse the target syntax tree subsequently and generate at least one code segment. In addition, the at least one string is constructed into the target syntax tree, which can facilitate storage of the at least one string, and the association relationship between the at least one string is also stored, which is beneficial to subsequent data processing.

[0099] S106: obtaining a preset code template matched with the target business;

[0100] In the embodiment of the present application, the preset code template includes a common part of the code; wherein the common part is a necessary code part in the case that the target code executes the business operation of the target business.

[0101] Specifically, as shown in the figure, Figure 3 The obtaining of the preset code template matched with the target business includes:

[0102] S301: determining, according to the demand information of the target business, a code template matched with the target business from a plurality of preset code templates;

[0103] In the embodiment of the present application, the demand information includes the business demand of the target business, and the business demand represents the demand of executing the business operation of the target business. Taking the target business as a financial management business and the business operation as a consistency audit operation as an example, the business demand can include the demand of performing consistency audit on the merchant multi-institution account application form in the financial management system.

[0104] Specifically, before the determining of the code template matched with the target business from the plurality of preset code templates according to the demand information of the target business, the method further includes:

[0105] According to the demand information of different target businesses or different demand information of the same target business, a plurality of preset code templates are set.

[0106] Therefore, the embodiment of the present application can obtain the preset code template matched with the demand information of different target businesses or different demand information of the same target business.

[0107] S302: taking the matched code template as a target code template.

[0108] In the related art, the target code required to be written for executing the business operation of the target business usually includes a large amount of repeated content, so that the related technical personnel need to perform repetitive work, which not only consumes a large amount of labor, but also reduces the execution efficiency of the code.

[0109] In the embodiment of the present application, by setting the common code part of the target code in the preset code template, not only the labor can be greatly reduced, but also the execution efficiency of the code can be significantly improved.

[0110] S107: generating the target code based on the preset code template and the target syntax tree.

[0111] In the embodiment of the present application, the preset code template includes a common code part of the target code, and further includes at least one to-be-filled position.

[0112] In order to realize automatic filling of at least one to-be-filled position of the preset code template, thereby automatically generating target code having a function of performing the business operation, as shown in the following formula: Figure 4 In the embodiment of the present application, the generating of the target code based on the preset code template and the target syntax tree comprises:

[0113] S401: parsing the target syntax tree to generate at least one code segment;

[0114] In the embodiment of the present application, the at least one code segment is used to fill at least one to-be-filled position of the preset code template; by parsing the target syntax tree, the at least one code segment can be generated.

[0115] Specifically, the parsing of the target syntax tree to generate at least one code segment comprises:

[0116] B1, traversing the target syntax tree to obtain at least one string and an association relationship between the at least one string (traversal result);

[0117] B2, generating at least one code segment based on the at least one string and the association relationship between the at least one string.

[0118] Taking the target syntax tree in the following formula as an example, how to traverse the target syntax tree is described: Figure 9

[0119] For the target syntax tree in the following formula, the traversal result of the target syntax tree comprises the following multiple sub-results: Figure 9

[0120] 1, root→entity→joint operation→(joint type, joint entity 1, joint entity 2 and execution);

[0121] 2, joint type→joint all;

[0122] 3, joint entity 1→filter out data of a>3;

[0123] 4, joint entity 2→filter out data of a>3;

[0124] 5, execution→execute comparison of the filtered data of joint entity 1 and joint entity 2 respectively, and retain the same data;

[0125] 6, root→audit item→(audit type, audit entity 1, audit entity 2 and execution);

[0126] 7, audit type→consistency;

[0127] 8, audit entity 1→filter out data of a>3; ​​

[0128] 9. Audit entity 2→ filter out data of a>3;

[0129] 10. Execution→ consistency of data of a>3 in audit entity 1 and audit entity 2.

[0130] It should be noted that the content of audit entity 1 is the data obtained by one execution on the entity side; similarly, the content of audit entity 2 is the data obtained by another execution (not shown in the figure, similar principles) on the entity side. It can be understood that the entity side can realize the query of the data to be audited in the database, and the data queried is transmitted to the audit item side; and the audit item side can realize the consistency audit of the data queried by the entity side.

[0131] Based on this, at least one code segment is generated by a database program language according to the above traversal results 1-10. In a specific embodiment, the above database program language is preferably an SQL statement.

[0132] S402: Determine the position information of the at least one code segment in the preset code template;

[0133] S403: Based on the position information, the at least one code segment is transmitted to the preset code template to obtain the target code.

[0134] In the embodiment of the application, the position information is represented as the correspondence between the at least one code segment and at least one to-be-filled position in the preset code template; according to the correspondence between the at least one code segment and the at least one to-be-filled position, each code segment in the at least one code segment is filled into each to-be-filled position.

[0135] Specifically, the position information can be determined by the following method:

[0136] First, a formal parameter for transmitting a parameter value is set in the preset code template, and correspondingly, when at least one code segment is generated, the formal parameter corresponding to each code segment is determined, so that the code segment is taken as the parameter value of the corresponding formal parameter and returned to the corresponding to-be-filled position in the preset code template.

[0137] Second, an identifier is set for at least one to-be-filled position of the preset code template, and correspondingly, when at least one code segment is generated, the identifier corresponding to each code segment is determined, so that the identifier of the above to-be-filled position is replaced by the corresponding code segment to realize the filling of the preset code template. In the embodiment of the application, the above identifier is preferably the type of the string corresponding to the code segment, so as to save data resources.

[0138] Therefore, the embodiment of the present application can automatically fill the automatically generated at least one code segment into the corresponding to-be-filled position of the preset code template, thereby automatically generating the target code corresponding to the business operation of the target business.

[0139] In some embodiments, the method can further include:

[0140] executing the business operation corresponding to the target business based on the target code.

[0141] In the embodiment of the present application, the to-be-filled position of the preset code template is filled by using the at least one code segment obtained by parsing the target syntax tree in combination with the position information set in the preset code template, so that the target code matched with the target business can be automatically generated, the automation and intelligence of data processing are greatly improved, the efficiency of generating code and the correctness of the code can be improved compared with manually writing code, and the execution efficiency of the code in actual application can be improved.

[0142] In combination with the application scenario of the consistency audit code generation, the embodiment of the present application further provides a code generation method, as shown in Figure 5 The method includes:

[0143] S501: A preset syntax rule associated with the consistency audit is preset.

[0144] Specifically, the preset syntax rule can include a keyword, an entity, and an operation, and a syntax structure relationship between the keyword, the entity, and the operation; next, S503 is executed.

[0145] S502: A preset code template associated with the consistency audit is preset; next, S507 is executed.

[0146] The steps of S501 and S502 are not distinguished in terms of the execution sequence.

[0147] S503: The to-be-processed data input by the audit personnel through a user face terminal is acquired, the to-be-processed data is formatted according to the preset syntax rule, and the target processing data conforming to the preset syntax rule is obtained; next, S504 is executed.

[0148] S504: The target processing data is subjected to lexical analysis according to the keyword, the entity, and the operation corresponding to the preset syntax rule, so as to perform word segmentation on the target processing data, and at least one string is obtained; next, S505 is executed.

[0149] Specifically, the implementation of the lexical analysis can refer to the related description in the above embodiments, which is not repeated here.

[0150] S505: According to the syntax structure relationship between the keywords, entities and operations corresponding to the preset syntax rule, the target processing data is subjected to syntax analysis to construct at least one string into a target syntax tree; next, S506 is executed.

[0151] Specifically, the implementation of the syntax analysis can refer to the related description in the above embodiments, which will not be repeated here.

[0152] S506: The at least one string obtained by traversing the target syntax tree is subjected to compiling by using the SQL statement to generate at least one code segment; next, S507 is executed.

[0153] S507: The formal parameter corresponding to the at least one code segment is determined, and the formal parameter is set at the to-be-filled position of the preset code template; next, S508 is executed.

[0154] S508: The at least one code segment is returned to the corresponding to-be-filled position in the preset code template as a parameter value through the formal parameter, to generate a consistency audit code (target code).

[0155] It should be noted that the execution process of S501-S508 described above is not limited to the execution process described in the above embodiments. Figure 5

[0156] In the embodiments of the present application, the preset syntax rule and the preset code template associated with the consistency audit are set in advance, the to-be-audited content is formatted by using the preset syntax rule, the target processing data conforming to the preset syntax rule is obtained, the at least one string is obtained by performing lexical analysis on the target processing data based on the preset syntax rule, the at least one string is subjected to syntax analysis based on the preset syntax rule to construct the at least one string into a target syntax tree, the at least one code segment obtained by parsing the target syntax tree is used to fill the to-be-filled position of the preset code template, and thus the consistency audit code matched with the consistency audit business can be automatically generated, which greatly improves the automation and intelligence of data processing. Compared with manually writing the audit code, the efficiency of generating the code and the correctness of the code can be improved, and thus the audit efficiency can be improved.

[0157] The embodiments of the present application also provide a code generation device 600, as shown in the accompanying drawings, which comprises: Figure 6

[0158] The first acquisition module 601 is configured to acquire the to-be-processed data of a target business.

[0159] The data conversion module 602 is configured to perform data conversion on the to-be-processed data to obtain target processing data conforming to a preset syntax rule. ​​

[0160] The determination module 603 is used to determine the keywords, entities, and operations corresponding to the preset syntax rules;

[0161] Analysis module 604 is used to segment the target processing data according to the corresponding keywords, entities, and operations to obtain at least one string, and to determine the type of each string in the at least one string; wherein the type of the string is one of keywords, entities, and operations;

[0162] The construction module 605 is used to construct the at least one string into the target syntax tree according to the type of the at least one string, wherein the target syntax tree represents the relationship between the data to be processed in the target business;

[0163] The second acquisition module 606 is used to acquire a preset code template that matches the target business;

[0164] The generation module 607 is used to generate target code based on the preset code template and the target syntax tree.

[0165] In some embodiments, such as Figure 7 As shown, the device 600 further includes a third acquisition module 608; the third acquisition module 608 is used to acquire the preset syntax rules.

[0166] In some embodiments, the building module 605 further includes:

[0167] A determining unit is used to determine the syntactic structural relationship between the corresponding keywords, entities, and operations;

[0168] The analysis unit is further configured to determine the node type and node relationship of the at least one string based on the syntactic structure relationship and the type of the at least one string;

[0169] The construction unit is also configured to construct the target syntax tree from the at least one string according to the node type and node relationship of the at least one string.

[0170] In some embodiments, the generation module 607 further includes:

[0171] A parsing unit is used to parse the target syntax tree and generate at least one code snippet;

[0172] A determining unit is used to determine the position information of the at least one code segment in the preset code template;

[0173] A generation unit is used to transmit the at least one code fragment to the preset code template based on the location information to obtain the target code.

[0174] In some embodiments, the second obtaining module 606 further includes:

[0175] a determining unit, configured to determine, according to the requirement information of the target service, a code template matched with the target service from a plurality of preset code templates;

[0176] an obtaining unit, configured to obtain the matched code template as a target code template.

[0177] In some embodiments, the data conversion module 602 further includes:

[0178] a formatting unit, configured to format the to-be-processed data according to the preset syntax rule;

[0179] a determining unit, configured to determine the formatted to-be-processed data as the target processing data.

[0180] In some embodiments, as shown in Figure 7 The apparatus 600 further includes an executing module 609, configured to execute the target service corresponding business operation based on the target code.

[0181] The apparatus and the method in the apparatus embodiment are based on the same inventive concept, and how to implement the apparatus embodiment is not described herein.

[0182] The embodiment of the present application further provides a code generation device, which includes a processor and a memory, the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program is loaded and executed by the processor to realize the foregoing code generation method.

[0183] The apparatus and the method in the apparatus embodiment are based on the same inventive concept, and how to implement the apparatus embodiment is not described herein.

[0184] The method embodiment provided by the embodiment of the present application can be executed in a mobile terminal, a computer terminal, a server or similar computing devices. Taking the case of running on a server, Figure 10 is a hardware structure block diagram of a server for implementing the fault monitoring method provided by the embodiment of the present application. As shown in Figure 10As shown, the server 1000 can vary greatly in configuration and performance, and can include one or more Central Processing Units (CPU) 1010 (processor(s) 1010 can include, without limitation, processing devices such as microprocessors, microcontrollers, or programmable logic devices), memory 1030 for storing data, one or more storage media 1020 (such as one or more mass storage devices) for storing applications 1023 or data 1022. The memory 1030 and the storage media 1020 can be of any type of volatile or non-volatile storage, including, without limitation, magnetic storage, semiconductor storage, or solid state storage. The programs stored on the storage media 1020 can include one or more modules that each can include a series of instructions for operation of the server. Further, the CPU 1010 can be configured to communicate with the storage media 1020 to execute the series of instructions of the storage media 1020 on the server 1000. The server 1000 can also include one or more power supplies 1060, one or more wired or wireless network interfaces 1050, one or more input / output interfaces 1040, and / or one or more operating systems 1021, such as Windows Server TM , MacOS X TM , Unix TM , Linux TM , FreeBSD TM , and the like.

[0185] The input / output interface 1040 can be configured to receive or transmit data via a network. Examples of the network can include a wireless network provided by a communication provider of the server 1000. In one example, the input / output interface 1040 includes a network interface controller (NIC) that can be connected to other network devices through a base station to communicate with the Internet. In one example, the input / output interface 1040 can be a radio frequency (RF) module that is configured to communicate with the Internet through a wireless manner.

[0186] Those of ordinary skill in the art can understand, Figure 10 that the structure shown is merely illustrative and does not limit the structure of the electronic device described above. For example, the server 1000 can include more or fewer components than shown in Figure 10 or have a different configuration than shown in Figure 10 .

[0187] The embodiment of the present application further provides a computer readable storage medium, wherein at least one instruction or at least one program is stored in the storage medium, and the at least one instruction or the at least one program is loaded and executed by a processor to realize the code generation method.

[0188] According to an aspect of the present application, a computer program product or computer program is provided, which comprises computer instructions stored in a computer readable storage medium. A processor of a computer device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions to enable the computer device to perform the method provided in the various optional implementation manners.

[0189] Optionally, in the embodiment, the computer readable storage medium can be located in at least one of a plurality of network servers of a computer network. Optionally, in the embodiment, the computer readable storage medium can include, but is not limited to, a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various media capable of storing program codes.

[0190] It can be seen from the above embodiments of the code generation method, device, equipment and computer readable storage medium provided by the present application that, in the present application, the to-be-processed data is converted into target processing data conforming to a preset syntax rule, the target processing data is analyzed based on the preset syntax rule, a target syntax tree is constructed, and then the target code is automatically generated based on the target syntax tree and a preset code template. Not only the automation and intelligentization of code generation are realized, the repetitive work of writing code is greatly reduced, the code generation efficiency is improved, the quality of generated code is greatly improved, and the practical application of the generated code is facilitated.

[0191] It should be noted that the above-mentioned embodiments of the present application are only for description, and do not represent the advantages and disadvantages of the embodiments. The above-mentioned embodiments of the present application are described. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be executed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multi-task processing and parallel processing are possible or can be advantageous.

[0192] The various embodiments described in the specification are progressive in nature, and each embodiment highlights the differences from other embodiments. In particular, the device embodiments are described more simply because they are substantially similar to the method embodiments, and the relevant parts are referred to the description of the method embodiments.

[0193] Those skilled in the art can understand that all or part of the steps of the above-mentioned embodiments can be completed by hardware, or can be instructed by programs to complete the related hardware. The programs can be stored in a computer readable storage medium. The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk, etc.

[0194] The above description is only the preferred embodiment of the present application, and is not intended to limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A code generation method characterized by, The method comprises: obtaining to-be-processed data of a target service; performing data conversion on the to-be-processed data to obtain target processing data conforming to a preset syntax rule; determining keywords, entities and operations corresponding to the preset syntax rule; performing word segmentation on the target processing data according to the corresponding keywords, entities and operations to obtain at least one string, and determining the type of each string in the at least one string; wherein the type of the string is one of a keyword, an entity and an operation; constructing the at least one string into a target syntax tree according to the type of the at least one string, the target syntax tree representing an association relationship between the to-be-processed data of the target service; obtaining a preset code template matching the target service; generating target code based on the preset code template and the target syntax tree.

2. The method of claim 1, wherein, The method further comprises: obtaining the preset syntax rule.

3. The method of claim 1, wherein, The construction of the at least one string into the target syntax tree according to the type of the at least one string comprises: determining a syntax structure relationship between the corresponding keywords, entities and operations; determining the node type and node relationship of the at least one string according to the syntax structure relationship and the type of the at least one string; constructing the at least one string into the target syntax tree according to the node type and node relationship of the at least one string.

4. The method of claim 1, wherein, The generation of target code based on the preset code template and the target syntax tree comprises: parsing the target syntax tree to generate at least one code segment; determining position information of the at least one code segment in the preset code template; based on the position information, passing the at least one code segment to the preset code template to obtain the target code.

5. The method of claim 1, wherein, The obtaining of the preset code template matching the target service comprises: determining a code template matching the target service from a plurality of preset code templates according to requirement information of the target service; taking the matching code template as a target code template.

6. The method of claim 1, wherein, The data conversion on the to-be-processed data to obtain target processing data conforming to a preset syntax rule comprises: formatting the to-be-processed data according to the preset syntax rule; taking the formatted to-be-processed data as the target processing data.

7. The method according to any one of claims 1 to 6, characterized in that, The method further comprises: executing a business operation corresponding to the target service based on the target code.

8. A code generation apparatus characterized by comprising: The apparatus comprises: a first obtaining module configured to obtain to-be-processed data of a target service; a data conversion module configured to perform data conversion on the to-be-processed data to obtain target processing data conforming to a preset syntax rule; a determining module configured to determine keywords, entities and operations corresponding to the preset syntax rule; an analyzing module configured to perform word segmentation on the target processing data according to the corresponding keywords, entities and operations to obtain at least one string, and determine the type of each string in the at least one string; wherein the type of the string is one of a keyword, an entity and an operation; The constructing module is configured to construct the at least one string into a target syntax tree according to a type of the at least one string, the target syntax tree representing a correlation between to-be-processed data of the target service; The second obtaining module is configured to obtain a preset code template matched with the target service; The generating module is configured to generate a target code based on the preset code template and the target syntax tree.

9. A code generating apparatus characterized by comprising: The device includes a processor and a memory, the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program is loaded and executed by the processor to implement the code generation method in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The storage medium stores at least one instruction or at least one program, the at least one instruction or the at least one program is loaded and executed by the processor to implement the code generation method in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Software source code language translation system and method

    CN104391730A

  • Machine Identification of Grammar Rules That Match a Search Query

    US20170193099A1