Code annotation generation method and device, equipment, storage medium and program product

By generating SQL code lineage and business knowledge, and using a large language model to build high-quality code comments, the problem of inaccurate code comment generation in existing technologies is solved, improving the readability and understandability of code comments and enhancing the efficiency of code development and maintenance.

CN121387359APending Publication Date: 2026-01-23CHINA MOBILE GROUP ZHEJIANG +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510393590.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-31
Publication Date
2026-01-23

AI Technical Summary

Technical Problem

Existing code comment generation methods lack an understanding of code context and business knowledge, resulting in overly technical or abstract comments that fail to accurately reflect the business logic and goals of the code, leading to poor readability and impacting software development and maintenance.

Method used

By acquiring the SQL code to be analyzed, the SQL code lineage is generated based on a large language model. Code comments are generated by combining business knowledge. The large language model is used for code segmentation, parsing, and question answering to gradually build a complete code lineage and business knowledge, and generate high-quality code comments.

Benefits of technology

The generated code comments can effectively reflect the business logic and business objectives of the code, improve readability and understandability, and reduce the impact on software development and maintenance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121387359A_ABST
    Figure CN121387359A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, and provides a code annotation generation method and device, equipment, a storage medium and a program product. The method comprises the steps of obtaining a to-be-analyzed SQL code; based on a large language model, generating an SQL code blood relationship of the to-be-analyzed SQL code; generating business knowledge based on the SQL code blood relationship; and based on the SQL code consanguinity and the business knowledge, generating a code annotation of the to-be-analyzed SQL code through the large language model. By means of the mode, it can be avoided that the generated code annotation is too technically or abstractly generated, the service logic and the service target of the code can be effectively reflected, the code annotation has better readability and understandability, and the influence on subsequent development and maintenance of software is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

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

[0002] Code annotation is an explanatory text annotation in natural language for program code, which can promote developers to quickly understand the intention and workflow of the code. In various aspects of software development and subsequent maintenance, high-quality code annotations play an irreplaceable role: in the development stage, it promotes developers to quickly understand the code logic, thereby improving programming efficiency; in the maintenance stage, it can help maintenance personnel quickly locate problems and reduce the difficulty of code maintenance.

[0003] However, in actual application, code annotations often have problems such as low annotation writing efficiency, low accuracy, inconsistency with actual code content, and missing key explanations. Since manual supplement or correction of annotations has the problems of large workload and low efficiency, how to realize the automatic generation of code annotations has become a problem to be solved.

[0004] In the prior art, a sample pair of code and code annotation is constructed, and a deep learning model is trained using the sample pair to optimize the processing of the code feature vector by the model, improve the representation ability of the code feature vector by the model, and achieve better annotation effect.

[0005] However, the existing code annotation generation method usually lacks understanding of the code context and the overall architecture of the code, lacks understanding and application of business knowledge and business rules, resulting in code annotations that are too technical or abstract, which are difficult to accurately reflect the business logic and business goals of the code, have poor readability, and are likely to affect subsequent development and maintenance of software. SUMMARY

[0006] The embodiments of the present application provide a code annotation generation method, device, equipment, storage medium and program product to solve the technical problem that the code annotations generated by the existing code annotation generation method are too technical or abstract, difficult to accurately reflect the business logic and business goals of the code, have poor readability, and are likely to affect subsequent development and maintenance of software.

[0007] In a first aspect, the embodiments of the present application provide a code annotation generation method, comprising: obtaining a SQL code to be analyzed; generating a SQL code blood relationship of the SQL code to be analyzed based on a large language model; generating business knowledge based on the SQL code blood relationship; and generating a code annotation of the SQL code to be analyzed by the large language model based on the SQL code blood relationship and the business knowledge.

[0008] In one embodiment, based on a large language model, the SQL code blood relationship of the SQL code to be analyzed is generated, including: code cutting is performed on the SQL code to be analyzed to obtain a plurality of SQL code blocks; according to the execution order of the SQL code to be analyzed, each SQL code block and a question and answer prompt word are input into the large language model, each SQL code block is parsed, and the intra-block blood relationship of each SQL code block is obtained; the intra-block blood relationship of each SQL code block is textually concatenated to obtain the SQL code blood relationship of the SQL code to be analyzed.

[0009] In one embodiment, according to the execution order of the SQL code to be analyzed, each SQL code block and a question and answer prompt word are input into the large language model, each SQL code block is parsed, and the intra-block blood relationship of each SQL code block is obtained, including: according to the execution order of the SQL code to be analyzed, the corresponding SQL code block and the first question and answer prompt word are input into the large language model, the result table and the source table are parsed, the source table name and the result table name of the corresponding SQL code block are generated; the corresponding SQL code block, the source table name, the result table name, and the second question and answer prompt word are input into the large language model, the result table structure is parsed, and the result table field of the corresponding SQL code block is generated; the corresponding SQL code block, the source table name, the result table name, the result table field, and the third question and answer prompt word are input into the large language model, the relationship between the result table field and the source table field is parsed, and the intra-block blood relationship of the corresponding SQL code block is generated.

[0010] In one embodiment, the business knowledge includes first business knowledge and second business knowledge, the first business knowledge is business domain knowledge of a source table of the SQL code to be analyzed, and the second business knowledge is business domain knowledge of each intermediate table and each intermediate table field in the SQL code to be analyzed; based on the SQL code blood relationship, the business knowledge is generated, including: based on the SQL code blood relationship, data dictionary database matching is performed to obtain the first business knowledge; based on the SQL code blood relationship and the first business knowledge, the second business knowledge is determined.

[0011] In one embodiment, based on the SQL code blood relationship and the first business knowledge, the second business knowledge is determined, including: the SQL code blood relationship, the first business knowledge, and the fourth question and answer prompt word are input into the large language model to obtain the second business knowledge output by the large language model.

[0012] In one embodiment, based on the SQL code blood relationship and the business knowledge, the code annotation of the SQL code to be analyzed is generated through the large language model, including: the SQL code blood relationship, the first business knowledge, the second business knowledge, and the fifth question and answer prompt word are input into the large language model to obtain the code annotation of the SQL code to be analyzed output by the large language model.

[0013] In a second aspect, an embodiment of the present application provides a code annotation generation apparatus, comprising: an acquisition module configured to acquire a SQL code to be analyzed; a bloodline generation module configured to generate a SQL code bloodline of the SQL code to be analyzed based on a large language model; a business knowledge generation module configured to generate business knowledge based on the SQL code bloodline; and a code annotation generation module configured to generate a code annotation of the SQL code to be analyzed based on the SQL code bloodline and the business knowledge through the large language model.

[0014] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, and the processor implements any of the above code annotation generation methods when executing the computer program.

[0015] In a fourth aspect, an embodiment of the present application provides a non-transitory computer-readable storage medium having a computer program stored thereon, and the computer program is executed by a processor to implement any of the above code annotation generation methods.

[0016] In a fifth aspect, an embodiment of the present application provides a computer program product comprising a computer program, and the computer program is executed by a processor to implement any of the above code annotation generation methods.

[0017] The code annotation generation method, apparatus, device, storage medium, and program product provided by the embodiments of the present application acquire a SQL code to be analyzed, generate a SQL code bloodline of the SQL code to be analyzed based on a large language model, generate business knowledge based on the SQL code bloodline, and generate a code annotation of the SQL code to be analyzed based on the SQL code bloodline and the business knowledge through the large language model. In this way, the large language model can use the complete SQL code bloodline to generate code annotations, so that the business knowledge can be transmitted along the SQL code bloodline, the generated code annotations can cover the understanding of the code context and the overall architecture of the code, and the relevant business knowledge can be introduced into the code annotations, avoiding the generated code annotations from being too technical or abstract, effectively reflecting the business logic and business goals of the code, making the code annotations have better readability and understandability, and reducing the impact on subsequent development and maintenance of software. BRIEF DESCRIPTION OF DRAWINGS

[0018] In order to more clearly illustrate the technical solutions of the present application or the prior art, the following will briefly introduce the drawings needed in the embodiments or prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and those skilled in the art can also obtain other drawings according to these drawings without creative labor.

[0019] Figure 1is a flowchart of a code annotation generation method provided by an embodiment of the present application.

[0020] Figure 2 is a workflow diagram of an intelligent question and answer model provided by an embodiment of the present application.

[0021] Figure 3 is a flowchart of data preprocessing provided by an embodiment of the present application.

[0022] Figure 4 is a flowchart of intra-block bloodline analysis provided by an embodiment of the present application.

[0023] Figure 5 is a flowchart of generating first business knowledge provided by an embodiment of the present application.

[0024] Figure 6 is a flowchart of generating second business knowledge provided by an embodiment of the present application.

[0025] Figure 7 is a flowchart of generating code annotations provided by an embodiment of the present application.

[0026] Figure 8 is a structural diagram of a code annotation generation apparatus provided by an embodiment of the present application.

[0027] Figure 9 is a structural diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0028] To make the objectives, technical solutions, and advantages of the present application clearer, the technical solutions in the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some but not all of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.

[0029] Please refer to Figure 1 , Figure 1 is a flowchart of a code annotation generation method provided by an embodiment of the present application. As shown in Figure 1 , in the embodiment of the present application, the code annotation generation method includes steps S110 to S140, and each step is specifically as follows: S110: Obtain the SQL code to be analyzed.

[0030] S120: Based on a large language model, generate the SQL code bloodline of the SQL code to be analyzed.

[0031] Specifically, the embodiment of the present application proposes a SQL code annotation generation method, aiming to improve the readability and understandability of the generated SQL code annotation, and at the same time, to enhance the transmission and application of business knowledge, to provide more code context information for developers by automatically generating complex SQL code annotations, and to improve the efficiency of code development and maintenance. Since the SQL code annotation generation method of the embodiment of the present application needs to generate code annotations through a question and answer mode, it is necessary to first build a large language model (i.e. an intelligent question and answer model).

[0032] Optionally, the intelligent question and answer model is built by using the LangGraph framework, and the intelligent question and answer model can efficiently determine which tool and path to use for SQL code analysis and information annotation through the question and answer mechanism.

[0033] Please refer to Figure 2 , Figure 2 is the working process schematic diagram of the intelligent question and answer model provided by the embodiment of the present application.

[0034] As Figure 2 indicated, the intelligent question and answer model can extract key information and intent by analyzing user questions, and automatically build a SQL code analysis workflow according to the input data and output data of each node. The specific working steps of the intelligent question and answer model include: (1) Identify the terminal point: The terminal point is usually the final goal of SQL code analysis, i.e. generating code annotations (the final output result), which is the last step of the execution chain. The intelligent question and answer model will automatically determine what kind of input data is needed to generate code annotations.

[0035] (2) Backtracking dependency: Starting from the input of code annotation generation, the intelligent question and answer model can backtrack each dependent node / tool. For example, the business knowledge, intermediate knowledge, etc. that the code annotation generation depends on, which in turn depend on the blood relationship and preprocessed data.

[0036] (3) Plan the path: Through backtracking, the intelligent question and answer model can find the dependency relationship of each node or tool to generate the necessary information or supplementary knowledge, arrange them in the correct order, and finally form an analysis path from the initial input to the final output.

[0037] Optionally, in order to automatically build a complete SQL code annotation analysis process, the intelligent question and answer model can preinstall 5 tools including data preprocessing, analyzing blood relationship, supplementing business knowledge, generating intermediate knowledge, and generating code annotations, to ensure smooth execution of the SQL code analysis workflow.

[0038] It can be understood that, due to the length limitation of the input data of the large language model, the common large language model usually supports 8K to 32K data as input, and the code file cannot guarantee that the SQL code to be analyzed is arranged in the execution order due to the influence of the SQL code writing style. Therefore, inputting all the SQL code to be analyzed into the large language model at one time for parsing cannot guarantee that the large language model can parse all the SQL code to be analyzed, and it is easy to cause the generated code comments to lack the description of the code context and the expression of the code logic, which seriously affects the code comment effect. Based on this, before code commenting, the SQL code to be analyzed needs to be preprocessed.

[0039] Please refer to Figure 3 , Figure 3 is a flowchart of data preprocessing provided by the embodiment of the application.

[0040] As Figure 3 indicated, the data preprocessing process can be completed by the large language model. The large language model can call the data preprocessing tool according to the user prompt word, first acquire the unannotated SQL code to be analyzed from the log file according to the execution order; according to the characteristics of the SQL language, the SQL code usually takes a semicolon as a delimiter, therefore, the SQL code to be analyzed can be code cut according to the delimiter in the SQL code to be analyzed, and a plurality of SQL code blocks arranged in the execution order of the SQL code to be analyzed are obtained.

[0041] It can be understood that, if the large language model cannot cut the SQL code to be analyzed into a plurality of SQL code blocks (i.e. cannot answer the question), the data preprocessing tool needs to be called again according to the user prompt word for code cutting until the large language model successfully cuts a plurality of SQL code blocks.

[0042] For example, for a piece of labor competition index SQL code to be analyzed, the business goal of the SQL code to be analyzed is to calculate the sales scale of the newly added mobile phones in the statistical period; according to the characteristics of the SQL language, the large language model can take a semicolon as a delimiter to cut the SQL code to be analyzed (or use the corresponding SQL code tool, which can also achieve the same effect), and obtain a plurality of SQL code blocks arranged in the execution order of the SQL code to be analyzed.

[0043] Further, each SQL code block is input into the large language model for 3 rounds of question and answer, realizing the intra-block blood relation analysis of each SQL code block, and outputting the data table, field and other intra-block blood relations of each SQL code block; after traversing and analyzing all the SQL code blocks, the intra-block blood relations of all the SQL code blocks are text concatenated, and a complete SQL code blood relation can be generated.

[0044] S130: generate business knowledge based on the SQL code bloodline.

[0045] Optionally, the business knowledge includes first business knowledge and second business knowledge.

[0046] The first business knowledge is business domain knowledge of a source table of the SQL code to be analyzed, and the second business knowledge is business domain knowledge of each intermediate table and each intermediate table field in the SQL code to be analyzed.

[0047] Specifically, first, the data dictionary database is matched based on the SQL code bloodline to obtain the first business knowledge, and then the second business knowledge is determined based on the SQL code bloodline and the first business knowledge.

[0048] S140: based on the SQL code bloodline and the business knowledge, generate code comments of the SQL code to be analyzed by a large language model.

[0049] Specifically, the SQL code bloodline, the first business knowledge, the second business knowledge, and the corresponding question and answer prompt words are input into the large language model to obtain the code comments of the SQL code to be analyzed output by the large language model.

[0050] The code comment generation method provided by the embodiment of the application obtains the SQL code to be analyzed, generates the SQL code bloodline of the SQL code to be analyzed based on the large language model, generates the business knowledge based on the SQL code bloodline, and generates the code comments of the SQL code to be analyzed by the large language model based on the SQL code bloodline and the business knowledge. In the above manner, the large language model can use the complete SQL code bloodline to generate code comments, so that the business knowledge can be transmitted along the SQL code bloodline, which can not only ensure that the generated code comments cover the understanding of the code context and the code overall architecture, but also can introduce relevant business knowledge in the code comments, avoid the generated code comments being too technical or abstract, effectively reflect the business logic and business target of the code, make the code comments have better readability and understandability, and reduce the impact on the subsequent development and maintenance of the software.

[0051] In some embodiments, based on the large language model, the SQL code bloodline of the SQL code to be analyzed includes: code cutting of the SQL code to be analyzed to obtain a plurality of SQL code blocks; according to an execution order of the SQL code to be analyzed, each SQL code block and a question and answer prompt word are input into the large language model respectively, each SQL code block is parsed to obtain an intra-block bloodline of each SQL code block; and the intra-block bloodlines of each SQL code block are concatenated in text to obtain the SQL code bloodline of the SQL code to be analyzed.

[0052] Specifically, the large language model can call a data preprocessing tool according to a user prompt word, and first obtain unannotated SQL code to be analyzed from the log file according to the execution order; according to the characteristics of the SQL language, the SQL code is usually separated by a semicolon as a delimiter, therefore, the SQL code to be analyzed can be code cut according to the delimiter in the SQL code to be analyzed, and a plurality of SQL code blocks arranged according to the execution order of the SQL code to be analyzed are obtained.

[0053] Further, according to the execution order of the SQL code to be analyzed, each SQL code block and the question and answer prompt word are respectively input into the large language model, each SQL code block is parsed, and the intra-block blood relationship of each SQL code block is obtained.

[0054] Specifically, after obtaining the plurality of SQL code blocks arranged according to the execution order of the SQL code to be analyzed, each SQL code block can be traversed in turn according to the execution order of the SQL code to be analyzed.

[0055] Among them, for each SQL code block, the SQL code block and the question and answer prompt word can be input into the large language model, the large language model can perform intra-block blood relationship analysis on the SQL code block to obtain the intra-block blood relationship of the SQL code block.

[0056] Further, after traversing all SQL code blocks and generating the intra-block blood relationship of each SQL code block, the intra-block blood relationship of each SQL code block is concatenated in text to obtain the SQL code blood relationship of the SQL code to be analyzed.

[0057] In some embodiments, according to the execution order of the SQL code to be analyzed, each SQL code block and the question and answer prompt word are respectively input into the large language model, each SQL code block is parsed, and the intra-block blood relationship of each SQL code block is obtained, including: according to the execution order of the SQL code to be analyzed, the corresponding SQL code block and the first question and answer prompt word are input into the large language model, and the result table and the source table are parsed to generate the source table name and the result table name of the corresponding SQL code block; the corresponding SQL code block, the source table name, the result table name, and the second question and answer prompt word are input into the large language model, and the result table structure is parsed to generate the result table field of the corresponding SQL code block; the corresponding SQL code block, the source table name, the result table name, the result table field, and the third question and answer prompt word are input into the large language model, and the relationship between the result table field and the source table field is parsed to generate the intra-block blood relationship of the corresponding SQL code block.

[0058] Please refer to Figure 4 , Figure 4 is a flowchart of intra-block blood relationship analysis provided by the embodiments of the present application.

[0059] AsFigure 4 As shown, the process of block-in lineage analysis can be completed by the large language model. After code slicing is performed on the SQL code to be analyzed, a plurality of SQL code blocks arranged in the execution order of the SQL code to be analyzed can be obtained, and at this time, the corresponding SQL code blocks can be selected in turn according to the execution order of the SQL code to be analyzed and three rounds of question-answering can be performed to realize block-in lineage analysis of each SQL code block.

[0060] Specifically, in the first round of question-answering, a SQL code block and a first question-answering prompt are input into the large language model, the large language model can analyze the result table and the source table in the SQL code block, generate the source table name and the result table name of the SQL code block, and thus construct the table-level lineage of the SQL code block.

[0061] Optionally, the first question-answering prompt is “input the code block, and require to return the source table name and the output table name in the input code block”.

[0062] For example, the result table name output by the large language model is TMP JS24 5GZD CITY 1, and the corresponding source table name of the result table is DW TMNL SALE and DW RES IMEI.

[0063] Further, in the second round of question-answering, the SQL code block, the source table name, the result table name and a second question-answering prompt are input into the large language model, the large language model can analyze the result table structure, and generate the result table field of the SQL code block, and thus construct the table structure (i.e., the field lineage) of the result table of the SQL code block.

[0064] Optionally, the second question-answering prompt is “input the code block, the source table name and the result table name, and require to return the result table field”.

[0065] For example, the result table TABLE TMP JS24 5GZD CITY 1 can include the result table fields IMEI, RES CODE, PHONE SEQUENCE, etc.

[0066] Further, in the third round of question-answering, the SQL code block, the source table name, the result table name, the result table field and a third question-answering prompt are input into the large language model, the large language model can analyze the relationship between the result table field and the source table field, and thus construct the complete block-in lineage of the SQL code block (i.e., all table-level lineage relationships and all field lineages of the SQL code block).

[0067] Optionally, the third question-answering prompt is “input the result table field, the code block, the source table name and the result table name, and require to return the source of all table fields”.

[0068] For example, the result table field IMEI of the result table TABLE TMP JS24 5GZD CITY 1 is derived from the source table field IMEI of the source table DW TMNL SALE.

[0069] At this time, the intra-block lineage analysis of one SQL code block has been completed.

[0070] Further, according to the execution order of the SQL code to be analyzed, the next SQL code block to be executed is selected, and the step of inputting the SQL code block and the first question and answer prompt word into the large language model is returned to, until the intra-block lineage of each SQL code block is generated.

[0071] After traversing all SQL code blocks in the execution order of the SQL code to be analyzed and repeating the above three rounds of question and answer, text concatenation can be further performed to form a complete SQL code lineage.

[0072] In some embodiments, the business knowledge includes first business knowledge and second business knowledge, the first business knowledge is business domain knowledge of a source table of the SQL code to be analyzed, and the second business knowledge is business domain knowledge of each intermediate table and each intermediate table field in the SQL code to be analyzed; based on the SQL code lineage, the business knowledge is generated, including: based on the SQL code lineage, data dictionary database matching is performed to obtain the first business knowledge; and based on the SQL code lineage and the first business knowledge, the second business knowledge is determined.

[0073] In some embodiments, based on the SQL code lineage and the first business knowledge, the second business knowledge is determined, including: inputting the SQL code lineage, the first business knowledge and a fourth question and answer prompt word into the large language model to obtain the second business knowledge output by the large language model.

[0074] Please refer to Figure 5 , Figure 5 is a flowchart of a process for generating first business knowledge provided by an embodiment of the present application.

[0075] As Figure 5 indicated, the process of generating the first business knowledge can be completed by the large language model: after obtaining the complete SQL code lineage, through the form of user question and answer, the large language model calls a supplementary business domain knowledge tool to match each table and each field in the SQL code lineage with a data dictionary database to obtain business information (including table Chinese name, table Chinese description, field Chinese name, field Chinese meaning, field type, etc.) of each table and each field, after the large language model supplements the business knowledge, the first business knowledge is generated, and the first business knowledge is business domain knowledge of part of the tables and part of the fields in the SQL code lineage.

[0076] It should be noted that for the source table and part of the result table, the corresponding business domain knowledge can be obtained through data dictionary database matching, but there may be intermediate tables and intermediate table fields generated by code processing in the SQL code to be analyzed, which cannot be obtained through data dictionary database matching. Therefore, intermediate knowledge generation is needed based on the source table to supplement the business domain knowledge corresponding to the intermediate table and the intermediate table field.

[0077] Please refer to Figure 6 , Figure 6 is a flowchart for generating second business knowledge provided by the embodiment of the present application.

[0078] As Figure 6 indicated, the process of generating second business knowledge can be completed by a large language model: after obtaining the complete SQL code blood relationship and the first business knowledge, input the SQL code blood relationship, the first business knowledge and the fourth question and answer prompt word into the large language model, let the large language model call the intermediate knowledge generation tool to generate intermediate knowledge, obtain the second business knowledge (i.e. intermediate business knowledge) output by the large language model, and the intermediate business knowledge includes the business information corresponding to the intermediate table and the intermediate table field.

[0079] In some embodiments, based on the SQL code blood relationship and the business knowledge, the code annotation of the SQL code to be analyzed is generated by the large language model, including: inputting the SQL code blood relationship, the first business knowledge, the second business knowledge and the fifth question and answer prompt word into the large language model, and obtaining the code annotation of the SQL code to be analyzed output by the large language model.

[0080] Please refer to Figure 7 , Figure 7 is a flowchart for generating code annotation provided by the embodiment of the present application.

[0081] As Figure 7 indicated, the first business knowledge and the second business knowledge are the business domain knowledge of the full table and the full field in the SQL code to be analyzed; inputting the SQL code blood relationship, the business knowledge information in the first business knowledge, Figure 7 , the intermediate business knowledge in the second business knowledge Figure 7 and the fifth question and answer prompt word into the large language model can obtain the code annotation of the SQL code to be analyzed output by the large language model, thus completing the generation of the code annotation of the SQL code to be analyzed.

[0082] The code annotation generation method provided in the embodiments of the present application gradually analyzes the intra-block blood relationship of each SQL code block in a large language model through three rounds of question and answer, then concatenates the intra-block blood relationship of each SQL code block to form a complete SQL code blood relationship, then completes the business domain knowledge based on the complete SQL code blood relationship, generates intermediate knowledge, and finally generates SQL code annotations based on the complete business knowledge. This code annotation method based on code blood relationship enables the business domain knowledge to be transmitted along the code blood relationship, ensuring that the SQL code annotations cover not only the description of the code context and the expression of the code logic, but also the relevant business domain knowledge. The code annotations generated by this method can effectively reflect the overall architecture of the code and the business rules behind the code, and have better readability and understandability.

[0083] The embodiments of the present application also provide a code annotation generation device. Please refer to Figure 8 , Figure 8 is a structural schematic diagram of the code annotation generation device provided by the embodiments of the present application. In the embodiments of the present application, the code annotation generation device comprises an acquisition module 810, a blood relationship generation module 820, a business knowledge generation module 830 and a code annotation generation module 840.

[0084] The acquisition module 810 is configured to acquire the SQL code to be analyzed.

[0085] The blood relationship generation module 820 is configured to generate the SQL code blood relationship of the SQL code to be analyzed based on the large language model.

[0086] The business knowledge generation module 830 is configured to generate the business knowledge based on the SQL code blood relationship.

[0087] The code annotation generation module 840 is configured to generate the code annotation of the SQL code to be analyzed through the large language model based on the SQL code blood relationship and the business knowledge.

[0088] In some embodiments, the blood relationship generation module 820 is configured to perform code cutting on the SQL code to be analyzed to obtain a plurality of SQL code blocks; input each SQL code block and a question and answer prompt word into the large language model according to the execution order of the SQL code to be analyzed, analyze each SQL code block, and obtain the intra-block blood relationship of each SQL code block; and concatenate the intra-block blood relationship of each SQL code block in text to obtain the SQL code blood relationship of the SQL code to be analyzed.

[0089] In some embodiments, the bloodline generation module 820 is configured to input the corresponding SQL code block and the first question and answer prompt word into the large language model according to the execution order of the SQL code to be analyzed, parse the result table and the source table, and generate the source table name and the result table name of the corresponding SQL code block; input the corresponding SQL code block, the source table name, the result table name, and the second question and answer prompt word into the large language model, parse the result table structure, and generate the result table field of the corresponding SQL code block; and input the corresponding SQL code block, the source table name, the result table name, the result table field, and the third question and answer prompt word into the large language model, parse the relationship between the result table field and the source table field, and generate the block-in bloodline of the corresponding SQL code block.

[0090] In some embodiments, the business knowledge includes first business knowledge and second business knowledge, the first business knowledge is business domain knowledge of a source table of the SQL code to be analyzed, and the second business knowledge is business domain knowledge of each intermediate table and each intermediate table field in the SQL code to be analyzed.

[0091] The business knowledge generation module 830 is configured to perform data dictionary database matching based on the SQL code bloodline to obtain the first business knowledge, and determine the second business knowledge based on the SQL code bloodline and the first business knowledge.

[0092] In some embodiments, the business knowledge generation module 830 is configured to input the SQL code bloodline, the first business knowledge, and the fourth question and answer prompt word into the large language model to obtain the second business knowledge output by the large language model.

[0093] In some embodiments, the code annotation generation module 840 is configured to input the SQL code bloodline, the first business knowledge, the second business knowledge, and the fifth question and answer prompt word into the large language model to obtain the code annotation of the SQL code to be analyzed output by the large language model.

[0094] The present application also provides an electronic device, Figure 9 is a structural schematic diagram of an electronic device provided by the present application, as Figure 9 shown, the electronic device can include a processor 910, a communications interface 920, a memory 930, and a communications bus 940, wherein the processor 910, the communications interface 920, and the memory 930 communicate with each other through the communications bus 940. The processor 910 can invoke the logic instructions in the memory 930 to execute the code annotation generation method.

[0095] In addition, the logic instructions in the memory 930 described above can be implemented in the form of software function units and sold or used as independent products, and can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or the parts that contribute to the prior art or parts of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.

[0096] The embodiments of the present application also provide a non-transitory computer readable storage medium, which stores a computer program. The computer program is executed by a processor to implement the code annotation generation method provided by the above methods.

[0097] The embodiments of the present application also provide a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer readable storage medium. When the computer program is executed by a processor, the computer can execute the code annotation generation method provided by the above methods.

[0098] The device embodiments described above are only schematic, wherein the units described as separate components can or can not be physically separate, and the components displayed as units can or can not be physical units, i.e., they can be located in one place, or distributed on multiple network units. Some or all of the modules can be selected to achieve the purpose of the embodiments according to actual needs. Those skilled in the art can understand and implement without creative labor.

[0099] From the above description of the embodiments, those skilled in the art can clearly understand that the embodiments can be implemented by means of software plus necessary universal hardware platforms, and of course, can also be implemented by hardware. Based on such understanding, the above technical solutions essentially or the parts that contribute to the prior art can be embodied in the form of a software product. The computer software product can be stored in a computer readable storage medium, such as a ROM / RAM, a magnetic disk, an optical disk, etc., and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0100] It should be pointed out finally that the above embodiments are only used to illustrate the technical solutions of the present application, but not to limit the same; and although the present application has been described in detail with reference to the foregoing embodiments, it should be appreciated by those skilled in the art that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features thereof can be replaced equivalently; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A code comment generation method characterized by, The method comprises the following steps: acquiring SQL code to be analyzed; generating SQL code blood relationship of the SQL code to be analyzed based on a large language model; generating business knowledge based on the SQL code blood relationship; generating code comments of the SQL code to be analyzed through the large language model based on the SQL code blood relationship and the business knowledge.

2. The code annotation generation method according to claim 1, characterized by, The method of generating the SQL code blood relationship of the SQL code to be analyzed based on the large language model comprises the following steps: code cutting is performed on the SQL code to be analyzed to obtain a plurality of SQL code blocks; each SQL code block and a question and answer prompt word are input into the large language model according to an execution order of the SQL code to be analyzed, each SQL code block is parsed to obtain block-in blood relationship of each SQL code block; text concatenation is performed on the block-in blood relationship of each SQL code block to obtain the SQL code blood relationship of the SQL code to be analyzed.

3. The code annotation generation method according to claim 2, characterized by, The method of parsing each SQL code block to obtain block-in blood relationship of each SQL code block comprises the following steps: according to the execution order of the SQL code to be analyzed, a corresponding SQL code block and a first question and answer prompt word are input into the large language model, a result table and a source table are parsed to generate a source table name and a result table name of the corresponding SQL code block; the corresponding SQL code block, the source table name, the result table name and a second question and answer prompt word are input into the large language model, a result table structure is parsed to generate a result table field of the corresponding SQL code block; the corresponding SQL code block, the source table name, the result table name, the result table field and a third question and answer prompt word are input into the large language model, a relationship between the result table field and a source table field is parsed to generate the block-in blood relationship of the corresponding SQL code block.

4. The code annotation generation method according to claim 1, characterized by, The business knowledge comprises first business knowledge and second business knowledge, the first business knowledge is business domain knowledge of a source table of the SQL code to be analyzed, and the second business knowledge is business domain knowledge of each intermediate table and each intermediate table field in the SQL code to be analyzed. The method of generating business knowledge based on the SQL code blood relationship comprises the following steps: based on the SQL code blood relationship, data dictionary database matching is performed to acquire the first business knowledge; based on the SQL code blood relationship and the first business knowledge, the second business knowledge is determined.

5. The code annotation generation method according to claim 4, characterized in that, The method of determining the second business knowledge based on the SQL code blood relationship and the first business knowledge comprises the following steps: the SQL code blood relationship, the first business knowledge and a fourth question and answer prompt word are input into the large language model to obtain the second business knowledge output by the large language model.

6. The code annotation generation method according to claim 4, characterized by, The method of generating code comments of the SQL code to be analyzed through the large language model based on the SQL code blood relationship and the business knowledge comprises the following steps: The SQL code bloodline, the first business knowledge, the second business knowledge and the fifth question and answer prompt word are input into the large language model, and code annotation of the to-be-analyzed SQL code output by the large language model is obtained.

7. A code comment generation apparatus characterized by comprising: Comprise: An acquisition module is configured to acquire to-be-analyzed SQL code. A bloodline generation module is configured to generate, based on a large language model, a SQL code bloodline of the to-be-analyzed SQL code. A business knowledge generation module is configured to generate, based on the SQL code bloodline, business knowledge. A code annotation generation module is configured to generate, based on the SQL code bloodline and the business knowledge, code annotation of the to-be-analyzed SQL code by the large language model.

8. An electronic device comprising a memory, a processor, and a computer program stored on the memory and running on the processor, characterized in that, The processor executes the computer program to implement the code annotation generation method of any one of claims 1 to 6. 9.A non-transitory computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the code annotation generation method of any one of claims 1 to 6.

10. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to implement the code annotation generation method of any one of claims 1 to 6.