Source code comment generation system, source code comment generation method

The system accurately generates source code comments by associating design document terms with source code units, addressing inaccuracies in existing techniques and enhancing code comprehension.

JP2026054260APending Publication Date: 2026-03-26HITACHI LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
JP · JP
Patent Type
Applications
Current Assignee / Owner
Filing Date
2024-09-13
Publication Date
2026-03-26

AI Technical Summary

Technical Problem

Existing source code comment generation techniques often fail to accurately reflect the scope of the source code, leading to inaccurate comments due to insufficient or inappropriate design document inclusion.

Method used

A system and method that utilizes a computer with a processor and memory to associate terms from a design document with their meanings, divides source code into predetermined scope units, and generates comments using a large language model to ensure accuracy.

Benefits of technology

Enables the generation of comments that accurately reflect the scope and intent of the source code, improving understanding and clarity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 2026054260000001_ABST
    Figure 2026054260000001_ABST
Patent Text Reader

Abstract

Generates accurate comments appropriate to the scope of the source code. [Solution] The source code comment generation system has terminology information that associates terms used in design documents input to the source code comment generation system with the meanings of those terms, divides the source code into source code units of a predetermined scope, and generates commented source code that includes comments of a predetermined scope for the source code units, based on the meaning of the source code units of the scope and the terms with a predetermined relationship in meaning, the source code units of the scope and a predetermined language model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a comment generation technique for facilitating the understanding of source code.

Background Art

[0002] Conventionally, a technique has been proposed in which reference information is added to an input question sentence to generate a prompt, and the generated prompt is input into a large language model to generate an answer sentence. For example, in Patent Document 1, it is described in paragraph 0011 that "by adding a ~ sentence as reference information to the question sentence, a prompt for input into a large language model is generated."

Prior Art Documents

Patent Documents

[0003]

Patent Document 1

Summary of the Invention

Problems to be Solved by the Invention

[0004] However, as described in Patent Document 1, simply adding a design document with a character count that does not exceed the inputable character count limit to the input question sentence may not be sufficient. For example, the added design document may not necessarily be appropriate for the scope where comments are to be output in the source code constituting the question sentence. In such a case, the source code comments generated by the large language model may be inaccurate or may not accurately reflect the intention of the question sentence. Thus, in the prior art, there has been a need for a technique capable of generating comments with high accuracy according to the scope of the source code.

[0005] An object of the present invention is to provide a source code comment generation system and a source code comment generation method capable of generating comments with high accuracy according to the scope of the source code. [Means for solving the problem]

[0006] The source code comment generation system according to the present invention is a source code comment generation system that generates comments to source code using a computer having a processor and memory, wherein the source code comment generation system has term information that associates terms used in a design document input to the source code comment generation system with the meanings of those terms, and the processor divides the source code into source code of predetermined scope units, and generates commented source code including comments of predetermined scope units for the source code of predetermined scope units based on the meaning of the terms having a predetermined relationship with the meaning of the source code of predetermined scope units, the source code of predetermined scope units, and a predetermined language model. [Effects of the Invention]

[0007] According to the present invention, it is possible to generate comments with high accuracy according to the scope of the source code. Problems, configurations, and effects other than those described above will be clarified by the following description of embodiments. [Brief explanation of the drawing]

[0008] [Figure 1A] This figure shows an example of the configuration of a source code comment generator. [Figure 1B] This is a diagram illustrating an example of a computer schematic. [Figure 2] This is an example of a source code database that stores source code, commented source code, update date and time, and updater ID. [Figure 3] This is an example of a function source code database that stores function source code, function source code with comments, and the source code ID associated with the corresponding function source code. [Figure 4]This is an example of a block source code database that stores block source code, block source code with comments, and function source code IDs associated with the corresponding block source code. [Figure 5] This is an example of a row source code database that stores row source code, row source code with comments, and the block source code ID associated with the corresponding row source code. [Figure 6] This shows an example of a design document database that stores the document name, document content, and document vector of the design document. [Figure 7] This example shows a design document terminology database that stores term names, their meanings, and semantic vectors used in design documents. [Figure 8] This example shows an input section that performs source code and design document input, source code analysis, and design document terminology dictionary construction. [Figure 9] This figure shows an example of a display section that shows a source code ID selection button and the source code with comments. [Figure 10] This figure shows an example of the processing flow of the design document preprocessing unit. [Figure 11] This figure shows an example of the processing flow of the source code analysis unit. [Figure 12] This figure shows an example of the processing flow of the design document terminology generation unit. [Figure 13] This figure shows an example of the processing flow of the source code comment generation unit. [Figure 14] This figure shows an example of the flow of the function comment generation process. [Figure 15] This figure shows an example of the block comment generation process flow. [Figure 16] This figure shows an example of the flow of the line comment generation process. [Figure 17] This figure shows an example of the comment regeneration process flow. [Figure 18] Figure 15 shows an example of a results display screen for showing the search results and cosine similarity calculation results in S1504. [Figure 19A]This is a diagram for explaining a specific example of source code. [Figure 19B] This is a diagram showing an example of a comment generated in function units. [Figure 19C] This is a diagram showing an example of a comment generated in block units. [Figure 19D] This is a diagram showing an example of a comment generated in line units. [Figure 19E] This is a diagram showing an example of a comment regenerated in line units. [Figure 19F] This is a diagram showing an example of a comment regenerated in block units. [Figure 19G] This is a diagram showing an example of a comment regenerated in function units.

Embodiments for Carrying Out the Invention

[0009] Hereinafter, embodiments of the present invention will be described with reference to the drawings. The examples are for illustrating the present invention and are appropriately omitted and simplified for clarity of explanation. The present invention can be implemented in various other forms. Unless otherwise particularly limited, each component may be in a single or plural number. In the drawings, the positions, sizes, shapes, ranges, etc. of each component shown may not represent the actual positions, sizes, shapes, ranges, etc. for the purpose of facilitating understanding of the invention. Therefore, the present invention is not necessarily limited to the positions, sizes, shapes, ranges, etc. disclosed in the drawings.

[0010] As examples of various information, it may be described in expressions such as "table", "list", "queue", etc., but the various information may be represented by other data structures. For example, various information such as "XX table", "XX list", "XX queue" may be referred to as "XX information". When explaining identification information, expressions such as "identification information", "identifier", "name", "ID", "number", etc. are used, and these can be mutually replaced.

[0011] When there are multiple components with the same or similar function, they may be described using the same symbol but with different subscripts. Furthermore, if it is not necessary to distinguish between these multiple components, the subscripts may be omitted in the description.

[0012] In the examples, the processes performed by executing a program may be described. Here, the computer executes the program using a processor (e.g., CPU, GPU) and performs the processing defined in the program using memory resources (e.g., memory) and interface devices (e.g., communication ports). Therefore, the main entity performing the processing by executing the program may be the processor. Similarly, the main entity performing the processing by executing the program may be a controller, device, system, computer, or node having a processor. The main entity performing the processing by executing the program may be an arithmetic unit, and may include dedicated circuits that perform specific processing. Here, dedicated circuits include, for example, FPGAs (Field Programmable Gate Arrays), ASICs (Application Specific Integrated Circuits), CPLDs (Complex Programmable Logic Devices), etc.

[0013] The program may be installed on the computer from the program source. The program source may be, for example, a program distribution server or a storage medium readable by the computer. If the program source is a program distribution server, the program distribution server includes a processor and storage resources for storing the program to be distributed, and the processor of the program distribution server may distribute the program to other computers. In addition, in the embodiment, two or more programs may be implemented as one program, or one program may be implemented as two or more programs.

[0014] Figure 1A shows an example of the configuration of the source code comment generator 101 according to this embodiment. The source code comment generator 101 is a device that, in order to facilitate the developer's understanding of source code, accurately searches for design documents corresponding to the source code and outputs semantic source code comments using a large-scale language model device 105, while considering the scope units of the source code and the source code descriptions between those scopes. Scope refers to the range within which descriptions for executing source code, such as functions, code blocks, lines of code, methods, and files, are valid, depending on the hierarchy of the source code. In the following, as an example, the scope is explained using functions, code blocks, and lines of code as units of descriptions according to the hierarchy of the source code, but the same consideration may be applied to other descriptions as described above.

[0015] The source code comment generator 101 first inputs the design document 102 into the input unit 106, executes the design document preprocessing unit 111, and stores the output result in the design document DB 109e of the data holding unit 109. Next, the design document terminology DB generation unit 112 executes processing using the large-scale language model device 105 and stores the output result in the design document terminology DB 109f. The source code comment generator 101 also inputs the source code 103 into the input unit 106, executes the source code analysis unit 107, and stores the output result in the source code DB 109a. The source code comment generator 101 takes the source code from the source code DB 109a and the design document terminology DB 109f as input, executes the source code comment generation unit 108, and updates the source code DB 109a.

[0016] The source code comment generation unit 108 comprises a function processing unit 108a, a block processing unit 108b, and a line processing unit 108c, and generates appropriate comments for each scope based on the scope structure of the source code. For example, the function processing unit 108a generates comments for the entire function, the block processing unit 108b generates comments for code blocks consisting of multiple lines, and the line processing unit 108c generates comments for individual lines.

[0017] The large-scale language model device 105 is a component that hosts machine learning models used to perform natural language processing tasks with high accuracy. One example is GPT-4, provided by OpenAI. GPT-4 is a transformer-based large-scale language model with billions of parameters, capable of pre-training on vast amounts of text data and handling a variety of natural language processing tasks.

[0018] The information obtained via the input unit 106 includes source code 103 and design document 102. Source code 103 may be source code in different programming languages, such as Java® files or Python® files. Design document 102 may be a document containing diagrams and tables.

[0019] The display unit 110 displays the DB information stored in the data storage unit 109, which is a typical storage device in hardware. The display unit 110 also outputs the commented source code 104. The display unit 110 may use a typical display device such as a display.

[0020] The source code comment generation device 101 shown in Figure 1A can be realized by a general-purpose computer 1600, which includes, for example, a CPU 1601, memory 1602, an external storage device 1603 such as an HDD (Hard Disk Drive), a reader 1607 for reading and writing information to a portable storage medium 1608 such as a CD (Compact Disk) or USB memory, an input device 1606 for receiving various types of information such as a keyboard and mouse, an output device 1605 such as a display for outputting various types of information that are input and used for processing, a communication device 1604 such as a NIC (Network Interface Card) for connecting to a communication network, and an internal communication line (called a system bus) 1609 such as a system bus that connects these.

[0021] Furthermore, various data stored in the control device 3 or used for processing (for example, a database such as the source code DB 109a) can be realized by the CPU 1601 reading and using it from memory 1602 or external storage device 1603. In addition, each part of the control device 5 (for example, the source code analysis unit 107, the source code comment generation unit 108, the design document preprocessing unit 111, and the design document terminology DB generation unit 112) can be realized by the CPU 1601 loading a predetermined program stored in the external storage device 1603 into memory 1602 and executing it.

[0022] The aforementioned programs and data may be stored (downloaded) from the storage medium 1608 via the reading device 1607, or from the network via the communication device 1604, into the external storage device 1603, and then loaded onto the memory 1602 and executed by the CPU 1601. Alternatively, they may be loaded directly onto the memory 1602 via the reading device 1607 from the storage medium 1608, or from the network via the communication device 1604, and then executed by the CPU 1601.

[0023] In the following example, the control device 5 is described as being composed of a single computer, but all or part of these functions may be distributed across one or more computers, such as a cloud, and similar functions may be realized by them communicating with each other via a network.

[0024] The source code DB109a is explained using Figure 2. The source code DB109a includes source code ID 201, source code file name 202, source code 203, commented source code 204, source code update date and time 205, source code updater ID 206, commented source code update date and time 207, and commented source code updater ID 208. The source code DB109a is a database that stores source code output by the source code analysis unit 107 and commented source code to which source code comments have been added by the source code comment generation unit 108.

[0025] Source code ID 201 is an ID used to identify the source code. Source code file name 202 is the file name of the input source code. Source code 203 is the source code text. Commented source code 204 is the source code to which source code comments have been added by the source code comment generation unit 108 to source code 203. Source code update date and time 205 is the date and time when source code 203 was updated. Source code updater ID 206 is an ID that identifies the person who updated source code 203. Commented source code update date and time 207 is the date and time when commented source code 204 was updated. Commented source code updater ID 208 is an ID used to identify the person or AI that updated commented source code 204.

[0026] Figure 3 illustrates the function source code DB109b. The function source code DB109b includes function source code ID 301, function source code 302, commented function source code 303, and source code ID 304. The function source code DB109b is a database that stores the scope of a function in its source code, representing the range within which it is valid, as a single scope unit.

[0027] Function source code ID 301 is an ID used by the function processing unit 108a to divide and identify source code 203 in units of scope represented by a function. Function source code 302 is the text data of the function source code. Commented function source code 303 is source code to which the source code comment generation unit 108 has added source code comments to function source code 302. Source code ID 304 is source code ID 201 used to identify source code 203, which includes function source code 302.

[0028] In Figure 3, for example, the range 290 in which the function of the source code identified by source code ID "001" shown in Figure 2 is valid is stored as a single scope unit in the function source code 302 identified by function source code ID "001".

[0029] The block source code DB109c is explained using Figure 4. The block source code DB109c includes block source code ID 401, block source code 402, commented block source code 403, and function source code ID 404. The block source code DB109c is a database that stores the range in which a code block, which is the scope in function source code, is valid, as a single scope unit.

[0030] Block source code ID 401 is an ID used to identify block source code, which is obtained by the block processing unit 108b by dividing the function source code 302 into scope units represented by code blocks. Block source code 402 is the text data of the block source code. Commented block source code 403 is the source code to which the source code comment generation unit 108 has added source code comments to the block source code 402. Function source code ID 404 is function source code ID 301, which identifies the function source code 302 that includes block source code 402.

[0031] In Figure 4, for example, a certain code block within the function source code identified by the function source code ID "003" shown in Figure 3, with a valid range 390, is stored as a single scope unit in block source code 402, identified by block source code ID "001".

[0032] Figure 5 illustrates the row source code DB109d. Row source code DB109d includes row source code ID 501, row source code 502, commented row source code 503, and block source code ID 504. Row source code DB109d is a database that stores the range in which a code line, which is the scope in block source code, is valid, as a single scope unit.

[0033] Line source code ID 501 is an ID used to identify line source code obtained by the line processing unit 108c by dividing the block source code 402 into scope units represented by code lines. Line source code 502 is the text data of the line source code. Line source code with comments 503 is the source code to which the source code comment generation unit 108 has added source code comments to the line source code 502. Block source code ID 504 is block source code ID 401 used to identify the block source code 402 that contains the line source code 502.

[0034] In Figure 5, for example, a range 490 in which a certain line of code is valid, from the block source code identified by block source code ID "001" shown in Figure 4, is stored as a single scope unit in line source code 502, identified by line source code ID "001".

[0035] The design document DB109e is explained using Figure 6. The design document DB109e includes document ID 601, document internal ID 602, document name 603, document content 604, document vector 605, update date and time 606, and document publication scope 607. The design document DB109e is a database that stores the results executed by the design document preprocessing unit 111 on the input design document 102.

[0036] Document ID 601 is a unique ID used to identify the design document. Document ID 602 ​​is an ID used for identification within the document and indicates the internal structure of the document. Document name 603 is the name of the design document and corresponds to the file name of the design document. Document content 604 is text data that shows the specific contents of the design document and contains information related to the source code corresponding to document ID 602. Document vector 605 is the document content 604 converted into a numerical vector and is used to search the contents of the document. Update date and time 606 indicates the date and time when the document ID 601 was last updated. Document access range 607 is an attribute that indicates the scope to which the design document is made public and the scope of users who can access it. For example, if the access range is Public, all users can access it, and if it is Project01, only members with access rights to Project01 can access it. Design documents identified by document ID 601 are generally large in volume, and processing them in one go can be resource-intensive. Therefore, in Figure 6, the design document is divided and stored as one or more documents within a document, each identified by document ID 602.

[0037] The design document terminology database 109f is explained using Figure 7. The design document terminology database 109f includes term ID 701, term name 702, term meaning 703, term meaning vector 704, document ID 705, update date and time 706, and updater ID 707. The design document terminology database 109f is a database that stores the meanings of terms obtained as a result of processing using the large-scale language model device 105.

[0038] Term ID 701 is a unique ID used to identify a term within a design document. Term Name 702 is the name of the term used within the design document. Term Meaning 703 is text data that shows the specific meaning of the term and contains a description of the term. Term Meaning Vector 704 is a numerical vector derived from Term Meaning 703 and is used to search for the meaning of a term within a design document. Document ID 705 is an ID that identifies the design document containing the term. Update Date and Time 706 indicates the date and time when Term ID 701 was last updated. Updater ID 707 is an ID used to identify the person or AI that updated the term.

[0039] The input unit 106 will be explained using Figure 8. The input unit 106 is an interface consisting of a screen with, for example, the following four buttons. The input unit 106 includes a source code input button 801, a design document input button 802, a source code analysis execution button 803, and a design document terminology dictionary construction execution button 804. The user selects source code 103 using the source code input button 801 and selects design document 102 using the design document input button 802. Then, the user starts processing in the design document preprocessing unit 111 using the design document terminology dictionary construction execution button 804. Finally, the user starts processing in the source code analysis unit 107 using the source code analysis execution button 803 and generates commented source code 104.

[0040] The display unit 110 will be explained using Figure 9. The display unit 110 is an interface consisting of a screen for visually displaying information from the source code DB 109a and the commented source code 104. The display unit 110 includes a source code ID selection button 901, a source code display area 902, and a commented source code display area 903. When the source code ID selection button 901 is pressed, the source code 203 and the commented source code 204 corresponding to source code ID 201 are displayed on the display unit 110. The display unit 110 also includes an external output button 904, and when this button is pressed, the commented source code 104 can be exported.

[0041] The processing of the design document preprocessing unit 111 will be explained using Figure 10. The design document preprocessing unit 111 is a component for preprocessing the design document 102. An example of its processing flow is shown below.

[0042] S1001: The design document preprocessing unit 111 reads the file format of the design document 102 and extracts text. For example, the design document preprocessing unit 111 obtains text data from PDF or Word files.

[0043] S1002: The design document preprocessing unit 111 removes non-text data from the text, such as blank lines and symbols. For example, the design document preprocessing unit 111 deletes blank lines and filters out paragraph marks, line break codes, tab characters, and special characters such as "¥".

[0044] S1003: The design document preprocessing unit 111 divides the text into segments of a fixed number of characters. For example, it divides the text into segments of 500 characters each.

[0045] S1004: The design document preprocessing unit 111 vectorizes the text. For example, it uses natural language processing techniques to convert each segmented text data into a numerical vector. S1005: The design document preprocessing unit 111 updates the design document DB 109e with the document ID 602, document name 603, document content 604, document vector 605, and update date and time 606. For example, the design document preprocessing unit 111 generates the document ID 602 ​​as a unique identifier, sets the document name 603 to the input file name, sets the document content 604 to the extracted and processed text data, and sets the document vector 605 to the converted numerical vector. Furthermore, the design document preprocessing unit 111 sets the update date and time 606 to the current date and time and stores it in the design document DB 109e.

[0046] The processing of the source code analysis unit 107 will be explained using Figure 11. The source code analysis unit 107 is a component that analyzes the source code 103 and updates the source code DB 109a. An example of its processing flow is shown below.

[0047] S1101: The source code analysis unit 107 updates the source code file name 202, source code 203, source code update date and time 205, and source code updater ID 206 in the source code DB 109a. For example, for a newly entered source code 103, the source code analysis unit 107 sets the source code file name 202 and stores the source code 203. The source code analysis unit 107 sets the current date and time for the source code update date and time 205 and sets the ID that identifies the person who made the update for the source code updater ID 206.

[0048] Figure 12 illustrates the processing of the design document terminology database generation unit 112. This flowchart shows the process by which the design document terminology database generation unit 112 retrieves design documents from the design document database 109e, extracts terms from the documents using the large-scale language model device 105, and vectorizes their meanings. This process exemplifies a case where a design document with a certain document ID stored in the design document database 109e is divided at S1003 in Figure 10, and processing is performed for each document ID stored at S1005. However, similar processing is performed for other design documents.

[0049] S1201: This is the process by which the design document terminology database generation unit 112 retrieves a document from the design document database 109e. In this process, the design document terminology database generation unit 112 refers to the document ID 602 ​​in the design document database 109e and retrieves the document content 604.

[0050] S1202: This is the process in which the design document terminology database generation unit 112 extracts terms from the document. In this process, the design document terminology database generation unit 112 extracts terms from the design document based on the acquired document content 604. For example, the design document terminology database generation unit 112 extracts terms from the design document when the large-scale language model device 105 executes a prompt containing a term extraction command. The following processes S1203 to S1205 are performed for each term extracted in S1202.

[0051] S1203: This is the process in which the design document terminology database generation unit 112 outputs the meaning of the extracted terms from the document content 604 using the large-scale language model device 105. Alternatively, the input may be a combination of the document content 604 of document ID 601 instead of document ID 602, or all document content 604 present in the design document database 109e.

[0052] S1204: The design document terminology database generation unit 112 performs the process of vectorizing the meaning of terms. The design document terminology database generation unit 112 converts the meaning of the extracted terms into numerical vectors, for example, using natural language processing technology.

[0053] S1205: This is the process by which the design document terminology DB generation unit 112 stores the term name 702, the term meaning 703, the term meaning vector 704, and the document ID 705 in the design document terminology DB 109f. The design document terminology DB generation unit 112 sets the extracted term name as the term name 702, the meaning generated by the large-scale language model device 105 and obtained from the large-scale language model device 105 as the term meaning 703, the vectorized meaning as the term meaning vector 704, and the document ID 602 ​​as the document ID 705, and stores them in the design document terminology DB 109f.

[0054] The processing of the source code comment generation unit 108 is explained using Figure 13. This flowchart shows the process of generating comments from source code for each specific scope unit (function, block, line), adding appropriate comments by referring to the design document corresponding to each scope unit, and regenerating for each specific scope unit (function, block, line) to improve accuracy. As will be explained in detail below, the source code comment generation unit 108 processes with functions as the scope, which are higher levels, then processes with blocks as the scope, which are middle levels, and then processes with lines as the scope, which are lower levels. Therefore, even if there is no matching description pattern in the translation dictionary, as in the conventional technology, the design document corresponding to the source code can be searched with high accuracy by changing the scope of the hierarchy in the source code being searched. Then, processing is performed with blocks as the scope, which are middle levels, by incorporating the processing results of the lower levels, and processing is performed with functions as the scope, which are higher levels, by incorporating the processing results of the middle levels.

[0055] Thus, in the processing of the source code comment generation unit 108, processing corresponding to the scope of each hierarchy, such as the upper, middle, and lower levels of the source code, is performed step by step toward the lower level, and then recursively toward the original middle level and the original upper level. In other words, by recursively executing LLM on a source code scope basis and outputting source code comments, it becomes possible to add source code comments while considering the hierarchical units and the influence of their structure between source code sections.

[0056] In the flowchart, the extracted scope unit is shown as a "function" as an example, but as mentioned above, it could also be a "class," "method," or "source code file."

[0057] S1301: The source code comment generation unit 108 is responsible for extracting functions from the source code. In this process, the start and end positions of each function are identified from the source code 103, and each function is extracted as an independent scope unit. For example, in a Java program, the source code comment generation unit 108 detects functions from method declaration keywords such as "void" and "int", divides each function from start to finish into a single block, and extracts the divided function block. At this time, the function processing unit 108a of the source code comment generation unit 108 registers the extracted function in function source code 302 along with function source code ID 301 and source code ID 304.

[0058] S1302: The source code comment generation unit 108 generates comments for each function, which is a single scope. This process refers to the design document 102 for each function and generates appropriate comments based on the content of the design document corresponding to the function source code 302. For example, if the extracted function performs database connection processing, the source code comment generation unit 108 refers to the explanation of database connection in the design document and generates comments for that function.

[0059] S1303: This is the process by which the source code comment generation unit 108 generates comments in units of code blocks, which constitute a single scope. The source code comment generation unit 108 extracts code blocks consisting of multiple lines within a function and generates comments for those blocks. In this process, the source code comment generation unit 108 refers to the relevant section of the design document and assigns appropriate comments to the multi-line processing that constitutes the code block. For example, if an error handling block exists, the source code comment generation unit 108 generates comments for that block by referring to the section of the design document related to error handling.

[0060] S1304: This is the process by which the source code comment generation unit 108 generates comments in units of code lines, which constitute a single scope. For each code line within a code block, the source code comment generation unit 108 refers to the design document and generates an appropriate comment for each line. For example, for a line that performs a specific calculation, the source code comment generation unit 108 refers to the algorithm description section of the design document and adds a comment explaining the purpose and meaning of that calculation.

[0061] S1305: This is the process by which the source code comment generation unit 108 regenerates the generated comments. In this process, the source code comment generation unit 108 re-examines the comments for a specific scope unit (function, block, line) that were initially generated and makes final adjustments to further improve accuracy and applicability. For example, the source code comment generation unit 108 re-examines the content of the comments for functions and blocks, verifies whether there are any inconsistencies or errors in the comments for functions, and corrects and regenerates the comments as necessary.

[0062] Figure 14 illustrates the process performed by the function processing unit 108a. This flowchart shows the process by which the function processing unit 108a takes function source code as input, outputs the meaning of that process, searches for the design document with the closest content in the design document DB 109e, generates appropriate comments, and adds them to the function source code.

[0063] S1401: This process involves the function processing unit 108a receiving the function source code 302 as input, querying the large-scale language model device 105 for the meaning of that processing, and obtaining the result from the large-scale language model device 105. In this process, the large-scale language model device 105 analyzes the contents of the function source code input from the function processing unit 108a and outputs the intended meaning of that processing in natural language. For example, if the design document for calculating cosine similarity is in Japanese, the large-scale language model device 105 will output the meaning of the processing of the function source code output by the function processing unit 108a and queried, in Japanese.

[0064] S1402: The function processing unit 108a is responsible for vectorizing the meaning of the function source code. The function processing unit 108a converts the meaning of the process output in S1401 into a numerical vector.

[0065] S1403: The function processing unit 108a searches the design document terminology DB 109f for the closest meaning of the term 703 to the meaning of the function source code, and calculates the cosine similarity between the term and the meaning of the term.

[0066] S1404: The function processing unit 108a determines whether the cosine similarity calculated in S1403 is equal to or greater than a predetermined threshold.

[0067] S1405: If the cosine similarity is greater than or equal to a threshold (S1404; YES), the function processing unit 108a considers that the processing of the function source code and the meaning of the terms in the design document are sufficiently consistent, and inputs the function source code 302 and the meaning of the terms 703 to the large-scale language model device 105. The large-scale language model device 105 uses this input information to perform a natural language processing task, and the function processing unit 108a obtains commented function source code 303 in which the meaning of the terms obtained from the execution is embedded as comments in the function source code.

[0068] S1406: This is the process in which the function processing unit 108a updates the function source code DB109b with the commented function source code 303. The function processing unit 108a adds the generated comments to the function source code and updates the function source code DB109b.

[0069] Figure 15 illustrates the process performed by the block processing unit 108b. This flowchart shows the process by which the block processing unit 108b extracts block source code from function source code, outputs the meaning of that process, searches for the design document with the closest content in the design document DB 109e, generates appropriate comments, and adds them to the block source code.

[0070] S1501: This is the process by which the block processing unit 108b extracts block source code 402 from function source code 302. In this process, the block processing unit 108b identifies the start and end positions of each code block from the function source code 302 and extracts each code block as an independent scope unit. For example, in a Java program, if there is one or more blank lines, the block processing unit 108b divides the code lines from the preceding blank line to the blank line in question into one block and extracts the divided block. At this time, the block processing unit 108b of the source code comment generation unit 108 registers the extracted block along with block source code ID 401 and function source code ID 404 in block source code 402.

[0071] S1502: The block processing unit 108b takes block source code 402 as input, queries the large-scale language model device 105 for the meaning of the processing, and obtains the result from the large-scale language model device 105. In this process, the large-scale language model device 105 analyzes the contents of block source code 402 input from the block processing unit 108b and outputs the intended meaning of the processing in natural language.

[0072] S1503: The block processing unit 108b performs the process of vectorizing the meaning of the block source code 402. The block processing unit 108b converts the meaning of the process output in S1502 into a numerical vector.

[0073] S1504: This is the process in which the block processing unit 108b searches the design document terminology database 109f for the design document that most closely matches the meaning of the block source code, and calculates the cosine similarity between the meaning of the term and the design document. In this process, the block processing unit 108b compares the vectorized meaning with the contents of the design document terminology database 109f and identifies the design document with the highest similarity.

[0074] S1505: The block processing unit 108b determines whether the cosine similarity calculated in S1504 is equal to or greater than a predetermined threshold.

[0075] S1506: If the cosine similarity is greater than or equal to a threshold (S1505; YES), the block processing unit 108b inputs the block source code 402 and the term meanings 703 to the large-scale language model device 105. The large-scale language model device 105 uses this input information to perform a natural language processing task, and the block processing unit 108b obtains a commented block source code 403 in which the term meanings obtained from the execution are embedded as comments in the block source code.

[0076] S1507: This is the process in which the block processing unit 108b updates the block source code DB109c with the commented block source code 403. The block processing unit 108b adds the generated comments to the block source code and updates the block source code DB109c.

[0077] Figure 16 illustrates the process performed by the row processing unit 108c. This flowchart shows the process by which the row processing unit 108c extracts row source code from block source code, outputs the meaning of that process, searches for the design document with the closest content in the design document DB 109e, generates appropriate comments, and adds them to the row source code.

[0078] S1601: This is the process by which the line processing unit 108c extracts line source code 502 from block source code 402. In this process, the line processing unit 108c identifies the start and end positions of each line of code from block source code 402 and extracts each line as an independent scope unit. For example, in a Java program, the line processing unit 108c detects each line of code based on the semicolon ";" and newline character, divides it into individual lines of code, and extracts the block of the divided lines of code. At this time, the line processing unit 108c of the source code comment generation unit 108 registers the extracted lines of code in line source code 502 along with line source code ID 501 and block source code ID 504.

[0079] S1602: The line processing unit 108c takes line source code 502 as input, queries the large-scale language model device 105 for the meaning of that process, and retrieves the result from the large-scale language model device 105. In this process, the large-scale language model device 105 analyzes the content of line source code 502 input from the line processing unit 108c and outputs the intended meaning of that process in natural language. For example, for lines that perform a specific calculation process, the line processing unit 108c outputs the purpose and meaning of that calculation process in natural language.

[0080] S1603: Line processing unit 108c is responsible for vectorizing the meaning of the processing in line source code 502. Line processing unit 108c converts the meaning of the processing output in S1602 into a numerical vector.

[0081] S1604: The line processing unit 108c searches the design document database 109f for the design document that most closely matches the meaning of the processing in line source code 502, and calculates the cosine similarity between the meaning of the term and the design document. In this process, the vectorized meaning is compared with the contents of the design document database 109f to identify the design document with the highest similarity.

[0082] S1605: The row processing unit 108c determines whether the cosine similarity calculated in S1604 is equal to or greater than a predetermined threshold.

[0083] S1606: If the cosine similarity is greater than or equal to a threshold (S1605; YES), the line processing unit 108c inputs the line source code 502 and the term meaning 703 to the large-scale language model device 105. The large-scale language model device 105 uses this input information to perform a natural language processing task, and the line processing unit 108c obtains commented line source code 503 in which the term meaning obtained from the execution is embedded as a comment in the line source code.

[0084] S1607: This is the process in which the row processing unit 108c updates the row source code DB109d with the commented row source code 503. The row processing unit 108c adds the generated comment to the row source code and updates the row source code DB109d.

[0085] Figure 17 illustrates the process performed by the comment regeneration processing unit 108d. This flowchart shows the process by which the comment regeneration processing unit 108d re-examines the commented source code generated in specific scope units (functions, blocks, lines) and makes final adjustments to further improve accuracy and applicability.

[0086] S1701: This is the process by which the comment regeneration processing unit 108d retrieves the commented line source code 503 and block source code ID 504 from the line source code DB 109d. In this process, the comment regeneration processing unit 108d retrieves the commented line source code 503 for each code line and the block source code ID 504 corresponding to that commented line source code 503 from the line source code DB 109d.

[0087] S1702: This is the process by which the comment regeneration processing unit 108d retrieves block source code 402 and function source code ID 404 from block source code DB 109c. In this process, the comment regeneration processing unit 108d retrieves block source code 402 and function source code ID 404 corresponding to block source code ID 504 from block source code DB 109c, based on the block source code ID 504 obtained in S1701.

[0088] S1703: This is the process by which the comment regeneration processing unit 108d retrieves the function source code 302 from the function source code DB 109b. In this process, the comment regeneration processing unit 108d retrieves the function source code 302 corresponding to the function source code ID 404 from the function source code DB 109b, based on the function source code ID 404 obtained in S1702.

[0089] S1704: This is the process in which the comment regeneration processing unit 108d takes the commented function source code 303 and the commented block source code 403 as input and regenerates the comments in the commented line source code 503 using the large-scale language model device 105.

[0090] S1705: This is the process in which the comment regeneration processing unit 108d updates the row source code DB109d with the commented row source code 503. The comment regeneration processing unit 108d adds the comments regenerated in S1704 to the row source code and updates the row source code DB109d.

[0091] S1706: This is the process in which the comment regeneration processing unit 108d takes the commented line source code 503 and the commented function source code 303 as input and regenerates the comments of the commented block source code 403 using the large-scale language model device 105.

[0092] S1707: This is the process in which the comment regeneration processing unit 108d updates the block source code DB109c with the commented block source code 403. The comment regeneration processing unit 108d adds the comments regenerated in S1706 to the block source code and updates the block source code DB109c.

[0093] S1708: This is the process in which the comment regeneration processing unit 108d takes the commented line source code 503 and the commented block source code 403 as input and regenerates the comments of the commented function source code 303 using the large-scale language model device 105.

[0094] S1709: This is the process in which the comment regeneration processing unit 108d updates the function source code DB109b with the commented function source code 303. The comment regeneration processing unit 108d adds the comments regenerated in S1708 to the function source code and updates the function source code DB109b.

[0095] In the above explanation, in S1403 in Figure 14, S1504 in Figure 15, and S1604 in Figure 16, in order to expedite the processing, the obtained commented function source code, commented block source code, and commented line source code are not displayed on the screen before proceeding to the next step. However, as shown in Figure 18, for example, the block processing unit 108b may output the search results and the cosine similarity calculation results from S1504 shown in Figure 15 to the display unit 110.

[0096] Figure 18 shows an example of a results display screen for displaying the search results and cosine similarity calculation results in S1504 shown in Figure 15.

[0097] As shown in Figure 18, the results display screen 1800 displays the following items in association: the search result 1801, which shows the meaning of a term retrieved from the design document terminology DB 109f using the meaning of the block source code processing as a query; the term name 1802, which corresponds to the term shown in the search result; the document name 1803 of the design document containing the term name 1802; the update date and time of the document 1804; and the score 1805, which is the result of calculating the cosine similarity (degree of cosine similarity). For example, on the results display screen 1800, the score value for 1805 is "0.2343," and the record 1806, which has the highest cosine similarity, displays the search result "The next … NF9" for the term name "getParameter…" searched from the design document term DB109f, the document name of the design document containing that term (document name 603 corresponding to document ID 705) is "wiki…," and the update date and time of the design document (update date and time 706) is "Sun Oct 15 16:03:30 2023."

[0098] The leftmost column is the search result ID used to identify each search result. In this example, the top 10 terms with the highest cosine similarity scores are displayed as search results. Figure 18 illustrates the display of the processing results for S1504 shown in Figure 15, but similar screens may be output for S1403 in Figure 14 and S1604 in Figure 16. By displaying such a results screen, the user can easily check the information that forms the basis of the commented source code 104 that is ultimately displayed in the display section (for example, information such as the score).

[0099] The process of the source code comment generation unit 108 will be explained in more detail below, based on Figures 13 and 17. A specific example of the source code to be targeted is shown in Figure 19A.

[0100] First, in S1302, the source code comment generation unit 108 (function processing unit 108a) generates comments by referring to the source code and the design document terminology DB109f for each function, which is a single scope. Figure 19B shows an example of comments initially generated for each function. In Figure 19B, it can be seen that the function-specific comments 1901 have been generated by the processing in S1302.

[0101] Next, the source code comment generation unit 108 (block processing unit 108b) generates comments for the blocks within the function in S1303. Figure 19C shows that the comment 1902 for the blocks within the function is generated by the processing in S1303.

[0102] Next, the source code comment generation unit 108 (line processing unit 108c) generates comments for each line in S1304. Figure 19D shows that comments 1903a, 1903b, and 1903c are generated for each line by the processing in S1304.

[0103] Next, the source code comment generation unit 108 (comment regeneration processing unit 108d) executes S1305. This will be explained in detail below.

[0104] 1. Regeneration process for commented line source code 503 (Figure 17 S1704) When the S1704 process is performed, the regeneration result is obtained as a line-by-line regeneration result, as shown in Figure 19E. In S1704, the dates and text of the comments for the lines generated in S1304 are written in a more appropriate Japanese style by the large-scale language model device 105. That is, the comment regeneration processing unit 108d inputs the commented function source code generated in S1302, the commented block source code generated in S1303, and the terms used in these comments into the large-scale language model device 105, similar to the process in S1606. Then, the comment regeneration processing unit 108d updates the commented line source code 503, which was updated in S1607, to include new comments (comments 1904a, 1904b, 1904c) for each line obtained from the results of the natural language processing task performed by the large-scale language model device 105.

[0105] 2. Regeneration process for commented block source code 403 (Figure 17 S1706) When the S1706 process is performed, the regeneration result is obtained as a block-level regeneration result, as shown in Figure 19F. In S1706, the date and text of the comments for the blocks generated in S1303 are written in a more appropriate Japanese style by the large-scale language model device 105. That is, the comment regeneration processing unit 108d inputs the commented function source code generated in S1302, the commented line source code generated in S1304, and the terms used in these comments into the large-scale language model device 105, similar to the process in S1506. Then, the comment regeneration processing unit 108d updates the commented block source code 403, which was updated in S1507, to include a new comment (comment 1905) for the block obtained from the results of the natural language processing task performed by the large-scale language model device 105.

[0106] 3. Regeneration process for commented function source code 303 (Figure 17 S1708) When the S1708 process is performed, the regeneration result is obtained as a function-level regeneration result, as shown in Figure 19G. In S1708, the date and text of the comments for the function generated in S1302 are written in a more appropriate Japanese style by the large-scale language model device 105. That is, the comment regeneration processing unit 108d inputs the commented block source code generated in S1303, the commented line source code generated in S1304, and the terms used in these comments into the large-scale language model device 105, similar to the process in S1405. Then, the comment regeneration processing unit 108d updates the commented function source code 303 updated in S1406 to include a new comment (comment 1906) for the function obtained from the results of the natural language processing task performed by the large-scale language model device 105.

[0107] As described above, the source code comment generation unit 108 (comment regeneration processing unit 108d) inputs source code and terminology from a different hierarchical level (e.g., function unit, block unit) into the large-scale language model device 105. The comment regeneration processing unit 108d then updates the commented source code generated in the predetermined scope units (e.g., line unit) with new comments (e.g., comments reflecting function-unit comments, block-unit comments) obtained through analysis by the large-scale language model device 105. This process allows for a re-examination of the generated scope-unit comments and final adjustments to improve accuracy and applicability. As a result, it becomes possible to add source code comments that take into account the scope influence between the design document and the source code with even greater accuracy.

[0108] The embodiment has been described above with reference to the drawings. In this embodiment, as described with reference to Figures 1, 13, etc., a source code comment generation system (for example, a source code comment generation device 101) that generates comments to source code using a computer having a processor and memory, the source code comment generation system has terminology information (for example, design document terminology DB109f) that associates terms used in the design document input to the source code comment generation system with the meaning of those terms, and the processor generates the source code into predetermined scope units (for example, function units, block units, line units) (for example, function source code DB109b, block source code DB109c, The source code is divided into rows (DB109d) (for example, processing S1301 in Figure 13, S1501 in Figure 15, and S1601 in Figure 16), and based on the above-mentioned terms that have a predetermined relationship (for example, a relationship where the cosine similarity is greater than or equal to a predetermined threshold) with the meaning of the source code in the above-mentioned scope unit, the above-mentioned source code in the above-mentioned scope unit, and a predetermined language model (for example, processing S1404 in Figure 14, processing S1505 in Figure 15, and processing S1605 in Figure 16), commented source code including the above-mentioned predetermined scope unit comments is generated for the above-mentioned scope unit source code (for example, processing S1302, S1303, and S1304 in Figure 13).

[0109] This process enables the generation of highly accurate comments tailored to the scope of the source code. For example, it becomes possible to generate comments that consider the impact of references in design documents on a per-source code scope basis. Specifically, according to this embodiment, even if there is no matching description pattern in the translation dictionary, as in the conventional technology, it is possible to accurately search for the corresponding design document by changing the source code scope being searched.

[0110] Furthermore, as explained in S1203 to S1205 in Figure 12, the above processor is The terms used in the above design document are input into a predetermined language model (for example, a language model similar to the one above), and the meanings of the input terms obtained from the predetermined language model are associated with the input terms to generate term information. This makes it possible to generate a term dictionary that includes highly accurate term meanings obtained from the results of various natural language processing tasks.

[0111] Furthermore, as explained in S1003 to S1005 of Figure 10, the processor divides the text contained in the input design document into predetermined units (for example, units of 500 characters), performs natural language processing on each of the divided texts, and stores them as design documents for generating the term information. As a result, the target of natural language processing is subdivided, making it possible to generate a term dictionary while reducing the processing load.

[0112] Furthermore, as explained in Figure 3-5, the processor divides the source code into predetermined scope units, in units of functions, blocks, and lines. This makes it possible to generate comments according to the various levels of the source code, particularly functions, code blocks, and lines of code.

[0113] Furthermore, as explained in Figures 10, 12, 14-16, etc., the processor converts the meaning of the terms obtained through the natural language processing into numerical vectors. This makes it possible to quantitatively and accurately grasp the semantic similarity between terms.

[0114] Furthermore, as explained in Figures 1, 14-16, etc., the processor inputs the source code in the scope unit into the predetermined language model (for example, the process in S1401 in Figure 14, the process in S1502 in Figure 15, and the process in S1602 in Figure 16), obtains the meaning of the source code in the scope unit analyzed by the predetermined language model, and determines the predetermined relationship between the obtained meaning of the source code in the scope unit and the meaning of the terms (for example, the process in S1404 in Figure 14, the process in S1505 in Figure 15, and the process in S1605 in Figure 16). This makes it possible to determine the predetermined relationship (for example, by determining cosine similarity) based on the highly accurate meaning of the source code obtained from the execution results of the natural language processing task.

[0115] Furthermore, as explained in Figures 1, 14-16, etc., the processor inputs the scope-unit source code and the terms whose predetermined relationships have been determined into the predetermined language model, obtains commented source code including the scope-unit comments analyzed by the predetermined language model (for example, the process in S1404 in Figure 14, the process in S1505 in Figure 15, and the process in S1605 in Figure 16), and performs the above generation by updating the scope-unit source code with the obtained commented source code (S1406, S1507, S1607). As a result, for source code containing terms that satisfy the predetermined relationships, an even more accurate comment can be obtained by having the same language model perform a natural language processing task.

[0116] Furthermore, as explained in Figures 13 and 17, the processor inputs source code and terminology from a different hierarchical level of the specified scope unit than the commented source code generated in the specified scope unit into the specified language model, and updates the commented source code generated in the specified scope unit with new comments (for example, comments reflecting function-level comments or block-level comments) obtained by analysis by the specified language model. This makes it possible to generate source code that includes comments reflecting comments from other levels with even higher accuracy than the accuracy obtained by executing a natural language processing task using the same language model. As a result of recursively executing a large-scale language model in scope units of the source code structure and outputting source code comments, it becomes possible to add source code comments that take into account the influence of scope units and their structures between source code.

[0117] Furthermore, as explained in Figures 15 and 18, the processor outputs information to the display device screen (for example, the results display screen for displaying the search results and cosine similarity calculation results in S1504 shown in Figure 15) that associates the meaning of a term that has a predetermined relationship with the meaning of the source code in the scope unit, the term that shows that meaning, the design document containing that term, and a score that shows the degree of the predetermined relationship. This allows users of the system to easily check the information that underlies the comments in the commented source code obtained by the system (for example, the meaning of the term and the score value).

[0118] The present invention is not limited to the embodiments described above, and in the implementation stage, the components can be modified and implemented without departing from the gist of the invention, or the multiple components disclosed in the embodiments can be appropriately combined. [Explanation of Symbols]

[0119] 101 Source Code Comment Generator 102 Design document 103 Source Code 104 Source code with comments 105 Large-scale language model device 106 Input section 107 Source Code Analysis Department 108 Source Code Comment Generation Unit 108a Function Processing Unit 108b Block Processing Unit 108c Line Processing Unit 108d Comment regeneration 109 Data storage unit 109a Source Code Database 109b Function Source Code DB 109c Block Source Code DB 109e Design document DB 109f Design document terminology DB 110 Display section 111 Design Document Preprocessing Section 112 Design terminology generator 201 Source Code ID 202 Source code file name 203 Source Code 204 Source code with comments 205 Source code update date 206 Source code updater ID 207 Commented source code update date 208 Source code updater ID with comments 301 Function source code ID 302 Function Source Code 303 Commented function source code 304 Source Code ID 401 Block Source Code ID 402 Block Source Code 403 Commented block source code 404 Function Source Code ID 501 line source code ID 502 lines of source code 503 Commented line source code 504 Block Source Code ID 601 Document ID 602 Document ID 603 Document name 604 Document Contents 605 Document Vector 606 Update date and time 607 Scope of Document Disclosure 701 Term ID 702 Term name 703 Meaning of Terms 704 Semantic vectors of terms 705 Document ID 706 Update date and time 707 Updater ID 801 Source code input button 802 Design Document Input Button 803 Source code analysis execution button 804 Execute button for building design document terminology dictionary 901 Source Code ID Selection Button 902 Source code display area 903 Source code display area with comments 904 External Output

Claims

1. A source code comment generation system that generates comments to source code using a computer having a processor and memory, The aforementioned source code comment generation system is: The source code comment generation system has terminology information that associates terms used in the design document input with the meaning of those terms, The aforementioned processor, The aforementioned source code is divided into source code units of a predetermined scope, Based on the meaning of the term having a predetermined relationship with the meaning of the source code within the scope unit, the source code within the scope unit, and a predetermined language model, the system generates commented source code that includes comments within the predetermined scope unit for the source code within the scope unit. A source code comment generation system characterized by the following features.

2. The aforementioned processor, The terminology used in the aforementioned design document is input into a predetermined language model. The system generates term information by associating the meaning of the input term obtained from the predetermined language model with the input term. The source code comment generation system according to feature 1.

3. The aforementioned processor, The text included in the input design document is divided into predetermined units, Each of the divided texts is subjected to natural language processing and stored as a design document for generating the term information. The source code comment generation system according to feature 2.

4. The aforementioned processor, The division into predetermined scope units is performed at the unit of functions, blocks, and lines that constitute the source code. The source code comment generation system according to feature 1.

5. The aforementioned processor, The meaning of the term obtained by performing the aforementioned natural language processing is converted into a numerical vector. The source code comment generation system according to feature 3.

6. The aforementioned processor, The source code of the scope unit is input into the predetermined language model, and the meaning of the source code of the scope unit analyzed by the predetermined language model is obtained. The predetermined relationship between the meaning of the acquired source code in the scope unit and the meaning of the term is determined. The source code comment generation system according to feature 1.

7. The aforementioned processor, The source code of the scope unit and the term for which the predetermined relationship has been determined are input into the predetermined language model, and commented source code including the comment of the scope unit analyzed by the predetermined language model is obtained. The generation is performed by updating the source code for each scope with the acquired commented source code. The source code comment generation system according to feature 6.

8. The aforementioned processor, The source code and terminology of a predetermined scope unit at a different hierarchical level from the commented source code generated in the predetermined scope unit are input into the predetermined language model. The commented source code generated in the predetermined scope unit is updated with new comments obtained by analysis using the predetermined language model. The source code comment generation system according to feature 1.

9. The aforementioned processor, The system outputs information on the display device screen that associates the meaning of a term having a predetermined relationship with the meaning of the source code in the scope unit, the term representing that meaning, the design document containing that term, and a score indicating the degree of the predetermined relationship. The source code comment generation system according to feature 1.

10. A source code comment generation method that generates comments to source code using a computer, The computer is then input to a computer that contains terminology information that associates the terms used in the design document with the meanings of those terms. The aforementioned source code is divided into source code units of a predetermined scope, Based on the meaning of the term having a predetermined relationship with the meaning of the source code within the scope unit, the source code within the scope unit, and a predetermined language model, the system generates commented source code that includes comments within the predetermined scope unit for the source code within the scope unit. A method for generating source code comments characterized by the following features.

Citation Information

Patent Citations

  • Text generation device and text generation method

    JP7325152B1