A method of automatic programming of code

By combining rules and deep learning models to analyze natural language requirements, high-quality code is generated, solving the problems of accuracy and adaptability in code generation in existing technologies, and realizing an efficient and flexible automatic programming method.

CN120335783BActive Publication Date: 2025-11-18SHANDONG LINGRAN INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510387539.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-31
Publication Date
2025-11-18
Estimated Expiration
2045-03-31

AI Technical Summary

Technical Problem

Existing automated programming technologies suffer from problems such as insufficient code generation accuracy, poor adaptability, and inability to handle complex business logic, making it difficult to generate high-quality code.

Method used

By analyzing natural language requirements using rule-based and deep learning-based semantic analysis models, and combining historical records and contextual information, code templates are generated and automatically tested to evaluate code adaptability and reliability.

Benefits of technology

It improves the accuracy and consistency of code generation, reduces human error, lowers development difficulty and cost, supports rapid iteration and multi-language applications, and promotes development efficiency and flexibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120335783B_ABST
    Figure CN120335783B_ABST
Patent Text Reader

Abstract

The application discloses a kind of code automatic programming method, including using rule-based semantic analysis model, deep learning semantic analysis model is carried out to the demand of user input semantic analysis, and the analysis result of different model is fused, and the integrated semantic vector is obtained;Comprehensive semantic vector after fusion is revised, and according to the key information of integrated semantic vector after revision identification;According to key information in template library, template is looked up and matched, and code is generated according to the template after replacement;Real-time monitoring performance index in code running process, according to performance index monitoring result, calculate code fitness value;Code is tested automatically, and code reliability dimension is obtained, and code automatic programming effect is evaluated based on fuzzy inference in combination with code fitness value.The application solves the problem that flexibility is poor in the prior art, complex requirements cannot be well understood, improves development efficiency, can also reduce human error, improves the accuracy and quality of software development.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of software development technology, and more specifically, to a method for automatic code programming. Background Technology

[0002] As software development continues to evolve, programmers' work has become increasingly complex and demanding. Traditional manual programming methods are time-consuming and error-prone, especially when dealing with large-scale, complex systems, making it increasingly difficult to write high-quality code. To improve development efficiency and reduce human error, researchers have proposed automated programming techniques, including template-based code generation, rule-driven programming, and intelligent programming assistants. With the rapid development of artificial intelligence and automation technologies, the software development field is facing unprecedented challenges and opportunities. Traditional programming methods rely on manual code writing, which is not only time-consuming and labor-intensive but also prone to errors due to human factors. In recent years, automated programming technologies have gradually emerged, aiming to reduce human intervention and improve code generation efficiency and quality through intelligent algorithms and machine learning techniques.

[0003] However, existing automated programming technologies still have many limitations, such as insufficient accuracy in code generation, poor adaptability, and inability to handle complex business logic. A more efficient and intelligent solution is urgently needed. Although some automated code generation solutions have been proposed, these solutions typically suffer from poor flexibility, limited functionality, or an inability to adequately understand complex requirements. Therefore, developing a system capable of accurately generating high-quality code based on natural language requirements has broad application prospects.

[0004] To address the above problems, this invention proposes a solution. Summary of the Invention

[0005] To overcome the aforementioned deficiencies of the prior art, embodiments of the present invention provide a method for automatic code programming, which solves the problems mentioned in the background art by developing a system capable of accurately generating high-quality code according to natural language requirements.

[0006] To achieve the above objectives, the present invention provides the following technical solution:

[0007] A method for automated code programming includes the following steps:

[0008] Users input their requirements for the code's functionality in natural language.

[0009] The semantic analysis of user input is performed using rule-based semantic analysis models and deep learning semantic analysis models, and the analysis results of different models are fused to obtain a comprehensive semantic vector.

[0010] By combining historical demand records and contextual information of current demands, the fused comprehensive semantic vector is corrected, and key information is identified based on the corrected comprehensive semantic vector;

[0011] A code template library is pre-built. Templates are searched for and matched based on key information in the template library, and code is generated based on the replaced template.

[0012] Real-time monitoring of performance metrics during code execution; and calculation of code fitness value based on the performance metrics monitoring results.

[0013] Automated testing of the code yields a code reliability dimension, which, combined with the code fitness value, is used to evaluate the effectiveness of automated code programming based on fuzzy inference.

[0014] In a preferred embodiment, the requirement to input code functionality in natural language includes:

[0015] Describe the basic functional requirements and indicate the key operations;

[0016] Please describe in detail the data type and format of the input, as well as the expected output;

[0017] It also describes performance requirements, error handling methods, or information about interactions with other systems.

[0018] In a preferred embodiment, the specific steps for performing semantic analysis on user input requirements using a rule-based semantic analysis model are as follows:

[0019] The input user text is broken down into individual words or phrases, and the words or phrases are tagged with parts of speech and stop words are removed.

[0020] Analyze the dependency relationships between words in a sentence, construct a syntax tree based on grammatical rules, and represent the structure of words within the sentence;

[0021] Based on rules and dictionary mappings, reasoning is performed on different words, and semantic vectors are obtained based on rule-based semantic representations.

[0022] In a preferred embodiment, the specific steps for performing semantic analysis based on user input requirements using a deep learning semantic analysis model are as follows:

[0023] Text cleaning is performed on user input, including word segmentation and stop word removal;

[0024] Each word is converted into a fixed-dimensional vector using a pre-trained word vector model;

[0025] The BERT model calculates the dynamic vector of each word based on the context of the sentence;

[0026] A deep learning model is trained using labeled data, and semantic vectors are generated based on the model's output layer.

[0027] In a preferred embodiment, the process of fusing the analysis results of different models to obtain a comprehensive semantic vector is as follows:

[0028] The analysis results of rule-based semantic analysis models and deep learning semantic analysis models are fused together, and a weighted average method is used to calculate the comprehensive semantic vector. The specific calculation formula is as follows: In the formula, It is a comprehensive semantic vector. It is a semantic vector obtained from a rule-based semantic analysis model. It is the semantic vector of the deep learning semantic analysis model, and α is the weight coefficient, with a value range of [0,1].

[0029] In a preferred embodiment, the process of correcting the fused comprehensive semantic vector by combining historical demand records and contextual information of current demands is as follows:

[0030] Obtain the context requirement record based on the context information of the current requirement, and obtain the semantic vector of the context requirement based on the context requirement record;

[0031] Obtain the semantic vector of historical requirements based on historical requirement records;

[0032] The integrated semantic vector after fusion is modified based on the semantic vectors of contextual and historical requirements.

[0033] In a preferred embodiment, the process of identifying key information based on the modified comprehensive semantic vector is as follows:

[0034] Calculate the sum of the dimensions of the corrected integrated semantic vector;

[0035] The sum of the dimensions of the corrected comprehensive semantic vector is then compared and analyzed with the preset dimension threshold.

[0036] If the sum of the dimensions of the corrected integrated semantic vector is greater than the preset dimension threshold, then the information corresponding to the corrected integrated semantic vector is considered to be key information.

[0037] In a preferred embodiment, the code generation process based on the replaced template is as follows:

[0038] A pre-built template library containing various common code functions is provided, with each template corresponding to a specific code function and including replaceable placeholders.

[0039] Based on the identified key information, the most matching code template is found in the template library;

[0040] If several matching templates are found, the placeholder in the template with the highest match to the key information will be replaced with the actual parameter.

[0041] If a matching template is found, the placeholders in the template are replaced with the actual parameters;

[0042] If no exact matching template is found in the template library, a machine learning model is used to generate the code.

[0043] In a preferred embodiment, the process of calculating the code fitness value based on the performance metric monitoring results is as follows:

[0044] The performance metrics include execution time and memory usage percentage;

[0045] Obtain the execution time by calculating the time taken from the start to the end of the program's execution.

[0046] The percentage of memory used by a program relative to the total computer memory is obtained as the memory usage percentage.

[0047] The fitness value of the code is calculated by combining the execution time and memory usage percentage with the baseline execution time and baseline memory usage percentage.

[0048] In a preferred embodiment, the process of evaluating the effectiveness of automated code programming based on fuzzy reasoning is as follows:

[0049] Get the number of times the code was automated tested, the number of times the code passed the tests, and the maximum number of consecutive tests passed.

[0050] The accuracy coefficient of automated code programming is obtained by dividing the number of times the test passed by the number of times the code was automated tested.

[0051] The code automation stability coefficient is obtained by dividing the maximum number of consecutive test passes by the number of automated tests performed on the code.

[0052] The code reliability dimension is obtained by weighting and combining the accuracy coefficient and stability coefficient of automatic code programming.

[0053] Define code reliability dimension and code fitness value as input variables, and divide them into different fuzzy sets respectively;

[0054] The effect of automatic code programming is defined as the output variable, which is then divided into fuzzy sets.

[0055] Formulate fuzzy rules to describe the impact of input variables on output variables;

[0056] Fuzzy reasoning is performed based on fuzzy rules to determine the effectiveness of automatic code programming.

[0057] The technical effects and advantages of the automatic code programming method of the present invention are as follows:

[0058] 1. This invention significantly reduces development time through automated code generation, especially for repetitive or structured code sections, allowing programmers to focus more on core business logic. Because the code generation process is based on an automated system, common errors in traditional manual programming, such as syntax and logic errors, are avoided. The automatically generated code conforms to best practices in programming languages, possessing high efficiency and maintainability, and is easy to extend and optimize. Non-professional users or beginners can also generate high-quality code by inputting requirements in natural language, lowering the programming threshold. Automated programming methods often follow unified code standards and templates, resulting in highly consistent and standardized code, reducing syntax errors and logical loopholes caused by human factors, and improving code stability and reliability. The generated code has a clear structure and distinct hierarchy, with well-defined modules and functions, facilitating subsequent modification, extension, and maintenance by developers, reducing maintenance costs and difficulty. For some technically demanding fields or complex programming tasks, automated code generation methods enable even those without in-depth professional knowledge to participate in development, reducing the difficulty of programming and promoting the popularization and application of related technologies.

[0059] 2. This invention significantly reduces the time and workload of manual coding by automatically generating large amounts of basic code and even complex logic code, allowing developers to focus more on core business logic and innovation, thus significantly shortening project development cycles. In the face of constantly changing and iterating product requirements, it can quickly generate or modify code according to new requirements and specifications, meeting the demands of rapid iterative development and enabling enterprises to respond more flexibly to market changes. It can automatically complete some tedious and repetitive coding tasks, such as data access layer code and interface layout code, avoiding developers repeatedly writing similar code and increasing the enjoyment and creativity of the work. It solidifies industry best practices and common programming patterns into automated programming tools or methods, realizing knowledge reuse and inheritance, allowing new projects to quickly inherit the experience and achievements of previous projects. It reduces the need for a large number of professional programmers, especially for some routine and standardized development tasks, which can be completed by fewer people through automated code programming, reducing the labor costs of software development. When processing large amounts of data and complex business logic, it can ensure the accuracy and consistency of the code, avoiding the oversights and inconsistencies that may occur during manual coding, thus improving the overall quality and stability of the system. Many automated code programming methods support multiple operating system platforms and programming languages, allowing developers to choose flexibly according to project needs and improving code portability and versatility. Attached Figure Description

[0060] Figure 1 This is a schematic diagram of the structure of a method for automatic code programming according to the present invention. Detailed Implementation

[0061] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.

[0062] Example 1, Figure 1 This invention provides a method for automatic code programming.

[0063] S10, the user inputs a description of their code functionality requirements in natural language.

[0064] The requirements for code functionality, including inputting in natural language, include:

[0065] Describe the basic functional requirements and indicate the key operations;

[0066] Please describe in detail the data type and format of the input, as well as the expected output;

[0067] It also describes performance requirements, error handling methods, or information about interactions with other systems.

[0068] Users input their requirements for code functionality in natural language, which plays several key roles in automated code programming:

[0069] Reduced communication costs: Traditional development processes typically require multiple communications between developers and users to clarify requirements. With natural language input, users can directly express their needs, which developers or automated tools can understand more easily, reducing misunderstandings and unnecessary communication costs.

[0070] For example, a user might describe, "I need a Python program that can calculate the average of a given list." This description is more concise than a more technical requirement (e.g., "Please implement a function to calculate the average of a list") and helps developers quickly understand the requirement.

[0071] Improving development efficiency: After describing requirements using natural language, code generation tools based on AI or automation systems (such as the GPT series models) can quickly parse these requirements and convert them into corresponding code. This not only significantly shortens development time but also improves development efficiency, especially for simple tasks or common programming problems.

[0072] For example, a user can simply describe, "I need a sorting algorithm that can sort an array in ascending order," and the system can directly generate the corresponding sorting code.

[0073] Helping non-technical developers: Not every user knows programming, and many users without a technical background also want to automate tasks or develop functions. Natural language input allows these non-technical developers to easily describe the functions they want without learning programming languages. AI systems can then generate the necessary code based on these needs, reducing the technical barrier to entry.

[0074] For example, a user might say, "I need a Python script to read my file and count the occurrences of each word." This requirement is clear to non-programmers, and AI can generate code based on this.

[0075] Improving code quality and consistency: Automated code generation tools can follow best practices and common coding standards, reducing human error and inconsistencies during code generation. Furthermore, automated programming systems can optimize performance or select the best algorithm based on requirements analysis, further improving code quality.

[0076] For example, if a user inputs the requirement "Please write a function to determine whether a given string is a palindrome", the automation tool will generate a function that conforms to Python programming standards and ensure that it has optimal performance.

[0077] Facilitates rapid iteration and prototyping: Using natural language input can help achieve rapid prototyping or fast iteration. Users can change the functionality of the code by modifying the requirement description, and automation tools can provide rapid responses based on new requirements.

[0078] For example, if an initial requirement is "create a simple web form" but is later changed to "add data validation and display the submission result", the automation tool can quickly modify the generated code based on the changed description.

[0079] Supports multiple programming languages ​​and frameworks: Users can describe their needs in natural language, and the automation tool can select the appropriate programming language, library, and framework to generate code based on those needs. Users do not need to worry about the underlying implementation or technology stack; they can focus on describing the functionality.

[0080] For example, a user can simply describe, "I want to create a simple user registration API using Flask," and the system can automatically generate the code for the Flask framework.

[0081] Enhancing code customization: Users can obtain highly customized code by refining their natural language descriptions. With advancements in Natural Language Processing (NLP) technology, automated tools are able to parse complex requirement descriptions and generate personalized code that meets those requirements.

[0082] For example, a user might describe: "I need a program that takes an Excel file, groups the data according to different conditions, and outputs it to another Excel file." This kind of customized requirement can be efficiently generated using automation tools.

[0083] By inputting requirements through natural language, automated programming not only makes code generation more convenient and efficient, but also lowers the technical barriers between users and developers, promoting a diverse and personalized development experience. It helps non-technical personnel express their needs through intuitive language, greatly improving development efficiency, reducing the chance of errors, and driving rapid innovation and prototyping.

[0084] S20 uses rule-based semantic analysis models and deep learning semantic analysis models to perform semantic analysis on user input requirements, and fuses the analysis results of different models to obtain a comprehensive semantic vector;

[0085] The specific steps for performing semantic analysis on user input based on a rule-based semantic analysis model are as follows:

[0086] The input user text is broken down into individual words or phrases, and the words or phrases are tagged with parts of speech and stop words are removed.

[0087] Analyze the dependency relationships between words in a sentence, construct a syntax tree based on grammatical rules, and represent the structure of words within the sentence;

[0088] Based on rules and dictionary mappings, reasoning is performed on different words, and semantic vectors are obtained based on rule-based semantic representations.

[0089] It should be noted that part-of-speech tagging (POS) is performed using the Natural Language Processing (NLTK) tool, employing the Penn Treebank POS tag set for rapid POS tagging of English text. For Chinese text POS tagging, the Harbin Institute of Technology (HIT) LTP toolkit can be used. This tool supports various NLP tasks, and its Python interface enables POS tagging of Chinese text. Dependency analysis employs a neural network-based dependency parsing model, such as the BiLSTM-CRF model from the AllenNLP library, using a CoNLL format dataset for training. Chinese dependency analysis can also utilize the LTP toolkit, whose dependency parsing function can analyze the dependency relationships between words in Chinese sentences. A syntactic tree is constructed based on the dependency analysis results, and a graphical syntactic tree is built using the Python NetworkX library in conjunction with the dependency analysis results. By introducing a knowledge graph, words are associated with concepts in the graph, enhancing reasoning capabilities. The knowledge graph is built using the Neo4j graph database and operated using the py2neo library. Example steps are as follows: Data Import: Domain-related knowledge is organized into triples and imported into the Neo4j database; Lexical Reasoning: When reasoning about words in the text, the knowledge graph is queried using py2neo to obtain relevant concepts and relationships, assisting the reasoning process.

[0090] The specific steps for performing semantic analysis on user input based on a deep learning semantic analysis model are as follows:

[0091] Text cleaning is performed on user input, including word segmentation and stop word removal;

[0092] Each word is converted into a fixed-dimensional vector using a pre-trained word vector model;

[0093] The BERT model calculates the dynamic vector of each word based on the context of the sentence;

[0094] A deep learning model is trained using labeled data, and semantic vectors are generated based on the model's output layer.

[0095] The process of fusing the analysis results from different models to obtain a comprehensive semantic vector is as follows:

[0096] The analysis results of rule-based semantic analysis models and deep learning semantic analysis models are fused together, and a weighted average method is used to calculate the comprehensive semantic vector. The specific calculation formula is as follows: In the formula, It is a comprehensive semantic vector. It is a semantic vector obtained from a rule-based semantic analysis model. It is the semantic vector of the deep learning semantic analysis model, and α is the weight coefficient, with a value range of [0,1].

[0097] It should be noted that a large amount of labeled user demand text and corresponding accurate semantic vectors are collected. The error between the integrated semantic vector after model fusion and the labeled semantic vector is used as the optimization objective. The gradient descent algorithm is used to train and obtain the optimal weight coefficients. The specific process is as follows: First, simulated rule-based semantic vectors, deep learning semantic vectors, and accurate semantic vectors are generated. Then, two weight coefficients, weight_rule and weight_dl, are defined and set as trainable parameters. Next, the mean squared error loss function and stochastic gradient descent optimizer are defined. In the training loop, the integrated semantic vector is calculated each time, and then the loss is calculated. The gradient is calculated through backpropagation and the weight coefficients are updated until the specified number of training iterations is reached. Finally, the optimal weight coefficients obtained by training are output.

[0098] S30, combining historical demand records and contextual information of current demands, corrects the fused comprehensive semantic vector, and identifies key information based on the corrected comprehensive semantic vector;

[0099] Obtain the context requirement record based on the context information of the current requirement, and obtain the semantic vector of the context requirement based on the context requirement record;

[0100] Obtain the semantic vector of historical requirements based on historical requirement records;

[0101] The fused semantic vector is corrected based on the semantic vectors of contextual and historical requirements. The specific calculation formula is as follows: In the formula, It is the corrected comprehensive semantic vector. It is a comprehensive semantic vector. It is a semantic vector of contextual requirements. is the semantic vector of historical demand, β is the context influence coefficient, and γ is the historical demand influence coefficient.

[0102] The process of identifying key information based on the corrected comprehensive semantic vector is as follows:

[0103] Calculate the sum of the dimensions of the corrected integrated semantic vector;

[0104] The sum of the dimensions of the corrected comprehensive semantic vector is then compared and analyzed with the preset dimension threshold.

[0105] If the sum of the dimensions of the corrected integrated semantic vector is greater than the preset dimension threshold, then the information corresponding to the corrected integrated semantic vector is considered to be key information.

[0106] S40: A code template library is pre-built. Based on key information, templates are searched in the template library for matching, and code is generated based on the replaced template.

[0107] A pre-built template library containing various common code functions is provided, with each template corresponding to a specific code function and including some replaceable placeholders.

[0108] Based on the identified key information, the most matching code template is found in the template library;

[0109] If several matching templates are found, the placeholder in the template with the highest match to the key information will be replaced with the actual parameter.

[0110] If a matching template is found, the placeholders in the template are replaced with the actual parameters;

[0111] If no exact matching template is found in the template library, a machine learning model is used to generate the code.

[0112] S50 monitors performance metrics during code execution in real time and calculates code fitness values ​​based on the performance metrics monitoring results.

[0113] The performance metrics include execution time and memory usage percentage;

[0114] Obtain the execution time by calculating the time taken from the start to the end of the program's execution.

[0115] The percentage of memory used by a program relative to the total computer memory is obtained as the memory usage percentage.

[0116] The fitness value of the code is calculated by combining the execution time and memory usage percentage with the baseline execution time and baseline memory usage percentage. The specific calculation formula is as follows: In the formula, F is the code fitness value, w1 is the execution time weighting factor, and T is the execution time. b This is the baseline execution time, w2 is the memory usage percentage weighting factor, and M is the memory usage percentage. b This is the baseline memory usage percentage.

[0117] S60 performs automated testing on the code, obtains the code reliability dimension, and evaluates the effectiveness of automated code programming based on fuzzy inference by combining the code fitness value.

[0118] Get the number of times the code was automated tested, the number of times the code passed the tests, and the maximum number of consecutive tests passed.

[0119] The accuracy coefficient of automated code programming is obtained by dividing the number of times the test passed by the number of times the code was automated tested.

[0120] The code automation stability coefficient is obtained by dividing the maximum number of consecutive test passes by the number of automated tests performed on the code.

[0121] The code reliability dimension is obtained by weighting and combining the accuracy coefficient and stability coefficient of automatic code programming.

[0122] The process of evaluating the effectiveness of automated code programming based on fuzzy reasoning is as follows:

[0123] Step C1: Define the code reliability dimension and code fitness value as input variables, and divide them into different fuzzy sets.

[0124] For example, "Low", "Medium", and "High" represent the code reliability dimension, while "Low", "Medium", and "High" represent the code fitness value.

[0125] Step C2, the code auto-programming effect is defined as the output variable, which is divided into fuzzy sets, such as "Low" and "High", for the code auto-programming effect.

[0126] Step C3 involves developing a set of fuzzy rules to describe the impact of different input variables on the output variable. The rules can be defined based on professional knowledge or obtained through data analysis and experimentation. For example:

[0127] We can define the following: label code reliability as L, code fitness value as F, and code auto-programming effect as P.

[0128] Rule 1: If (L is High) and (F is High), then (P is High).

[0129] Rule 2: If (L is Low) and (F is Low), then (P is Low). ...

[0131] Step C4: Perform fuzzy reasoning based on fuzzy rules to determine the effect of automatic code programming.

[0132] It should be noted that the division of fuzzy sets can be adjusted according to the actual situation. For example, although this embodiment uses three fuzzy sets as an example, the code reliability dimension, code fitness value, and code automatic programming effect can actually be divided into more than three sets to facilitate more accurate identification.

[0133] Furthermore, regarding the code reliability dimension, the judgment of the code fitness value can be made by setting thresholds according to the actual situation; when the code reliability dimension is higher than 80%, it is marked as "High", and when the code fitness value is higher than 75%, it is marked as "High", etc., which will not be elaborated here.

[0134] The above formulas are all dimensionless calculations. The formulas are derived from software simulations based on a large amount of collected data to obtain the most recent real-world results. The preset parameters in the formulas are set by those skilled in the art according to the actual situation.

[0135] The above embodiments can be implemented, in whole or in part, by software, hardware, firmware, or any other combination thereof. When implemented using software, the above embodiments can be implemented, in whole or in part, in the form of a computer program product.

[0136] Those skilled in the art will recognize that the modules and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0137] In addition, the functional modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module.

[0138] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

[0139] In conclusion, the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for automatic code programming, characterized in that, Includes the following steps: Users input their requirements for the code's functionality in natural language. The semantic analysis of user input is performed using rule-based semantic analysis models and deep learning semantic analysis models, and the analysis results of different models are fused to obtain a comprehensive semantic vector. By combining historical demand records and contextual information of current demands, the fused comprehensive semantic vector is corrected, and key information is identified based on the corrected comprehensive semantic vector; A code template library is pre-built. Templates are searched for and matched based on key information in the template library, and code is generated based on the replaced template. Real-time monitoring of performance metrics during code execution, including execution time and memory usage percentage; obtaining the execution time by acquiring the time taken from the start to the end of program execution; The memory usage percentage is obtained by measuring the proportion of total computer memory used by the program; combined with the baseline execution time and baseline memory usage percentage, the fitness value of the code is calculated using the following formula: F = w1 * In the formula, F is the code fitness value, w1 is the execution time weighting factor, and T is the execution time. b This is the baseline execution time, w2 is the memory usage percentage weighting factor, and M is the memory usage percentage. b This is the baseline memory usage percentage; Perform automated testing on the code and obtain the total number of tests, the number of tests passed, and the maximum number of consecutive tests passed. The ratio of the number of successful tests to the total number of tests is used as the accuracy coefficient for automatic code programming, and the ratio of the maximum number of consecutive successful tests to the total number of tests is used as the stability coefficient for automatic code programming. The code reliability dimension is obtained by weighted summation. The code reliability dimension and the code fitness value are defined as input variables and divided into different fuzzy sets. The automatic code programming effect is defined as the output variable and divided into fuzzy sets. Fuzzy inference is performed according to fuzzy rules to determine the effect of automatic code programming.

2. The method for automatic code programming according to claim 1, characterized in that, The requirement for inputting code functionality in natural language includes: Describe the basic functional requirements and indicate the key operations; Please describe in detail the data type and format of the input, as well as the expected output; It also describes performance requirements, error handling methods, or information about interactions with other systems.

3. The method for automatic code programming according to claim 2, characterized in that, The specific steps for performing semantic analysis on user input based on a rule-based semantic analysis model are as follows: The input user text is broken down into individual words or phrases, and the words or phrases are tagged with parts of speech and stop words are removed. Analyze the dependency relationships between words in a sentence, construct a syntax tree based on grammatical rules, and represent the structure of words within the sentence; Based on rules and dictionary mappings, reasoning is performed on different words, and semantic vectors are obtained based on rule-based semantic representations.

4. The method for automatic code programming according to claim 3, characterized in that, The specific steps for performing semantic analysis on user input based on a deep learning semantic analysis model are as follows: Text cleaning is performed on user input, including word segmentation and stop word removal; Each word is converted into a fixed-dimensional vector using a pre-trained word vector model; The BERT model calculates the dynamic vector of each word based on the context of the sentence; A deep learning model is trained using labeled data, and semantic vectors are generated based on the model's output layer.

5. The method for automatic code programming according to claim 4, characterized in that, The process of fusing the analysis results from different models to obtain a comprehensive semantic vector is as follows: The analysis results of rule-based semantic analysis models and deep learning semantic analysis models are fused together, and a weighted average method is used to calculate the comprehensive semantic vector. The specific calculation formula is as follows: In the formula, It is a comprehensive semantic vector. It is a semantic vector obtained from a rule-based semantic analysis model. It is the semantic vector of the deep learning semantic analysis model, and α is the weight coefficient, with a value range of [0,1].

6. The method for automatic code programming according to claim 5, characterized in that, The process of correcting the fused comprehensive semantic vector by combining historical demand records and contextual information of current demands is as follows: Obtain the context requirement record based on the context information of the current requirement, and obtain the semantic vector of the context requirement based on the context requirement record; Obtain the semantic vector of historical requirements based on historical requirement records; The fused semantic vector is corrected based on the semantic vectors of contextual and historical requirements. The specific calculation formula is as follows: In the formula, It is the corrected comprehensive semantic vector. It is a comprehensive semantic vector. It is a semantic vector of contextual requirements. is the semantic vector of historical demand, β is the context influence coefficient, and γ is the historical demand influence coefficient.

7. The method for automatic code programming according to claim 6, characterized in that, The process of identifying key information based on the corrected comprehensive semantic vector is as follows: Calculate the sum of the dimensions of the corrected integrated semantic vector; The sum of the dimensions of the corrected comprehensive semantic vector is then compared and analyzed with the preset dimension threshold. If the sum of the dimensions of the corrected integrated semantic vector is greater than the preset dimension threshold, then the information corresponding to the corrected integrated semantic vector is considered to be key information.

8. The method for automatic code programming according to claim 7, characterized in that, The process of generating code based on the replaced template is as follows: A pre-built template library containing various common code functions is provided, with each template corresponding to a specific code function and including replaceable placeholders. Based on the identified key information, the most matching code template is found in the template library; If several matching templates are found, the placeholder in the template with the highest match to the key information will be replaced with the actual parameter. If a matching template is found, the placeholders in the template are replaced with the actual parameters; If no exact matching template is found in the template library, a machine learning model is used to generate the code.

Citation Information

Patent Citations

  • Visual intelligent programming method based on large language model

    CN119045806A

  • Code generation method and apparatus, storage medium and electronic device

    WO2024174911A1