Code generation system and method based on cloud computing

By quantifying the independence and functions of code snippets, building a necessary code group library, and optimizing code generation based on the cloud computing platform, the problem of poor code generation in the existing technology is solved, and efficient, fast and functionally accurate code generation is achieved.

CN120353454AActive Publication Date: 2025-07-22XIAN HENGGE DIGITAL TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202410486469.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-22
Publication Date
2025-07-22
Estimated Expiration
2044-04-22

AI Technical Summary

Technical Problem

The existing cloud-based code generation systems and methods fail to effectively evaluate the quality and efficiency of code snippets, resulting in insufficient quality of generated codes and poor performance in resource consumption, execution speed, code function accuracy and operational effectiveness.

Method used

By quantifying the independence and function of each extracted code snippet, combining the overall function of generating code, building a necessary code group library, and filtering the code snippets based on the code efficiency and quality values, optimizing the code combination using the preset cloud computing platform.

Benefits of technology

Ensure that the resource consumption of generated code is small, the execution speed is fast, the function is accurate, the execution effect is good, and the expected requirements are met.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120353454A_ABST
    Figure CN120353454A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of code generation, and particularly discloses a code generation system and method based on cloud computing, and the system comprises a division module which is used for obtaining the independence degree of each extracted code snippet and all code group libraries based on the parameter information of each complete code; the obtaining module is used for obtaining all necessary code group libraries based on the received overall functions of the generated codes; the calculation module is used for obtaining a code efficiency value and a code quality value of each extracted code snippet based on all the extracted code snippets; the combination module is used for obtaining an optimal extracted code combination based on the code efficiency values and the code quality values of all the extracted code snippets; and the generation module is used for obtaining a generated code based on the optimal extracted code combination. According to the method, the good performance of the generated code finally formed by combining the extracted code snippets in the aspects of resource consumption, execution speed, code function accuracy, code running effect and the like is guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of code generation, and particularly relates to a code generation system and method based on cloud computing. Background Art

[0002] At present, how to effectively improve the quality and efficiency of software development is the core issue concerned in the field of software engineering. All along, many researchers have improved the automation level of software development by improving software development methods and using technical means. Among them, code automatic generation refers to using certain technologies to automatically generate software source code to achieve the purpose of automatically programming according to the needs of programmers. Code automatic generation technology is considered an important method to improve the automation degree and quality of software development and has received extensive attention from the academic and industrial circles.

[0003] However, the existing code generation systems and methods based on cloud computing only generate codes through the created code generation templates, and only combine the filled content and common content in the code generation templates to obtain the code generation templates, but do not evaluate the code quality and code efficiency of the code segments before combination, and cannot guarantee the effect after the combination of the code segments, resulting in the problem that the codes generated based on the existing technologies may have poor quality. For example, the patent with the publication number "CN106528165B" and the patent name "Code Generation Method and Code Generation System", the method includes the following steps: obtaining a target sample code, and creating a code generation template according to the target sample code, wherein the code generation template contains a differential content replacement identifier and common content; when receiving an instruction to generate a code, determining the filled content corresponding to the differential content replacement identifier, and using the filled content to fill the differential content replacement identifier to obtain a processed code generation template; generating the code according to the processed code generation template, effectively improving the development efficiency of the code and ensuring the standardization and correctness of the code. However, it does not consider the performance of the generated code in terms of resource consumption, execution speed, code function accuracy, code running effect, etc.

[0004] Therefore, the present invention proposes a code generation system and method based on cloud computing. Summary of the Invention

[0005] The present invention provides a code generation system and method based on cloud computing, which quantifies the independence of each extracted code segment in the complete code, combines the overall function of the received generated code to obtain all sub-functions, constructs a necessary code library that can implement each sub-function, and further determines the code efficiency and code quality of each extracted code segment in the necessary code library according to the independence degree of all extracted code segments in each necessary code library. That is, by determining the code efficiency value and using the code efficiency value to screen the extracted code segments in the generated code, it is ensured that the resource consumption of the extracted code segments finally combined into the generated code is relatively small and the execution speed is relatively high. And by determining the code quality value and using the code quality value to screen the extracted code segments in the generated code, it is ensured that the accuracy of the code implementation function and the code execution effect of the finally combined generated code are guaranteed. Furthermore, by using the preset cloud computing platform and the code efficiency values and code quality values of all extracted code segments in all necessary code libraries, it is ensured that the finally combined generated code has relatively small resource consumption, relatively high execution speed, and the implemented function more meets the expected requirements, and has a good execution effect.

[0006] The present invention provides a code generation system based on cloud computing, including:

[0007] A division module, configured to perform code extraction on all complete codes, obtain all extracted code segments in each complete code, and obtain the independence degree and code segment function of each extracted code segment based on the parameter information of each complete code, and obtain all code libraries based on the independence degree and code segment function of all extracted code segments;

[0008] An acquisition module, configured to obtain all sub-functions based on the overall function of the received generated code, and obtain all necessary code libraries based on all sub-functions and all code libraries;

[0009] A calculation module, configured to obtain the code efficiency value and code quality value of each extracted code segment in the corresponding necessary code library based on the independence degree of all extracted code segments in each necessary code library;

[0010] A combination module, configured to obtain the best combination of extracted codes based on the preset cloud computing platform and the code efficiency values and code quality values of all extracted code segments in all necessary code libraries;

[0011] A generation module, configured to splice the codes of all extracted code segments in the best combination of extracted codes to obtain the generated code.

[0012] Preferably, the division module includes:

[0013] The sub-module for division is used to obtain all the complete codes in the database, and extract codes corresponding to each complete code based on the code comments of each complete code, so as to obtain all the extracted code segments in each complete code;

[0014] The parameter information acquisition module is used to obtain the parameter information of each complete code based on a variety of preset tools, where the parameter information includes the call frequency, call time, and data transfer type of all the extracted code segments in the complete code;

[0015] The sub-module for calculating the independence degree is used to obtain the independence degree and code segment function of each extracted code segment in the corresponding complete code based on the parameter information of each complete code;

[0016] The sub-module for constructing the code group library is used to obtain all the code group libraries based on the independence degree and code segment function of all the extracted code segments in all the complete codes.

[0017] Preferably, the sub-module for division includes:

[0018] The acquisition unit is used to obtain all the complete codes in the database and the code comments of each complete code;

[0019] The division unit is used to screen out all the comments with preset features from the code comments of each complete code as all the function comments, and use a complete code block covered by each function comment of the corresponding complete code as the extracted code segment in the corresponding complete code, so as to obtain all the extracted code segments in each complete code.

[0020] Preferably, the sub-module for calculating the independence degree includes:

[0021] The parameter acquisition unit is used to obtain the call frequency, call time, and data transfer type of all the extracted code segments in each complete code from the parameter information of each complete code;

[0022] The assignment unit is used to assign values to the corresponding extracted code segments based on the data transfer type of each extracted code segment in each complete code, so as to obtain the data transfer assignment results of each extracted code segment in each complete code;

[0023] The calculation unit is used to calculate the independence degree of each extracted code segment in each complete code based on the call frequency and call time of all the extracted code segments in each complete code, that is:

[0024]

[0025] Wherein, δ is the independence degree of a single extracted code snippet in the currently calculated complete code, T is the running time of the currently calculated complete code, t is the call time of the currently calculated extracted code snippet in the currently calculated complete code, ε is the call frequency of the currently calculated extracted code snippet in the currently calculated complete code, ε0 is the average value of the call frequencies of all extracted code snippets in the currently calculated complete code, σ is the data transfer assignment result of the currently calculated extracted code snippet in the currently calculated complete code, ln is the natural logarithm function, and the value of the natural constant e is 2.718;

[0026] The code snippet function acquisition unit is used to regard the function annotated by the function annotation of each extracted code snippet as the code snippet function of the corresponding extracted code snippet, and obtain the code snippet function of each extracted code snippet.

[0027] Preferably, the code group library construction sub-module includes:

[0028] The first construction unit is used to screen out all extracted code snippets with an independence degree greater than the preset independence degree threshold from all extracted code snippets in all complete codes as independent code snippets;

[0029] The second construction unit is used to obtain the code snippet functions of all independent code snippets, and summarize all independent code snippets with the same code snippet function as a single code group library to obtain all code group libraries.

[0030] Preferably, the acquisition module includes:

[0031] The receiving sub-module is used to receive the overall function of the generated code uploaded by the user to the code generation system, and obtain all sub-functions based on the received overall function of the generated code and the preset function decomposition model;

[0032] The necessary code group library sub-module is used to screen out and summarize the code group libraries with the same function annotation as each sub-function from all code group libraries to obtain all necessary code group libraries.

[0033] Preferably, the calculation module includes:

[0034] The calculation parameter acquisition sub-module is used to obtain the memory value occupied by the code, the total number of code lines, and the running time of all extracted code snippets in each necessary code group library;

[0035] The first calculation sub-module is used to calculate the code efficiency value and code quality value of each extracted code snippet in each necessary code group library based on the memory value occupied by the code, the total number of code lines, the running time, and the independence degree of all extracted code snippets in each necessary code group library, that is:

[0036]

[0037]

[0038] Among them, ρ is the code efficiency value of the currently calculated extracted code snippet, τ is the code quality value of the currently calculated extracted code snippet, r is the running time of the currently calculated extracted code snippet, max(r) is the maximum value among the running times of all extracted code snippets in the necessary code library to which the currently calculated extracted code snippet belongs, q is the memory occupied by the code of the currently calculated extracted code snippet, max(q) is the maximum value among the memory occupied by the codes of all extracted code snippets in the necessary code library to which the currently calculated extracted code snippet belongs, w is the number of lines of code of the currently calculated extracted code snippet, max(w) is the maximum value among the number of lines of code of all extracted code snippets in the necessary code library to which the currently calculated extracted code snippet belongs, and δ is the independence degree of the currently calculated extracted code snippet.

[0039] Preferably, the combination module includes:

[0040] The combination sub-module is used to combine one extracted code snippet selected from each necessary code library to obtain all extracted code combinations, where the extracted code combination contains one extracted code snippet from each necessary code library;

[0041] The second calculation sub-module is used to calculate the comprehensive quality value of each extracted code combination based on the preset cloud computing platform and the code efficiency values and code quality values of all extracted code snippets in all necessary code libraries, that is:

[0042]

[0043] Among them, is the comprehensive quality value of a single extracted code combination, i is the i-th extracted code snippet in the corresponding extracted code combination, n is the total number of extracted code snippets in the corresponding extracted code combination, ρ i is the code efficiency value of the i-th extracted code snippet in the corresponding extracted code combination, τ i is the code quality value of the i-th extracted code snippet in the corresponding extracted code combination, ln is the natural logarithm function, and the value of the natural constant e is 2.718;

[0044] The judgment sub-module is used to use the extracted code combination with the largest comprehensive quality value among all extracted code combinations as the best extracted code combination.

[0045] Preferably, the combination module includes:

[0046] The construction sub-module is used to construct a code splicing model;

[0047] A combinatorial sub-module for combining the best extraction codes and inputting them into a code splicing model for code splicing to obtain generated codes.

[0048] The present invention provides a code generation method based on cloud computing, which is applied to any one of Embodiments 1 to 9 and includes:

[0049] S1: Extract codes from all complete codes to obtain all extraction code segments in each complete code, and obtain the independence degree and code segment function of each extraction code segment based on the parameter information of each complete code. Obtain all code libraries based on the independence degree and code segment function of all extraction code segments;

[0050] S2: Obtain all sub-functions based on the overall function of the generated code received, and obtain all necessary code libraries based on all sub-functions and all code libraries;

[0051] S3: Obtain the code efficiency value and code quality value of each extraction code segment corresponding to the necessary code library based on the independence degree of all extraction code segments in each necessary code library;

[0052] S4: Obtain the best extraction code combination based on the preset cloud computing platform and the code efficiency values and code quality values of all extraction code segments in all necessary code libraries;

[0053] S5: Splice the extraction code segments in the best extraction code combination to obtain the generated code.

[0054] The beneficial effects of the present invention compared with the prior art are as follows: By quantifying the independence of each extraction code segment in the complete code and combining the overall function of the generated code received, all sub-functions are obtained, and a necessary code library that can implement each sub-function is built. Further, according to the independence degree of all extraction code segments in each necessary code library, the code efficiency and code quality of each extraction code segment in the necessary code library are determined, that is, by determining the code efficiency value and using the code efficiency value to screen the extraction code segments in the generated code, it is ensured that the resource consumption of the extraction code segments finally combined into the generated code is relatively small and the execution speed is relatively high. And by determining the code quality value and using the code quality value to screen the extraction code segments in the generated code, it is ensured that the accuracy of the code implementation function and the code execution effect of the finally combined generated code are ensured. Furthermore, by using the preset cloud computing platform and the code efficiency values and code quality values of all extraction code segments in all necessary code libraries, it is ensured that the finally combined generated code has relatively small resource consumption, relatively high execution speed, and the implemented function more meets the expected requirements, and has a better execution effect.

[0055] Other features and advantages of the present invention will be set forth in the following description, and in part will be obvious from the description, or may be learned by practice of the present invention. The objectives and other advantages of the present invention may be realized and attained by the structure particularly pointed out in the written application documents.

[0056] The technical solutions of the present invention will be further described in detail below through the accompanying drawings and embodiments. Description of the Drawings

[0057] The drawings are used to provide a further understanding of the present invention, and constitute a part of the description. They are used together with the embodiments of the present invention to explain the present invention, and do not constitute a limitation to the present invention. In the drawings:

[0058] Figure 1 It is a schematic diagram of a code generation system based on cloud computing in an embodiment of the present invention;

[0059] Figure 2 It is a flowchart of a code generation method based on cloud computing in an embodiment of the present invention. Detailed Embodiments

[0060] The following describes the preferred embodiments of the present invention with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are only for the purpose of illustrating and explaining the present invention, and are not used to limit the present invention.

[0061] Embodiment 1:

[0062] The present invention provides a reference Figure 1 , including:

[0063] A partitioning module, configured to extract codes from all complete codes, obtain all extracted code segments in each complete code, and obtain the independence degree and code segment function of each extracted code segment based on the parameter information of each complete code, and obtain all code libraries based on the independence degree and code segment function of all extracted code segments;

[0064] An obtaining module, configured to obtain all sub-functions based on the overall function of the generated code received, and obtain all necessary code libraries based on all sub-functions and all code libraries;

[0065] A calculating module, configured to obtain the code efficiency value and code quality value of each extracted code segment of the corresponding necessary code library based on the independence degree of all extracted code segments of each necessary code library;

[0066] A combining module, configured to obtain the best combination of extracted codes based on a preset cloud computing platform and the code efficiency values and code quality values of all extracted code segments in all necessary code libraries;

[0067] A generation module for splicing all the extracted code snippets in the optimal extraction code combination to obtain generated code.

[0068] In this embodiment, the complete code is all the fully operational code extracted from a pre-set database (containing code samples that have been put into use).

[0069] In this embodiment, code extraction is the process of obtaining all the extracted code snippets in each complete code.

[0070] In this embodiment, an extracted code snippet is a code snippet that can implement at least a simple function obtained by performing code extraction on each complete code, and the code snippet contains multiple code statements.

[0071] In this embodiment, the parameter information of the complete code is a parameter that reflects the running conditions of all the extracted code snippets within the running of the complete code.

[0072] In this embodiment, the independence degree is a numerical value obtained based on the parameter information of each complete code, representing the degree of independence of each extracted code snippet from the remaining code of the corresponding complete code. The greater the independence degree, the smaller the difference between the code function when the code snippet is independently implemented and the corresponding partial function in the overall code function implemented in the complete code where it is located, that is, the smaller the deviation between its function after independence and its function implemented in the complete code.

[0073] In this embodiment, the code snippet function is the function annotation of the extracted code snippet.

[0074] In this embodiment, the code group library is a code snippet library containing all the extracted code snippets that can implement a certain sub-function extracted from all the complete codes.

[0075] In this embodiment, the overall function of the generated code is the function that the user inputs to the cloud computing-based code generation system and expects the finally generated code to achieve. For example, filtering out all user information that meets condition A1 in database A.

[0076] In this embodiment, the sub-function is a partial sub-function obtained from the received overall function of the generated code and a preset function decomposition model.

[0077] In this embodiment, the necessary code group library is a code group library selected from all the code group libraries with the same function annotation as each sub-function.

[0078] In this embodiment, the code efficiency value is a performance value representing the performance of each extracted code snippet in the corresponding necessary code library in terms of resource consumption and execution speed, obtained based on the memory occupied by the code, the total number of code lines, and the running time of all the extracted code snippets in each necessary code library. That is, the larger the code efficiency value, the relatively smaller the resource consumption and the relatively faster the execution speed, and vice versa.

[0079] In this embodiment, the code quality value is a performance value calculated based on the memory occupied by the code, the total number of code lines, the running time, and the independence degree of all the extracted code snippets in each necessary code library, characterizing the performance of each extracted code snippet in the necessary code library in terms of code function accuracy and code running effect (such as resource consumption size, code execution speed, etc.). That is, the larger the code quality value, the higher the performance in terms of function accuracy and execution effect, and vice versa.

[0080] In this embodiment, the preset cloud computing platform is a pre-set platform used to decompose computing tasks and accelerate the calculation of the comprehensive quality value of each extracted code combination, such as Microsoft Azure.

[0081] In this embodiment, the best extracted code combination is the best combination of multiple extracted code snippets required to implement the overall function of the generated code.

[0082] In this embodiment, code splicing is the new code obtained by inputting the best extracted code combination into the code splicing model for code splicing.

[0083] The beneficial effects of the above technologies are as follows: By quantifying the independence of each extracted code snippet in the complete code and combining the received overall function of the generated code to obtain all sub-functions, a necessary code library that can implement each sub-function is built. Further, according to the independence degree of all the extracted code snippets in each necessary code library, the code efficiency and code quality of each extracted code snippet in the necessary code library are determined. That is, by determining the code efficiency value and using the code efficiency value to screen the extracted code snippets in the generated code, it is ensured that the resource consumption of the extracted code snippets finally combined into the generated code is relatively small and the execution speed is relatively high. And by determining the code quality value and using the code quality value to screen the extracted code snippets in the generated code, it is ensured that the code implementation function accuracy and code execution effect of the finally combined generated code are guaranteed. Furthermore, by using the preset cloud computing platform and the code efficiency values and code quality values of all the extracted code snippets in all the necessary code libraries, it is ensured that the finally combined generated code has relatively small resource consumption, relatively high execution speed, and the implemented function more meets the expected requirements, and has a better execution effect.

[0084] Embodiment 2:

[0085] Based on Embodiment 1, modules are divided, including:

[0086] A sub-module for dividing is used to obtain all complete codes in the database, and based on the code comments of each complete code, code extraction is performed on the corresponding complete code to obtain all extracted code segments in each complete code;

[0087] A parameter information acquisition module is used to obtain the parameter information of each complete code based on multiple preset tools, where the parameter information includes the call frequency, call time, and data transfer type of all extracted code segments in the complete code;

[0088] An independence calculation sub-module is used to obtain the independence degree and code segment function of each extracted code segment in the corresponding complete code based on the parameter information of each complete code;

[0089] A code group library construction sub-module is used to obtain all code group libraries based on the independence degree and code segment function of all extracted code segments in all complete codes.

[0090] In this embodiment, the code comment is the explanatory text added by the programmer to the code, which is used to describe the function, logic, parameters, return value, and other matters that need attention of the code.

[0091] In this embodiment, the preset tool is a tool pre-set to obtain the parameter information of each complete code, such as an IDE tool, logging, performance analysis tool, etc.

[0092] In this embodiment, the call frequency of the extracted code segment is the number of times the extracted code segment is called by the remaining code segments in the complete code during the running process of the entire program (from program startup to program end).

[0093] In this embodiment, the call time is the total duration of the extracted code segment being called multiple times by other code segments during the running process of the entire program (from program startup to program end).

[0094] In this embodiment, the data transfer type is the type of information, variable, or value transfer between different code segments, such as value transfer, reference transfer, pointer transfer, etc.

[0095] The beneficial effects of the above technology are as follows: Code extraction is performed on all complete codes to obtain all extracted code segments in each complete code, the codes that do not directly implement specific functions in the complete code are removed, and the independence degree and code segment function of each extracted code segment are obtained based on the parameter information of each complete code, quantifying the independence of each extracted code segment in the complete code, thereby facilitating the subsequent constraint of the independence of the extracted code segments during the construction of the code group library.

[0096] Example 3:

[0097] Based on Example 2, sub - modules are divided, including:

[0098] An acquisition unit, configured to acquire all complete codes in the database and the code comments of each complete code;

[0099] A division unit, configured to screen out all comments with preset features from the code comments of each complete code as all function comments, and use a complete code block covered by each function comment corresponding to a complete code as an extracted code segment in the corresponding complete code, so as to obtain all extracted code segments in each complete code.

[0100] In this embodiment, the preset feature is the feature of including comments describing the code function.

[0101] In this embodiment, a complete code block covered by a function comment is a code segment that can implement the code function in the function comment, and it contains multiple code statements.

[0102] The beneficial effects of the above - mentioned technology are as follows: Based on function comments, code extraction of all complete codes is realized, all extracted code segments in each complete code are obtained, and then the codes in the complete codes that do not directly implement specific functions can be eliminated.

[0103] Example 4:

[0104] Based on Example 2, an independent - degree calculation sub - module is included, including:

[0105] A parameter acquisition unit, configured to acquire the call frequency, call time, and data transfer type of all extracted code segments in each complete code from the parameter information of each complete code;

[0106] An assignment unit, configured to assign values to the corresponding extracted code segments based on the data transfer type of each extracted code segment in each complete code, so as to obtain the data transfer assignment results of each extracted code segment in each complete code;

[0107] A calculation unit, configured to calculate the independent degree of each extracted code segment in each complete code based on the call frequency and call time of all extracted code segments in each complete code, that is:

[0108]

[0109] Among them, δ is the independence degree of a single extracted code snippet in the currently calculated complete code, T is the running time of the currently calculated complete code, t is the call time of the currently calculated extracted code snippet in the currently calculated complete code, ε is the call frequency of the currently calculated extracted code snippet in the currently calculated complete code, ε0 is the average value of the call frequencies of all extracted code snippets in the currently calculated complete code, σ is the data transfer assignment result of the currently calculated extracted code snippet in the currently calculated complete code, ln is the natural logarithm function, and the value of the natural constant e is 2.718;

[0110] The code snippet function acquisition unit is used to regard the function annotated by the function comment of each extracted code snippet as the code snippet function of the corresponding extracted code snippet, and obtain the code snippet function of each extracted code snippet.

[0111] In this embodiment, assigning values to the corresponding extracted code snippets based on the data transfer types of each extracted code snippet in each complete code is as follows:

[0112] When the data transfer type of each extracted code snippet in each complete code is value transfer, set the data transfer assignment result of the corresponding extracted code snippet to 1;

[0113] When the data transfer type of each extracted code snippet in each complete code is reference transfer, set the data transfer assignment result of the corresponding extracted code snippet to 2;

[0114] When the data transfer type of each extracted code snippet in each complete code is pointer transfer, set the data transfer assignment result of the corresponding extracted code snippet to 3;

[0115] When the data transfer type of each extracted code snippet in each complete code is message transfer, set the data transfer assignment result of the corresponding extracted code snippet to 4;

[0116] When the data transfer type of each extracted code snippet in each complete code is a callback function, set the data transfer assignment result of the corresponding extracted code snippet to 5;

[0117] When there are multiple cases for the data transfer type of each extracted code snippet in each complete code, take the one with the largest data transfer assignment result as the data transfer assignment result of the corresponding extracted code snippet.

[0118] In this embodiment, the data transfer assignment result is the result of assigning values to the data transfer types of each extracted code snippet in each complete code.

[0119] The beneficial effects of the above technology are as follows: The independence degree and the function of each extracted code snippet are obtained according to the parameter information of each complete code, that is, the independence of the extracted code snippet is accurately calculated from the perspective of the association with other code snippets, which is convenient for the subsequent construction of the code group library.

[0120] Embodiment 5:

[0121] Based on Embodiment 2, the code group library construction sub-module includes:

[0122] The first construction unit is used to screen out all the extracted code snippets with an independence degree greater than the preset independence degree threshold from all the extracted code snippets in all the complete codes as independent code snippets;

[0123] The second construction unit is used to obtain the function of all the independent code snippets, and summarize all the independent code snippets with the same code snippet function as a single code group library to obtain all the code group libraries.

[0124] In this embodiment, the preset independence degree threshold is the independence degree threshold used for screening out independent code snippets from all the extracted code snippets in all the complete codes.

[0125] In this embodiment, the independent code snippet is the code snippet that can be separately extracted from all the extracted code snippets in all the complete codes.

[0126] The beneficial effects of the above technology are as follows: All the code group libraries are obtained according to the independence degree and the function of all the extracted code snippets. This embodiment gives a specific method for obtaining all the code group libraries based on all the extracted code snippets in all the complete codes.

[0127] Embodiment 6:

[0128] Based on Embodiment 1, the acquisition module includes:

[0129] The receiving sub-module is used to receive the overall function of the generated code uploaded by the user to the code generation system, and obtain all the sub-functions based on the received overall function of the generated code and the preset function decomposition model;

[0130] The necessary code group library sub-module is used to screen out and summarize the code group libraries with function annotations the same as each sub-function from all the code group libraries to obtain all the necessary code group libraries.

[0131] In this embodiment, the preset function decomposition model is a model that is pre-trained with a large number of overall functions and all the sub-functions corresponding to the overall functions as training samples, and can output all the sub-functions when the overall function is input.

[0132] The beneficial effects of the above technology are as follows: The preset function decomposition model is used to decompose the overall function of the generated code, and the code group library that can implement the sub - functions is screened out as the necessary code combination.

[0133] Example 7:

[0134] Based on Example 1, the calculation module includes:

[0135] A calculation parameter acquisition sub - module, which is used to acquire the memory occupied by the code, the total number of code lines, and the running time of all extracted code segments in each necessary code group library;

[0136] A first calculation sub - module, which is used to calculate the code efficiency value and the code quality value of each extracted code segment in each necessary code group library based on the memory occupied by the code, the total number of code lines, the running time, and the independence degree of all extracted code segments in each necessary code group library, that is:

[0137]

[0138]

[0139] Among them, ρ is the code efficiency value of the currently calculated extracted code segment, τ is the code quality value of the currently calculated extracted code segment, r is the running time of the currently calculated extracted code segment, max(r) is the maximum value of the running times of all extracted code segments in the necessary code group library to which the currently calculated extracted code segment belongs, q is the memory occupied by the code of the currently calculated extracted code segment, max(q) is the maximum value of the memory occupied by the code of all extracted code segments in the necessary code group library to which the currently calculated extracted code segment belongs, w is the number of code lines of the currently calculated extracted code segment, max(w) is the maximum value of the number of code lines of all extracted code segments in the necessary code group library to which the currently calculated extracted code segment belongs, and δ is the independence degree of the currently calculated extracted code segment.

[0140] In this embodiment, the memory occupied by the code is the running memory value occupied by each extracted code segment in the necessary code group library during code execution.

[0141] In this embodiment, the total number of code lines is the number of code lines of each extracted code segment in the necessary code group library.

[0142] In this embodiment, the running time is the running time of each extracted code segment in the necessary code group library during code execution.

[0143] The beneficial effects of the above technology are as follows: comprehensively and quantitatively evaluate each extracted code snippet in terms of resource consumption, execution speed, code function accuracy, code running effect, etc. This embodiment provides a specific method for comprehensively and quantitatively evaluating each extracted code snippet in terms of resource consumption, execution speed, code function accuracy, code running effect, etc.

[0144] Embodiment 8:

[0145] Based on Embodiment 1, the combination module includes:

[0146] A combination sub-module for combining one extracted code snippet selected from each necessary code group library to obtain all extracted code combinations, where an extracted code combination contains one extracted code snippet from each necessary code group library;

[0147] A second calculation sub-module for calculating the comprehensive quality value of each extracted code combination based on the code efficiency value and code quality value of all extracted code snippets of all necessary code group libraries on a preset cloud computing platform, that is:

[0148]

[0149] Wherein, is the comprehensive quality value of a single extracted code combination, i is the i-th extracted code snippet in the corresponding extracted code combination, n is the total number of extracted code snippets in the corresponding extracted code combination, ρ i is the code efficiency value of the i-th extracted code snippet in the corresponding extracted code combination, τ i is the code quality value of the i-th extracted code snippet in the corresponding extracted code combination, ln is the natural logarithm function, and the value of the natural constant e is 2.718;

[0150] A judgment sub-module for taking the extracted code combination with the largest comprehensive quality value among all extracted code combinations as the best extracted code combination.

[0151] In this embodiment, the comprehensive quality value is a comprehensive quantitative evaluation of the code generated after splicing each extracted code combination in terms of resource consumption, execution speed, code function accuracy, code running effect, etc., calculated based on the code efficiency value and code quality value of all extracted code snippets of all necessary code group libraries.

[0152] The beneficial effects of the above technology are as follows: efficiently and accurately obtain the best extracted code combination according to the code efficiency value and code quality value of all extracted code snippets of a preset cloud computing platform and all necessary code group libraries, which is convenient for subsequent code splicing. This embodiment provides a specific method for obtaining the best extracted code combination based on the code efficiency value and code quality value of all extracted code snippets of all necessary code group libraries.

[0153] Example 9:

[0154] Based on Example 1, the combination module includes:

[0155] A construction sub-module for constructing a code splicing model;

[0156] A combination sub-module for inputting the best extraction code combination into the code splicing model for code splicing to obtain a generated code.

[0157] In this embodiment, the code splicing model is a model that can input multiple code fragments and output a complete code, which is trained with a large number of pre-acquired code samples that have been put into use and manually programmed, and all the extracted code fragments extracted according to the code extraction process described in Embodiments 2 and 3 as training samples.

[0158] The beneficial effect of the above technology is: By performing code splicing on all the extracted code fragments in the best extraction code combination, the generated code is accurately obtained.

[0159] Example 10:

[0160] The present invention provides a code generation method based on cloud computing, which is applied to execute any one of the cloud computing-based code generation systems in Embodiments 1 to 9. Refer to Figure 2 including:

[0161] S1: Perform code extraction on all complete codes to obtain all the extracted code fragments in each complete code, and obtain the independence and code fragment function of each extracted code fragment based on the parameter information of each complete code, and obtain all code libraries based on the independence and code fragment function of all the extracted code fragments;

[0162] S2: Obtain all sub-functions based on the overall function of the received generated code, and obtain all necessary code libraries based on all the sub-functions and all the code libraries;

[0163] S3: Obtain the code efficiency value and code quality value of each extracted code fragment of the corresponding necessary code library based on the independence of all the extracted code fragments of each necessary code library;

[0164] S4: Obtain the best extraction code combination based on the preset cloud computing platform and the code efficiency values and code quality values of all the extracted code fragments in all the necessary code libraries;

[0165] S5: Perform code splicing on all the extracted code fragments in the best extraction code combination to obtain a generated code.

[0166] The beneficial effects of the above technology are as follows: By quantifying the independence of each extracted code snippet in the complete code and combining with the overall function of the generated code received, all sub-functions are obtained, and a necessary code library for implementing each sub-function is built. Further, according to the degree of independence of all extracted code snippets in each necessary code library, the code efficiency and code quality of each extracted code snippet in the necessary code library are determined. That is, by determining the code efficiency value and using the code efficiency value to screen the extracted code snippets in the generated code, it is ensured that the resource consumption of the extracted code snippets finally combined into the generated code is relatively small and the execution speed is relatively high. And by determining the code quality value and using the code quality value to screen the extracted code snippets in the generated code, the accuracy of the code implementation function and the code execution effect of the finally combined generated code are ensured. Furthermore, by using the preset cloud computing platform and the code efficiency values and code quality values of all extracted code snippets in all necessary code libraries, it is ensured that the finally combined generated code has relatively small resource consumption, relatively high execution speed, and the implemented function is more in line with the expected requirements, and has a better execution effect.

[0167] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalent technologies, the present invention also intends to include these changes and modifications.

Claims

1. A code generation system based on cloud computing, characterized in that, Including: A partitioning module, configured to perform code extraction on all complete codes, obtain all extracted code snippets in each complete code, and obtain the independence degree and code snippet function of each extracted code snippet based on the parameter information of each complete code, and obtain all code libraries based on the independence degree and code snippet function of all extracted code snippets; An acquisition module, configured to obtain all sub-functions based on the received overall function of the generated code, and obtain all necessary code libraries based on all sub-functions and all code libraries; A calculation module, configured to obtain the code efficiency value and code quality value of each extracted code snippet of the corresponding necessary code library based on the independence degree of all extracted code snippets of each necessary code library; A combination module, configured to obtain the best combination of extracted codes based on the preset cloud computing platform and the code efficiency value and code quality value of all extracted code snippets in all necessary code libraries; A generation module, configured to splice the code of all extracted code snippets in the best combination of extracted codes to obtain the generated code.

2. The code generation system based on cloud computing according to claim 1, characterized in that The partitioning module includes: A sub-partitioning module, configured to obtain all complete codes in the database, and perform code extraction on the corresponding complete code based on the code comment of each complete code, to obtain all extracted code snippets in each complete code; A parameter information acquisition module, configured to obtain the parameter information of each complete code based on a variety of preset tools, where the parameter information includes the call frequency, call time, and data transfer type of all extracted code snippets in the complete code; An independence degree calculation sub-module, configured to obtain the independence degree and code snippet function of each extracted code snippet in the corresponding complete code based on the parameter information of each complete code; A code library construction sub-module, configured to obtain all code libraries based on the independence degree and code snippet function of all extracted code snippets in all complete codes.

3. The code generation system based on cloud computing according to claim 2, wherein, The sub-partitioning module includes: An acquisition unit, configured to obtain all complete codes in the database and the code comments of each complete code; A partitioning unit, configured to screen out all comments with preset characteristics from the code comments of each complete code as all function comments, and use a complete code block covered by each function comment of the corresponding complete code as an extracted code snippet in the corresponding complete code, to obtain all extracted code snippets in each complete code.

4. A code generation system based on cloud computing according to claim 2, characterized in that, The independence degree calculation sub-module includes: A parameter acquisition unit, configured to obtain the call frequency, call time, and data transfer type of all extracted code snippets in each complete code from the parameter information of each complete code; An assignment unit, configured to assign a value to the corresponding extracted code snippet based on the data transfer type of each extracted code snippet in each complete code, to obtain the data transfer assignment result of each extracted code snippet in each complete code; A calculation unit, configured to calculate the independence degree of each extracted code snippet in each complete code based on the call frequency and call time of all extracted code snippets in each complete code, that is: Among them, δ is the independence degree of a single extracted code snippet in the currently calculated complete code, T is the running time of the currently calculated complete code, t is the call time of the currently calculated extracted code snippet in the currently calculated complete code, ε is the call frequency of the currently calculated extracted code snippet in the currently calculated complete code, ε0 is the average value of the call frequencies of all extracted code snippets in the currently calculated complete code, σ is the data transfer assignment result of the currently calculated extracted code snippet in the currently calculated complete code, ln is the natural logarithm function, and the value of the natural constant e is 2.718; The code snippet function acquisition unit is used to regard the function annotated by the function annotation of each extracted code snippet as the code snippet function of the corresponding extracted code snippet, and obtain the code snippet function of each extracted code snippet.

5. A code generation system based on cloud computing according to claim 2, wherein, The code group library construction sub-module includes: The first construction unit is used to screen out all extracted code snippets with an independence degree greater than the preset independence degree threshold from all extracted code snippets in all complete codes as independent code snippets; The second construction unit is used to obtain the code snippet functions of all independent code snippets, and summarize all independent code snippets with the same code snippet function as a single code group library to obtain all code group libraries.

6. A code generation system based on cloud computing according to claim 1, characterized in that, The acquisition module includes: The receiving sub-module is used to receive the overall function of the generated code uploaded by the user to the code generation system, and obtain all sub-functions based on the received overall function of the generated code and the preset function decomposition model; The necessary code group library sub-module is used to screen out and summarize the code group libraries with function annotations the same as each sub-function from all code group libraries to obtain all necessary code group libraries.

7. A code generation system based on cloud computing according to claim 1, characterized in that, The calculation module includes: The calculation parameter acquisition sub-module is used to obtain the memory occupied by the code, the total number of code lines, and the running time of all extracted code snippets in each necessary code group library; The first calculation sub-module is used to calculate the code efficiency value and the code quality value of each extracted code snippet in each necessary code group library based on the memory occupied by the code, the total number of code lines, the running time, and the independence degree of all extracted code snippets in each necessary code group library, that is: Among them, ρ is the code efficiency value of the currently calculated extracted code snippet, τ is the code quality value of the currently calculated extracted code snippet, r is the running time of the currently calculated extracted code snippet, max(r) is the maximum value of the running times of all extracted code snippets in the necessary code group library to which the currently calculated extracted code snippet belongs, q is the memory occupied by the code of the currently calculated extracted code snippet, max(q) is the maximum value of the memory occupied by the code of all extracted code snippets in the necessary code group library to which the currently calculated extracted code snippet belongs, w is the number of code lines of the currently calculated extracted code snippet, max(w) is the maximum value of the number of code lines of all extracted code snippets in the necessary code group library to which the currently calculated extracted code snippet belongs, and δ is the independence degree of the currently calculated extracted code snippet.

8. A code generation system based on cloud computing according to claim 1, characterized in that, The combination module includes: A combinatorial sub-module, configured to combine one extracted code snippet selected from each necessary code library to obtain all combinations of extracted codes, where a combination of extracted codes contains one extracted code snippet from each necessary code library; A second calculation sub-module, configured to calculate the comprehensive quality value of each combination of extracted codes based on the code efficiency value and code quality value of all the extracted code snippets of all the necessary code libraries on a preset cloud computing platform, that is: Among them, is the comprehensive quality value of a single extraction code combination, i is the i-th extraction code segment within the corresponding extraction code combination, n is the total number of extraction code segments within the corresponding extraction code combination, ρ i is the code efficiency value of the i-th extraction code segment within the corresponding extraction code combination, τ i is the code quality value of the i-th extraction code segment within the corresponding extraction code combination, ln is the natural logarithm function, and the value of the natural constant e is 2.718; A judgment sub-module, configured to use the combination of extracted codes with the largest comprehensive quality value among all combinations of extracted codes as the optimal combination of extracted codes.

9. A code generation system based on cloud computing according to claim 1, characterized in that, A combination module, including: A construction sub-module, configured to construct a code splicing model; A combination sub-module, configured to input the optimal combination of extracted codes into the code splicing model for code splicing to obtain generated codes.

10. A code generation method based on cloud computing, characterized in that, Applied to execute a code generation system based on cloud computing according to any one of claims 1 to 9, including: S1: Extract codes from all complete codes to obtain all extracted code snippets in each complete code, and obtain the independence degree and code snippet function of each extracted code snippet based on the parameter information of each complete code, and obtain all code libraries based on the independence degree and code snippet function of all extracted code snippets; S2: Obtain all sub-functions based on the overall function of the generated codes received, and obtain all necessary code libraries based on all sub-functions and all code libraries; S3: Obtain the code efficiency value and code quality value of each extracted code snippet of the corresponding necessary code library based on the independence degree of all the extracted code snippets of each necessary code library; S4: Obtain the optimal combination of extracted codes based on the code efficiency value and code quality value of all the extracted code snippets of all the necessary code libraries on a preset cloud computing platform; S5: Perform code splicing on all the extracted code snippets in the optimal combination of extracted codes to obtain generated codes.

Citation Information

Patent Citations

  • Code generation methods and code generation systems

    CN106528165B

  • Code similarity detection method and device

    CN114742069A

  • Code generation method based on image recognition and related equipment

    CN115145568A

  • Code quality inspection method, code quality inspection device, electronic equipment and storage medium

    CN115934552A

  • Intelligent auxiliary method and system for software development based on cloud computing

    CN117032654A