Code generation method and device, equipment and storage medium

CN122816640APending Publication Date: 2026-09-25BEIJING QIYI CENTURY SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611029184.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-10
Publication Date
2026-09-25

AI Technical Summary

Technical Problem

然而,使用代码模板进行代码开发的方法,无法理解业务需求,使用低代码平台进行代码开发的方法,仅支持可视化拖拽,无法生成代码

Benefits of technology

[0009]本公开实施例提供的技术方案与现有技术相比具有如下优点:

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122816640A_ABST
    Figure CN122816640A_ABST
Patent Text Reader

Abstract

The present disclosure relates to a code generation method, device, equipment and storage medium. According to the pseudo code logic structure common to multiple businesses contained in the pseudo code knowledge base, the first element module in the business requirement described in natural language is converted into the element logic structure in the form of pseudo code. The pseudo code logic structure represents the first logical relationship between the pseudo code logic blocks, and the element logic structure represents the second logical relationship between the first element modules. Then, the program code elements corresponding to the element logic structure obtained from the code library are filled into the element logic structure to generate executable code data corresponding to the programming language. The program code elements include classes, functions, constants and variables that meet the preset code writing rules. In this way, the natural language description of the business requirement is first converted into the element logic structure in the form of pseudo code, and then the program code elements are filled into the element logic structure in the form of pseudo code, thereby improving the code development efficiency and quality.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of code development technology, and in particular to a code generation method, apparatus, device and storage medium. Background Technology

[0002] With the rapid development of science and technology and the continuous improvement of human needs, how to improve code development efficiency and quality is a problem that code developers are closely concerned about.

[0003] Currently, code templates or low-code platforms are commonly used to assist developers in code development, which can alleviate their workload to some extent. However, using code templates fails to understand business requirements, and low-code platforms only support visual drag-and-drop and cannot generate code. Clearly, existing code generation methods are insufficient to improve code development efficiency and quality. Summary of the Invention

[0004] To address the aforementioned technical problems, this disclosure provides a code generation method, apparatus, device, and storage medium.

[0005] In a first aspect, this disclosure provides a code generation method applied to a code generation device, the method comprising: Obtain the first requirement information of the target business, wherein the first requirement information is requirement information described using natural language; Based on the pseudocode logical structure contained in the preset pseudocode knowledge base, the first element module contained in the first requirement information is converted into an element logical structure corresponding to the first syntax format. The pseudocode logical structure is a general pseudocode structure that is common to the requirement information of at least two businesses. The pseudocode logical structure represents the first logical relationship between at least two pseudocode logical blocks in the pseudocode knowledge base. The element logical structure represents the second logical relationship between the at least two first element modules. The first syntax format is a syntax format between natural language and programming language. The program code elements corresponding to the logical structure of the element are obtained from the preset code library, and the program code elements are filled into the logical structure of the element to generate executable code data corresponding to the second syntax format. The program code elements include at least one of the classes, functions, constants, and variables that meet the preset code writing rules. The second syntax format is the syntax format for writing code using a programming language.

[0006] Secondly, this disclosure provides a code generation apparatus configured in a code generation device, the apparatus comprising: The requirement acquisition module is used to acquire the first requirement information of the target business, wherein the first requirement information is requirement information described using natural language; The requirement conversion module is used to convert the first element module contained in the first requirement information into an element logic structure corresponding to a first syntax format based on the pseudocode logic structure contained in the preset pseudocode knowledge base. The pseudocode logic structure is a general pseudocode structure that corresponds to the requirement information of at least two businesses. The pseudocode logic structure represents the first logical relationship between at least two pseudocode logic blocks in the pseudocode knowledge base. The element logic structure represents the second logical relationship between the at least two first element modules. The first syntax format is a syntax format between natural language and programming language. The code generation module is used to obtain the program code elements corresponding to the logical structure of the element from a preset code library, and fill the program code elements into the logical structure of the element to generate executable code data corresponding to the second syntax format. The program code elements include at least one of the classes, functions, constants, and variables that meet the preset code writing rules. The second syntax format is the syntax format for writing code using a programming language.

[0007] Thirdly, this disclosure also provides a code generation device, which includes: One or more processors; Storage device for storing one or more programs. When one or more programs are executed by one or more processors, the one or more processors implement the methods provided in the first aspect.

[0008] Fourthly, embodiments of this disclosure also provide a computer-readable storage medium having a computer program stored thereon that, when executed by a processor, implements the method provided in the first aspect.

[0009] The technical solution provided in this disclosure has the following advantages compared with the prior art: This disclosure discloses a code generation method, apparatus, device, and storage medium. First, it acquires first requirement information of a target business described in natural language. Then, based on multiple pseudocode logical structures common to various businesses contained in a pseudocode knowledge base, it converts the first element modules contained in the first requirement information into element logical structures with a syntax format between natural language and programming languages. The pseudocode logical structures represent a first logical relationship between at least two pseudocode logical blocks in the pseudocode knowledge base, and the element logical structures represent a second logical relationship between at least two first element modules. Finally, it retrieves program code elements corresponding to the element logical structures from a preset code library and fills these program code elements into the element logical structures to generate executable code data corresponding to a programming language. The program code elements include at least one of classes, functions, constants, and variables that satisfy preset code writing rules. In this way, by first converting the business requirements described in natural language into a pseudocode-form element logical structure, and then filling the pseudocode-form element logical structure with program code elements, it achieves automatic code development by understanding the business requirements, thereby improving code development efficiency and quality. Attached Figure Description

[0010] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.

[0011] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0012] Figure 1 A flowchart illustrating a code generation method provided in an embodiment of this disclosure; Figure 2 A flowchart illustrating another code generation method provided in this embodiment of the disclosure; Figure 3 A flowchart illustrating yet another code generation method provided in this disclosure embodiment; Figure 4 A flowchart illustrating another code generation method provided in an embodiment of this disclosure; Figure 5 A logical schematic diagram of a code generation method provided in an embodiment of this disclosure; Figure 6 This is a schematic diagram of the structure of a code generation apparatus provided in an embodiment of the present disclosure; Figure 7 This is a schematic diagram of the structure of a code generation device provided in an embodiment of this disclosure. Detailed Implementation

[0013] To better understand the above-mentioned objectives, features, and advantages of this disclosure, the solutions disclosed herein will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.

[0014] Numerous specific details are set forth in the following description in order to provide a full understanding of this disclosure, but this disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some, and not all, of the embodiments of this disclosure.

[0015] In related technologies, AI-powered code completion technology is also used for code development. However, this method can only generate code snippets and cannot generate complete code tailored to product requirements.

[0016] To address the aforementioned problems, this embodiment provides a code generation method. The following describes the method in conjunction with... Figures 1-5 The code generation method provided in this disclosure is described below. In this disclosure, the code generation method can be executed by a code generation device. The code generation device can be understood as a code development server. Optionally, the code generation device can be a cloud server or a server cluster.

[0017] Figure 1 A flowchart illustrating a code generation method provided in an embodiment of this disclosure is shown.

[0018] As shown in Figure 1, the code generation method may include the following steps.

[0019] S110. Obtain the first requirement information of the target business, wherein the first requirement information is requirement information described using natural language.

[0020] The first requirement information refers to the original requirement information determined to achieve the target business function. Specifically, the first requirement information can be stored in the Product Requirements Document (PRD).

[0021] Optionally, the first requirement information may include the business name, business type, execution logic of each business module, logical relationship between different business modules, execution conditions of each business module, and execution results of each business module.

[0022] For example, the target business is video playback, specifically including: a main feature viewing module, a skip end credits module, a skip advertisement module, a trailer viewing module, and a bonus episode viewing module. The first requirement information includes the business name of the video playback business as Player A, the business type as a film and television business, and the execution logic of each business module includes the execution logic of the skip end credits module, the skip advertisement module, the trailer viewing module, and the bonus episode viewing module. The logical relationship between the different business logic modules is as follows: after the main feature viewing module is executed, the skip end credits module, the trailer viewing module, and the bonus episode viewing module are executed; or, after the main feature viewing module is executed, the trailer viewing module or the bonus episode viewing module is executed.

[0023] For example, the target business is the "Collect Five Blessings" business, which specifically includes: a "Blessing" character confirmation module, a "Blessing" character overlay module, a "Blessing" character conversion module, and a "Blessing" character synthesis module. The first requirement information includes the business name of the "Collect Five Blessings" business as "Blessing Character Collection Business," and the business type as an entertainment and interactive business. The execution logic of each business module includes the execution logic of the "Blessing" character confirmation module, the execution logic of the "Blessing" character overlay module, the execution logic of the "Blessing" character conversion module, and the execution logic of the "Blessing" character synthesis module. The logical relationship between the different business logic modules is as follows: after the "Blessing" character confirmation module is completed, the "Blessing" character overlay module, the "Blessing" character conversion module, and the "Blessing" character synthesis module are executed; or, after the "Blessing" character confirmation module is completed, the "Blessing" character overlay module and the "Blessing" character conversion module are executed simultaneously.

[0024] S120. Based on the pseudocode logical structure contained in the preset pseudocode knowledge base, the first element module contained in the first requirement information is converted into the element logical structure corresponding to the first syntax format.

[0025] The pseudocode knowledge base is a collection of pseudocode that implements the target business functions.

[0026] The pseudocode logical structure is a general pseudocode structure that corresponds to the requirements of at least two business scenarios. In other words, the pseudocode logical structure is a general logical structure that is not limited to any particular business scenario. Or, pseudocode data is an informal, structured description method that lies between natural language and programming language. It is used to clearly and concisely express the logical flow of the algorithm or program of the target business, without relying on the syntax rules of any specific programming language.

[0027] The pseudocode logical structure represents the first logical relationship between at least two pseudocode logical blocks in the pseudocode knowledge base.

[0028] Optionally, the first logical relationship includes, but is not limited to, dependency relationships, parallel relationships, etc.

[0029] For example, the code logic structure includes two pseudocode logic blocks. The first pseudocode logic block has the output Z of X as the input of Y, and the second pseudocode logic block has Y+M=N. The first logical relationship between these two pseudocode logic blocks is a dependency relationship.

[0030] The element logical structure is a logical structure specific to a particular business scenario, specifically a personalized pseudocode structure corresponding to the target business. In other words, the element logical structure is the basic structure of executable code data, including only the code framework and not detailed information such as classes, functions, constants, and variables. Therefore, the element logical structure is not executable code data that is directly run by the code execution device.

[0031] The element logical structure represents the second logical relationship between at least two first element modules.

[0032] Optionally, the second logical relationship includes, but is not limited to, dependency relationships, parallel relationships, etc.

[0033] The first syntax format is a syntax format that lies between natural language and programming language. The logical structure of the elements corresponding to the first syntax format can be stored in the development documentation.

[0034] In some embodiments, the code generation device inputs the pseudocode logical structure and the first requirement information into a preset large model and performs logical structure conversion to obtain the first element module contained in the first requirement information, which is converted into the element logical structure corresponding to the first syntax format.

[0035] In some embodiments, the code generation device first performs semantic understanding on the first element module in the first requirement information, and then determines the element logical structure corresponding to the first syntax format based on the semantic understanding result of the first element module and the pseudocode logical structure.

[0036] In this way, by combining a pseudocode logic structure that is universal across various business scenarios, the element modules of the target business described in natural language are transformed into a personalized pseudocode logic structure corresponding to that business, thereby obtaining the basic structure for generating executable code data.

[0037] S130. Obtain the program code elements corresponding to the logical structure of the features from the preset code library, and fill the corresponding program code elements into the logical structure of the features to generate executable code data corresponding to the second syntax format.

[0038] Among them, the program code element contains detailed information about the logical structure of the elements.

[0039] Optionally, program code elements include at least one of the following: classes, functions, constants, and variables, which satisfy preset code writing rules.

[0040] The second syntax format is the syntax format for writing code using a programming language.

[0041] Understandably, since the element logical structure only includes the code framework and does not contain detailed information such as classes, functions, constants, and variables, the detailed information such as classes and functions must be filled into the corresponding functional structure to generate complete code data, and this complete code is identified as executable code data that can be directly run by the code execution device.

[0042] In this way, detailed code information is filled into the logical structure of the elements representing the functional structure, so as to realize the automatic generation of complete code data, thereby improving the efficiency and quality of code generation.

[0043] An embodiment of this disclosure discloses a code generation method. First, it obtains first requirement information of a target business described in natural language. Then, based on multiple pseudocode logical structures common to various businesses contained in a pseudocode knowledge base, it converts the first element modules contained in the first requirement information into element logical structures with a syntax format between natural language and programming language. The pseudocode logical structures represent a first logical relationship between at least two pseudocode logical blocks in the pseudocode knowledge base, and the element logical structures represent a second logical relationship between at least two first element modules. Finally, it obtains program code elements corresponding to the element logical structures from a preset code library and fills these program code elements into the element logical structures to generate executable code data corresponding to a programming language. The program code elements include at least one of classes, functions, constants, and variables that satisfy preset code writing rules. In this way, by first converting the business requirements described in natural language into a pseudocode-form element logical structure, and then filling the pseudocode-form element logical structure with program code elements, it achieves automatic code development by understanding the business requirements, thereby improving code development efficiency and quality.

[0044] In another embodiment of this application, the implementation method of S110 will be explained in detail.

[0045] Figure 2 A flowchart illustrating another code generation method provided in an embodiment of this disclosure is shown.

[0046] like Figure 2 As shown, the code generation method may include the following steps.

[0047] S210. Obtain the second requirement information of the target business, wherein the second requirement information is requirement information described using natural language.

[0048] Wherein, the second requirement information has the same meaning as the first requirement information, both are original requirement information determined for realizing the target business function. The difference between them is that the second requirement information includes problem points, and the first requirement information is the requirement information obtained after removing problem points from the second requirement information.

[0049] S220, based on a preset business knowledge base corresponding to the target business, determining an abnormal element module from the second requirement information, correcting the abnormal element module, and generating the first requirement information.

[0050] Wherein, the abnormal element module is an element module with problem points.

[0051] In one example, the element modules of the second requirement information may include: a fortune character confirmation module, a fortune character superposition module, a fortune character conversion module and a fortune character synthesis module. Under normal conditions, the fortune character confirmation module determines a type A fortune character according to a user's triggering operation on the type A fortune character. When the fortune character confirmation module malfunctions, the fortune character confirmation module determines a type B fortune character according to the user's triggering operation on the type A fortune character, then the fortune character confirmation module is determined as the abnormal element module.

[0052] In some embodiments, S220 is specifically determined through the following steps: performing semantic understanding on the second requirement information, determining global constraint information corresponding to the second requirement information and a third logical relationship between at least two second element modules in the second requirement information; taking the at least two second element modules as nodes and the third logical relationship as connecting lines between the nodes, generating a path satisfying the global constraint information, and determining the path as a business execution path corresponding to the second requirement information; determining the abnormal element module from the business execution path based on the preset business knowledge base.

[0053] Wherein, the global constraint information is a precondition commonly depended on by at least two second element modules.

[0054] Optionally, the global constraint information includes but is not limited to environmental conditions, time conditions and the like that are commonly depended on by at least two second element modules.

[0055] In one example, the second element modules of the second requirement information may include: a fortune character confirmation module, a fortune character superposition module, a fortune character conversion module and a fortune character synthesis module, and the global constraint information is a specific time period during the Spring Festival.

[0056] Wherein, the third logical relationship represents the execution order between at least two second element modules.

[0057] Optionally, the third logical relationship includes but is not limited to a dependency relationship, a parallel relationship and the like.

[0058] In some embodiments, based on a preset business knowledge base, abnormal element modules are determined from the business execution path. Specifically, this is achieved through the following steps: obtaining at least one second target element module from the business execution path and determining the first semantic information represented by the second target element module; obtaining the third element module corresponding to the second target element module from the preset knowledge base based on the first semantic information and the semantic information represented by each element module in the preset business knowledge base; if the first semantic information is different from the second semantic information represented by the third element module, then the second target element module is determined to be an abnormal element module.

[0059] The second target element module can be any second element module in the second requirement information.

[0060] The module function corresponding to the third element module is the same as the module function corresponding to the second target element module.

[0061] Specifically, the code generation device calls a preset large model to perform semantic understanding on the second target element module in the business execution path, determine the first semantic information, and then performs semantic understanding on each element module in the preset business knowledge base to determine the semantic information corresponding to each element module. Then, the first semantic information is matched with the semantic information corresponding to each element module in turn, and the third element module that is consistent with the module function that the second target element module wants to achieve is obtained from the preset knowledge base. Finally, even if the third element module is consistent with the function that the second target element module wants to achieve, if the semantic information corresponding to the two is different, the second target element module in the business execution path can be determined to be an abnormal element module.

[0062] In some embodiments, the abnormal element module is modified to generate first requirement information, which is determined by the following steps: obtaining the fourth element module corresponding to the abnormal element module from the preset business knowledge base; replacing the internal execution logic corresponding to the abnormal element module with the internal execution logic corresponding to the fourth element module to generate first requirement information.

[0063] Internal execution logic refers to the execution logic that a feature module possesses in order to realize its functions.

[0064] The fourth element module has the same function as the abnormal element module, and its internal execution logic is correct. Therefore, by replacing the internal execution logic of the abnormal element module with that of the fourth element module, the abnormal element module can be modified to obtain the first requirement information where the abnormal element module does not exist.

[0065] Optionally, the fourth element module and the third element module can be the same module or different modules.

[0066] In some embodiments, after performing the step of "determining the abnormal element module from the second requirement information based on the preset business knowledge base corresponding to the target business" in S220, the method further includes: generating prompt information, wherein the prompt information is used to remind the user of the abnormal element module; and determining the second requirement information after the abnormal element module is corrected as the first requirement information.

[0067] In some embodiments, after S220 is executed, the method further includes: adding the first requirement information to the business knowledge base to obtain an updated preset business knowledge base.

[0068] Therefore, the business knowledge base is continuously updated based on the revised requirements information to guide the search for subsequent business issues.

[0069] In this way, by understanding the original business requirements and their corresponding business knowledge base, anomalies can be identified from the original requirements. Then, by combining the business knowledge base, the anomalies can be fixed, thereby obtaining accurate business requirements. This allows for precise code development based on accurate business requirements.

[0070] S230. Based on the pseudocode logical structure contained in the preset pseudocode knowledge base, the first element module contained in the first requirement information is converted into the element logical structure corresponding to the first syntax format.

[0071] The pseudocode logic structure is a general pseudocode structure that corresponds to the requirement information of at least two business processes.

[0072] The pseudocode logical structure represents the first logical relationship between at least two pseudocode logical blocks in the pseudocode knowledge base.

[0073] The element logical structure represents the second logical relationship between at least two first element modules.

[0074] The first syntax format is a syntax format that lies between natural language and programming language.

[0075] S240. Obtain the program code elements corresponding to the logical structure of the features from the preset code library, and fill the corresponding program code elements into the logical structure of the features to generate executable code data corresponding to the second syntax format.

[0076] The program code elements include at least one of the following: classes, functions, constants, and variables, which meet the preset code writing rules.

[0077] The second syntax format is the syntax format for writing code using a programming language.

[0078] In another embodiment of this application, the implementation method of S120 will be explained in detail.

[0079] Figure 3 A flowchart illustrating another code generation method provided in an embodiment of this disclosure is shown.

[0080] like Figure 3 As shown, the code generation method may include the following steps.

[0081] S310. Obtain the first requirement information of the target business, wherein the first requirement information is requirement information described using natural language.

[0082] S310 is similar to S110, so it will not be described in detail here.

[0083] S320. Perform semantic understanding on the first element module contained in the first requirement information, and determine the element objects in the first element module and the third logical relationship between at least two first element modules.

[0084] Among them, the element object includes at least the object name that forms the first element module, and the third logical relationship includes at least the execution action corresponding to the object name and the execution condition corresponding to the object name.

[0085] Specifically, the code generation device can call a preset large model to perform semantic understanding on the first element module contained in the first requirement information, so as to determine the element objects in the first element module and the logical relationship between different first element modules.

[0086] It is understandable that during the semantic understanding of the first element module contained in the first demand information, the resource data consumed by the large model in the semantic understanding of the first demand information can also be obtained, thus obtaining the resource consumption data of the demand information semantic understanding stage.

[0087] In some embodiments, after S320 is executed, the method further includes: generating a prompt message, wherein the prompt message is used to remind the user to optimize the feature object and the third logical relationship between different first feature modules, and adding the optimized feature object and the optimized third logical relationship to a preset pseudocode knowledge base to obtain an updated preset pseudocode knowledge base.

[0088] In this way, the optimized pseudocode knowledge base can be continuously determined, providing a better data foundation for the pseudocode generation process of subsequent business operations.

[0089] S330. Obtain the element pseudocode corresponding to the element object and the relation pseudocode corresponding to the second logical relation from the pseudocode logical structure.

[0090] Among them, the feature pseudocode is the pseudocode structure corresponding to the feature object. The relation pseudocode is the pseudocode structure representing the relationship between different first feature modules.

[0091] In some embodiments, the code generation device inputs the pseudocode logic structure into a preset large model to extract relevant information, thereby obtaining the feature pseudocode corresponding to the feature object and the relation pseudocode corresponding to the second logical relation.

[0092] It is understandable that in the process of extracting element pseudocode and relation pseudocode from the pseudocode logical structure, we can also obtain the resource data consumed by the large model in analyzing the pseudocode logical structure, and obtain the resource consumption data of the pseudocode logical structure analysis stage.

[0093] S340. Based on the element pseudocode and relation pseudocode, generate the element logical structure corresponding to the first syntax format.

[0094] In some embodiments, the code generation device can input feature pseudocode and relation pseudocode into a preset large model, and use the large model to apply deterministic constraints and / or explicit constraints to the input information. Specifically, if non-deterministic pseudocode corresponding to a feature object is obtained from the pseudocode logical structure, the non-deterministic pseudocode is replaced with deterministic pseudocode, and the deterministic pseudocode is used as the feature pseudocode; and / or, if implicit pseudocode corresponding to a feature object is obtained from the pseudocode logical structure, the implicit pseudocode is replaced with explicit pseudocode, and the explicit pseudocode is used as the feature pseudocode.

[0095] It is understandable that during the process of generating the logical structure of elements based on the pseudocode of elements and the pseudocode of relationships, the resources consumed in the stage of generating the logical structure of elements can also be obtained, thus obtaining the resource consumption data of the pseudocode generation stage.

[0096] Furthermore, the code generation device can also superimpose the resource consumption data corresponding to the above three stages to obtain the resource data consumed by the pseudocode corresponding to the generation requirement information.

[0097] In this way, after semantically understanding the business requirements, and combining a general pseudocode logic structure, the element objects of each element module in the requirement information and the logical relationships between different element modules are transformed into pseudocode form, so as to automatically generate the basic pseudocode structure as executable code data.

[0098] S350. Obtain the program code elements corresponding to the logical structure of the elements from the preset code library, and fill the program code elements into the logical structure of the elements accordingly to generate executable code data corresponding to the second syntax format.

[0099] The program code elements include at least one of the following: classes, functions, constants, and variables, which meet the preset code writing rules.

[0100] The second syntax format is the syntax format for writing code using a programming language.

[0101] In another embodiment of this application, the implementation method of S130 will be explained in detail.

[0102] Figure 4 A flowchart illustrating another code generation method provided in an embodiment of this disclosure is shown.

[0103] like Figure 4 As shown, the code generation method may include the following steps.

[0104] S410. Obtain the first requirement information of the target business, wherein the first requirement information is the requirement information described using natural language.

[0105] S420. Based on the pseudocode logical structure contained in the preset pseudocode knowledge base, the first element module contained in the first requirement information is converted into the element logical structure corresponding to the first syntax format.

[0106] Among them, the pseudocode logical structure is a general pseudocode structure that corresponds to the requirement information of at least two businesses. The pseudocode logical structure represents the first logical relationship between at least two pseudocode logical blocks in the pseudocode knowledge base.

[0107] The element logical structure represents the second logical relationship between at least two first element modules.

[0108] The first syntax format is a syntax format that lies between natural language and programming language.

[0109] S430. Based on the element pseudocode and relation pseudocode contained in the pseudocode logical structure, obtain the first code element corresponding to the element pseudocode and the second code element corresponding to the relation pseudocode from the preset code library, and determine the first code element and the second code element as program code elements.

[0110] The program code elements include at least one of the following: classes, functions, constants, and variables, which meet the preset code writing rules.

[0111] Optionally, the first code element includes, but is not limited to, variables and functions. The second code element includes, but is not limited to, classes and memory environments.

[0112] Specifically, the code generation device calls the intelligent code editor (Cursor), which in turn calls the model context protocol. Based on the feature pseudocode and relation pseudocode, it retrieves the first code element corresponding to the feature pseudocode and the second code element corresponding to the relation pseudocode from the preset code library, thereby determining the program code elements more safely and efficiently.

[0113] The context protocol can be an interface specification based on the Lightweight Data Exchange Format (JSON) - Remote Procedure Call (RPC), used to enable neural network models to access external data securely and efficiently.

[0114] S440. Fill the first code element into the feature pseudocode and the second code element into the relation pseudocode to generate executable code data corresponding to the second syntax format.

[0115] The second syntax format is the syntax format for writing code using a programming language.

[0116] It is understandable that the feature pseudocode is the code framework of the corresponding feature module, without containing detailed information, and the relationship pseudocode is the code relationship framework between different feature modules, also without containing detailed information. The first code element is the detailed information corresponding to the feature pseudocode, and the second code element is the detailed information corresponding to the relationship pseudocode.

[0117] Specifically, when developing code for the target business for the first time, the code generation device can continue to call the Cursor to directly fill the first code element into the feature pseudocode and the second code element into the relation pseudocode, thereby generating the complete code data corresponding to the business and determining the complete code data as executable code data.

[0118] In other cases, when code development for the target business is not being performed for the first time, after executing S430, the method further includes the following steps: obtaining existing code data corresponding to the target business, and determining the existing logical structure corresponding to the existing code data from a preset pseudocode knowledge base; comparing the existing logical structure domain and the element logical structure to determine the logical structure to be updated; obtaining the third code element corresponding to the logical structure to be updated from the first code element, and obtaining the fourth code element corresponding to the logical structure to be updated from the second code element; filling the third code element into the element pseudocode in the logical structure to be updated, and filling the fourth code element into the relation pseudocode pair in the element logical structure, thereby generating executable code data corresponding to the second syntax format.

[0119] The existing code data refers to the executable code data that has been written and stored in the preset code library. Specifically, it can be the code data of the previous version of the target business.

[0120] The existing logical structure refers to the pseudocode structure generated in the pre-defined pseudocode knowledge base, which can specifically be the pseudocode structure of the previous version of the target business.

[0121] The logic structure to be updated is the pseudocode structure that needs to be generated. Specifically, it can be the pseudocode structure showing the differences between the previous and current versions of the target business.

[0122] Optionally, the third code element includes, but is not limited to, variables and functions. The fourth code element includes, but is not limited to, classes and memory environments.

[0123] Specifically, the code generation device can continue to call the Cursor to directly fill the pseudocode of the element in the logical structure to be updated with the third code element, and fill the pseudocode of the relationship in the logical structure to be updated with the fourth code element, thereby generating the complete code data corresponding to the business, and determining the complete code data as executable code data.

[0124] In some embodiments, after S440 is executed, the method further includes: storing the executable code data in a preset code library to obtain an updated code library.

[0125] This allows for the continuous identification and optimization of the codebase, providing a better data foundation for the subsequent business code generation process.

[0126] In this way, the corresponding program code elements are first determined from the code library, and the corresponding program code elements are filled into the element pseudocode and relation pseudocode at the end of the pseudocode, thereby automatically generating complete executable code data that can be run by the machine, improving code development efficiency and quality.

[0127] In another embodiment of this application, the overall implementation process of the code generation method is explained in detail.

[0128] Figure 5 A logical schematic diagram of a code generation method provided in an embodiment of this disclosure is shown.

[0129] like Figure 5 As shown, the code generation method may include the following steps.

[0130] S510. Determine the requirements information.

[0131] In some embodiments, the code generation device obtains the original requirement information of the target business, and determines the abnormal element module from the original requirement information based on the preset business knowledge base corresponding to the target business to realize the anomaly point analysis. Then, it automatically corrects the abnormal element module, generates the corrected requirement information, and stores the automatically corrected requirement information in the form of a requirement document.

[0132] In some embodiments, the code generation device can also generate requirement correction prompts to indicate whether the user needs to manually correct the requirement information. If no manual correction is required, the original requirement information is saved directly. If manual correction is required, the manually corrected requirement information is obtained and stored in the form of a requirement document.

[0133] S520, Development Documentation Generation.

[0134] Specifically, the code generation device first parses the requirements document, and based on the pseudocode logical structure contained in the preset pseudocode knowledge base, converts the first element module contained in the requirements information into the element logical structure corresponding to the first syntax format, and stores the element logical structure corresponding to the first syntax format in the form of a development document.

[0135] Furthermore, the code generation device can also generate feature correction prompts to indicate whether the user needs to manually modify the feature logic structure. If manual modification of the feature logic structure is not required, the feature logic structure is saved directly. If manual modification of the requirement information is required, the manually modified feature logic structure is obtained to optimize the pseudocode data. The modified feature logic structure is then stored in the form of a development document, and the optimized pseudocode data is added to the pseudocode knowledge base to obtain an updated pseudocode knowledge base.

[0136] S530, code generation.

[0137] In some embodiments, the code generation device first uses the Cursor to invoke the model context protocol, reads the code library and pseudocode data, specifically obtains the program code elements corresponding to the feature logical structure from the preset code library, and fills the program code elements into the feature logical structure accordingly to generate executable code data corresponding to the second syntax format.

[0138] In some embodiments, the code generation device first uses the Cursor to invoke the model context protocol, reads the code library, pseudocode data and existing code data, and automatically generates executable code data corresponding to the second syntax format based on the code library, pseudocode data and existing code data.

[0139] This disclosure also provides a code generation apparatus for implementing the above-described code generation method, which will be described below in conjunction with... Figure 6 The following explanation is provided. In this embodiment, the code generation apparatus can be executed by a code generation device. The code generation device can be understood as a code development server. Optionally, the code generation device can be a cloud server or a server cluster.

[0140] Figure 6 A schematic diagram of the structure of a code generation apparatus provided in an embodiment of this disclosure is shown.

[0141] like Figure 6 As shown, the code generation device 600 may include: The requirement acquisition module 610 is used to acquire the first requirement information of the target business, wherein the first requirement information is requirement information described using natural language; The requirement conversion module 620 is used to convert the first element module contained in the first requirement information into an element logical structure corresponding to a first syntax format based on the pseudocode logical structure contained in the preset pseudocode knowledge base. The pseudocode logical structure is a general pseudocode structure that corresponds to the requirement information of at least two businesses. The pseudocode logical structure represents the first logical relationship between at least two pseudocode logical blocks in the pseudocode knowledge base. The element logical structure represents the second logical relationship between the at least two first element modules. The first syntax format is a syntax format between natural language and programming language. The code generation module 630 is used to obtain the program code elements corresponding to the element logical structure from the preset code library, and fill the program code elements into the element logical structure to generate executable code data corresponding to the second syntax format. The program code elements include at least one of the classes, functions, constants, and variables that meet the preset code writing rules. The second syntax format is the syntax format for writing code using a programming language.

[0142] An embodiment of this disclosure provides a code generation apparatus. First, it acquires first requirement information of a target business described in natural language. Then, based on multiple pseudocode logical structures common to various businesses contained in a pseudocode knowledge base, it converts the first element modules contained in the first requirement information into element logical structures corresponding to a syntax format between natural language and programming languages. The pseudocode logical structures represent a first logical relationship between at least two pseudocode logical blocks in the pseudocode knowledge base, and the element logical structures represent a second logical relationship between at least two first element modules. Finally, it acquires program code elements corresponding to the element logical structures from a preset code library and fills these program code elements into the element logical structures to generate executable code data corresponding to a programming language. The program code elements include at least one of classes, functions, constants, and variables that satisfy preset code writing rules. In this way, by first converting the business requirements described in natural language into a pseudocode-form element logical structure, and then filling the pseudocode-form element logical structure with program code elements, it achieves automatic code development by understanding the business requirements, thereby improving code development efficiency and quality.

[0143] In some embodiments of this disclosure, the demand acquisition module 610 includes: The first acquisition unit is used to acquire the second requirement information of the target service; The first determining unit is used to determine the abnormal element module from the second requirement information based on the preset business knowledge base corresponding to the target business, and to correct the abnormal element module to generate the first requirement information.

[0144] In some embodiments of this disclosure, the first determining unit includes: A semantic understanding subunit is used to perform semantic understanding on the second requirement information, determine the global constraint information corresponding to the second requirement information and the third logical relationship between at least two second element modules in the second requirement information, wherein the global constraint information is a precondition that the at least two second element modules commonly depend on, and the third logical relationship represents the execution order between the at least two second element modules; The path generation subunit is used to generate a path that satisfies the global constraint information, with the at least two second element modules as nodes and the third logical relationship as the connection between the nodes, and to determine the path as the business execution path corresponding to the second requirement information. The subunit is determined based on the preset business knowledge base to identify the abnormal element module from the business execution path.

[0145] In some embodiments of this disclosure, a subunit is defined, specifically for: At least one second target element module is obtained from the business execution path, and the first semantic information represented by the second target element module is determined; Based on the first semantic information and the semantic information represented by each element module in the preset business knowledge base, the third element module corresponding to the second target element module is obtained from the preset knowledge base, wherein the module function corresponding to the third element module is consistent with the module function corresponding to the second target element module. If the first semantic information is different from the second semantic information represented by the third element module, then the second target element module is determined to be the abnormal element module.

[0146] In some embodiments of this disclosure, the first determining unit is specifically used for: Obtain the fourth element module corresponding to the anomaly element module from the preset business knowledge base; The internal execution logic corresponding to the abnormal element module is replaced with the internal execution logic corresponding to the fourth element module to generate the first requirement information.

[0147] In some embodiments of this disclosure, the demand conversion module 620 is specifically used for: Semantic understanding is performed on the first element module contained in the first requirement information to determine the element objects in the first element module and the third logical relationship between at least two first element modules. The element object includes at least the object name that forms the first element module, and the third logical relationship includes at least the execution action corresponding to the object name and the execution condition corresponding to the object name. From the pseudocode logic structure, obtain the element pseudocode corresponding to the element object and the relation pseudocode corresponding to the second logical relation; Based on the element pseudocode and the relation pseudocode, the element logical structure corresponding to the first syntax format is generated.

[0148] In some embodiments of this disclosure, the code generation module 630 is specifically used for: Based on the element pseudocode and relation pseudocode contained in the pseudocode logical structure, the first code element corresponding to the element pseudocode and the second code element corresponding to the relation pseudocode are obtained from the preset code library, and the first code element and the second code element are determined as the program code elements; The first code element is filled into the element pseudocode, and the second code element is filled into the relation pseudocode to generate executable code data corresponding to the second syntax format.

[0149] In some embodiments of this disclosure, the code generation module 630 is further configured to: Obtain existing code data corresponding to the target business, and determine the existing logical structure corresponding to the existing code data from the preset pseudocode knowledge base; The existing logical structure and the element logical structure are compared to determine the logical structure to be updated. Obtain the third code element corresponding to the logical structure to be updated from the first code element, and obtain the fourth code element corresponding to the logical structure to be updated from the second code element; The third code element is filled into the element pseudocode in the logical structure to be updated, and the fourth code element is filled into the relation pseudocode in the logical structure to be updated, thereby generating executable code data corresponding to the second syntax format.

[0150] It should be noted that, Figure 6 The code generation device 600 shown can execute Figures 1-5 The various steps in the method embodiment shown are implemented. Figures 1-5 The processes and effects in the method embodiments shown are not described in detail here.

[0151] Figure 7 A schematic diagram of the structure of a code generation device provided in an embodiment of this disclosure is shown.

[0152] like Figure 7 As shown, the code generation device may include a processor 701 and a memory 702 storing computer program instructions.

[0153] Specifically, the processor 701 may include a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.

[0154] Memory 702 may include a large-capacity storage device for advertising or instructions. For example, and not limitingly, memory 702 may include a hard disk drive (HDD), a floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or a Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, memory 702 may include removable or non-removable (or fixed) media. Where appropriate, memory 702 may be internal or external to the integrated gateway device. In a particular embodiment, memory 702 is a non-volatile solid-state memory. In a particular embodiment, memory 702 includes read-only memory (ROM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (Electrically Programmable ROM, EPROM), an electrically erasable programmable PROM (EEPROM), an electrically alterable ROM (EAROM), or flash memory, or a combination of two or more of these.

[0155] The processor 701 acquires and executes computer program instructions stored in the memory 702 to perform the steps of the code generation method provided in the embodiments of this disclosure.

[0156] In one example, the code generation device may also include a transceiver 703 and a bus 704. Wherein, as... Figure 7 As shown, the processor 701, memory 702 and transceiver 703 are connected via bus 704 and communicate with each other.

[0157] Bus 704 includes hardware, software, or both. For example, and not limitingly, a bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industrial Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a MicroChannel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses, or a combination of two or more of these. Where appropriate, bus 704 may include one or more buses. Although specific buses are described and illustrated in the embodiments of this application, this application considers any suitable bus or interconnection.

[0158] The following are embodiments of a computer-readable storage medium provided in this disclosure. This computer-readable storage medium and the code generation methods of the above embodiments belong to the same inventive concept. For details not described in detail in the embodiments of the computer-readable storage medium, please refer to the embodiments of the above code generation methods.

[0159] This embodiment provides a storage medium containing computer-executable instructions. When executed by a computer processor, the computer-executable instructions are used to perform a code generation method applied to a code generation device. The method includes: Obtain the first requirement information of the target business, wherein the first requirement information is requirement information described using natural language; Based on the pseudocode logical structure contained in the preset pseudocode knowledge base, the first element module contained in the first requirement information is converted into an element logical structure corresponding to the first syntax format. The pseudocode logical structure is a general pseudocode structure that is common to the requirement information of at least two businesses. The pseudocode logical structure represents the first logical relationship between at least two pseudocode logical blocks in the pseudocode knowledge base. The element logical structure represents the second logical relationship between the at least two first element modules. The first syntax format is a syntax format between natural language and programming language. The program code elements corresponding to the logical structure of the element are obtained from the preset code library, and the program code elements are filled into the logical structure of the element to generate executable code data corresponding to the second syntax format. The program code elements include at least one of the classes, functions, constants, and variables that meet the preset code writing rules. The second syntax format is the syntax format for writing code using a programming language.

[0160] Of course, the computer-executable instructions provided in the embodiments of this disclosure are not limited to the above-described method operations, but can also perform related operations in the information push method provided in any embodiment of this disclosure.

[0161] Based on the above description of the implementation methods, those skilled in the art can clearly understand that this disclosure can be implemented using software and necessary general-purpose hardware, and of course, it can also be implemented using hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk, or optical disk, etc., including several instructions to cause a computer cloud platform (which may be a personal computer, a server, or a network cloud platform, etc.) to execute the information push method provided in the various embodiments of this disclosure.

[0162] Note that the above description is merely a preferred embodiment and the technical principles employed in this disclosure. Those skilled in the art will understand that this disclosure is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of this disclosure. Therefore, although this disclosure has been described in detail through the above embodiments, it is not limited to the above embodiments. Many other equivalent embodiments may be included without departing from the concept of this disclosure, and the scope of this disclosure is determined by the scope of the appended claims.

Claims

1. A code generation method, characterized in that, Applied to a code generation device, the method includes: Obtain the first requirement information of the target business, wherein the first requirement information is requirement information described using natural language; Based on the pseudocode logical structure contained in the preset pseudocode knowledge base, the first element module contained in the first requirement information is converted into an element logical structure corresponding to the first syntax format. The pseudocode logical structure is a general pseudocode structure that is common to the requirement information of at least two businesses. The pseudocode logical structure represents the first logical relationship between at least two pseudocode logical blocks in the pseudocode knowledge base. The element logical structure represents the second logical relationship between the at least two first element modules. The first syntax format is a syntax format between natural language and programming language. The program code elements corresponding to the logical structure of the element are obtained from the preset code library, and the program code elements are filled into the logical structure of the element to generate executable code data corresponding to the second syntax format. The program code elements include at least one of the classes, functions, constants, and variables that meet the preset code writing rules. The second syntax format is the syntax format for writing code using a programming language.

2. The method according to claim 1, characterized in that, The acquisition of the first requirement information of the target business includes: Obtain the second requirement information of the target service, wherein the second requirement information is requirement information described using natural language; Based on the preset business knowledge base corresponding to the target business, the abnormal element module is determined from the second requirement information, and the abnormal element module is corrected to generate the first requirement information.

3. The method according to claim 2, characterized in that, The module for determining abnormal elements from the second requirement information based on the preset business knowledge base corresponding to the target business includes: The second requirement information is semantically understood to determine the global constraint information corresponding to the second requirement information and the third logical relationship between at least two second element modules in the second requirement information. The global constraint information is a precondition that the at least two second element modules commonly depend on, and the third logical relationship represents the execution order between the at least two second element modules. Using the at least two second element modules as nodes and the third logical relationship as the connection between nodes, a path that satisfies the global constraint information is generated, and the path is determined as the business execution path corresponding to the second requirement information; Based on the preset business knowledge base, the abnormal element module is determined from the business execution path.

4. The method according to claim 3, characterized in that, The module for determining the abnormal elements from the business execution path based on the preset business knowledge base includes: At least one second target element module is obtained from the business execution path, and the first semantic information represented by the second target element module is determined; Based on the first semantic information and the semantic information represented by each element module in the preset business knowledge base, the third element module corresponding to the second target element module is obtained from the preset knowledge base, wherein the module function corresponding to the third element module is consistent with the module function corresponding to the second target element module. If the first semantic information is different from the second semantic information represented by the third element module, then the second target element module is determined to be the abnormal element module.

5. The method according to claim 2, characterized in that, The step of correcting the abnormal element module to generate the first requirement information includes: Obtain the fourth element module corresponding to the anomaly element module from the preset business knowledge base; The internal execution logic corresponding to the abnormal element module is replaced with the internal execution logic corresponding to the fourth element module to generate the first requirement information.

6. The method according to claim 1, characterized in that, The pseudocode logical structure contained in the preset pseudocode knowledge base transforms the first element module contained in the first requirement information into an element logical structure corresponding to the first syntax format, including: Semantic understanding is performed on the first element module contained in the first requirement information to determine the element objects in the first element module and the third logical relationship between at least two first element modules. The element object includes at least the object name that forms the first element module, and the third logical relationship includes at least the execution action corresponding to the object name and the execution condition corresponding to the object name. From the pseudocode logic structure, obtain the element pseudocode corresponding to the element object and the relation pseudocode corresponding to the second logical relation; Based on the element pseudocode and the relation pseudocode, the element logical structure corresponding to the first syntax format is generated.

7. The method according to claim 1, characterized in that, The step of obtaining the program code elements corresponding to the logical structure of the elements from a preset code library and filling the program code elements into the logical structure of the elements to generate executable code data corresponding to the second syntax format includes: Based on the element pseudocode and relation pseudocode contained in the pseudocode logical structure, the first code element corresponding to the element pseudocode and the second code element corresponding to the relation pseudocode are obtained from the preset code library, and the first code element and the second code element are determined as the program code elements; The first code element is filled into the element pseudocode, and the second code element is filled into the relation pseudocode to generate executable code data corresponding to the second syntax format.

8. The method according to claim 7, characterized in that, After determining the first code element and the second code element as the program code element, the method further includes: Obtain existing code data corresponding to the target business, and determine the existing logical structure corresponding to the existing code data from the preset pseudocode knowledge base; The existing logical structure and the element logical structure are compared to determine the logical structure to be updated. Obtain the third code element corresponding to the logical structure to be updated from the first code element, and obtain the fourth code element corresponding to the logical structure to be updated from the second code element; The third code element is filled into the element pseudocode in the logical structure to be updated, and the fourth code element is filled into the relation pseudocode in the logical structure to be updated, thereby generating executable code data corresponding to the second syntax format.

9. A code generation device, characterized in that, Configured in a code generation device, the device includes: The requirement acquisition module is used to acquire the first requirement information of the target business, wherein the first requirement information is requirement information described using natural language; The requirement conversion module is used to convert the first element module contained in the first requirement information into an element logic structure corresponding to a first syntax format based on the pseudocode logic structure contained in the preset pseudocode knowledge base. The pseudocode logic structure is a general pseudocode structure that corresponds to the requirement information of at least two businesses. The pseudocode logic structure represents the first logical relationship between at least two pseudocode logic blocks in the pseudocode knowledge base. The element logic structure represents the second logical relationship between the at least two first element modules. The first syntax format is a syntax format between natural language and programming language. The code generation module is used to obtain the program code elements corresponding to the logical structure of the element from a preset code library, and fill the program code elements into the logical structure of the element to generate executable code data corresponding to the second syntax format. The program code elements include at least one of the classes, functions, constants, and variables that meet the preset code writing rules. The second syntax format is the syntax format for writing code using a programming language.

10. A code generation device, characterized in that, include: processor; Memory, used to store executable instructions; The processor is configured to retrieve the executable instructions from the memory and execute the executable instructions to implement the method of any one of claims 1-8.

11. A computer-readable storage medium having a computer program stored thereon, characterized in that, The storage medium stores a computer program that, when executed by a processor, causes the processor to implement the method described in any one of claims 1-8.