system
A system that analyzes and comments code using static and dynamic analysis, generating natural language explanations, addresses the inefficiency of understanding and commenting on others' code, allowing for rapid comprehension.
Patent Information
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2024-08-26
- Publication Date
- 2026-03-10
AI Technical Summary
Understanding and adding comments to others' code is time-consuming and cumbersome, hindering efficient program development, especially when learning new frameworks or algorithms.
A system that inputs code, analyzes its structure and functionality using static and dynamic analysis, generates natural language comments, and inserts them into the code at appropriate positions, utilizing an abstract syntax tree for detailed analysis.
Enables users to quickly and accurately understand others' code, reducing the time required to learn new frameworks and algorithms by providing commented code that is easy to comprehend.
Smart Images

Figure 2026041589000001_ABST
Abstract
Description
[Technical Field]
[0001] The technology of the present disclosure relates to a system. [Background technology]
[0002] Patent document 1 discloses a persona chatbot control method performed by at least one processor, the method including the steps of receiving a user utterance, adding the user utterance to a prompt including an instruction sentence related to a description of the chatbot character, encoding the prompt, and inputting the encoded prompt into a language model to generate a chatbot utterance in response to the user utterance. [Prior art documents] [Patent documents]
[0003] [Patent Document 1] Japanese Patent Publication No. 2022-180282 Summary of the Invention [Problem to be solved by the invention]
[0004] In program development, understanding code written by others requires a great deal of time and effort. In particular, when learning a new framework or algorithm, it is necessary to analyze and understand the structure and function of the code in detail. However, this process is very cumbersome and hinders efficient development work. Therefore, there is a need to provide a system that allows users to quickly and accurately understand other users' code and easily use it by adding comments. [Means for solving the problem]
[0005] To solve this problem, the present invention provides a system including: a means for inputting code; a means for analyzing the code to extract structures and functions; a means for generating natural language comments based on the extracted structures and functions; a means for inserting the generated comments at appropriate positions in the code; and a means for providing the commented code to a user. The system also includes means for identifying the structure and functions of the code using static and dynamic analysis, generating an abstract syntax tree of the code, and analyzing each portion of the code based on the tree.
[0006] "Means for inputting code" refers to an interface through which a user provides the system with source code that the user wishes to analyze.
[0007] "Means for analyzing code to extract structure and functionality" refers to techniques for analyzing input code and identifying its structure (e.g., functions, classes, and variable relationships) and functionality (e.g., computations, input / output operations).
[0008] "Means for generating natural language comments based on the extracted structure and functions" refers to technology that automatically generates comments in natural language based on the analysis results in a way that is easy for humans to understand.
[0009] "Means for inserting generated comments into appropriate positions in code" refers to a technique for inserting generated comments into the original code at appropriate positions to improve the readability and comprehension of the code.
[0010] "Means for providing commented code to users" means an interface or functionality that allows users to view, edit, save, or use commented code in other development environments.
[0011] "Methods for determining the structure and functionality of code using static analysis" refers to techniques for analyzing code to detect syntax errors and to analyze the structure and functionality of the code without executing the code.
[0012] "Methods of using dynamic analysis to verify the runtime behavior of code" refers to a technique that actually executes code and observes and analyzes its execution results and behavior.
[0013] "Means for generating an abstract syntax tree of code" refers to a technology that analyzes code and generates a data structure (abstract syntax tree) that represents its syntactic structure in a tree format.
[0014] "Means for analyzing each part of the code based on the generated abstract syntax tree" refers to a technology that uses the generated abstract syntax tree to analyze in detail the role and function of each part of the code. [Brief explanation of the drawings]
[0015] [Figure 1] 1 is a conceptual diagram showing an example of the configuration of a data processing system according to a first embodiment. [Figure 2] 1 is a conceptual diagram showing an example of main functions of a data processing device and a smart device according to a first embodiment. [Figure 3] FIG. 10 is a conceptual diagram showing an example of the configuration of a data processing system according to a second embodiment. [Figure 4] FIG. 10 is a conceptual diagram showing an example of main functions of a data processing device and smart glasses according to a second embodiment. [Figure 5] FIG. 10 is a conceptual diagram showing an example of the configuration of a data processing system according to a third embodiment. [Figure 6] FIG. 11 is a conceptual diagram showing an example of main functions of a data processing device and a headset-type terminal according to a third embodiment. [Figure 7] FIG. 10 is a conceptual diagram showing an example of the configuration of a data processing system according to a fourth embodiment. [Figure 8] FIG. 10 is a conceptual diagram showing an example of main functions of a data processing device and a robot according to a fourth embodiment. [Figure 9] 1 shows an emotion map onto which multiple emotions are mapped. [Figure 10] 1 shows an emotion map onto which multiple emotions are mapped. [Figure 11] FIG. 3 is a sequence diagram showing a processing flow of the data processing system according to the first embodiment. [Figure 12] FIG. 10 is a sequence diagram showing the flow of processing in the data processing system in Application Example 1. [Figure 13] FIG. 10 is a sequence diagram showing the flow of processing in the data processing system according to the second embodiment when an emotion engine is combined. [Figure 14] FIG. 10 is a sequence diagram showing the flow of processing in the data processing system in Application Example 2 when an emotion engine is combined. DETAILED DESCRIPTION OF THE INVENTION
[0016] An example of an embodiment of a system according to the technology of the present disclosure will be described below with reference to the accompanying drawings.
[0017] First, the terms used in the following description will be explained.
[0018] In the following embodiments, a coded processor (hereinafter simply referred to as a "processor") may be a single arithmetic device or a combination of multiple arithmetic devices. Furthermore, a processor may be a single type of arithmetic device or a combination of multiple types of arithmetic devices. Examples of arithmetic devices include a CPU (Central Processing Unit), a GPU (Graphics Processing Unit), a GPGPU (General-Purpose computing on Graphics Processing Units), and an APU (Accelerated Processing Unit).
[0019] In the following embodiments, a coded RAM (Random Access Memory) is a memory in which information is temporarily stored and is used as a working memory by a processor.
[0020] In the following embodiments, the coded storage is one or more non-volatile storage devices that store various programs, various parameters, etc. Examples of non-volatile storage devices include flash memory (SSD (Solid State Drive)), magnetic disks (e.g., hard disks), and magnetic tapes.
[0021] In the following embodiments, a communication I / F (Interface) with a symbol is an interface including a communication processor, an antenna, etc. The communication I / F controls communication between multiple computers. Examples of communication standards applied to the communication I / F include wireless communication standards including 5G (5th Generation Mobile Communication System), Wi-Fi (registered trademark), Bluetooth (registered trademark), etc.
[0022] In the following embodiments, "A and / or B" is synonymous with "at least one of A and B." In other words, "A and / or B" means that it may be only A, only B, or a combination of A and B. Furthermore, in this specification, the same concept as "A and / or B" is also applied when three or more things are expressed connected by "and / or."
[0023] [First embodiment]
[0024] FIG. 1 shows an example of the configuration of a data processing system 10 according to the first embodiment.
[0025] 1, a data processing system 10 includes a data processing device 12 and a smart device 14. An example of the data processing device 12 is a server.
[0026] The data processing device 12 includes a computer 22, a database 24, and a communication I / F 26. The computer 22 is an example of a "computer" according to the technology of the present disclosure. The computer 22 includes a processor 28, a RAM 30, and a storage 32. The processor 28, the RAM 30, and the storage 32 are connected to a bus 34. The database 24 and the communication I / F 26 are also connected to the bus 34. The communication I / F 26 is connected to a network 54. Examples of the network 54 include a WAN (Wide Area Network) and / or a LAN (Local Area Network).
[0027] The smart device 14 includes a computer 36, a reception device 38, an output device 40, a camera 42, and a communication I / F 44. The computer 36 includes a processor 46, a RAM 48, and a storage 50. The processor 46, the RAM 48, and the storage 50 are connected to a bus 52. The reception device 38, the output device 40, and the camera 42 are also connected to the bus 52.
[0028] The reception device 38 includes a touch panel 38A, a microphone 38B, and the like, and receives user input. The touch panel 38A detects contact with an indicator (for example, a pen or a finger) to receive user input by the touch of the indicator. The microphone 38B detects the user's voice to receive user input by voice. The control unit 46A transmits data indicating the user input received by the touch panel 38A and the microphone 38B to the data processing device 12. In the data processing device 12, the specific processing unit 290 acquires the data indicating the user input.
[0029] The output device 40 includes a display 40A and a speaker 40B, and presents data to the user 20 by outputting the data in a form of expression that the user 20 can perceive (for example, audio and / or text). The display 40A displays visible information such as text and images in accordance with instructions from the processor 46. The speaker 40B outputs audio in accordance with instructions from the processor 46. The camera 42 is a compact digital camera equipped with an optical system including a lens, aperture, and shutter, and an imaging element such as a CMOS (Complementary Metal-Oxide-Semiconductor) image sensor or a CCD (Charge Coupled Device) image sensor.
[0030] The communication I / F 44 is connected to a network 54. The communication I / Fs 44 and 26 control the exchange of various information between the processor 46 and the processor 28 via the network 54.
[0031] FIG. 2 shows an example of the main functions of the data processing device 12 and the smart device 14.
[0032] 2, in the data processing device 12, a specific process is performed by the processor 28. A specific processing program 56 is stored in the storage 32. The specific processing program 56 is an example of a "program" according to the technology of the present disclosure. The processor 28 reads the specific processing program 56 from the storage 32 and executes the read specific processing program 56 on the RAM 30. The specific process is realized by the processor 28 operating as a specific processing unit 290 in accordance with the specific processing program 56 executed on the RAM 30.
[0033] The storage 32 stores a data generation model 58 and an emotion identification model 59. The data generation model 58 and the emotion identification model 59 are used by the identification processing unit 290.
[0034] In the smart device 14, the processor 46 performs the reception output process. The storage 50 stores a reception output program 60. The reception output program 60 is used in conjunction with the specific processing program 56 by the data processing system 10. The processor 46 reads the reception output program 60 from the storage 50 and executes the read reception output program 60 on the RAM 48. The reception output process is realized by the processor 46 operating as the control unit 46A in accordance with the reception output program 60 executed on the RAM 48.
[0035] Next, a description will be given of the specific processing performed by the specific processing unit 290 of the data processing device 12. In the following description, the data processing device 12 will be referred to as a "server" and the smart device 14 will be referred to as a "terminal."
[0036] This invention relates to a code analysis system that helps users quickly and accurately understand other people's source code and add comments to that code. A specific embodiment of the system is described below.
[0037] In this system, a user inputs source code, a server analyzes the code, generates comments and inserts comments, and a terminal outputs the commented code.
[0038] Entering Code
[0039] The user uses an interface to upload source code to be analyzed into the system, which is implemented via drag-and-drop or a file selection dialog.
[0040] Code Analysis
[0041] The server receives the uploaded code, first uses a parser to split the code into tokens and generate an Abstract Syntax Tree (AST), then uses static and dynamic analysis techniques to perform a detailed analysis of the code's structure and functionality.
[0042] Comment Generation
[0043] Based on the analysis results, the server uses an automatic comment generation module to generate natural language explanations for each part of the code. For example, for a function definition, it generates a comment such as "This function adds the arguments a and b."
[0044] Inserting comments
[0045] The server inserts the generated comments into the corresponding code locations, including techniques to preserve the readability and proper indentation and formatting of the original code.
[0046] Provides commented code
[0047] The server generates commented code and sends it to the user's device, which then displays the received commented code and prepares it for the user to view and edit.
[0048] Specific examples
[0049] Suppose a user uploads the following Python code to the system:
[0050] python
[0051] def add_numbers(a, b):
[0052] return a + b
[0053] result = add_numbers(5, 3)
[0054] print(result)
[0055] The server will parse this code and generate and insert the following comment:
[0056] Example of the parsed code:
[0057] python
[0058] A function that adds two numbers
[0059] def add_numbers(a, b):
[0060] return a + b
[0061] Use the add_numbers function to add 5 and 3 and assign the result to result
[0062] result = add_numbers(5, 3)
[0063] Output the results
[0064] print(result)
[0065] The terminal displays this commented code to the user, allowing the user to immediately understand the intent of the code.
[0066] How to use
[0067] The user experience when using the system is as follows:
[0068] 1. The user uploads the source code through the system interface.
[0069] 2. The server analyzes the received source code and generates comments.
[0070] 3. The server inserts the generated comments into the code and generates commented code.
[0071] 4. The terminal displays the generated commented code to the user.
[0072] This process allows developers to quickly understand others' code and significantly reduces the time it takes to learn new frameworks and algorithms.
[0073] As can be seen, the present invention is a system that allows users to efficiently understand and learn chords.
[0074] The processing flow will be explained below.
[0075] Step 1:
[0076] Users upload the source code they wish to analyze into the system's interface, which provides a file selection dialog and drag-and-drop functionality.
[0077] Step 2:
[0078] The device receives the uploaded source code and sends it to the server, which temporarily stores the code file.
[0079] Step 3:
[0080] The server parses the received code file, using a parser to split the code into tokens and generate an abstract syntax tree (AST).
[0081] Step 4:
[0082] The server parses the generated abstract syntax tree (AST) to extract the structure and functionality of the code, identifying function definitions, variable assignments, control structures, etc.
[0083] Step 5:
[0084] The server performs static and dynamic analysis: static analysis analyzes source code without executing it to identify dependencies and potential errors in the code, and dynamic analysis actually executes the code and observes its behavior.
[0085] Step 6:
[0086] The server generates a natural language comment based on the analysis results. Specifically, it generates a description of the function of each analyzed part. For example, for the function add_numbers, a comment such as "This function adds the arguments a and b" is created.
[0087] Step 7:
[0088] The server inserts the generated comments into the original source code at the appropriate places, respecting syntax and taking into account indentation and comment placement to maintain code readability.
[0089] Step 8:
[0090] The server generates commented source code and sends it to the user's terminal.
[0091] Step 9:
[0092] The terminal will display the received commented source code to the user, allowing the user to review the code comments and understand the content.
[0093] Step 10:
[0094] The user can edit the commented code as needed, save it, or use it in other development environments.
[0095] Example 1
[0096] Next, a description will be given of Example 1. In the following description, the data processing device 12 will be referred to as a "server" and the smart device 14 will be referred to as a "terminal."
[0097] Analyzing program code and quickly and accurately understanding its structure and function requires a lot of time and effort. It is also extremely time-consuming to manually insert appropriate comments based on the analysis results. This task is even more difficult when trying to understand someone else's code at first glance. A method for efficiently solving these problems is needed.
[0098] The specific processing by the specific processing unit 290 of the data processing device 12 in the first embodiment is realized by the following means.
[0099] In this invention, the server includes: [means for dividing code into tokens and generating an abstract syntax tree]; [means for extracting code structure and function using static analysis and dynamic analysis]; and [means for generating natural language comments using a generative AI model based on the extracted structure and function]. This automates the work of code analysis and comment generation / insertion, enabling users to quickly and accurately understand the intent of the code.
[0100] "Means for entering code" means the interface through which a user can upload program code to the system, including means such as drag-and-drop and file selection dialogs.
[0101] "Means for dividing code into tokens and generating an abstract syntax tree" refers to an analysis technology that divides program code into the smallest units called tokens and generates an abstract syntax tree (AST) based on them.
[0102] "Means for extracting the structure and function of code using static and dynamic analysis" refers to means for extracting detailed information about code using both static analysis, which analyzes the structure and function of program code without executing it, and dynamic analysis, which monitors its behavior during execution.
[0103] "Means for generating natural language comments using a generative AI model based on the extracted structure and functions" refers to means for automatically generating appropriate comments in natural language using a generative AI model (e.g., a large-scale language model) based on the code structure and functions obtained through analysis.
[0104] "Means for inserting generated comments into the appropriate places in the code while preserving indentation and formatting" refers to a technique for properly inserting generated comments into the corresponding places in the program code while maintaining the readability of the original code.
[0105] "Means for providing users with commented code" refers to means for providing users with program code with automatically inserted comments in a form that allows them to view and edit it.
[0106] MODE FOR CARRYING OUT THE INVENTION
[0107] The present invention relates to a code analysis system that helps users quickly and accurately understand other people's source code and add comments to that code. A specific embodiment of this system will be described below.
[0108] Users first upload their source code through an interface that makes it easy to provide source code using drag-and-drop functionality or a file selection dialog.
[0109] The server receives the uploaded source code and uses a parser to break the code into tokens. It then generates an Abstract Syntax Tree (AST) and performs static and dynamic analysis to analyze the code's structure and functionality in detail. This analysis phase uses the tokenized information and the AST to understand how each piece of code works.
[0110] Next, the server uses a generative AI model based on the analysis results to generate natural language comments. The generative AI model uses a large-scale language model (e.g., GPT) to generate natural language explanations for the structure and function of the analyzed code. These generated comments include explanations of the purpose of functions, the roles of variables, and the implementation intention of the algorithm.
[0111] The generated comments are inserted in the appropriate positions, adjusting indentation and line spacing appropriately to maintain the readability of the original code. The server generates the code with the comments and sends it to the user's terminal.
[0112] The terminal receives the commented code sent from the server and displays it to the user. By viewing this commented code, the user can quickly understand the intent and function of the source code. Furthermore, the user can also modify or add to the code as needed.
[0113] Specific examples
[0114] A specific example of operation is shown below.
[0115] If a user uploads Python code:
[0116] python
[0117] def add_numbers(a, b):
[0118] return a + b
[0119] result = add_numbers(5, 3)
[0120] print(result)
[0121] The server performs the process in the following steps.
[0122] 1. Break the code into tokens and analyze its structure.
[0123] 2. Generate a comment for the function definition "def add_numbers(a, b):" that says "This function takes two arguments and returns their sum."
[0124] 3. For the part "result = add_numbers(5, 3)", create a comment that says "Use the add_numbers function to add 5 and 3 and assign the result to result."
[0125] 4. Create a comment for the "print(result)" part, saying "Print the result", and insert comments into each part.
[0126] This results in the following commented generated code:
[0127] python
[0128] A function that adds two numbers
[0129] def add_numbers(a, b):
[0130] return a + b
[0131] Use the add_numbers function to add 5 and 3 and assign the result to result
[0132] result = add_numbers(5, 3)
[0133] Output the results
[0134] print(result)
[0135] Example prompt sentence:
[0136] To analyze the source code, follow these steps:
[0137] 1. Upload your source code files by dragging and dropping them into the system interface or by selecting them from the file selection dialog.
[0138] This system allows users to quickly and easily understand the structure and function of their code, greatly improving the efficiency of their development work.
[0139] The flow of the identification process in the first embodiment will be described with reference to FIG.
[0140] The flow of this system's program processing
[0141] Step 1: Upload your source code
[0142] Step 2: Receive the code and prepare it for analysis
[0143] Step 3: Tokenization and Abstract Syntax Tree Generation
[0144] Step 4: Static and Dynamic Analysis
[0145] Step 5: Auto-generating comments
[0146] Step 6: Inserting comments
[0147] Step 7: Provide commented code
[0148] Specific explanation of each processing step
[0149] Step 1: Upload your source code
[0150] The user uploads a source code file using the system's interface. The input is a source code file specified by the user (e.g., "example.py"). The output is that the uploaded source code file is sent to the server. The interface is provided using a drag-and-drop function or a file selection dialog.
[0151] Step 2: Receive the code and prepare it for analysis
[0152] The server receives source code uploaded by users. The input is the uploaded source code file. The server stores the source code in temporary memory and prepares it for the next analysis step. The output is the temporarily stored source code.
[0153] Step 3: Tokenization and Abstract Syntax Tree Generation
[0154] The server runs the received source code through a parser and divides it into tokens. The input is the stored source code. After tokenization, the server generates an abstract syntax tree (AST) based on the tokens. The output is the generated abstract syntax tree. Specifically, in this step, the code is decomposed according to the syntax rules to form a tree structure.
[0155] Step 4: Static and Dynamic Analysis
[0156] The server uses the generated abstract syntax tree to perform static and dynamic analysis. The input is the abstract syntax tree. Static analysis analyzes the code structure and interrelationships between functions, while dynamic analysis analyzes the changes in variables at runtime and the execution order of functions. The output is a detailed analysis result. Specifically, it analyzes function inputs and outputs, variable scopes, dependencies, etc.
[0157] Step 5: Auto-generating comments
[0158] The server uses a generative AI model based on the analysis results to generate natural language comments. The input is the detailed analysis results. The generative AI model (e.g., GPT) generates explanatory comments for each code section based on the analyzed data. The output is the generated comments. Specifically, the AI model generates function descriptions, variable uses, etc.
[0159] Step 6: Inserting comments
[0160] The server inserts the generated comments into the corresponding code positions. The input is the generated comments. The comments are inserted properly before the code, preserving indentation and formatting. The output is the source code with the comments inserted. This step uses techniques to place comments in the appropriate positions, taking into account the readability of the original code.
[0161] Step 7: Provide commented code
[0162] The server generates commented code and sends it to the user's device. The input is the source code with comments inserted. The device displays the received commented code for the user to view and edit. The output is the commented code displayed to the user. Specifically, the commented code is displayed on the user's device, allowing the user to quickly understand the intent of the code.
[0163] (Application example 1)
[0164] Next, a description will be given of Application Example 1. In the following description, the data processing device 12 will be referred to as a "server" and the smart device 14 will be referred to as a "terminal."
[0165] Traditional source code analysis tools have not been able to provide sufficient support for quickly and accurately understanding other people's source code. In particular, it takes a lot of time and effort to gain a deep understanding of the code's structure and functionality, and manually adding comments to aid in code understanding is tedious. This makes it inefficient for developers to learn new frameworks and algorithms.
[0166] The specific processing by the specific processing unit 290 of the data processing device 12 in the application example 1 is realized by the following means.
[0167] In this invention, the server includes means for inputting code, means for analyzing the code to extract structures and functions, means for generating natural language comments based on the extracted structures and functions, means for inserting the generated comments at appropriate positions in the code, means for providing the commented code to a user, means for transmitting the code uploaded to the user terminal to a cloud server, and means for performing syntax analysis, AST generation, static analysis, and dynamic analysis on the cloud server, thereby enabling rapid and accurate understanding of code and automating comment generation.
[0168] "Means for inputting code" refers to an interface that allows a user to upload source code to be analyzed into the system.
[0169] "Means for analyzing code to extract structure and functionality" refers to the process of dividing uploaded code into tokens, generating an abstract syntax tree, and analyzing its structure and functionality.
[0170] "Means for generating natural language comments based on extracted structure and function" refers to technology for automatically generating explanatory text for each part of code based on the analysis results.
[0171] "Means for inserting generated comments into appropriate locations in the code" refers to a process for inserting generated comments while preserving the readability of the original code.
[0172] "Means for providing commented code to a user" refers to technology that transmits the commented code to a user's device so that it can be displayed.
[0173] "Means for sending code uploaded to a user's device to a cloud server" refers to the function that allows a user to send source code from their own device to a server on the cloud.
[0174] "Means for performing syntax analysis, AST generation, static analysis, and dynamic analysis on a cloud server" refers to technologies for analyzing source code on a cloud server and performing syntax analysis, generating abstract syntax trees, and performing static and dynamic analysis.
[0175] This invention relates to a source code analysis system that helps users quickly and accurately understand other people's source code and add comments to that code. The configuration and operation of a specific system for implementing this invention are described below.
[0176] Entering Code
[0177] Users upload source code to be analyzed to the system using a drag-and-drop or file selection dialog interface on their terminal, allowing users to easily input code.
[0178] Sending the code
[0179] The user device sends the uploaded code to the cloud server via a method such as an HTTP POST request.
[0180] Code Analysis
[0181] The cloud server analyzes the received code. As a first step, it uses a parser to split the code into tokens and generate an Abstract Syntax Tree (AST). Next, the server uses static and dynamic analysis techniques to perform a detailed analysis of the code's structure and functionality.
[0182] Comment Generation
[0183] Based on the analysis results, the cloud server uses an automatic comment generation module to generate natural language explanations for each code section. The generative AI model used here can be, for example, GPT-4 (registered trademark). The generation process is performed by passing the following prompt sentence to the model:
[0184] python
[0185] prompt_text = "Generate comments for the following Python code, explaining the meaning of each line.\n\n{}\n\n Add your comments:".format(original_code)
[0186] Inserting comments
[0187] The cloud server inserts the generated comments into the corresponding code locations, using techniques that preserve proper indentation and formatting to preserve the readability of the original code.
[0188] Provides commented code
[0189] The cloud server generates commented code and sends it to the user's device, which displays the received commented code and arranges it for the user to view and edit.
[0190] Hardware and software used
[0191] Smartphone: Used to implement the user interface and send and receive code.
[0192] Cloud Server: The central source code analysis and comment generation center, including a parser, an AST generator, static analysis, and dynamic analysis modules.
[0193] Generative AI models: Generate comments using natural language processing models such as GPT-4.
[0194] Specific examples
[0195] Suppose a user uploads the following Python code to the system:
[0196] python
[0197] def multiply_numbers(x, y):
[0198] return xy
[0199] result = multiply_numbers(7, 8)
[0200] print(result)
[0201] The cloud server will parse this code and generate and insert comments like this:
[0202] python
[0203] A function that multiplies two numbers
[0204] def multiply_numbers(x, y):
[0205] return xy
[0206] Multiply 7 and 8 using the multiply_numbers function and assign the result to result
[0207] result = multiply_numbers(7, 8)
[0208] Output the results
[0209] print(result)
[0210] This process allows developers to quickly understand others' code and significantly reduces the time it takes to learn new frameworks and algorithms.
[0211] The flow of the specific processing in the application example 1 will be described with reference to FIG.
[0212] Step 1:
[0213] The user launches the application on their smartphone and selects the source code file to analyze. The user uploads the code using a file selection dialog or drag-and-drop function, and the application reads the code file. The input here is the source code file, and the output is the content of that file.
[0214] Step 2:
[0215] The user device sends the loaded source code to the cloud server. This transmission is performed using an HTTP POST request, etc. The input here is the string data of the source code, and the output is a confirmation of successful transmission to the cloud server.
[0216] Step 3:
[0217] The cloud server invokes a parser to parse the received source code, splitting the code into tokens, and then generates an Abstract Syntax Tree (AST), where the input is the received source code and the output is the generated AST.
[0218] Step 4:
[0219] The cloud server performs static and dynamic analysis based on the generated AST. Static analysis identifies the code's structure and functionality, while dynamic analysis checks the code's behavior at runtime. The input here is the AST, and the output is a detailed analysis of the code's structure and functionality.
[0220] Step 5:
[0221] Based on the analysis results, the cloud server uses a generative AI model (e.g., GPT-4) to generate natural language comments for each piece of code. Comment generation is done using the following prompt:
[0222] python
[0223] prompt_text = "Generate comments for the following Python code, explaining the meaning of each line.\n\n{}\n\n Add your comments:".format(original_code)
[0224] The input here is the analysis result and the prompt statement, and the output is the generated comment.
[0225] Step 6:
[0226] The cloud server inserts the generated comments into the corresponding code locations, performs formatting to maintain proper indentation and formatting, and generates highly readable commented code. The input here is the generated comments and the original code, and the output is the code with the comments inserted.
[0227] Step 7:
[0228] The cloud server sends the commented code to the user's device, where the input is the commented code and the output is a confirmation of successful transmission to the user's device.
[0229] Step 8:
[0230] The user device displays the received commented code on the screen and arranges it for easy viewing by the user. The input here is the commented code, and the output is the display result presented to the user.
[0231] This series of steps allows developers to quickly and accurately understand other people's code and efficiently learn new frameworks and algorithms with reduced effort.
[0232] Furthermore, an emotion engine that estimates the user's emotion may be combined. That is, the identification processing unit 290 may estimate the user's emotion using the emotion identification model 59 and perform identification processing using the user's emotion.
[0233] The present invention relates to a system that promotes user understanding by combining a code analysis system with an emotion engine to recognize the user's emotional state and reflect this in the generation and presentation of comments based on the analysis results.
[0234] In addition to the basic functions of analyzing the source code entered by the user and generating and inserting comments, this system also uses an emotion engine to recognize the user's emotions and adjust the content of the comments based on that information.
[0235] Entering Code
[0236] Users upload source code to be analyzed into the system's interface, which provides file selection dialogs and drag-and-drop functionality.
[0237] Code Analysis
[0238] The server receives the uploaded code file, first splits the code into tokens using a parser and generates an Abstract Syntax Tree (AST), then uses static and dynamic analysis techniques to analyze the code's structure and functionality in detail.
[0239] Emotion recognition
[0240] The server recognizes the user's emotional state using an emotion engine, which evaluates the user's current stress level, satisfaction, excitement, etc. based on the input code and the user's interactions.
[0241] Comment Generation
[0242] The server generates a natural language comment based on the analysis results. It adjusts the content and tone of the comment based on the user's emotional state, as determined by the emotion engine. For example, if the user is feeling stressed, the comment will be more polite and kind.
[0243] Inserting comments
[0244] The server inserts the generated comments into the original source code at the appropriate places, taking into account indentation and comment positioning to maintain code readability.
[0245] Provides commented code
[0246] The server generates commented source code and sends it to the user's terminal.
[0247] Presenting to the user
[0248] The terminal displays the source code with comments to the user, allowing the user to quickly understand the content of the source code by checking the comments adapted to the emotions.
[0249] Specific examples
[0250] As an example, consider the following Python code uploaded by a user to the system:
[0251] python
[0252] def add_numbers(a, b):
[0253] return a + b
[0254] result = add_numbers(5, 3)
[0255] print(result)
[0256] The server analyzes this code and uses an emotion engine to recognize the user's emotional state, then generates and inserts a comment such as: For example, if the user is feeling stressed, the comment will be kind and polite.
[0257] Example of the parsed code:
[0258] python
[0259] Hello! This function adds two numbers.
[0260] def add_numbers(a, b):
[0261] return a + b
[0262] Use the add_numbers function to add 5 and 3 and assign the result to result.
[0263] result = add_numbers(5, 3)
[0264] Finally, print the results.
[0265] print(result)
[0266] The terminal will display this commented code to the user to make it easier for them to understand.
[0267] How to use
[0268] The user experience when using the system is as follows:
[0269] 1. The user uploads the source code through the system interface.
[0270] 2. The server analyzes the received source code and generates comments.
[0271] 3. The server uses an emotion engine to recognize the user's emotions and adjust the content of the comment.
[0272] 4. The server inserts the generated comments into the code, generating commented code.
[0273] 5. The terminal will display the generated commented code to the user.
[0274] This process not only allows developers to quickly understand others' code and significantly reduces the time it takes to learn new frameworks and algorithms, but also provides empathetic support.
[0275] The processing flow will be explained below.
[0276] Step 1:
[0277] Users upload the source code they want to analyze into the system's interface, which provides a file selection dialog and drag-and-drop functionality.
[0278] Step 2:
[0279] The device receives the uploaded source code and sends it to the server, which temporarily stores the code file.
[0280] Step 3:
[0281] The server parses the received code file, using a parser to split the code into tokens and generate an Abstract Syntax Tree (AST).
[0282] Step 4:
[0283] The server parses the generated abstract syntax tree (AST) to extract the structure and functionality of the code, identifying function definitions, variable assignments, control structures, etc.
[0284] Step 5:
[0285] The server performs static and dynamic analysis: static analysis analyzes source code without executing it to identify dependencies and potential errors in the code, and dynamic analysis actually executes the code and observes its behavior.
[0286] Step 6:
[0287] The server recognizes the user's emotional state using an emotion engine, which analyzes inputs and the user's past interactions to assess the user's stress level, satisfaction, excitement, etc.
[0288] Step 7:
[0289] The server generates natural language comments based on the analysis results and the output of the emotion engine. For example, if the user is feeling stressed, the comment will be changed to be more kind and polite.
[0290] Step 8:
[0291] The server inserts the generated comments into the original source code at the appropriate places, respecting syntax and taking into account indentation and comment placement to maintain code readability.
[0292] Step 9:
[0293] The server generates commented source code and sends it to the user's terminal.
[0294] Step 10:
[0295] The terminal will display the received commented source code to the user, who can then review the generated comments and quickly understand the code content.
[0296] As a concrete example, consider the case where a user uploads the following Python code to the system:
[0297] python
[0298] def add_numbers(a, b):
[0299] return a + b
[0300] result = add_numbers(5, 3)
[0301] print(result)
[0302] The server analyzes this code. First, it generates an abstract syntax tree using a parser, then performs static and dynamic analysis. Based on the analysis results, it uses an emotion engine to recognize the user's emotional state.
[0303] For example, if a user is feeling stressed, the following comment is generated and inserted:
[0304] python
[0305] Hello! This function adds two numbers.
[0306] def add_numbers(a, b):
[0307] return a + b
[0308] Use the add_numbers function to add 5 and 3 and assign the result to result.
[0309] result = add_numbers(5, 3)
[0310] Finally, print the results.
[0311] print(result)
[0312] The terminal will display this commented code to the user for easier understanding, and the user can review it, edit it, and save it as needed. In this way, the system can provide comments that respond to the user's emotions, improving their understanding and learning of the code.
[0313] Example 2
[0314] Next, a description will be given of Example 2. In the following description, the data processing device 12 will be referred to as a "server" and the smart device 14 will be referred to as a "terminal."
[0315] Current code analysis systems analyze code structure and function and insert comments to aid code comprehension, but they do not take the user's emotional state into account. As a result, if a user is feeling stressed or confused, the generated comments may not be appropriate for the user's state and may actually hinder comprehension. Furthermore, existing systems lack detailed code analysis using static and dynamic analysis, making it difficult to generate high-quality comments.
[0316] The specific processing by the specific processing unit 290 of the data processing device 12 in the second embodiment is realized by the following means.
[0317] In this invention, the server includes: [means for inputting code;] [means for analyzing the code to extract structure and function;] [means for generating natural language comments based on the extracted structure and function;] [means for inserting the generated comments at appropriate positions in the code;] [means for providing the commented code to a user;] [means for recognizing the user's emotional state and adjusting the content of the comments;] [means for identifying the structure and function of the code using static analysis] and [means for confirming the runtime behavior of the code using dynamic analysis]; [means for recognizing the user's emotional state using an emotion recognition engine] and [means for adjusting the tone of the comments based on the emotion recognition engine]. This makes it possible to insert polite and kind comments that are adapted to the user's emotional state, thereby promoting understanding of the code and reducing user stress and confusion.
[0318] "Means for inputting code" refers to a function that provides an interface for users to upload source code to be analyzed into the system.
[0319] "Means for analyzing code and extracting structure and function" refers to a function in which the server analyzes uploaded code and performs processing to understand its internal structure and operation.
[0320] "Means for generating natural language comments based on the extracted structure and functions" refers to a function in which the server generates comments in natural language based on the results of code analysis.
[0321] "Means for inserting generated comments into appropriate positions in code" is a function for adding generated comments into appropriate positions in code to improve code readability and comprehension.
[0322] "Means for providing commented code to users" means a function for sending users source code with added comments.
[0323] "Means for recognizing a user's emotional state and adjusting the content of comments" refers to a function that uses an emotion recognition engine to grasp a user's emotions and appropriately adjust the tone and content of comments based on that state.
[0324] "Means of identifying the structure and functionality of code using static analysis" refers to a feature that provides a way to analyze the structure and potential problems of code before it is executed.
[0325] "Means of using dynamic analysis to check the runtime behavior of code" is a feature that provides a way to actually run code and check its behavior and performance.
[0326] "Means for generating an abstract syntax tree of code" refers to a function that analyzes code and generates an abstract syntax tree (AST) that represents its structure in a tree-like format.
[0327] The "means for analyzing each part of the code based on the generated abstract syntax tree" is a function that uses the generated abstract syntax tree to analyze in detail the meaning and role of each part of the code.
[0328] "Means for recognizing a user's emotional state using an emotion recognition engine" refers to a function that uses a specific algorithm or artificial intelligence to read a user's emotions.
[0329] The "means for adjusting the tone of comments based on an emotion recognition engine" is a function that appropriately changes the content and expression of comments depending on the results of the user's emotions obtained by the emotion recognition engine.
[0330] This invention relates to a system that recognizes the user's emotional state and reflects it in the generation and presentation of comments based on the analysis results by combining an emotion engine with a code analysis system. In addition to the basic functions of analyzing source code entered by the user and generating and inserting comments, this system also uses the emotion engine to recognize the user's emotions and adjusts the content of the comments based on that information.
[0331] Basic system configuration
[0332] Entering Code
[0333] Users upload source code to be analyzed into the system's interface, which provides file selection dialogs and drag-and-drop functionality.
[0334] Receive and save the code
[0335] The server receives the uploaded code file and saves it in a local directory. Specifically, it receives an HTTP POST request and saves the file on the server side.
[0336] Code Analysis
[0337] The server analyzes the code using the following techniques:
[0338] Parsing: Split the uploaded code into tokens and generate an Abstract Syntax Tree (AST). Use the Python ast module and the ast.parse function to generate an AST.
[0339] Static analysis: Using tools such as pylint, potential problems in the code are identified.
[0340] Dynamic analysis: Running unit tests to verify that the code behaves as expected.
[0341] Emotion recognition
[0342] The server uses an emotion engine to recognize the user's emotional state, using the Google® Cloud Natural Language API and IBM Watson® Tone Analyzer, and evaluates the user's current stress level, satisfaction, excitement, etc. based on the code entered by the user and past interaction data.
[0343] Comment Generation
[0344] The server generates a natural language comment based on the analysis results, using a generative AI model (e.g., GPT-3 (registered trademark)). The prompt for comment generation is set as follows:
[0345] "Generate polite comments for the following code:"
[0346] The analyzed code content is entered following the prompt statement to query the AI model.
[0347] Inserting comments
[0348] The server inserts the generated comment into the original source code at the appropriate position. When inserting the comment, it places it in the correct position based on the abstract syntax tree and formats it using Python's autopep8. For example, if the generated comment is "This function is for adding two numbers," it will be inserted just before the function definition.
[0349] Provides commented code
[0350] The server generates source code with the added comments and sends it to the user's terminal.
[0351] Presenting to the user
[0352] The device displays the commented source code to the user, who can then view it in a web browser or dedicated application, with highlighting features to help users easily identify emotionally charged comments.
[0353] Specific examples
[0354] As an example, consider the case where a user uploads the following Python code to the system:
[0355] python
[0356] def add_numbers(a, b):
[0357] return a + b
[0358] result = add_numbers(5, 3)
[0359] print(result)
[0360] The server analyzes this code, uses an emotion engine to recognize the user's emotional state, and then generates and inserts a comment like this:
[0361] python
[0362] Hello! This function adds two numbers.
[0363] def add_numbers(a, b):
[0364] return a + b
[0365] Use the add_numbers function to add 5 and 3 and assign the result to result.
[0366] result = add_numbers(5, 3)
[0367] Finally, print the results.
[0368] print(result)
[0369] The terminal displays this commented code to the user to make it easier for the user to understand.
[0370] This system not only allows developers to quickly understand other people's code and significantly reduces the time it takes to learn new frameworks and algorithms, but also provides support that responds to the user's emotions.
[0371] The flow of the identification process in the second embodiment will be described with reference to FIG.
[0372] Step 1:
[0373] The user uploads the source code to be analyzed into the system interface by opening a file selection dialog or dropping the code file into the drag-and-drop area.
[0374] Input: Source code file
[0375] Output: Uploaded source code data
[0376] Step 2:
[0377] The server receives the uploaded source code file and saves it to a local directory. The server receives an HTTP POST request and writes the file.
[0378] Input: Uploaded source code data
[0379] Output: Source code files stored on the server
[0380] Step 3:
[0381] The server uses a parser to split the source code into tokens and generate an Abstract Syntax Tree (AST). Specifically, it uses the Python ast module and the ast.parse function to generate an AST.
[0382] Input: Source code files stored on the server
[0383] Output: Abstract syntax tree (AST)
[0384] Step 4:
[0385] The server analyzes the source code using static analysis tools (e.g., pylint) to determine the structure and functionality of the code. This analysis identifies potential issues and areas for improvement in the source code.
[0386] Input: Abstract Syntax Tree (AST)
[0387] Output: Static analysis result data
[0388] Step 5:
[0389] The server performs dynamic analysis to verify the runtime behavior of the code, specifically by running unit tests to verify that the source code behaves as expected.
[0390] Input: Source code file
[0391] Output: Dynamic analysis result data
[0392] Step 6:
[0393] The server uses an emotion engine to recognize the user's emotional state, using Google Cloud Natural Language API and IBM Watson Tone Analyzer to evaluate the code entered by the user and past interaction data to obtain an emotion score.
[0394] Input: Source code and user interaction data
[0395] Output: User's emotional state data
[0396] Step 7:
[0397] The server generates a natural language comment based on the analysis results and the user's emotional state. Using a generative AI model (e.g., GPT-3), the server queries the AI model by entering the prompt "Please generate a polite comment for the following code."
[0398] Input: Static analysis result data, dynamic analysis result data, user emotional state data
[0399] Output: Generated natural language comment
[0400] Step 8:
[0401] The server inserts the generated comments into the appropriate positions in the source code based on the abstract syntax tree, and then formats the entire code using a formatting tool such as Python's autopep8.
[0402] Input: Source code files, generated natural language comments
[0403] Output: Commented source code
[0404] Step 9:
[0405] The server sends the commented source code to the user's terminal. Specifically, the server returns the commented source code as an HTTP response.
[0406] Input: Commented source code
[0407] Output: Commented source code sent to the user's terminal
[0408] Step 10:
[0409] The device displays the commented source code to the user. Specifically, the code is displayed in a web browser or a dedicated application, and the user can easily check the comments using highlighting functions.
[0410] Input: Commented source code sent to the user's terminal
[0411] Output: Commented source code displayed to the user
[0412] The above is the specific processing flow of this system.
[0413] (Application example 2)
[0414] Next, a description will be given of Application Example 2. In the following description, the data processing device 12 will be referred to as a "server" and the smart device 14 will be referred to as a "terminal."
[0415] Factory robot programs are complex, requiring engineers to understand them quickly and accurately. However, engineers often experience stress and difficulty in understanding the programs, resulting in decreased production efficiency and work accuracy. Furthermore, there has been no method to provide real-time support that responds to the engineers' emotions, so a new method to help them understand the programs is needed.
[0416] The specific processing by the specific processing unit 290 of the data processing device 12 in Application Example 2 is realized by the following means. In this invention, the server includes means for inputting code, means for analyzing the code to extract its structure and function, means for generating comments in natural language based on the extracted structure and function, means for adjusting the content of the generated comments based on the user's emotional state, and means for providing the commented code to a display device in real time. This allows the provision of commented code that is adapted to the engineer's emotional state, enabling the engineer to quickly and easily understand the program.
[0417] A "means for inputting code" is an interface or mechanism that allows a technician to upload the program code of a factory robot into the system.
[0418] "Means of analyzing code to extract structure and function" is the process of breaking down code into tokens and parsing it to generate an abstract syntax tree (AST) of the code, identifying its structure and function in detail.
[0419] "Means for generating natural language comments based on extracted structures and functions" is a mechanism that automatically generates natural language explanations for each part of the analyzed code to make it easier to understand.
[0420] "Means for adjusting the content of generated comments based on the emotional state of the user" refers to a process in which the emotional engine recognizes the emotional state of the engineer and adjusts the tone and content of the generated comments accordingly.
[0421] The "means for providing commented code to a display device in real time" is a mechanism for quickly transmitting the generated commented code to a display device such as a head-mounted display worn by the engineer and displaying it in real time.
[0422] To implement this invention, it is necessary to build a system for analyzing factory robot programs and generating comments. This system consists of a server, a terminal, and a user interface. The specific operation of each component and the hardware and software used are described below.
[0423] Server roles and technologies used
[0424] The server initially receives the robot's program code uploaded by the engineer through an input interface that provides a file selection dialog and drag-and-drop functionality.
[0425] To perform the code analysis process, the server first uses a parsing library to split the code into tokens and generate an Abstract Syntax Tree (AST), then uses static and dynamic analysis techniques to identify the code's structure and functionality for further analysis.
[0426] Next, an emotion engine library is used to recognize the technician's emotional state, which is evaluated based on the technician's inputs and interactions, taking into account stress levels, satisfaction, excitement, etc.
[0427] Generate natural language comments based on the analyzed information and emotional state, with the tone and content of the comments tailored based on the specific code analysis results and emotional state.
[0428] The generated comments are inserted into the code at the appropriate point, automatically adjusting indentation and comment positioning, and then the commented code is delivered in real time to the engineer's terminal or head-mounted display (HMD).
[0429] Device role and technology used
[0430] The engineer's terminal, especially the head-mounted display (HMD), displays the commented code sent from the server in real time, allowing the engineer to always check the latest comments and code while working, improving understanding and work efficiency.
[0431] User roles and operating procedures
[0432] The engineer uploads the program code through the system's interface, then inputs the current emotional state into the interface, which the system analyzes with its emotion engine.
[0433] Engineers can use the HMD to view commented code displayed in real time as they work, making it easier to understand the program and allowing them to quickly and accurately modify or create new programs for factory robots.
[0434] Examples of specific examples and prompts
[0435] As a concrete example, consider the case where an engineer uploads the following robot program code:
[0436] python
[0437] def control_robot(speed, direction):
[0438] move_robot(speed, direction)
[0439] check_obstacle()
[0440] return 'Success'
[0441] If the engineer's emotional state is recognized as "Stress: 0.8, Satisfaction: 0.5", the system will generate and insert the following comment:
[0442] python
[0443] Hello! Functions for controlling the speed and direction of a robot.
[0444] def control_robot(speed, direction):
[0445] move_robot(speed, direction)
[0446] Check for obstructions.
[0447] check_obstacle()
[0448] Finally, it returns whether the operation was successful.
[0449] return 'Success'
[0450] This commented code is displayed in real time on the HMD, helping engineers to quickly understand it.
[0451] Prompt Sentence Examples
[0452] "Analyze the robot's operating program code and generate and display comments based on the engineer's emotional state emotion_state."
[0453] In this way, the system of the present invention provides commented code that is adapted to the emotional state of the engineer, thereby promoting understanding of factory robot programs and improving the engineer's work efficiency.
[0454] The flow of the specific processing in the application example 2 will be described with reference to FIG.
[0455] Step 1:
[0456] Users upload factory robot program code through an input interface that provides file selection dialogs and drag-and-drop functionality. The uploaded code is sent to a server and prepared for analysis.
[0457] Step 2:
[0458] The server processes the received program code with a code analysis library, splitting the code into tokens, and then uses a parser to generate an Abstract Syntax Tree (AST). This analysis process extracts the structure and functionality of the code.
[0459] Output: Abstract syntax tree and detailed code structure information
[0460] Step 3:
[0461] The server then performs further analysis of the extracted structural information using static and dynamic analysis: static analysis identifies the code's components, and dynamic analysis examines the code's behavior at runtime, providing a complete understanding of the code's functionality and behavior.
[0462] Output: Detailed code functionality and behavior information
[0463] Step 4:
[0464] The user inputs their current emotional state into the input interface. The emotional state is input as numerical data such as stress level, satisfaction level, and excitement level, and is then sent to the server.
[0465] Input: User's emotional state data
[0466] Step 5:
[0467] The server uses an emotion engine to analyze the received emotional state data and evaluate the user's current emotional state, which in turn evaluates the user's stress level, satisfaction, excitement, etc.
[0468] Output: Evaluation result of the user's emotional state
[0469] Step 6:
[0470] The server generates natural language comments based on the analyzed code structure and function information, as well as the emotional state assessment results. The comments are created using a generative AI model and are adjusted in tone and content according to the user's emotional state.
[0471] Output: Tailored natural language comments
[0472] Step 7:
[0473] The server inserts the generated comments into the original program code at the appropriate positions, automatically adjusting indentation and comment positioning to maintain code readability.
[0474] Output: Commented program code
[0475] Step 8:
[0476] The server sends commented program code to the engineer's terminal or head-mounted display (HMD) in real time, and the terminal displays the received commented code in real time, allowing the engineer to quickly understand the content of the code.
[0477] Output: Commented code displayed in real time
[0478] For example, you can use the following prompt to see it in action:
[0479] "Analyze the robot's operating program code and generate and display comments based on the engineer's emotional state emotion_state."
[0480] The specific processing unit 290 transmits the result of the specific processing to the smart device 14. In the smart device 14, the control unit 46A causes the output device 40 to output the result of the specific processing. The microphone 38B acquires audio indicating a user input regarding the result of the specific processing. The control unit 46A transmits audio data indicating the user input acquired by the microphone 38B to the data processing device 12. In the data processing device 12, the specific processing unit 290 acquires the audio data.
[0481] The data generation model 58 is a so-called generative AI (Artificial Intelligence). An example of the data generation model 58 is ChatGPT (registered trademark) (Internet search engine).<URL: https: / / openai.com / blog / chatgpt> ), Gemini (registered trademark) (Internet search <url: https: gemini.google.com ?hl="ja">) and other generation AIs. The data generation model 58 is obtained by performing deep learning on a neural network. A prompt including an instruction is input to the data generation model 58, and inference data such as voice data indicating voice, text data indicating text, and image data indicating an image is also input. The data generation model 58 performs inference on the input inference data in accordance with the instruction indicated by the prompt, and outputs the inference result in a data format such as voice data and text data. Here, inference refers to, for example, analysis, classification, prediction, and / or summarization.
[0482] In the above embodiment, an example in which the specific process is performed by the data processing device 12 has been given, but the technology of the present disclosure is not limited to this, and the specific process may be performed by the smart device 14.
[0483] [Second embodiment]
[0484] FIG. 3 shows an example of the configuration of a data processing system 210 according to the second embodiment.
[0485] 3, the data processing system 210 includes the data processing device 12 and smart glasses 214. An example of the data processing device 12 is a server.
[0486] The data processing device 12 includes a computer 22, a database 24, and a communication I / F 26. The computer 22 is an example of a "computer" according to the technology of the present disclosure. The computer 22 includes a processor 28, a RAM 30, and a storage 32. The processor 28, the RAM 30, and the storage 32 are connected to a bus 34. The database 24 and the communication I / F 26 are also connected to the bus 34. The communication I / F 26 is connected to a network 54. Examples of the network 54 include a WAN (Wide Area Network) and / or a LAN (Local Area Network).
[0487] The smart glasses 214 include a computer 36, a microphone 238, a speaker 240, a camera 42, and a communication I / F 44. The computer 36 includes a processor 46, a RAM 48, and a storage 50. The processor 46, the RAM 48, and the storage 50 are connected to a bus 52. The microphone 238, the speaker 240, and the camera 42 are also connected to the bus 52.
[0488] The microphone 238 receives instructions and the like from the user 20 by receiving voice uttered by the user 20. The microphone 238 captures the voice uttered by the user 20, converts the captured voice into audio data, and outputs it to the processor 46. The speaker 240 outputs audio in accordance with instructions from the processor 46.
[0489] Camera 42 is a small digital camera equipped with an optical system including a lens, aperture, and shutter, and an imaging element such as a CMOS (Complementary Metal-Oxide-Semiconductor) image sensor or a CCD (Charge Coupled Device) image sensor, and captures images of the surroundings of user 20 (for example, an imaging range defined by an angle of view equivalent to the field of vision of a typical healthy person).
[0490] The communication I / F 44 is connected to a network 54. The communication I / Fs 44 and 26 are responsible for the exchange of various information between the processor 46 and the processor 28 via the network 54. The exchange of various information between the processor 46 and the processor 28 using the communication I / Fs 44 and 26 is carried out in a secure state.
[0491] Fig. 4 shows an example of the main functions of the data processing device 12 and the smart glasses 214. As shown in Fig. 4, in the data processing device 12, a specific process is performed by the processor 28. A specific process program 56 is stored in the storage 32.
[0492] The specific processing program 56 is an example of a "program" according to the technology of the present disclosure. The processor 28 reads the specific processing program 56 from the storage 32 and executes the read specific processing program 56 on the RAM 30. The specific processing is realized by the processor 28 operating as a specific processing unit 290 in accordance with the specific processing program 56 executed on the RAM 30.
[0493] The storage 32 stores a data generation model 58 and an emotion identification model 59. The data generation model 58 and the emotion identification model 59 are used by the identification processing unit 290.
[0494] In the smart glasses 214, the processor 46 performs the reception output process. A reception output program 60 is stored in the storage 50. The processor 46 reads the reception output program 60 from the storage 50 and executes the read reception output program 60 on the RAM 48. The reception output process is realized by the processor 46 operating as the control unit 46A in accordance with the reception output program 60 executed on the RAM 48.
[0495] Next, a description will be given of the identification process performed by the identification processing unit 290 of the data processing device 12. In the following description, the data processing device 12 will be referred to as the "server" and the smart glasses 214 will be referred to as the "terminal."
[0496] This invention relates to a code analysis system that helps users quickly and accurately understand other people's source code and add comments to that code. A specific embodiment of the system is described below.
[0497] In this system, a user inputs source code, a server analyzes the code, generates comments and inserts comments, and a terminal outputs the commented code.
[0498] Entering Code
[0499] The user uses an interface to upload source code to be analyzed into the system, which is implemented via drag-and-drop or a file selection dialog.
[0500] Code Analysis
[0501] The server receives the uploaded code, first uses a parser to split the code into tokens and generate an Abstract Syntax Tree (AST), then uses static and dynamic analysis techniques to perform a detailed analysis of the code's structure and functionality.
[0502] Comment Generation
[0503] Based on the analysis results, the server uses an automatic comment generation module to generate natural language explanations for each part of the code. For example, for a function definition, it generates a comment such as "This function adds the arguments a and b."
[0504] Inserting comments
[0505] The server inserts the generated comments into the corresponding code locations, including techniques to preserve the readability and proper indentation and formatting of the original code.
[0506] Provides commented code
[0507] The server generates commented code and sends it to the user's device, which then displays the received commented code and prepares it for the user to view and edit.
[0508] Specific examples
[0509] Suppose a user uploads the following Python code to the system:
[0510] python
[0511] def add_numbers(a, b):
[0512] return a + b
[0513] result = add_numbers(5, 3)
[0514] print(result)
[0515] The server will parse this code and generate and insert the following comment:
[0516] Example of the parsed code:
[0517] python
[0518] A function that adds two numbers
[0519] def add_numbers(a, b):
[0520] return a + b
[0521] Use the add_numbers function to add 5 and 3 and assign the result to result
[0522] result = add_numbers(5, 3)
[0523] Output the results
[0524] print(result)
[0525] The terminal displays this commented code to the user, allowing the user to immediately understand the intent of the code.
[0526] How to use
[0527] The user experience when using the system is as follows:
[0528] 1. The user uploads the source code through the system interface.
[0529] 2. The server analyzes the received source code and generates comments.
[0530] 3. The server inserts the generated comments into the code and generates commented code.
[0531] 4. The terminal displays the generated commented code to the user.
[0532] This process allows developers to quickly understand others' code and significantly reduces the time it takes to learn new frameworks and algorithms.
[0533] As can be seen, the present invention is a system that allows users to efficiently understand and learn chords.
[0534] The processing flow will be explained below.
[0535] Step 1:
[0536] Users upload the source code they wish to analyze into the system's interface, which provides a file selection dialog and drag-and-drop functionality.
[0537] Step 2:
[0538] The device receives the uploaded source code and sends it to the server, which temporarily stores the code file.
[0539] Step 3:
[0540] The server parses the received code file, using a parser to split the code into tokens and generate an abstract syntax tree (AST).
[0541] Step 4:
[0542] The server parses the generated abstract syntax tree (AST) to extract the structure and functionality of the code, identifying function definitions, variable assignments, control structures, etc.
[0543] Step 5:
[0544] The server performs static and dynamic analysis: static analysis analyzes source code without executing it to identify dependencies and potential errors in the code, and dynamic analysis actually executes the code and observes its behavior.
[0545] Step 6:
[0546] The server generates a natural language comment based on the analysis results. Specifically, it generates a description of the function of each analyzed part. For example, for the function add_numbers, a comment such as "This function adds the arguments a and b" is created.
[0547] Step 7:
[0548] The server inserts the generated comments into the original source code at the appropriate places, respecting syntax and taking into account indentation and comment placement to maintain code readability.
[0549] Step 8:
[0550] The server generates commented source code and sends it to the user's terminal.
[0551] Step 9:
[0552] The terminal will display the received commented source code to the user, allowing the user to review the code comments and understand the content.
[0553] Step 10:
[0554] The user can edit the commented code as needed, save it, or use it in other development environments.
[0555] Example 1
[0556] Next, a description will be given of Example 1. In the following description, the data processing device 12 will be referred to as a "server" and the smart glasses 214 will be referred to as a "terminal."
[0557] Analyzing program code and quickly and accurately understanding its structure and function requires a lot of time and effort. It is also extremely time-consuming to manually insert appropriate comments based on the analysis results. This task is even more difficult when trying to understand someone else's code at first glance. A method for efficiently solving these problems is needed.
[0558] The specific processing by the specific processing unit 290 of the data processing device 12 in the first embodiment is realized by the following means.
[0559] In this invention, the server includes: [means for dividing code into tokens and generating an abstract syntax tree]; [means for extracting code structure and function using static analysis and dynamic analysis]; and [means for generating natural language comments using a generative AI model based on the extracted structure and function]. This automates the work of code analysis and comment generation / insertion, enabling users to quickly and accurately understand the intent of the code.
[0560] "Means for entering code" means the interface through which a user can upload program code to the system, including means such as drag-and-drop and file selection dialogs.
[0561] "Means for dividing code into tokens and generating an abstract syntax tree" refers to an analysis technology that divides program code into the smallest units called tokens and generates an abstract syntax tree (AST) based on them.
[0562] "Means for extracting the structure and function of code using static and dynamic analysis" refers to means for extracting detailed information about code using both static analysis, which analyzes the structure and function of program code without executing it, and dynamic analysis, which monitors its behavior during execution.
[0563] "Means for generating natural language comments using a generative AI model based on the extracted structure and functions" refers to means for automatically generating appropriate comments in natural language using a generative AI model (e.g., a large-scale language model) based on the code structure and functions obtained through analysis.
[0564] "Means for inserting generated comments into the appropriate places in the code while preserving indentation and formatting" refers to a technique for properly inserting generated comments into the corresponding places in the program code while maintaining the readability of the original code.
[0565] "Means for providing users with commented code" refers to means for providing users with program code with automatically inserted comments in a form that allows them to view and edit it.
[0566] MODE FOR CARRYING OUT THE INVENTION
[0567] The present invention relates to a code analysis system that helps users quickly and accurately understand other people's source code and add comments to that code. A specific embodiment of this system will be described below.
[0568] Users first upload their source code through an interface that makes it easy to provide source code using drag-and-drop functionality or a file selection dialog.
[0569] The server receives the uploaded source code and uses a parser to break the code into tokens. It then generates an Abstract Syntax Tree (AST) and performs static and dynamic analysis to analyze the code's structure and functionality in detail. This analysis phase uses the tokenized information and the AST to understand how each piece of code works.
[0570] Next, the server uses a generative AI model based on the analysis results to generate natural language comments. The generative AI model uses a large-scale language model (e.g., GPT) to generate natural language explanations for the structure and function of the analyzed code. These generated comments include explanations of the purpose of functions, the roles of variables, and the implementation intention of the algorithm.
[0571] The generated comments are inserted at the appropriate positions, adjusting indentation and line spacing appropriately to maintain the readability of the original code. The server generates the code with the comments and sends it to the user's terminal.
[0572] The terminal receives the commented code sent from the server and displays it to the user. By viewing this commented code, the user can quickly understand the intent and function of the source code. Furthermore, the user can also modify or add to the code as needed.
[0573] Specific examples
[0574] A specific example of operation is shown below.
[0575] If a user uploads Python code:
[0576] python
[0577] def add_numbers(a, b):
[0578] return a + b
[0579] result = add_numbers(5, 3)
[0580] print(result)
[0581] The server performs the process in the following steps.
[0582] 1. Break the code into tokens and analyze its structure.
[0583] 2. Generate a comment for the function definition "def add_numbers(a, b):" that says "This function takes two arguments and returns their sum."
[0584] 3. For the part "result = add_numbers(5, 3)", create a comment that says "Use the add_numbers function to add 5 and 3 and assign the result to result."
[0585] 4. Create a comment for the "print(result)" part, saying "Print the result", and insert comments into each part.
[0586] This results in the following commented generated code:
[0587] python
[0588] A function that adds two numbers
[0589] def add_numbers(a, b):
[0590] return a + b
[0591] Use the add_numbers function to add 5 and 3 and assign the result to result
[0592] result = add_numbers(5, 3)
[0593] Output the results
[0594] print(result)
[0595] Example prompt sentence:
[0596] To analyze the source code, follow these steps:
[0597] 1. Upload your source code files by dragging and dropping them into the system interface or by selecting them from the file selection dialog.
[0598] This system allows users to quickly and easily understand the structure and function of their code, greatly improving the efficiency of their development work.
[0599] The flow of the identification process in the first embodiment will be described with reference to FIG.
[0600] The flow of this system's program processing
[0601] Step 1: Upload your source code
[0602] Step 2: Receive the code and prepare it for analysis
[0603] Step 3: Tokenization and Abstract Syntax Tree Generation
[0604] Step 4: Static and Dynamic Analysis
[0605] Step 5: Auto-generating comments
[0606] Step 6: Inserting comments
[0607] Step 7: Provide commented code
[0608] Specific explanation of each processing step
[0609] Step 1: Upload your source code
[0610] The user uploads a source code file using the system's interface. The input is a source code file specified by the user (e.g., "example.py"). The output is that the uploaded source code file is sent to the server. The interface is provided using a drag-and-drop function or a file selection dialog.
[0611] Step 2: Receive the code and prepare it for analysis
[0612] The server receives source code uploaded by users. The input is the uploaded source code file. The server stores the source code in temporary memory and prepares it for the next analysis step. The output is the temporarily stored source code.
[0613] Step 3: Tokenization and Abstract Syntax Tree Generation
[0614] The server runs the received source code through a parser and divides it into tokens. The input is the stored source code. After tokenization, the server generates an abstract syntax tree (AST) based on the tokens. The output is the generated abstract syntax tree. Specifically, in this step, the code is decomposed according to the syntax rules to form a tree structure.
[0615] Step 4: Static and Dynamic Analysis
[0616] The server uses the generated abstract syntax tree to perform static and dynamic analysis. The input is the abstract syntax tree. Static analysis analyzes the code structure and interrelationships between functions, while dynamic analysis analyzes the changes in variables at runtime and the execution order of functions. The output is a detailed analysis result. Specifically, it analyzes function inputs and outputs, variable scopes, dependencies, etc.
[0617] Step 5: Auto-generating comments
[0618] The server uses a generative AI model based on the analysis results to generate natural language comments. The input is the detailed analysis results. The generative AI model (e.g., GPT) generates explanatory comments for each code section based on the analyzed data. The output is the generated comments. Specifically, the AI model generates function descriptions, variable uses, etc.
[0619] Step 6: Inserting comments
[0620] The server inserts the generated comments into the corresponding code positions. The input is the generated comments. The comments are inserted properly before the code, preserving indentation and formatting. The output is the source code with the comments inserted. This step uses techniques to place comments in the appropriate positions, taking into account the readability of the original code.
[0621] Step 7: Provide commented code
[0622] The server generates commented code and sends it to the user's device. The input is the source code with comments inserted. The device displays the received commented code for the user to view and edit. The output is the commented code displayed to the user. Specifically, the commented code is displayed on the user's device, allowing the user to quickly understand the intent of the code.
[0623] (Application example 1)
[0624] Next, a description will be given of Application Example 1. In the following description, the data processing device 12 will be referred to as a "server" and the smart glasses 214 will be referred to as a "terminal."
[0625] Traditional source code analysis tools have not been able to provide sufficient support for quickly and accurately understanding other people's source code. In particular, it takes a lot of time and effort to gain a deep understanding of the code's structure and functionality, and manually adding comments to aid in code understanding is tedious. This makes it inefficient for developers to learn new frameworks and algorithms.
[0626] The specific processing by the specific processing unit 290 of the data processing device 12 in the application example 1 is realized by the following means.
[0627] In this invention, the server includes means for inputting code, means for analyzing the code to extract structures and functions, means for generating natural language comments based on the extracted structures and functions, means for inserting the generated comments at appropriate positions in the code, means for providing the commented code to a user, means for transmitting the code uploaded to the user terminal to a cloud server, and means for performing syntax analysis, AST generation, static analysis, and dynamic analysis on the cloud server, thereby enabling rapid and accurate understanding of code and automating comment generation.
[0628] "Means for inputting code" refers to an interface that allows a user to upload source code to be analyzed into the system.
[0629] "Means for analyzing code to extract structure and functionality" refers to the process of dividing uploaded code into tokens, generating an abstract syntax tree, and analyzing its structure and functionality.
[0630] "Means for generating natural language comments based on extracted structure and function" refers to technology for automatically generating explanatory text for each part of code based on the analysis results.
[0631] "Means for inserting generated comments into appropriate locations in the code" refers to a process for inserting generated comments while preserving the readability of the original code.
[0632] "Means for providing commented code to a user" refers to technology that transmits the commented code to a user's device so that it can be displayed.
[0633] "Means for sending code uploaded to a user's device to a cloud server" refers to the function that allows a user to send source code from their own device to a server on the cloud.
[0634] "Means for performing syntax analysis, AST generation, static analysis, and dynamic analysis on a cloud server" refers to technologies for analyzing source code on a cloud server and performing syntax analysis, generating abstract syntax trees, and performing static and dynamic analysis.
[0635] This invention relates to a source code analysis system that helps users quickly and accurately understand other people's source code and add comments to that code. The configuration and operation of a specific system for implementing this invention are described below.
[0636] Entering Code
[0637] Users upload source code to be analyzed to the system using a drag-and-drop or file selection dialog interface on their terminal, allowing users to easily input code.
[0638] Sending the code
[0639] The user device sends the uploaded code to the cloud server via a method such as an HTTP POST request.
[0640] Code Analysis
[0641] The cloud server analyzes the received code. As a first step, it uses a parser to split the code into tokens and generate an Abstract Syntax Tree (AST). Next, the server uses static and dynamic analysis techniques to perform a detailed analysis of the code's structure and functionality.
[0642] Comment Generation
[0643] Based on the analysis results, the cloud server uses an automatic comment generation module to generate natural language explanations for each code section. A generative AI model such as GPT-4 can be used here. The generation process is performed by passing the following prompt to the model:
[0644] python
[0645] prompt_text = "Generate comments for the following Python code, explaining the meaning of each line.\n\n{}\n\n Add your comments:".format(original_code)
[0646] Inserting comments
[0647] The cloud server inserts the generated comments into the corresponding code locations, using techniques that preserve proper indentation and formatting to preserve the readability of the original code.
[0648] Provides commented code
[0649] The cloud server generates commented code and sends it to the user's device, which displays the received commented code and arranges it for the user to view and edit.
[0650] Hardware and software used
[0651] Smartphone: Used to implement the user interface and send and receive code.
[0652] Cloud Server: The central source code analysis and comment generation center, including a parser, an AST generator, static analysis, and dynamic analysis modules.
[0653] Generative AI models: Generate comments using natural language processing models such as GPT-4.
[0654] Specific examples
[0655] Suppose a user uploads the following Python code to the system:
[0656] python
[0657] def multiply_numbers(x, y):
[0658] return xy
[0659] result = multiply_numbers(7, 8)
[0660] print(result)
[0661] The cloud server will parse this code and generate and insert comments like this:
[0662] python
[0663] A function that multiplies two numbers
[0664] def multiply_numbers(x, y):
[0665] return xy
[0666] Multiply 7 and 8 using the multiply_numbers function and assign the result to result
[0667] result = multiply_numbers(7, 8)
[0668] Output the results
[0669] print(result)
[0670] This process allows developers to quickly understand others' code and significantly reduces the time it takes to learn new frameworks and algorithms.
[0671] The flow of the specific processing in the application example 1 will be described with reference to FIG.
[0672] Step 1:
[0673] The user launches the application on their smartphone and selects the source code file to analyze. The user uploads the code using a file selection dialog or drag-and-drop function, and the application reads the code file. The input here is the source code file, and the output is the content of that file.
[0674] Step 2:
[0675] The user device sends the loaded source code to the cloud server. This transmission is performed using an HTTP POST request, etc. The input here is the string data of the source code, and the output is a confirmation of successful transmission to the cloud server.
[0676] Step 3:
[0677] The cloud server invokes a parser to parse the received source code, splitting the code into tokens, and then generates an Abstract Syntax Tree (AST), where the input is the received source code and the output is the generated AST.
[0678] Step 4:
[0679] The cloud server performs static and dynamic analysis based on the generated AST. Static analysis identifies the code's structure and functionality, while dynamic analysis checks the code's behavior at runtime. The input here is the AST, and the output is a detailed analysis of the code's structure and functionality.
[0680] Step 5:
[0681] Based on the analysis results, the cloud server uses a generative AI model (e.g., GPT-4) to generate natural language comments for each piece of code. Comment generation is done using the following prompt:
[0682] python
[0683] prompt_text = "Generate comments for the following Python code, explaining the meaning of each line.\n\n{}\n\n Add your comments:".format(original_code)
[0684] The input here is the analysis result and the prompt statement, and the output is the generated comment.
[0685] Step 6:
[0686] The cloud server inserts the generated comments into the corresponding code locations, performs formatting to maintain proper indentation and formatting, and generates highly readable commented code. The input here is the generated comments and the original code, and the output is the code with the comments inserted.
[0687] Step 7:
[0688] The cloud server sends the commented code to the user's device, where the input is the commented code and the output is a confirmation of successful transmission to the user's device.
[0689] Step 8:
[0690] The user device displays the received commented code on the screen and arranges it for easy viewing by the user. The input here is the commented code, and the output is the display result presented to the user.
[0691] This series of steps allows developers to quickly and accurately understand other people's code and efficiently learn new frameworks and algorithms with reduced effort.
[0692] Furthermore, an emotion engine that estimates the user's emotion may be further combined. That is, the identification processing unit 290 may estimate the user's emotion using the emotion identification model 59, and perform identification processing using the user's emotion.
[0693] The present invention relates to a system that promotes user understanding by combining a code analysis system with an emotion engine to recognize the user's emotional state and reflect this in the generation and presentation of comments based on the analysis results.
[0694] In addition to the basic functions of analyzing the source code entered by the user and generating and inserting comments, this system also uses an emotion engine to recognize the user's emotions and adjust the content of the comments based on that information.
[0695] Entering Code
[0696] Users upload source code to be analyzed into the system's interface, which provides file selection dialogs and drag-and-drop functionality.
[0697] Code Analysis
[0698] The server receives the uploaded code file, first splits the code into tokens using a parser and generates an Abstract Syntax Tree (AST), then uses static and dynamic analysis techniques to analyze the code's structure and functionality in detail.
[0699] Emotion recognition
[0700] The server recognizes the user's emotional state using an emotion engine, which evaluates the user's current stress level, satisfaction, excitement, etc. based on the input code and the user's interactions.
[0701] Comment Generation
[0702] The server generates a natural language comment based on the analysis results. It adjusts the content and tone of the comment based on the user's emotional state, as determined by the emotion engine. For example, if the user is feeling stressed, the comment will be more polite and kind.
[0703] Inserting comments
[0704] The server inserts the generated comments into the original source code at the appropriate places, taking into account indentation and comment positioning to maintain code readability.
[0705] Provides commented code
[0706] The server generates commented source code and sends it to the user's terminal.
[0707] Presenting to the user
[0708] The terminal displays the source code with comments to the user, allowing the user to quickly understand the content of the source code by checking the comments adapted to the emotions.
[0709] Specific examples
[0710] As an example, consider the following Python code uploaded by a user to the system:
[0711] python
[0712] def add_numbers(a, b):
[0713] return a + b
[0714] result = add_numbers(5, 3)
[0715] print(result)
[0716] The server analyzes this code and uses an emotion engine to recognize the user's emotional state, then generates and inserts a comment such as: For example, if the user is feeling stressed, the comment will be kind and polite.
[0717] Example of the parsed code:
[0718] python
[0719] Hello! This function adds two numbers.
[0720] def add_numbers(a, b):
[0721] return a + b
[0722] Use the add_numbers function to add 5 and 3 and assign the result to result.
[0723] result = add_numbers(5, 3)
[0724] Finally, print the results.
[0725] print(result)
[0726] The terminal will display this commented code to the user to make it easier for them to understand.
[0727] How to use
[0728] The user experience when using the system is as follows:
[0729] 1. The user uploads the source code through the system interface.
[0730] 2. The server analyzes the received source code and generates comments.
[0731] 3. The server uses an emotion engine to recognize the user's emotions and adjust the content of the comment.
[0732] 4. The server inserts the generated comments into the code, generating commented code.
[0733] 5. The terminal will display the generated commented code to the user.
[0734] This process not only allows developers to quickly understand others' code and significantly reduces the time it takes to learn new frameworks and algorithms, but also provides empathetic support.
[0735] The processing flow will be explained below.
[0736] Step 1:
[0737] Users upload the source code they want to analyze into the system's interface, which provides a file selection dialog and drag-and-drop functionality.
[0738] Step 2:
[0739] The device receives the uploaded source code and sends it to the server, which temporarily stores the code file.
[0740] Step 3:
[0741] The server parses the received code file, using a parser to split the code into tokens and generate an Abstract Syntax Tree (AST).
[0742] Step 4:
[0743] The server parses the generated abstract syntax tree (AST) to extract the structure and functionality of the code, identifying function definitions, variable assignments, control structures, etc.
[0744] Step 5:
[0745] The server performs static and dynamic analysis: static analysis analyzes source code without executing it to identify dependencies and potential errors in the code, and dynamic analysis actually executes the code and observes its behavior.
[0746] Step 6:
[0747] The server recognizes the user's emotional state using an emotion engine, which analyzes inputs and the user's past interactions to assess the user's stress level, satisfaction, excitement, etc.
[0748] Step 7:
[0749] The server generates natural language comments based on the analysis results and the output of the emotion engine. For example, if the user is feeling stressed, the comment will be changed to be more kind and polite.
[0750] Step 8:
[0751] The server inserts the generated comments into the original source code at the appropriate places, respecting syntax and taking into account indentation and comment placement to maintain code readability.
[0752] Step 9:
[0753] The server generates commented source code and sends it to the user's terminal.
[0754] Step 10:
[0755] The terminal will display the received commented source code to the user, who can then review the generated comments and quickly understand the code content.
[0756] As a concrete example, consider the case where a user uploads the following Python code to the system:
[0757] python
[0758] def add_numbers(a, b):
[0759] return a + b
[0760] result = add_numbers(5, 3)
[0761] print(result)
[0762] The server analyzes this code. First, it generates an abstract syntax tree using a parser, then performs static and dynamic analysis. Based on the analysis results, it uses an emotion engine to recognize the user's emotional state.
[0763] For example, if a user is feeling stressed, the following comment is generated and inserted:
[0764] python
[0765] Hello! This function adds two numbers.
[0766] def add_numbers(a, b):
[0767] return a + b
[0768] Use the add_numbers function to add 5 and 3 and assign the result to result.
[0769] result = add_numbers(5, 3)
[0770] Finally, print the results.
[0771] print(result)
[0772] The terminal will display this commented code to the user for easier understanding, and the user can review it, edit it, and save it as needed. In this way, the system can provide comments that respond to the user's emotions, improving their understanding and learning of the code.
[0773] Example 2
[0774] Next, a description will be given of Example 2. In the following description, the data processing device 12 will be referred to as a "server" and the smart glasses 214 will be referred to as a "terminal."
[0775] Current code analysis systems analyze code structure and function and insert comments to aid code comprehension, but they do not take the user's emotional state into account. As a result, if a user is feeling stressed or confused, the generated comments may not be appropriate for the user's state and may actually hinder comprehension. Furthermore, existing systems lack detailed code analysis using static and dynamic analysis, making it difficult to generate high-quality comments.
[0776] The specific processing by the specific processing unit 290 of the data processing device 12 in the second embodiment is realized by the following means.
[0777] In this invention, the server includes: [means for inputting code;] [means for analyzing the code to extract structure and function;] [means for generating natural language comments based on the extracted structure and function;] [means for inserting the generated comments at appropriate positions in the code;] [means for providing the commented code to a user;] [means for recognizing the user's emotional state and adjusting the content of the comments;] [means for identifying the structure and function of the code using static analysis] and [means for confirming the runtime behavior of the code using dynamic analysis]; [means for recognizing the user's emotional state using an emotion recognition engine] and [means for adjusting the tone of the comments based on the emotion recognition engine]. This makes it possible to insert polite and kind comments that are adapted to the user's emotional state, thereby promoting understanding of the code and reducing user stress and confusion.
[0778] "Means for inputting code" refers to a function that provides an interface for users to upload source code to be analyzed into the system.
[0779] "Means for analyzing code and extracting structure and function" refers to a function in which the server analyzes uploaded code and performs processing to understand its internal structure and operation.
[0780] "Means for generating natural language comments based on the extracted structure and functions" refers to a function in which the server generates comments in natural language based on the results of code analysis.
[0781] "Means for inserting generated comments into appropriate positions in code" is a function for adding generated comments into appropriate positions in code to improve code readability and comprehension.
[0782] "Means for providing commented code to users" means a function for sending users source code with added comments.
[0783] "Means for recognizing a user's emotional state and adjusting the content of comments" refers to a function that uses an emotion recognition engine to grasp a user's emotions and appropriately adjust the tone and content of comments based on that state.
[0784] "Means of identifying the structure and functionality of code using static analysis" refers to a feature that provides a way to analyze the structure and potential problems of code before it is executed.
[0785] "Means of using dynamic analysis to check the runtime behavior of code" is a feature that provides a way to actually run code and check its behavior and performance.
[0786] "Means for generating an abstract syntax tree of code" refers to a function that analyzes code and generates an abstract syntax tree (AST) that represents its structure in a tree-like format.
[0787] The "means for analyzing each part of the code based on the generated abstract syntax tree" is a function that uses the generated abstract syntax tree to analyze in detail the meaning and role of each part of the code.
[0788] "Means for recognizing a user's emotional state using an emotion recognition engine" refers to a function that uses a specific algorithm or artificial intelligence to read a user's emotions.
[0789] The "means for adjusting the tone of comments based on an emotion recognition engine" is a function that appropriately changes the content and expression of comments depending on the results of the user's emotions obtained by the emotion recognition engine.
[0790] This invention relates to a system that recognizes the user's emotional state and reflects it in the generation and presentation of comments based on the analysis results by combining an emotion engine with a code analysis system. In addition to the basic functions of analyzing source code entered by the user and generating and inserting comments, this system also uses the emotion engine to recognize the user's emotions and adjusts the content of the comments based on that information.
[0791] Basic system configuration
[0792] Entering Code
[0793] Users upload source code to be analyzed into the system's interface, which provides file selection dialogs and drag-and-drop functionality.
[0794] Receive and save the code
[0795] The server receives the uploaded code file and saves it in a local directory. Specifically, it receives an HTTP POST request and saves the file on the server side.
[0796] Code Analysis
[0797] The server analyzes the code using the following techniques:
[0798] Parsing: Split the uploaded code into tokens and generate an Abstract Syntax Tree (AST). Use the Python ast module and the ast.parse function to generate an AST.
[0799] Static analysis: Using tools such as pylint, potential problems in the code are identified.
[0800] Dynamic analysis: Running unit tests to verify that the code behaves as expected.
[0801] Emotion recognition
[0802] The server uses an emotion engine to recognize the user's emotional state, using the Google Cloud Natural Language API and IBM Watson Tone Analyzer, to assess the user's current stress level, satisfaction, excitement, etc. based on the code entered by the user and past interaction data.
[0803] Comment Generation
[0804] The server generates a natural language comment based on the analysis results, using a generative AI model (e.g., GPT-3). The prompt for comment generation is set as follows:
[0805] "Generate polite comments for the following code:"
[0806] The analyzed code content is entered following the prompt statement to query the AI model.
[0807] Inserting comments
[0808] The server inserts the generated comment into the original source code at the appropriate position. When inserting the comment, it places it in the correct position based on the abstract syntax tree and formats it using Python's autopep8. For example, if the generated comment is "This function is for adding two numbers," it will be inserted just before the function definition.
[0809] Provides commented code
[0810] The server generates source code with the added comments and sends it to the user's terminal.
[0811] Presenting to the user
[0812] The device displays the commented source code to the user, who can then view it in a web browser or dedicated application, with highlighting features to help users easily identify emotionally charged comments.
[0813] Specific examples
[0814] As an example, consider the case where a user uploads the following Python code to the system:
[0815] python
[0816] def add_numbers(a, b):
[0817] return a + b
[0818] result = add_numbers(5, 3)
[0819] print(result)
[0820] The server analyzes this code, uses an emotion engine to recognize the user's emotional state, and then generates and inserts a comment like this:
[0821] python
[0822] Hello! This function adds two numbers.
[0823] def add_numbers(a, b):
[0824] return a + b
[0825] Use the add_numbers function to add 5 and 3 and assign the result to result.
[0826] result = add_numbers(5, 3)
[0827] Finally, print the results.
[0828] print(result)
[0829] The terminal displays this commented code to the user to make it easier for the user to understand.
[0830] This system not only allows developers to quickly understand other people's code and significantly reduces the time it takes to learn new frameworks and algorithms, but also provides support that responds to the user's emotions.
[0831] The flow of the identification process in the second embodiment will be described with reference to FIG.
[0832] Step 1:
[0833] The user uploads the source code to be analyzed into the system interface by opening a file selection dialog or dropping the code file into the drag-and-drop area.
[0834] Input: Source code file
[0835] Output: Uploaded source code data
[0836] Step 2:
[0837] The server receives the uploaded source code file and saves it to a local directory. The server receives an HTTP POST request and writes the file.
[0838] Input: Uploaded source code data
[0839] Output: Source code files stored on the server
[0840] Step 3:
[0841] The server uses a parser to split the source code into tokens and generate an Abstract Syntax Tree (AST). Specifically, it uses the Python ast module and the ast.parse function to generate an AST.
[0842] Input: Source code files stored on the server
[0843] Output: Abstract syntax tree (AST)
[0844] Step 4:
[0845] The server analyzes the source code using static analysis tools (e.g., pylint) to determine the structure and functionality of the code. This analysis identifies potential issues and areas for improvement in the source code.
[0846] Input: Abstract Syntax Tree (AST)
[0847] Output: Static analysis result data
[0848] Step 5:
[0849] The server performs dynamic analysis to verify the runtime behavior of the code, specifically by running unit tests to verify that the source code behaves as expected.
[0850] Input: Source code file
[0851] Output: Dynamic analysis result data
[0852] Step 6:
[0853] The server uses an emotion engine to recognize the user's emotional state, using Google Cloud Natural Language API and IBM Watson Tone Analyzer to evaluate the code entered by the user and past interaction data to obtain an emotion score.
[0854] Input: Source code and user interaction data
[0855] Output: User's emotional state data
[0856] Step 7:
[0857] The server generates a natural language comment based on the analysis results and the user's emotional state. Using a generative AI model (e.g., GPT-3), the server queries the AI model by entering the prompt "Please generate a polite comment for the following code."
[0858] Input: Static analysis result data, dynamic analysis result data, user emotional state data
[0859] Output: Generated natural language comment
[0860] Step 8:
[0861] The server inserts the generated comments into the appropriate positions in the source code based on the abstract syntax tree, and then formats the entire code using a formatting tool such as Python's autopep8.
[0862] Input: Source code files, generated natural language comments
[0863] Output: Commented source code
[0864] Step 9:
[0865] The server sends the commented source code to the user's terminal. Specifically, the server returns the commented source code as an HTTP response.
[0866] Input: Commented source code
[0867] Output: Commented source code sent to the user's terminal
[0868] Step 10:
[0869] The device displays the commented source code to the user. Specifically, the code is displayed in a web browser or a dedicated application, and the user can easily check the comments using highlighting functions.
[0870] Input: Commented source code sent to the user's terminal
[0871] Output: Commented source code displayed to the user
[0872] The above is the specific processing flow of this system.
[0873] (Application example 2)
[0874] Next, a description will be given of Application Example 2. In the following description, the data processing device 12 will be referred to as a "server" and the smart glasses 214 will be referred to as a "terminal."
[0875] Factory robot programs are complex, requiring engineers to understand them quickly and accurately. However, engineers often experience stress and difficulty in understanding the programs, resulting in decreased production efficiency and work accuracy. Furthermore, there has been no method to provide real-time support that responds to the engineers' emotions, so a new method to help them understand the programs is needed.
[0876] The specific processing by the specific processing unit 290 of the data processing device 12 in Application Example 2 is realized by the following means. In this invention, the server includes means for inputting code, means for analyzing the code to extract its structure and function, means for generating comments in natural language based on the extracted structure and function, means for adjusting the content of the generated comments based on the user's emotional state, and means for providing the commented code to a display device in real time. This allows the provision of commented code that is adapted to the engineer's emotional state, enabling the engineer to quickly and easily understand the program.
[0877] A "means for inputting code" is an interface or mechanism that allows a technician to upload the program code of a factory robot into the system.
[0878] "Means of analyzing code to extract structure and function" is the process of breaking down code into tokens and parsing it to generate an abstract syntax tree (AST) of the code, identifying its structure and function in detail.
[0879] "Means for generating natural language comments based on extracted structures and functions" is a mechanism that automatically generates natural language explanations for each part of the analyzed code to make it easier to understand.
[0880] "Means for adjusting the content of generated comments based on the emotional state of the user" refers to a process in which the emotional engine recognizes the emotional state of the engineer and adjusts the tone and content of the generated comments accordingly.
[0881] The "means for providing commented code to a display device in real time" is a mechanism for quickly transmitting the generated commented code to a display device such as a head-mounted display worn by the engineer and displaying it in real time.
[0882] To implement this invention, it is necessary to build a system for analyzing factory robot programs and generating comments. This system consists of a server, a terminal, and a user interface. The specific operation of each component and the hardware and software used are described below.
[0883] Server roles and technologies used
[0884] The server initially receives the robot's program code uploaded by the engineer through an input interface that provides a file selection dialog and drag-and-drop functionality.
[0885] To perform the code analysis process, the server first uses a parsing library to split the code into tokens and generate an Abstract Syntax Tree (AST), then uses static and dynamic analysis techniques to identify the code's structure and functionality for further analysis.
[0886] Next, an emotion engine library is used to recognize the technician's emotional state, which is evaluated based on the technician's inputs and interactions, taking into account stress levels, satisfaction, excitement, etc.
[0887] Generate natural language comments based on the analyzed information and emotional state, with the tone and content of the comments tailored based on the specific code analysis results and emotional state.
[0888] The generated comments are inserted into the code at the appropriate point, automatically adjusting indentation and comment positioning, and then the commented code is delivered in real time to the engineer's terminal or head-mounted display (HMD).
[0889] Device role and technology used
[0890] The engineer's terminal, especially the head-mounted display (HMD), displays the commented code sent from the server in real time, allowing the engineer to always check the latest comments and code while working, improving understanding and work efficiency.
[0891] User roles and operating procedures
[0892] The engineer uploads the program code through the system's interface, then inputs the current emotional state into the interface, which the system analyzes with its emotion engine.
[0893] Engineers can use the HMD to view commented code displayed in real time as they work, making it easier to understand the program and allowing them to quickly and accurately modify or create new programs for factory robots.
[0894] Examples of specific examples and prompts
[0895] As a concrete example, consider the case where an engineer uploads the following robot program code:
[0896] python
[0897] def control_robot(speed, direction):
[0898] move_robot(speed, direction)
[0899] check_obstacle()
[0900] return 'Success'
[0901] If the engineer's emotional state is recognized as "Stress: 0.8, Satisfaction: 0.5", the system will generate and insert the following comment:
[0902] python
[0903] Hello! Functions for controlling the speed and direction of a robot.
[0904] def control_robot(speed, direction):
[0905] move_robot(speed, direction)
[0906] Check for obstructions.
[0907] check_obstacle()
[0908] Finally, it returns whether the operation was successful.
[0909] return 'Success'
[0910] This commented code is displayed in real time on the HMD, helping engineers to quickly understand it.
[0911] Prompt Sentence Examples
[0912] "Analyze the robot's operating program code and generate and display comments based on the engineer's emotional state emotion_state."
[0913] In this way, the system of the present invention provides commented code that is adapted to the emotional state of the engineer, thereby promoting understanding of factory robot programs and improving the engineer's work efficiency.
[0914] The flow of the specific processing in the application example 2 will be described with reference to FIG.
[0915] Step 1:
[0916] Users upload factory robot program code through an input interface that provides file selection dialogs and drag-and-drop functionality. The uploaded code is sent to a server and prepared for analysis.
[0917] Step 2:
[0918] The server processes the received program code with a code analysis library, splitting the code into tokens, and then uses a parser to generate an Abstract Syntax Tree (AST). This analysis process extracts the structure and functionality of the code.
[0919] Output: Abstract syntax tree and detailed code structure information
[0920] Step 3:
[0921] The server then performs further analysis of the extracted structural information using static and dynamic analysis: static analysis identifies the code's components, and dynamic analysis examines the code's behavior at runtime, providing a complete understanding of the code's functionality and behavior.
[0922] Output: Detailed code functionality and behavior information
[0923] Step 4:
[0924] The user inputs their current emotional state into the input interface. The emotional state is input as numerical data such as stress level, satisfaction level, and excitement level, and is then sent to the server.
[0925] Input: User's emotional state data
[0926] Step 5:
[0927] The server uses an emotion engine to analyze the received emotional state data and evaluate the user's current emotional state, which in turn evaluates the user's stress level, satisfaction, excitement, etc.
[0928] Output: Evaluation result of the user's emotional state
[0929] Step 6:
[0930] The server generates natural language comments based on the analyzed code structure and function information, as well as the emotional state assessment results. The comments are created using a generative AI model and are adjusted in tone and content according to the user's emotional state.
[0931] Output: Tailored natural language comments
[0932] Step 7:
[0933] The server inserts the generated comments into the original program code at the appropriate positions, automatically adjusting indentation and comment positioning to maintain code readability.
[0934] Output: Commented program code
[0935] Step 8:
[0936] The server sends commented program code to the engineer's terminal or head-mounted display (HMD) in real time, and the terminal displays the received commented code in real time, allowing the engineer to quickly understand the content of the code.
[0937] Output: Commented code displayed in real time
[0938] For example, you can use the following prompt to see it in action:
[0939] "Analyze the robot's operating program code and generate and display comments based on the engineer's emotional state emotion_state."
[0940] The specific processing unit 290 transmits the result of the specific processing to the smart glasses 214. In the smart glasses 214, the control unit 46A causes the speaker 240 to output the result of the specific processing. The microphone 238 acquires audio indicating a user input regarding the result of the specific processing. The control unit 46A transmits audio data indicating the user input acquired by the microphone 238 to the data processing device 12. In the data processing device 12, the specific processing unit 290 acquires the audio data.
[0941] The data generation model 58 is a so-called generative AI (Artificial Intelligence). An example of the data generation model 58 is ChatGPT (Internet Search<URL: https: / / openai.com / blog / chatgpt> ), Gemini (Internet search <url: https: gemini.google.com ?hl="ja">) and other generation AIs. The data generation model 58 is obtained by performing deep learning on a neural network. A prompt including an instruction is input to the data generation model 58, and inference data such as voice data indicating voice, text data indicating text, and image data indicating an image is also input. The data generation model 58 performs inference on the input inference data in accordance with the instruction indicated by the prompt, and outputs the inference result in a data format such as voice data and text data. Here, inference refers to, for example, analysis, classification, prediction, and / or summarization.
[0942] In the above embodiment, an example in which the specific processing is performed by the data processing device 12 has been given, but the technology of the present disclosure is not limited to this, and the specific processing may be performed by the smart glasses 214.
[0943] [Third embodiment]
[0944] FIG. 5 shows an example of the configuration of a data processing system 310 according to the third embodiment.
[0945] 5, the data processing system 310 includes the data processing device 12 and a headset type terminal 314. An example of the data processing device 12 is a server.
[0946] The data processing device 12 includes a computer 22, a database 24, and a communication I / F 26. The computer 22 is an example of a "computer" according to the technology of the present disclosure. The computer 22 includes a processor 28, a RAM 30, and a storage 32. The processor 28, the RAM 30, and the storage 32 are connected to a bus 34. The database 24 and the communication I / F 26 are also connected to the bus 34. The communication I / F 26 is connected to a network 54. Examples of the network 54 include a WAN (Wide Area Network) and / or a LAN (Local Area Network).
[0947] The headset type terminal 314 includes a computer 36, a microphone 238, a speaker 240, a camera 42, a communication I / F 44, and a display 343. The computer 36 includes a processor 46, a RAM 48, and a storage 50. The processor 46, the RAM 48, and the storage 50 are connected to a bus 52. The microphone 238, the speaker 240, the camera 42, and the display 343 are also connected to the bus 52.
[0948] The microphone 238 receives instructions and the like from the user 20 by receiving voice uttered by the user 20. The microphone 238 captures the voice uttered by the user 20, converts the captured voice into audio data, and outputs it to the processor 46. The speaker 240 outputs audio in accordance with instructions from the processor 46.
[0949] Camera 42 is a small digital camera equipped with an optical system including a lens, aperture, and shutter, and an imaging element such as a CMOS (Complementary Metal-Oxide-Semiconductor) image sensor or a CCD (Charge Coupled Device) image sensor, and captures images of the surroundings of user 20 (for example, an imaging range defined by an angle of view equivalent to the field of vision of a typical healthy person).
[0950] The communication I / F 44 is connected to a network 54. The communication I / Fs 44 and 26 are responsible for the exchange of various information between the processor 46 and the processor 28 via the network 54. The exchange of various information between the processor 46 and the processor 28 using the communication I / Fs 44 and 26 is carried out in a secure state.
[0951] Fig. 6 shows an example of the main functions of the data processing device 12 and the headset type terminal 314. As shown in Fig. 6, in the data processing device 12, a specific process is performed by the processor 28. A specific process program 56 is stored in the storage 32.
[0952] The specific processing program 56 is an example of a "program" according to the technology of the present disclosure. The processor 28 reads the specific processing program 56 from the storage 32 and executes the read specific processing program 56 on the RAM 30. The specific processing is realized by the processor 28 operating as a specific processing unit 290 in accordance with the specific processing program 56 executed on the RAM 30.
[0953] The storage 32 stores a data generation model 58 and an emotion identification model 59. The data generation model 58 and the emotion identification model 59 are used by the identification processing unit 290.
[0954] In the headset type terminal 314, a reception output process is performed by the processor 46. A reception output program 60 is stored in the storage 50. The processor 46 reads the reception output program 60 from the storage 50 and executes the read reception output program 60 on the RAM 48. The reception output process is realized by the processor 46 operating as the control unit 46A in accordance with the reception output program 60 executed on the RAM 48.
[0955] Next, a description will be given of the identification process performed by the identification processing unit 290 of the data processing device 12. In the following description, the data processing device 12 will be referred to as the "server" and the headset type terminal 314 will be referred to as the "terminal."
[0956] This invention relates to a code analysis system that helps users quickly and accurately understand other people's source code and add comments to that code. A specific embodiment of the system is described below.
[0957] In this system, a user inputs source code, a server analyzes the code, generates comments and inserts comments, and a terminal outputs the commented code.
[0958] Entering Code
[0959] The user uses an interface to upload source code to be analyzed into the system, which is implemented via drag-and-drop or a file selection dialog.
[0960] Code Analysis
[0961] The server receives the uploaded code, first uses a parser to split the code into tokens and generate an Abstract Syntax Tree (AST), then uses static and dynamic analysis techniques to perform a detailed analysis of the code's structure and functionality.
[0962] Comment Generation
[0963] Based on the analysis results, the server uses an automatic comment generation module to generate natural language explanations for each part of the code. For example, for a function definition, it generates a comment such as "This function adds the arguments a and b."
[0964] Inserting comments
[0965] The server inserts the generated comments into the corresponding code locations, including techniques to preserve the readability and proper indentation and formatting of the original code.
[0966] Provides commented code
[0967] The server generates commented code and sends it to the user's device, which then displays the received commented code and prepares it for the user to view and edit.
[0968] Specific examples
[0969] Suppose a user uploads the following Python code to the system:
[0970] python
[0971] def add_numbers(a, b):
[0972] return a + b
[0973] result = add_numbers(5, 3)
[0974] print(result)
[0975] The server will parse this code and generate and insert the following comment:
[0976] Example of the parsed code:
[0977] python
[0978] A function that adds two numbers
[0979] def add_numbers(a, b):
[0980] return a + b
[0981] Use the add_numbers function to add 5 and 3 and assign the result to result
[0982] result = add_numbers(5, 3)
[0983] Output the results
[0984] print(result)
[0985] The terminal displays this commented code to the user, allowing the user to immediately understand the intent of the code.
[0986] How to use
[0987] The user experience when using the system is as follows:
[0988] 1. The user uploads the source code through the system interface.
[0989] 2. The server analyzes the received source code and generates comments.
[0990] 3. The server inserts the generated comments into the code and generates commented code.
[0991] 4. The terminal displays the generated commented code to the user.
[0992] This process allows developers to quickly understand others' code and significantly reduces the time it takes to learn new frameworks and algorithms.
[0993] As can be seen, the present invention is a system that allows users to efficiently understand and learn chords.
[0994] The processing flow will be explained below.
[0995] Step 1:
[0996] Users upload the source code they wish to analyze into the system's interface, which provides a file selection dialog and drag-and-drop functionality.
[0997] Step 2:
[0998] The device receives the uploaded source code and sends it to the server, which temporarily stores the code file.
[0999] Step 3:
[1000] The server parses the received code file, using a parser to split the code into tokens and generate an abstract syntax tree (AST).
[1001] Step 4:
[1002] The server parses the generated abstract syntax tree (AST) to extract the structure and functionality of the code, identifying function definitions, variable assignments, control structures, etc.
[1003] Step 5:
[1004] The server performs static and dynamic analysis: static analysis analyzes source code without executing it to identify dependencies and potential errors in the code, and dynamic analysis actually executes the code and observes its behavior.
[1005] Step 6:
[1006] The server generates a natural language comment based on the analysis results. Specifically, it generates a description of the function of each analyzed part. For example, for the function add_numbers, a comment such as "This function adds the arguments a and b" is created.
[1007] Step 7:
[1008] The server inserts the generated comments into the original source code at the appropriate places, respecting syntax and taking into account indentation and comment placement to maintain code readability.
[1009] Step 8:
[1010] The server generates commented source code and sends it to the user's terminal.
[1011] Step 9:
[1012] The terminal will display the received commented source code to the user, allowing the user to review the code comments and understand the content.
[1013] Step 10:
[1014] The user can edit the commented code as needed, save it, or use it in other development environments.
[1015] Example 1
[1016] Next, a description will be given of Example 1. In the following description, the data processing device 12 will be referred to as a "server" and the headset type terminal 314 will be referred to as a "terminal."
[1017] Analyzing program code and quickly and accurately understanding its structure and function requires a lot of time and effort. It is also extremely time-consuming to manually insert appropriate comments based on the analysis results. This task is even more difficult when trying to understand someone else's code at first glance. A method for efficiently solving these problems is needed.
[1018] The specific processing by the specific processing unit 290 of the data processing device 12 in the first embodiment is realized by the following means.
[1019] In this invention, the server includes: [means for dividing code into tokens and generating an abstract syntax tree]; [means for extracting code structure and function using static analysis and dynamic analysis]; and [means for generating natural language comments using a generative AI model based on the extracted structure and function]. This automates the work of code analysis and comment generation / insertion, enabling users to quickly and accurately understand the intent of the code.
[1020] "Means for entering code" means the interface through which a user can upload program code to the system, including means such as drag-and-drop and file selection dialogs.
[1021] "Means for dividing code into tokens and generating an abstract syntax tree" refers to an analysis technology that divides program code into the smallest units called tokens and generates an abstract syntax tree (AST) based on them.
[1022] "Means for extracting the structure and function of code using static and dynamic analysis" refers to means for extracting detailed information about code using both static analysis, which analyzes the structure and function of program code without executing it, and dynamic analysis, which monitors its behavior during execution.
[1023] "Means for generating natural language comments using a generative AI model based on the extracted structure and functions" refers to means for automatically generating appropriate comments in natural language using a generative AI model (e.g., a large-scale language model) based on the code structure and functions obtained through analysis.
[1024] "Means for inserting generated comments into the appropriate places in the code while preserving indentation and formatting" refers to a technique for properly inserting generated comments into the corresponding places in the program code while maintaining the readability of the original code.
[1025] "Means for providing users with commented code" refers to means for providing users with program code with automatically inserted comments in a form that allows them to view and edit it.
[1026] MODE FOR CARRYING OUT THE INVENTION
[1027] The present invention relates to a code analysis system that helps users quickly and accurately understand other people's source code and add comments to that code. A specific embodiment of this system will be described below.
[1028] Users first upload their source code through an interface that makes it easy to provide source code using drag-and-drop functionality or a file selection dialog.
[1029] The server receives the uploaded source code and uses a parser to break the code into tokens. It then generates an Abstract Syntax Tree (AST) and performs static and dynamic analysis to analyze the code's structure and functionality in detail. This analysis phase uses the tokenized information and the AST to understand how each piece of code works.
[1030] Next, the server uses a generative AI model based on the analysis results to generate natural language comments. The generative AI model uses a large-scale language model (e.g., GPT) to generate natural language explanations for the structure and function of the analyzed code. These generated comments include explanations of the purpose of functions, the roles of variables, and the implementation intention of the algorithm.
[1031] The generated comments are inserted at the appropriate positions, adjusting indentation and line spacing appropriately to maintain the readability of the original code. The server generates the code with the comments and sends it to the user's terminal.
[1032] The terminal receives the commented code sent from the server and displays it to the user. By viewing this commented code, the user can quickly understand the intent and function of the source code. Furthermore, the user can also modify or add to the code as needed.
[1033] Specific examples
[1034] A specific example of operation is shown below.
[1035] If a user uploads Python code:
[1036] python
[1037] def add_numbers(a, b):
[1038] return a + b
[1039] result = add_numbers(5, 3)
[1040] print(result)
[1041] The server performs the process in the following steps.
[1042] 1. Break the code into tokens and analyze its structure.
[1043] 2. Generate a comment for the function definition "def add_numbers(a, b):" that says "This function takes two arguments and returns their sum."
[1044] 3. For the part "result = add_numbers(5, 3)", create a comment that says "Use the add_numbers function to add 5 and 3 and assign the result to result."
[1045] 4. Create a comment for the "print(result)" part, saying "Print the result", and insert comments into each part.
[1046] This results in the following commented generated code:
[1047] python
[1048] A function that adds two numbers
[1049] def add_numbers(a, b):
[1050] return a + b
[1051] Use the add_numbers function to add 5 and 3 and assign the result to result
[1052] result = add_numbers(5, 3)
[1053] Output the results
[1054] print(result)
[1055] Example prompt sentence:
[1056] To analyze the source code, follow these steps:
[1057] 1. Upload your source code files by dragging and dropping them into the system interface or by selecting them from the file selection dialog.
[1058] This system allows users to quickly and easily understand the structure and function of their code, greatly improving the efficiency of their development work.
[1059] The flow of the identification process in the first embodiment will be described with reference to FIG.
[1060] The flow of this system's program processing
[1061] Step 1: Upload your source code
[1062] Step 2: Receive the code and prepare it for analysis
[1063] Step 3: Tokenization and Abstract Syntax Tree Generation
[1064] Step 4: Static and Dynamic Analysis
[1065] Step 5: Auto-generating comments
[1066] Step 6: Inserting comments
[1067] Step 7: Provide commented code
[1068] Specific explanation of each processing step
[1069] Step 1: Upload your source code
[1070] The user uploads a source code file using the system's interface. The input is a source code file specified by the user (e.g., "example.py"). The output is that the uploaded source code file is sent to the server. The interface is provided using a drag-and-drop function or a file selection dialog.
[1071] Step 2: Receive the code and prepare it for analysis
[1072] The server receives source code uploaded by users. The input is the uploaded source code file. The server stores the source code in temporary memory and prepares it for the next analysis step. The output is the temporarily stored source code.
[1073] Step 3: Tokenization and Abstract Syntax Tree Generation
[1074] The server runs the received source code through a parser and divides it into tokens. The input is the stored source code. After tokenization, the server generates an abstract syntax tree (AST) based on the tokens. The output is the generated abstract syntax tree. Specifically, in this step, the code is decomposed according to the syntax rules to form a tree structure.
[1075] Step 4: Static and Dynamic Analysis
[1076] The server uses the generated abstract syntax tree to perform static and dynamic analysis. The input is the abstract syntax tree. Static analysis analyzes the code structure and interrelationships between functions, while dynamic analysis analyzes the changes in variables at runtime and the execution order of functions. The output is a detailed analysis result. Specifically, it analyzes function inputs and outputs, variable scopes, dependencies, etc.
[1077] Step 5: Auto-generating comments
[1078] The server uses a generative AI model based on the analysis results to generate natural language comments. The input is the detailed analysis results. The generative AI model (e.g., GPT) generates explanatory comments for each code section based on the analyzed data. The output is the generated comments. Specifically, the AI model generates function descriptions, variable uses, etc.
[1079] Step 6: Inserting comments
[1080] The server inserts the generated comments into the corresponding code positions. The input is the generated comments. The comments are inserted properly before the code, preserving indentation and formatting. The output is the source code with the comments inserted. This step uses techniques to place comments in the appropriate positions, taking into account the readability of the original code.
[1081] Step 7: Provide commented code
[1082] The server generates commented code and sends it to the user's device. The input is the source code with comments inserted. The device displays the received commented code for the user to view and edit. The output is the commented code displayed to the user. Specifically, the commented code is displayed on the user's device, allowing the user to quickly understand the intent of the code.
[1083] (Application example 1)
[1084] Next, a description will be given of Application Example 1. In the following description, the data processing device 12 will be referred to as a "server" and the headset type terminal 314 will be referred to as a "terminal."
[1085] Traditional source code analysis tools have not been able to provide sufficient support for quickly and accurately understanding other people's source code. In particular, it takes a lot of time and effort to gain a deep understanding of the code's structure and functionality, and manually adding comments to aid in code understanding is tedious. This makes it inefficient for developers to learn new frameworks and algorithms.
[1086] The specific processing by the specific processing unit 290 of the data processing device 12 in the application example 1 is realized by the following means.
[1087] In this invention, the server includes means for inputting code, means for analyzing the code to extract structures and functions, means for generating natural language comments based on the extracted structures and functions, means for inserting the generated comments at appropriate positions in the code, means for providing the commented code to a user, means for transmitting the code uploaded to the user terminal to a cloud server, and means for performing syntax analysis, AST generation, static analysis, and dynamic analysis on the cloud server, thereby enabling rapid and accurate understanding of code and automating comment generation.
[1088] "Means for inputting code" refers to an interface that allows a user to upload source code to be analyzed into the system.
[1089] "Means for analyzing code to extract structure and functionality" refers to the process of dividing uploaded code into tokens, generating an abstract syntax tree, and analyzing its structure and functionality.
[1090] "Means for generating natural language comments based on extracted structure and function" refers to technology for automatically generating explanatory text for each part of code based on the analysis results.
[1091] "Means for inserting generated comments into appropriate locations in the code" refers to a process for inserting generated comments while preserving the readability of the original code.
[1092] "Means for providing commented code to a user" refers to technology that transmits the commented code to a user's device so that it can be displayed.
[1093] "Means for sending code uploaded to a user's device to a cloud server" refers to the function that allows a user to send source code from their own device to a server on the cloud.
[1094] "Means for performing syntax analysis, AST generation, static analysis, and dynamic analysis on a cloud server" refers to technologies for analyzing source code on a cloud server and performing syntax analysis, generating abstract syntax trees, and performing static and dynamic analysis.
[1095] This invention relates to a source code analysis system that helps users quickly and accurately understand other people's source code and add comments to that code. The configuration and operation of a specific system for implementing this invention are described below.
[1096] Entering Code
[1097] Users upload source code to be analyzed to the system using a drag-and-drop or file selection dialog interface on their terminal, allowing users to easily input code.
[1098] Sending the code
[1099] The user device sends the uploaded code to the cloud server via a method such as an HTTP POST request.
[1100] Code Analysis
[1101] The cloud server analyzes the received code. As a first step, it uses a parser to split the code into tokens and generate an Abstract Syntax Tree (AST). Next, the server uses static and dynamic analysis techniques to perform a detailed analysis of the code's structure and functionality.
[1102] Comment Generation
[1103] Based on the analysis results, the cloud server uses an automatic comment generation module to generate natural language explanations for each code section. A generative AI model such as GPT-4 can be used here. The generation process is performed by passing the following prompt to the model:
[1104] python
[1105] prompt_text = "Generate comments for the following Python code, explaining the meaning of each line.\n\n{}\n\n Add your comments:".format(original_code)
[1106] Inserting comments
[1107] The cloud server inserts the generated comments into the corresponding code locations, using techniques that preserve proper indentation and formatting to preserve the readability of the original code.
[1108] Provides commented code
[1109] The cloud server generates commented code and sends it to the user's device, which displays the received commented code and arranges it for the user to view and edit.
[1110] Hardware and software used
[1111] Smartphone: Used to implement the user interface and send and receive code.
[1112] Cloud Server: The central source code analysis and comment generation center, including a parser, an AST generator, static analysis, and dynamic analysis modules.
[1113] Generative AI models: Generate comments using natural language processing models such as GPT-4.
[1114] Specific examples
[1115] Suppose a user uploads the following Python code to the system:
[1116] python
[1117] def multiply_numbers(x, y):
[1118] return xy
[1119] result = multiply_numbers(7, 8)
[1120] print(result)
[1121] The cloud server will parse this code and generate and insert comments like this:
[1122] python
[1123] A function that multiplies two numbers
[1124] def multiply_numbers(x, y):
[1125] return xy
[1126] Multiply 7 and 8 using the multiply_numbers function and assign the result to result
[1127] result = multiply_numbers(7, 8)
[1128] Output the results
[1129] print(result)
[1130] This process allows developers to quickly understand others' code and significantly reduces the time it takes to learn new frameworks and algorithms.
[1131] The flow of the specific processing in the application example 1 will be described with reference to FIG.
[1132] Step 1:
[1133] The user launches the application on their smartphone and selects the source code file to analyze. The user uploads the code using a file selection dialog or drag-and-drop function, and the application reads the code file. The input here is the source code file, and the output is the content of that file.
[1134] Step 2:
[1135] The user device sends the loaded source code to the cloud server. This transmission is performed using an HTTP POST request, etc. The input here is the string data of the source code, and the output is a confirmation of successful transmission to the cloud server.
[1136] Step 3:
[1137] The cloud server invokes a parser to parse the received source code, splitting the code into tokens, and then generates an Abstract Syntax Tree (AST), where the input is the received source code and the output is the generated AST.
[1138] Step 4:
[1139] The cloud server performs static and dynamic analysis based on the generated AST. Static analysis identifies the code's structure and functionality, while dynamic analysis checks the code's behavior at runtime. The input here is the AST, and the output is a detailed analysis of the code's structure and functionality.
[1140] Step 5:
[1141] Based on the analysis results, the cloud server uses a generative AI model (e.g., GPT-4) to generate natural language comments for each piece of code. Comment generation is done using the following prompt:
[1142] python
[1143] prompt_text = "Generate comments for the following Python code, explaining the meaning of each line.\n\n{}\n\n Add your comments:".format(original_code)
[1144] The input here is the analysis result and the prompt statement, and the output is the generated comment.
[1145] Step 6:
[1146] The cloud server inserts the generated comments into the corresponding code locations, performs formatting to maintain proper indentation and formatting, and generates highly readable commented code. The input here is the generated comments and the original code, and the output is the code with the comments inserted.
[1147] Step 7:
[1148] The cloud server sends the commented code to the user's device, where the input is the commented code and the output is a confirmation of successful transmission to the user's device.
[1149] Step 8:
[1150] The user device displays the received commented code on the screen and arranges it for easy viewing by the user. The input here is the commented code, and the output is the display result presented to the user.
[1151] This series of steps allows developers to quickly and accurately understand other people's code and efficiently learn new frameworks and algorithms with reduced effort.
[1152] Furthermore, an emotion engine that estimates the user's emotion may be further combined. That is, the identification processing unit 290 may estimate the user's emotion using the emotion identification model 59, and perform identification processing using the user's emotion.
[1153] The present invention relates to a system that promotes user understanding by combining a code analysis system with an emotion engine to recognize the user's emotional state and reflect this in the generation and presentation of comments based on the analysis results.
[1154] In addition to the basic functions of analyzing the source code entered by the user and generating and inserting comments, this system also uses an emotion engine to recognize the user's emotions and adjust the content of the comments based on that information.
[1155] Entering Code
[1156] Users upload source code to be analyzed into the system's interface, which provides file selection dialogs and drag-and-drop functionality.
[1157] Code Analysis
[1158] The server receives the uploaded code file, first splits the code into tokens using a parser and generates an Abstract Syntax Tree (AST), then uses static and dynamic analysis techniques to analyze the code's structure and functionality in detail.
[1159] Emotion recognition
[1160] The server recognizes the user's emotional state using an emotion engine, which evaluates the user's current stress level, satisfaction, excitement, etc. based on the input code and the user's interactions.
[1161] Comment Generation
[1162] The server generates a natural language comment based on the analysis results. It adjusts the content and tone of the comment based on the user's emotional state, as determined by the emotion engine. For example, if the user is feeling stressed, the comment will be more polite and kind.
[1163] Inserting comments
[1164] The server inserts the generated comments into the original source code at the appropriate places, taking into account indentation and comment positioning to maintain code readability.
[1165] Provides commented code
[1166] The server generates commented source code and sends it to the user's terminal.
[1167] Presenting to the user
[1168] The terminal displays the source code with comments to the user, allowing the user to quickly understand the content of the source code by checking the comments adapted to the emotions.
[1169] Specific examples
[1170] As an example, consider the following Python code uploaded by a user to the system:
[1171] python
[1172] def add_numbers(a, b):
[1173] return a + b
[1174] result = add_numbers(5, 3)
[1175] print(result)
[1176] The server analyzes this code and uses an emotion engine to recognize the user's emotional state, then generates and inserts a comment such as: For example, if the user is feeling stressed, the comment will be kind and polite.
[1177] Example of the parsed code:
[1178] python
[1179] Hello! This function adds two numbers.
[1180] def add_numbers(a, b):
[1181] return a + b
[1182] Use the add_numbers function to add 5 and 3 and assign the result to result.
[1183] result = add_numbers(5, 3)
[1184] Finally, print the results.
[1185] print(result)
[1186] The terminal will display this commented code to the user to make it easier for them to understand.
[1187] How to use
[1188] The user experience when using the system is as follows:
[1189] 1. The user uploads the source code through the system interface.
[1190] 2. The server analyzes the received source code and generates comments.
[1191] 3. The server uses an emotion engine to recognize the user's emotions and adjust the content of the comment.
[1192] 4. The server inserts the generated comments into the code, generating commented code.
[1193] 5. The terminal will display the generated commented code to the user.
[1194] This process not only allows developers to quickly understand others' code and significantly reduces the time it takes to learn new frameworks and algorithms, but also provides empathetic support.
[1195] The processing flow will be explained below.
[1196] Step 1:
[1197] Users upload the source code they want to analyze into the system's interface, which provides a file selection dialog and drag-and-drop functionality.
[1198] Step 2:
[1199] The device receives the uploaded source code and sends it to the server, which temporarily stores the code file.
[1200] Step 3:
[1201] The server parses the received code file, using a parser to split the code into tokens and generate an Abstract Syntax Tree (AST).
[1202] Step 4:
[1203] The server parses the generated abstract syntax tree (AST) to extract the structure and functionality of the code, identifying function definitions, variable assignments, control structures, etc.
[1204] Step 5:
[1205] The server performs static and dynamic analysis: static analysis analyzes source code without executing it to identify dependencies and potential errors in the code, and dynamic analysis actually executes the code and observes its behavior.
[1206] Step 6:
[1207] The server recognizes the user's emotional state using an emotion engine, which analyzes inputs and the user's past interactions to assess the user's stress level, satisfaction, excitement, etc.
[1208] Step 7:
[1209] The server generates natural language comments based on the analysis results and the output of the emotion engine. For example, if the user is feeling stressed, the comment will be changed to be more kind and polite.
[1210] Step 8:
[1211] The server inserts the generated comments into the original source code at the appropriate places, respecting syntax and taking into account indentation and comment placement to maintain code readability.
[1212] Step 9:
[1213] The server generates commented source code and sends it to the user's terminal.
[1214] Step 10:
[1215] The terminal will display the received commented source code to the user, who can then review the generated comments and quickly understand the code content.
[1216] As a concrete example, consider the case where a user uploads the following Python code to the system:
[1217] python
[1218] def add_numbers(a, b):
[1219] return a + b
[1220] result = add_numbers(5, 3)
[1221] print(result)
[1222] The server analyzes this code. First, it generates an abstract syntax tree using a parser, then performs static and dynamic analysis. Based on the analysis results, it uses an emotion engine to recognize the user's emotional state.
[1223] For example, if a user is feeling stressed, the following comment is generated and inserted:
[1224] python
[1225] Hello! This function adds two numbers.
[1226] def add_numbers(a, b):
[1227] return a + b
[1228] Use the add_numbers function to add 5 and 3 and assign the result to result.
[1229] result = add_numbers(5, 3)
[1230] Finally, print the results.
[1231] print(result)
[1232] The terminal will display this commented code to the user for easier understanding, and the user can review it, edit it, and save it as needed. In this way, the system can provide comments that respond to the user's emotions, improving their understanding and learning of the code.
[1233] Example 2
[1234] Next, a description will be given of Example 2. In the following description, the data processing device 12 will be referred to as a "server" and the headset type terminal 314 will be referred to as a "terminal."
[1235] Current code analysis systems analyze code structure and function and insert comments to aid code comprehension, but they do not take the user's emotional state into account. As a result, if a user is feeling stressed or confused, the generated comments may not be appropriate for the user's state and may actually hinder comprehension. Furthermore, existing systems lack detailed code analysis using static and dynamic analysis, making it difficult to generate high-quality comments.
[1236] The specific processing by the specific processing unit 290 of the data processing device 12 in the second embodiment is realized by the following means.
[1237] In this invention, the server includes: [means for inputting code;] [means for analyzing the code to extract structure and function;] [means for generating natural language comments based on the extracted structure and function;] [means for inserting the generated comments at appropriate positions in the code;] [means for providing the commented code to a user;] [means for recognizing the user's emotional state and adjusting the content of the comments;] [means for identifying the structure and function of the code using static analysis] and [means for confirming the runtime behavior of the code using dynamic analysis]; [means for recognizing the user's emotional state using an emotion recognition engine] and [means for adjusting the tone of the comments based on the emotion recognition engine]. This makes it possible to insert polite and kind comments that are adapted to the user's emotional state, thereby promoting understanding of the code and reducing user stress and confusion.
[1238] "Means for inputting code" refers to a function that provides an interface for users to upload source code to be analyzed into the system.
[1239] "Means for analyzing code and extracting structure and function" refers to a function in which the server analyzes uploaded code and performs processing to understand its internal structure and operation.
[1240] "Means for generating natural language comments based on the extracted structure and functions" refers to a function in which the server generates comments in natural language based on the results of code analysis.
[1241] "Means for inserting generated comments into appropriate positions in code" is a function for adding generated comments into appropriate positions in code to improve code readability and comprehension.
[1242] "Means for providing commented code to users" means a function for sending users source code with added comments.
[1243] "Means for recognizing a user's emotional state and adjusting the content of comments" refers to a function that uses an emotion recognition engine to grasp a user's emotions and appropriately adjust the tone and content of comments based on that state.
[1244] "Means of identifying the structure and functionality of code using static analysis" refers to a feature that provides a way to analyze the structure and potential problems of code before it is executed.
[1245] "Means of using dynamic analysis to check the runtime behavior of code" is a feature that provides a way to actually run code and check its behavior and performance.
[1246] "Means for generating an abstract syntax tree of code" refers to a function that analyzes code and generates an abstract syntax tree (AST) that represents its structure in a tree-like format.
[1247] The "means for analyzing each part of the code based on the generated abstract syntax tree" is a function that uses the generated abstract syntax tree to analyze in detail the meaning and role of each part of the code.
[1248] "Means for recognizing a user's emotional state using an emotion recognition engine" refers to a function that uses a specific algorithm or artificial intelligence to read a user's emotions.
[1249] The "means for adjusting the tone of comments based on an emotion recognition engine" is a function that appropriately changes the content and expression of comments depending on the results of the user's emotions obtained by the emotion recognition engine.
[1250] This invention relates to a system that recognizes the user's emotional state and reflects it in the generation and presentation of comments based on the analysis results by combining an emotion engine with a code analysis system. In addition to the basic functions of analyzing source code entered by the user and generating and inserting comments, this system also uses the emotion engine to recognize the user's emotions and adjusts the content of the comments based on that information.
[1251] Basic system configuration
[1252] Entering Code
[1253] Users upload source code to be analyzed into the system's interface, which provides file selection dialogs and drag-and-drop functionality.
[1254] Receive and save the code
[1255] The server receives the uploaded code file and saves it in a local directory. Specifically, it receives an HTTP POST request and saves the file on the server side.
[1256] Code Analysis
[1257] The server analyzes the code using the following techniques:
[1258] Parsing: Split the uploaded code into tokens and generate an Abstract Syntax Tree (AST). Use the Python ast module and the ast.parse function to generate an AST.
[1259] Static analysis: Using tools such as pylint, potential problems in the code are identified.
[1260] Dynamic analysis: Running unit tests to verify that the code behaves as expected.
[1261] Emotion recognition
[1262] The server uses an emotion engine to recognize the user's emotional state, using the Google Cloud Natural Language API and IBM Watson Tone Analyzer, to assess the user's current stress level, satisfaction, excitement, etc. based on the code entered by the user and past interaction data.
[1263] Comment Generation
[1264] The server generates a natural language comment based on the analysis results, using a generative AI model (e.g., GPT-3). The prompt for comment generation is set as follows:
[1265] "Generate polite comments for the following code:"
[1266] The analyzed code content is entered following the prompt statement to query the AI model.
[1267] Inserting comments
[1268] The server inserts the generated comment into the original source code at the appropriate position. When inserting the comment, it places it in the correct position based on the abstract syntax tree and formats it using Python's autopep8. For example, if the generated comment is "This function is for adding two numbers," it will be inserted just before the function definition.
[1269] Provides commented code
[1270] The server generates source code with the added comments and sends it to the user's terminal.
[1271] Presenting to the user
[1272] The device displays the commented source code to the user, who can then view it in a web browser or dedicated application, with highlighting features to help users easily identify emotionally charged comments.
[1273] Specific examples
[1274] As an example, consider the case where a user uploads the following Python code to the system:
[1275] python
[1276] def add_numbers(a, b):
[1277] return a + b
[1278] result = add_numbers(5, 3)
[1279] print(result)
[1280] The server analyzes this code, uses an emotion engine to recognize the user's emotional state, and then generates and inserts a comment like this:
[1281] python
[1282] Hello! This function adds two numbers.
[1283] def add_numbers(a, b):
[1284] return a + b
[1285] Use the add_numbers function to add 5 and 3 and assign the result to result.
[1286] result = add_numbers(5, 3)
[1287] Finally, print the results.
[1288] print(result)
[1289] The terminal displays this commented code to the user to make it easier for the user to understand.
[1290] This system not only allows developers to quickly understand other people's code and significantly reduces the time it takes to learn new frameworks and algorithms, but also provides support that responds to the user's emotions.
[1291] The flow of the identification process in the second embodiment will be described with reference to FIG.
[1292] Step 1:
[1293] The user uploads the source code to be analyzed into the system interface by opening a file selection dialog or dropping the code file into the drag-and-drop area.
[1294] Input: Source code file
[1295] Output: Uploaded source code data
[1296] Step 2:
[1297] The server receives the uploaded source code file and saves it to a local directory. The server receives an HTTP POST request and writes the file.
[1298] Input: Uploaded source code data
[1299] Output: Source code files stored on the server
[1300] Step 3:
[1301] The server uses a parser to split the source code into tokens and generate an Abstract Syntax Tree (AST). Specifically, it uses the Python ast module and the ast.parse function to generate an AST.
[1302] Input: Source code files stored on the server
[1303] Output: Abstract syntax tree (AST)
[1304] Step 4:
[1305] The server analyzes the source code using static analysis tools (e.g., pylint) to determine the structure and functionality of the code. This analysis identifies potential issues and areas for improvement in the source code.
[1306] Input: Abstract Syntax Tree (AST)
[1307] Output: Static analysis result data
[1308] Step 5:
[1309] The server performs dynamic analysis to verify the runtime behavior of the code, specifically by running unit tests to verify that the source code behaves as expected.
[1310] Input: Source code file
[1311] Output: Dynamic analysis result data
[1312] Step 6:
[1313] The server uses an emotion engine to recognize the user's emotional state, using Google Cloud Natural Language API and IBM Watson Tone Analyzer to evaluate the code entered by the user and past interaction data to obtain an emotion score.
[1314] Input: Source code and user interaction data
[1315] Output: User's emotional state data
[1316] Step 7:
[1317] The server generates a natural language comment based on the analysis results and the user's emotional state. Using a generative AI model (e.g., GPT-3), the server queries the AI model by entering the prompt "Please generate a polite comment for the following code."
[1318] Input: Static analysis result data, dynamic analysis result data, user emotional state data
[1319] Output: Generated natural language comment
[1320] Step 8:
[1321] The server inserts the generated comments into the appropriate positions in the source code based on the abstract syntax tree, and then formats the entire code using a formatting tool such as Python's autopep8.
[1322] Input: Source code files, generated natural language comments
[1323] Output: Commented source code
[1324] Step 9:
[1325] The server sends the commented source code to the user's terminal. Specifically, the server returns the commented source code as an HTTP response.
[1326] Input: Commented source code
[1327] Output: Commented source code sent to the user's terminal
[1328] Step 10:
[1329] The device displays the commented source code to the user. Specifically, the code is displayed in a web browser or a dedicated application, and the user can easily check the comments using highlighting functions.
[1330] Input: Commented source code sent to the user's terminal
[1331] Output: Commented source code displayed to the user
[1332] The above is the specific processing flow of this system.
[1333] (Application example 2)
[1334] Next, a description will be given of Application Example 2. In the following description, the data processing device 12 will be referred to as a "server" and the headset type terminal 314 will be referred to as a "terminal."
[1335] Factory robot programs are complex, requiring engineers to understand them quickly and accurately. However, engineers often experience stress and difficulty in understanding the programs, resulting in decreased production efficiency and work accuracy. Furthermore, there has been no method to provide real-time support that responds to the engineers' emotions, so a new method to help them understand the programs is needed.
[1336] The specific processing by the specific processing unit 290 of the data processing device 12 in Application Example 2 is realized by the following means. In this invention, the server includes means for inputting code, means for analyzing the code to extract its structure and function, means for generating comments in natural language based on the extracted structure and function, means for adjusting the content of the generated comments based on the user's emotional state, and means for providing the commented code to a display device in real time. This allows the provision of commented code that is adapted to the engineer's emotional state, enabling the engineer to quickly and easily understand the program.
[1337] A "means for inputting code" is an interface or mechanism that allows a technician to upload the program code of a factory robot into the system.
[1338] "Means of analyzing code to extract structure and function" is the process of breaking down code into tokens and parsing it to generate an abstract syntax tree (AST) of the code, identifying its structure and function in detail.
[1339] "Means for generating natural language comments based on extracted structures and functions" is a mechanism that automatically generates natural language explanations for each part of the analyzed code to make it easier to understand.
[1340] "Means for adjusting the content of generated comments based on the emotional state of the user" refers to a process in which the emotional engine recognizes the emotional state of the engineer and adjusts the tone and content of the generated comments accordingly.
[1341] The "means for providing commented code to a display device in real time" is a mechanism for quickly transmitting the generated commented code to a display device such as a head-mounted display worn by the engineer and displaying it in real time.
[1342] To implement this invention, it is necessary to build a system for analyzing factory robot programs and generating comments. This system consists of a server, a terminal, and a user interface. The specific operation of each component and the hardware and software used are described below.
[1343] Server roles and technologies used
[1344] The server initially receives the robot's program code uploaded by the engineer through an input interface that provides a file selection dialog and drag-and-drop functionality.
[1345] To perform the code analysis process, the server first uses a parsing library to split the code into tokens and generate an Abstract Syntax Tree (AST), then uses static and dynamic analysis techniques to identify the code's structure and functionality for further analysis.
[1346] Next, an emotion engine library is used to recognize the technician's emotional state, which is evaluated based on the technician's inputs and interactions, taking into account stress levels, satisfaction, excitement, etc.
[1347] Generate natural language comments based on the analyzed information and emotional state, with the tone and content of the comments tailored based on the specific code analysis results and emotional state.
[1348] The generated comments are inserted into the code at the appropriate point, automatically adjusting indentation and comment positioning, and then the commented code is delivered in real time to the engineer's terminal or head-mounted display (HMD).
[1349] Device role and technology used
[1350] The engineer's terminal, especially the head-mounted display (HMD), displays the commented code sent from the server in real time, allowing the engineer to always check the latest comments and code while working, improving understanding and work efficiency.
[1351] User roles and operating procedures
[1352] The engineer uploads the program code through the system's interface, then inputs the current emotional state into the interface, which the system analyzes with its emotion engine.
[1353] Engineers can use the HMD to view commented code displayed in real time as they work, making it easier to understand the program and allowing them to quickly and accurately modify or create new programs for factory robots.
[1354] Examples of specific examples and prompts
[1355] As a concrete example, consider the case where an engineer uploads the following robot program code:
[1356] python
[1357] def control_robot(speed, direction):
[1358] move_robot(speed, direction)
[1359] check_obstacle()
[1360] return 'Success'
[1361] If the engineer's emotional state is recognized as "Stress: 0.8, Satisfaction: 0.5", the system will generate and insert the following comment:
[1362] python
[1363] Hello! Functions for controlling the speed and direction of a robot.
[1364] def control_robot(speed, direction):
[1365] move_robot(speed, direction)
[1366] Check for obstructions.
[1367] check_obstacle()
[1368] Finally, it returns whether the operation was successful.
[1369] return 'Success'
[1370] This commented code is displayed in real time on the HMD, helping engineers to quickly understand it.
[1371] Prompt Sentence Examples
[1372] "Analyze the robot's operating program code and generate and display comments based on the engineer's emotional state emotion_state."
[1373] In this way, the system of the present invention provides commented code that is adapted to the emotional state of the engineer, thereby promoting understanding of factory robot programs and improving the engineer's work efficiency.
[1374] The flow of the specific processing in the application example 2 will be described with reference to FIG.
[1375] Step 1:
[1376] Users upload factory robot program code through an input interface that provides file selection dialogs and drag-and-drop functionality. The uploaded code is sent to a server and prepared for analysis.
[1377] Step 2:
[1378] The server processes the received program code with a code analysis library, splitting the code into tokens, and then uses a parser to generate an Abstract Syntax Tree (AST). This analysis process extracts the structure and functionality of the code.
[1379] Output: Abstract syntax tree and detailed code structure information
[1380] Step 3:
[1381] The server then performs further analysis of the extracted structural information using static and dynamic analysis: static analysis identifies the code's components, and dynamic analysis examines the code's behavior at runtime, providing a complete understanding of the code's functionality and behavior.
[1382] Output: Detailed code functionality and behavior information
[1383] Step 4:
[1384] The user inputs their current emotional state into the input interface. The emotional state is input as numerical data such as stress level, satisfaction level, and excitement level, and is then sent to the server.
[1385] Input: User's emotional state data
[1386] Step 5:
[1387] The server uses an emotion engine to analyze the received emotional state data and evaluate the user's current emotional state, which in turn evaluates the user's stress level, satisfaction, excitement, etc.
[1388] Output: Evaluation result of the user's emotional state
[1389] Step 6:
[1390] The server generates natural language comments based on the analyzed code structure and function information, as well as the emotional state assessment results. The comments are created using a generative AI model and are adjusted in tone and content according to the user's emotional state.
[1391] Output: Tailored natural language comments
[1392] Step 7:
[1393] The server inserts the generated comments into the original program code at the appropriate positions, automatically adjusting indentation and comment positioning to maintain code readability.
[1394] Output: Commented program code
[1395] Step 8:
[1396] The server sends commented program code to the engineer's terminal or head-mounted display (HMD) in real time, and the terminal displays the received commented code in real time, allowing the engineer to quickly understand the content of the code.
[1397] Output: Commented code displayed in real time
[1398] For example, you can use the following prompt to see it in action:
[1399] "Analyze the robot's operating program code and generate and display comments based on the engineer's emotional state emotion_state."
[1400] The specific processing unit 290 transmits the result of the specific processing to the headset type terminal 314. In the headset type terminal 314, the control unit 46A causes the speaker 240 and the display 343 to output the result of the specific processing. The microphone 238 acquires audio indicating a user input regarding the result of the specific processing. The control unit 46A transmits audio data indicating the user input acquired by the microphone 238 to the data processing device 12. In the data processing device 12, the specific processing unit 290 acquires the audio data.
[1401] The data generation model 58 is a so-called generative AI (Artificial Intelligence). An example of the data generation model 58 is ChatGPT (Internet Search<URL: https: / / openai.com / blog / chatgpt> ), Gemini (Internet search <url: https: gemini.google.com ?hl="ja">) and other generation AIs. The data generation model 58 is obtained by performing deep learning on a neural network. A prompt including an instruction is input to the data generation model 58, and inference data such as voice data indicating voice, text data indicating text, and image data indicating an image is also input. The data generation model 58 performs inference on the input inference data in accordance with the instruction indicated by the prompt, and outputs the inference result in a data format such as voice data and text data. Here, inference refers to, for example, analysis, classification, prediction, and / or summarization.
[1402] In the above embodiment, an example was given in which the specific processing is performed by the data processing device 12, but the technology of the present disclosure is not limited to this, and the specific processing may be performed by the headset type terminal 314.
[1403] [Fourth embodiment]
[1404] FIG. 7 shows an example of the configuration of a data processing system 410 according to the fourth embodiment.
[1405] 7, a data processing system 410 includes a data processing device 12 and a robot 414. An example of the data processing device 12 is a server.
[1406] The data processing device 12 includes a computer 22, a database 24, and a communication I / F 26. The computer 22 is an example of a "computer" according to the technology of the present disclosure. The computer 22 includes a processor 28, a RAM 30, and a storage 32. The processor 28, the RAM 30, and the storage 32 are connected to a bus 34. The database 24 and the communication I / F 26 are also connected to the bus 34. The communication I / F 26 is connected to a network 54. Examples of the network 54 include a WAN (Wide Area Network) and / or a LAN (Local Area Network).
[1407] The robot 414 includes a computer 36, a microphone 238, a speaker 240, a camera 42, a communication I / F 44, and a control target 443. The computer 36 includes a processor 46, a RAM 48, and a storage 50. The processor 46, the RAM 48, and the storage 50 are connected to a bus 52. The microphone 238, the speaker 240, the camera 42, and the control target 443 are also connected to the bus 52.
[1408] The microphone 238 receives instructions and the like from the user 20 by receiving voice uttered by the user 20. The microphone 238 captures the voice uttered by the user 20, converts the captured voice into audio data, and outputs it to the processor 46. The speaker 240 outputs audio in accordance with instructions from the processor 46.
[1409] Camera 42 is a small digital camera equipped with an optical system including a lens, aperture, and shutter, and an imaging element such as a CMOS (Complementary Metal-Oxide-Semiconductor) image sensor or a CCD (Charge Coupled Device) image sensor, and captures images of the surroundings of user 20 (for example, an imaging range defined by an angle of view equivalent to the field of vision of a typical healthy person).
[1410] The communication I / F 44 is connected to a network 54. The communication I / Fs 44 and 26 are responsible for the exchange of various information between the processor 46 and the processor 28 via the network 54. The exchange of various information between the processor 46 and the processor 28 using the communication I / Fs 44 and 26 is carried out in a secure state.
[1411] The control object 443 includes a display device, LEDs in the eyes, and motors for driving the arms, hands, and feet. The posture and gestures of the robot 414 are controlled by controlling the motors of the arms, hands, and feet. Some of the emotions of the robot 414 can be expressed by controlling these motors. In addition, the facial expressions of the robot 414 can also be expressed by controlling the light emission state of the LEDs in the eyes of the robot 414.
[1412] Fig. 8 shows an example of the main functions of the data processing device 12 and the robot 414. As shown in Fig. 8, in the data processing device 12, a specific process is performed by the processor 28. A specific process program 56 is stored in the storage 32.
[1413] The specific processing program 56 is an example of a "program" according to the technology of the present disclosure. The processor 28 reads the specific processing program 56 from the storage 32 and executes the read specific processing program 56 on the RAM 30. The specific processing is realized by the processor 28 operating as a specific processing unit 290 in accordance with the specific processing program 56 executed on the RAM 30.
[1414] The storage 32 stores a data generation model 58 and an emotion identification model 59. The data generation model 58 and the emotion identification model 59 are used by the identification processing unit 290.
[1415] In the robot 414, the processor 46 performs the reception output process. A reception output program 60 is stored in the storage 50. The processor 46 reads the reception output program 60 from the storage 50 and executes the read reception output program 60 on the RAM 48. The reception output process is realized by the processor 46 operating as the control unit 46A in accordance with the reception output program 60 executed on the RAM 48.
[1416] Next, a description will be given of the specific processing performed by the specific processing unit 290 of the data processing device 12. In the following description, the data processing device 12 will be referred to as a "server" and the robot 414 will be referred to as a "terminal."
[1417] This invention relates to a code analysis system that helps users quickly and accurately understand other people's source code and add comments to that code. A specific embodiment of the system is described below.
[1418] In this system, a user inputs source code, a server analyzes the code, generates comments and inserts comments, and a terminal outputs the commented code.
[1419] Entering Code
[1420] The user uses an interface to upload source code to be analyzed into the system, which is implemented via drag-and-drop or a file selection dialog.
[1421] Code Analysis
[1422] The server receives the uploaded code, first uses a parser to split the code into tokens and generate an Abstract Syntax Tree (AST), then uses static and dynamic analysis techniques to perform a detailed analysis of the code's structure and functionality.
[1423] Comment Generation
[1424] Based on the analysis results, the server uses an automatic comment generation module to generate natural language explanations for each part of the code. For example, for a function definition, it generates a comment such as "This function adds the arguments a and b."
[1425] Inserting comments
[1426] The server inserts the generated comments into the corresponding code locations, including techniques to preserve the readability and proper indentation and formatting of the original code.
[1427] Provides commented code
[1428] The server generates commented code and sends it to the user's device, which then displays the received commented code and prepares it for the user to view and edit.
[1429] Specific examples
[1430] Suppose a user uploads the following Python code to the system:
[1431] python
[1432] def add_numbers(a, b):
[1433] return a + b
[1434] result = add_numbers(5, 3)
[1435] print(result)
[1436] The server will parse this code and generate and insert the following comment:
[1437] Example of the parsed code:
[1438] python
[1439] A function that adds two numbers
[1440] def add_numbers(a, b):
[1441] return a + b
[1442] Use the add_numbers function to add 5 and 3 and assign the result to result
[1443] result = add_numbers(5, 3)
[1444] Output the results
[1445] print(result)
[1446] The terminal displays this commented code to the user, allowing the user to immediately understand the intent of the code.
[1447] How to use
[1448] The user experience when using the system is as follows:
[1449] 1. The user uploads the source code through the system interface.
[1450] 2. The server analyzes the received source code and generates comments.
[1451] 3. The server inserts the generated comments into the code and generates commented code.
[1452] 4. The terminal displays the generated commented code to the user.
[1453] This process allows developers to quickly understand others' code and significantly reduces the time it takes to learn new frameworks and algorithms.
[1454] As can be seen, the present invention is a system that allows users to efficiently understand and learn chords.
[1455] The processing flow will be explained below.
[1456] Step 1:
[1457] Users upload the source code they wish to analyze into the system's interface, which provides a file selection dialog and drag-and-drop functionality.
[1458] Step 2:
[1459] The device receives the uploaded source code and sends it to the server, which temporarily stores the code file.
[1460] Step 3:
[1461] The server parses the received code file, using a parser to split the code into tokens and generate an abstract syntax tree (AST).
[1462] Step 4:
[1463] The server parses the generated abstract syntax tree (AST) to extract the structure and functionality of the code, identifying function definitions, variable assignments, control structures, etc.
[1464] Step 5:
[1465] The server performs static and dynamic analysis: static analysis analyzes source code without executing it to identify dependencies and potential errors in the code, and dynamic analysis actually executes the code and observes its behavior.
[1466] Step 6:
[1467] The server generates a natural language comment based on the analysis results. Specifically, it generates a description of the function of each analyzed part. For example, for the function add_numbers, a comment such as "This function adds the arguments a and b" is created.
[1468] Step 7:
[1469] The server inserts the generated comments into the original source code at the appropriate places, respecting syntax and taking into account indentation and comment placement to maintain code readability.
[1470] Step 8:
[1471] The server generates commented source code and sends it to the user's terminal.
[1472] Step 9:
[1473] The terminal will display the received commented source code to the user, allowing the user to review the code comments and understand the content.
[1474] Step 10:
[1475] The user can edit the commented code as needed, save it, or use it in other development environments.
[1476] Example 1
[1477] Next, a description will be given of Example 1. In the following description, the data processing device 12 will be referred to as a "server" and the robot 414 will be referred to as a "terminal."
[1478] Analyzing program code and quickly and accurately understanding its structure and function requires a lot of time and effort. It is also extremely time-consuming to manually insert appropriate comments based on the analysis results. This task is even more difficult when trying to understand someone else's code at first glance. A method for efficiently solving these problems is needed.
[1479] The specific processing by the specific processing unit 290 of the data processing device 12 in the first embodiment is realized by the following means.
[1480] In this invention, the server includes: [means for dividing code into tokens and generating an abstract syntax tree]; [means for extracting code structure and function using static analysis and dynamic analysis]; and [means for generating natural language comments using a generative AI model based on the extracted structure and function]. This automates the work of code analysis and comment generation / insertion, enabling users to quickly and accurately understand the intent of the code.
[1481] "Means for entering code" means the interface through which a user can upload program code to the system, including means such as drag-and-drop and file selection dialogs.
[1482] "Means for dividing code into tokens and generating an abstract syntax tree" refers to an analysis technology that divides program code into the smallest units called tokens and generates an abstract syntax tree (AST) based on them.
[1483] "Means for extracting the structure and function of code using static and dynamic analysis" refers to means for extracting detailed information about code using both static analysis, which analyzes the structure and function of program code without executing it, and dynamic analysis, which monitors its behavior during execution.
[1484] "Means for generating natural language comments using a generative AI model based on the extracted structure and functions" refers to means for automatically generating appropriate comments in natural language using a generative AI model (e.g., a large-scale language model) based on the code structure and functions obtained through analysis.
[1485] "Means for inserting generated comments into the appropriate places in the code while preserving indentation and formatting" refers to a technique for properly inserting generated comments into the corresponding places in the program code while maintaining the readability of the original code.
[1486] "Means for providing users with commented code" refers to means for providing users with program code with automatically inserted comments in a form that allows them to view and edit it.
[1487] MODE FOR CARRYING OUT THE INVENTION
[1488] The present invention relates to a code analysis system that helps users quickly and accurately understand other people's source code and add comments to that code. A specific embodiment of this system will be described below.
[1489] Users first upload their source code through an interface that allows them to easily provide source code using drag-and-drop functionality or a file selection dialog.
[1490] The server receives the uploaded source code and uses a parser to break the code into tokens. It then generates an Abstract Syntax Tree (AST) and performs static and dynamic analysis to analyze the code's structure and functionality in detail. This analysis phase uses the tokenized information and the AST to understand how each piece of code works.
[1491] Next, the server uses a generative AI model based on the analysis results to generate natural language comments. The generative AI model uses a large-scale language model (e.g., GPT) to generate natural language explanations for the structure and function of the analyzed code. These generated comments include explanations of the purpose of functions, the roles of variables, and the implementation intention of the algorithm.
[1492] The generated comments are inserted in the appropriate positions, adjusting indentation and line spacing appropriately to maintain the readability of the original code. The server generates the code with the comments and sends it to the user's terminal.
[1493] The terminal receives the commented code sent from the server and displays it to the user. By viewing this commented code, the user can quickly understand the intent and function of the source code. Furthermore, the user can also modify or add to the code as needed.
[1494] Specific examples
[1495] A specific example of operation is shown below.
[1496] If a user uploads Python code:
[1497] python
[1498] def add_numbers(a, b):
[1499] return a + b
[1500] result = add_numbers(5, 3)
[1501] print(result)
[1502] The server performs the process in the following steps.
[1503] 1. Break the code into tokens and analyze its structure.
[1504] 2. Generate a comment for the function definition "def add_numbers(a, b):" that says "This function takes two arguments and returns their sum."
[1505] 3. For the part "result = add_numbers(5, 3)", create a comment that says "Use the add_numbers function to add 5 and 3 and assign the result to result."
[1506] 4. Create a comment for the "print(result)" part, saying "Print the result", and insert comments into each part.
[1507] This results in the following commented generated code:
[1508] python
[1509] A function that adds two numbers
[1510] def add_numbers(a, b):
[1511] return a + b
[1512] Use the add_numbers function to add 5 and 3 and assign the result to result
[1513] result = add_numbers(5, 3)
[1514] Output the results
[1515] print(result)
[1516] Example prompt sentence:
[1517] To analyze the source code, follow these steps:
[1518] 1. Upload your source code files by dragging and dropping them into the system interface or by selecting them from the file selection dialog.
[1519] This system allows users to quickly and easily understand the structure and function of their code, greatly improving the efficiency of their development work.
[1520] The flow of the identification process in the first embodiment will be described with reference to FIG.
[1521] The flow of this system's program processing
[1522] Step 1: Upload your source code
[1523] Step 2: Receive the code and prepare it for analysis
[1524] Step 3: Tokenization and Abstract Syntax Tree Generation
[1525] Step 4: Static and Dynamic Analysis
[1526] Step 5: Auto-generating comments
[1527] Step 6: Inserting comments
[1528] Step 7: Provide commented code
[1529] Specific explanation of each processing step
[1530] Step 1: Upload your source code
[1531] The user uploads a source code file using the system's interface. The input is a source code file specified by the user (e.g., "example.py"). The output is that the uploaded source code file is sent to the server. The interface is provided using a drag-and-drop function or a file selection dialog.
[1532] Step 2: Receive the code and prepare it for analysis
[1533] The server receives source code uploaded by users. The input is the uploaded source code file. The server stores the source code in temporary memory and prepares it for the next analysis step. The output is the temporarily stored source code.
[1534] Step 3: Tokenization and Abstract Syntax Tree Generation
[1535] The server runs the received source code through a parser and divides it into tokens. The input is the stored source code. After tokenization, the server generates an abstract syntax tree (AST) based on the tokens. The output is the generated abstract syntax tree. Specifically, in this step, the code is decomposed according to the syntax rules to form a tree structure.
[1536] Step 4: Static and Dynamic Analysis
[1537] The server uses the generated abstract syntax tree to perform static and dynamic analysis. The input is the abstract syntax tree. Static analysis analyzes the code structure and interrelationships between functions, while dynamic analysis analyzes the changes in variables at runtime and the execution order of functions. The output is a detailed analysis result. Specifically, it analyzes function inputs and outputs, variable scopes, dependencies, etc.
[1538] Step 5: Auto-generating comments
[1539] The server uses a generative AI model based on the analysis results to generate natural language comments. The input is the detailed analysis results. The generative AI model (e.g., GPT) generates explanatory comments for each code section based on the analyzed data. The output is the generated comments. Specifically, the AI model generates function descriptions, variable uses, etc.
[1540] Step 6: Inserting comments
[1541] The server inserts the generated comments into the corresponding code positions. The input is the generated comments. The comments are inserted properly before the code, preserving indentation and formatting. The output is the source code with the comments inserted. This step uses techniques to place comments in the appropriate positions, taking into account the readability of the original code.
[1542] Step 7: Provide commented code
[1543] The server generates commented code and sends it to the user's device. The input is the source code with comments inserted. The device displays the received commented code for the user to view and edit. The output is the commented code displayed to the user. Specifically, the commented code is displayed on the user's device, allowing the user to quickly understand the intent of the code.
[1544] (Application example 1)
[1545] Next, a description will be given of Application Example 1. In the following description, the data processing device 12 will be referred to as a "server" and the robot 414 will be referred to as a "terminal."
[1546] Traditional source code analysis tools have not been able to provide sufficient support for quickly and accurately understanding other people's source code. In particular, it takes a lot of time and effort to gain a deep understanding of the code's structure and functionality, and manually adding comments to aid in code understanding is tedious. This makes it inefficient for developers to learn new frameworks and algorithms.
[1547] The specific processing by the specific processing unit 290 of the data processing device 12 in the application example 1 is realized by the following means.
[1548] In this invention, the server includes means for inputting code, means for analyzing the code to extract structures and functions, means for generating natural language comments based on the extracted structures and functions, means for inserting the generated comments at appropriate positions in the code, means for providing the commented code to a user, means for transmitting the code uploaded to the user terminal to a cloud server, and means for performing syntax analysis, AST generation, static analysis, and dynamic analysis on the cloud server, thereby enabling rapid and accurate understanding of code and automating comment generation.
[1549] "Means for inputting code" refers to an interface that allows a user to upload source code to be analyzed into the system.
[1550] "Means for analyzing code to extract structure and functionality" refers to the process of dividing uploaded code into tokens, generating an abstract syntax tree, and analyzing its structure and functionality.
[1551] "Means for generating natural language comments based on extracted structure and function" refers to technology for automatically generating explanatory text for each part of code based on the analysis results.
[1552] "Means for inserting generated comments into appropriate locations in the code" refers to a process for inserting generated comments while preserving the readability of the original code.
[1553] "Means for providing commented code to a user" refers to technology that transmits the commented code to a user's device so that it can be displayed.
[1554] "Means for sending code uploaded to a user's device to a cloud server" refers to the function that allows a user to send source code from their own device to a server on the cloud.
[1555] "Means for performing syntax analysis, AST generation, static analysis, and dynamic analysis on a cloud server" refers to technologies for analyzing source code on a cloud server and performing syntax analysis, abstract syntax tree generation, and static and dynamic analysis.
[1556] This invention relates to a source code analysis system that helps users quickly and accurately understand other people's source code and add comments to that code. The configuration and operation of a specific system for implementing this invention are described below.
[1557] Entering Code
[1558] Users upload source code to be analyzed to the system using a drag-and-drop or file selection dialog interface on their terminal, which allows users to easily input code.
[1559] Sending the code
[1560] The user device sends the uploaded code to the cloud server via a method such as an HTTP POST request.
[1561] Code Analysis
[1562] The cloud server analyzes the received code. As a first step, it uses a parser to split the code into tokens and generate an Abstract Syntax Tree (AST). Next, the server uses static and dynamic analysis techniques to perform a detailed analysis of the code's structure and functionality.
[1563] Comment Generation
[1564] Based on the analysis results, the cloud server uses an automatic comment generation module to generate natural language explanations for each code section. A generative AI model such as GPT-4 can be used here. The generation process is performed by passing the following prompt to the model:
[1565] python
[1566] prompt_text = "Generate comments for the following Python code, explaining the meaning of each line.\n\n{}\n\n Add your comments:".format(original_code)
[1567] Inserting comments
[1568] The cloud server inserts the generated comments into the corresponding code locations, using techniques that preserve proper indentation and formatting to preserve the readability of the original code.
[1569] Provides commented code
[1570] The cloud server generates commented code and sends it to the user's device, which displays the received commented code and arranges it for the user to view and edit.
[1571] Hardware and software used
[1572] Smartphone: Used to implement the user interface and send and receive code.
[1573] Cloud Server: The central source code analysis and comment generation center, including a parser, an AST generator, static analysis, and dynamic analysis modules.
[1574] Generative AI models: Generate comments using natural language processing models such as GPT-4.
[1575] Specific examples
[1576] Suppose a user uploads the following Python code to the system:
[1577] python
[1578] def multiply_numbers(x, y):
[1579] return xy
[1580] result = multiply_numbers(7, 8)
[1581] print(result)
[1582] The cloud server will parse this code and generate and insert comments like this:
[1583] python
[1584] A function that multiplies two numbers
[1585] def multiply_numbers(x, y):
[1586] return xy
[1587] Multiply 7 and 8 using the multiply_numbers function and assign the result to result
[1588] result = multiply_numbers(7, 8)
[1589] Output the results
[1590] print(result)
[1591] This process allows developers to quickly understand others' code and significantly reduces the time it takes to learn new frameworks and algorithms.
[1592] The flow of the specific processing in the application example 1 will be described with reference to FIG.
[1593] Step 1:
[1594] The user launches the application on their smartphone and selects the source code file to analyze. The user uploads the code using a file selection dialog or drag-and-drop function, and the application reads the code file. The input here is the source code file, and the output is the content of that file.
[1595] Step 2:
[1596] The user device sends the loaded source code to the cloud server. This transmission is performed using an HTTP POST request, etc. The input here is the string data of the source code, and the output is a confirmation of successful transmission to the cloud server.
[1597] Step 3:
[1598] The cloud server invokes a parser to parse the received source code, splitting the code into tokens, and then generates an Abstract Syntax Tree (AST), where the input is the received source code and the output is the generated AST.
[1599] Step 4:
[1600] The cloud server performs static and dynamic analysis based on the generated AST. Static analysis identifies the code's structure and functionality, while dynamic analysis checks the code's behavior at runtime. The input here is the AST, and the output is a detailed analysis of the code's structure and functionality.
[1601] Step 5:
[1602] Based on the analysis results, the cloud server uses a generative AI model (e.g., GPT-4) to generate natural language comments for each piece of code. Comment generation is done using the following prompt:
[1603] python
[1604] prompt_text = "Generate comments for the following Python code, explaining the meaning of each line.\n\n{}\n\n Add your comments:".format(original_code)
[1605] The input here is the analysis result and the prompt statement, and the output is the generated comment.
[1606] Step 6:
[1607] The cloud server inserts the generated comments into the corresponding code locations, performs formatting to maintain proper indentation and formatting, and generates highly readable commented code. The input here is the generated comments and the original code, and the output is the code with the comments inserted.
[1608] Step 7:
[1609] The cloud server sends the commented code to the user's device, where the input is the commented code and the output is a confirmation of successful transmission to the user's device.
[1610] Step 8:
[1611] The user device displays the received commented code on the screen and arranges it for easy viewing by the user. The input here is the commented code, and the output is the display result presented to the user.
[1612] This series of steps allows developers to quickly and accurately understand other people's code and efficiently learn new frameworks and algorithms with reduced effort.
[1613] Furthermore, an emotion engine that estimates the user's emotion may be further combined. That is, the identification processing unit 290 may estimate the user's emotion using the emotion identification model 59, and perform identification processing using the user's emotion.
[1614] The present invention relates to a system that promotes user understanding by combining a code analysis system with an emotion engine to recognize the user's emotional state and reflect this in the generation and presentation of comments based on the analysis results.
[1615] In addition to the basic functions of analyzing the source code entered by the user and generating and inserting comments, this system also uses an emotion engine to recognize the user's emotions and adjust the content of the comments based on that information.
[1616] Entering Code
[1617] Users upload source code to be analyzed into the system's interface, which provides file selection dialogs and drag-and-drop functionality.
[1618] Code Analysis
[1619] The server receives the uploaded code file, first splits the code into tokens using a parser and generates an Abstract Syntax Tree (AST), then uses static and dynamic analysis techniques to analyze the code's structure and functionality in detail.
[1620] Emotion recognition
[1621] The server recognizes the user's emotional state using an emotion engine, which evaluates the user's current stress level, satisfaction, excitement, etc. based on the input code and the user's interactions.
[1622] Comment Generation
[1623] The server generates a natural language comment based on the analysis results. It adjusts the content and tone of the comment based on the user's emotional state, as determined by the emotion engine. For example, if the user is feeling stressed, the comment will be more polite and kind.
[1624] Inserting comments
[1625] The server inserts the generated comments into the original source code at the appropriate places, taking into account indentation and comment positioning to maintain code readability.
[1626] Provides commented code
[1627] The server generates commented source code and sends it to the user's terminal.
[1628] Presenting to the user
[1629] The terminal displays the source code with comments to the user, allowing the user to quickly understand the content of the source code by checking the comments adapted to the emotions.
[1630] Specific examples
[1631] As an example, consider the following Python code uploaded by a user to the system:
[1632] python
[1633] def add_numbers(a, b):
[1634] return a + b
[1635] result = add_numbers(5, 3)
[1636] print(result)
[1637] The server analyzes this code and uses an emotion engine to recognize the user's emotional state, then generates and inserts a comment such as: For example, if the user is feeling stressed, the comment will be kind and polite.
[1638] Example of the parsed code:
[1639] python
[1640] Hello! This function adds two numbers.
[1641] def add_numbers(a, b):
[1642] return a + b
[1643] Use the add_numbers function to add 5 and 3 and assign the result to result.
[1644] result = add_numbers(5, 3)
[1645] Finally, print the results.
[1646] print(result)
[1647] The terminal will display this commented code to the user to make it easier for them to understand.
[1648] How to use
[1649] The user experience when using the system is as follows:
[1650] 1. The user uploads the source code through the system interface.
[1651] 2. The server analyzes the received source code and generates comments.
[1652] 3. The server uses an emotion engine to recognize the user's emotions and adjust the content of the comment.
[1653] 4. The server inserts the generated comments into the code, generating commented code.
[1654] 5. The terminal will display the generated commented code to the user.
[1655] This process not only allows developers to quickly understand others' code and significantly reduces the time it takes to learn new frameworks and algorithms, but also provides empathetic support.
[1656] The processing flow will be explained below.
[1657] Step 1:
[1658] Users upload the source code they want to analyze into the system's interface, which provides a file selection dialog and drag-and-drop functionality.
[1659] Step 2:
[1660] The device receives the uploaded source code and sends it to the server, which temporarily stores the code file.
[1661] Step 3:
[1662] The server parses the received code file, using a parser to split the code into tokens and generate an Abstract Syntax Tree (AST).
[1663] Step 4:
[1664] The server parses the generated abstract syntax tree (AST) to extract the structure and functionality of the code, identifying function definitions, variable assignments, control structures, etc.
[1665] Step 5:
[1666] The server performs static and dynamic analysis: static analysis analyzes source code without executing it to identify dependencies and potential errors in the code, and dynamic analysis actually executes the code and observes its behavior.
[1667] Step 6:
[1668] The server recognizes the user's emotional state using an emotion engine, which analyzes inputs and the user's past interactions to assess the user's stress level, satisfaction, excitement, etc.
[1669] Step 7:
[1670] The server generates natural language comments based on the analysis results and the output of the emotion engine. For example, if the user is feeling stressed, the comment will be changed to be more kind and polite.
[1671] Step 8:
[1672] The server inserts the generated comments into the original source code at the appropriate places, respecting syntax and taking into account indentation and comment placement to maintain code readability.
[1673] Step 9:
[1674] The server generates commented source code and sends it to the user's terminal.
[1675] Step 10:
[1676] The terminal will display the received commented source code to the user, who can then review the generated comments and quickly understand the code content.
[1677] As a concrete example, consider the case where a user uploads the following Python code to the system:
[1678] python
[1679] def add_numbers(a, b):
[1680] return a + b
[1681] result = add_numbers(5, 3)
[1682] print(result)
[1683] The server analyzes this code. First, it generates an abstract syntax tree using a parser, then performs static and dynamic analysis. Based on the analysis results, it uses an emotion engine to recognize the user's emotional state.
[1684] For example, if a user is feeling stressed, the following comment is generated and inserted:
[1685] python
[1686] Hello! This function adds two numbers.
[1687] def add_numbers(a, b):
[1688] return a + b
[1689] Use the add_numbers function to add 5 and 3 and assign the result to result.
[1690] result = add_numbers(5, 3)
[1691] Finally, print the results.
[1692] print(result)
[1693] The terminal will display this commented code to the user for easier understanding, and the user can review it, edit it, and save it as needed. In this way, the system can provide comments that respond to the user's emotions, improving their understanding and learning of the code.
[1694] Example 2
[1695] Next, a description will be given of Example 2. In the following description, the data processing device 12 will be referred to as a "server" and the robot 414 will be referred to as a "terminal."
[1696] Current code analysis systems analyze code structure and function and insert comments to aid code comprehension, but they do not take the user's emotional state into account. As a result, if a user is feeling stressed or confused, the generated comments may not be appropriate for the user's state and may actually hinder comprehension. Furthermore, existing systems lack detailed code analysis using static and dynamic analysis, making it difficult to generate high-quality comments.
[1697] The specific processing by the specific processing unit 290 of the data processing device 12 in the second embodiment is realized by the following means.
[1698] In this invention, the server includes: [means for inputting code;] [means for analyzing the code to extract structure and function;] [means for generating natural language comments based on the extracted structure and function;] [means for inserting the generated comments at appropriate positions in the code;] [means for providing the commented code to a user;] [means for recognizing the user's emotional state and adjusting the content of the comments;] [means for identifying the structure and function of the code using static analysis] and [means for confirming the runtime behavior of the code using dynamic analysis]; [means for recognizing the user's emotional state using an emotion recognition engine] and [means for adjusting the tone of the comments based on the emotion recognition engine]. This makes it possible to insert polite and kind comments that are adapted to the user's emotional state, thereby promoting understanding of the code and reducing user stress and confusion.
[1699] "Means for inputting code" refers to a function that provides an interface for users to upload source code to be analyzed into the system.
[1700] "Means for analyzing code and extracting structure and function" refers to a function in which the server analyzes uploaded code and performs processing to understand its internal structure and operation.
[1701] "Means for generating natural language comments based on the extracted structure and functions" refers to a function in which the server generates comments in natural language based on the results of code analysis.
[1702] "Means for inserting generated comments into appropriate positions in code" is a function for adding generated comments into appropriate positions in code to improve code readability and comprehension.
[1703] "Means for providing commented code to users" means a function for sending users source code with added comments.
[1704] "Means for recognizing a user's emotional state and adjusting the content of comments" refers to a function that uses an emotion recognition engine to grasp a user's emotions and appropriately adjust the tone and content of comments based on that state.
[1705] "Means of identifying the structure and functionality of code using static analysis" refers to a feature that provides a way to analyze the structure and potential problems of code before it is executed.
[1706] "Means of using dynamic analysis to check the runtime behavior of code" is a feature that provides a way to actually run code and check its behavior and performance.
[1707] "Means for generating an abstract syntax tree of code" refers to a function that analyzes code and generates an abstract syntax tree (AST) that represents its structure in a tree-like format.
[1708] The "means for analyzing each part of the code based on the generated abstract syntax tree" is a function that uses the generated abstract syntax tree to analyze in detail the meaning and role of each part of the code.
[1709] "Means for recognizing a user's emotional state using an emotion recognition engine" refers to a function that uses a specific algorithm or artificial intelligence to read a user's emotions.
[1710] The "means for adjusting the tone of comments based on an emotion recognition engine" is a function that appropriately changes the content and expression of comments depending on the results of the user's emotions obtained by the emotion recognition engine.
[1711] This invention relates to a system that recognizes the user's emotional state and reflects it in the generation and presentation of comments based on the analysis results by combining an emotion engine with a code analysis system. In addition to the basic functions of analyzing source code entered by the user and generating and inserting comments, this system also uses the emotion engine to recognize the user's emotions and adjusts the content of the comments based on that information.
[1712] Basic system configuration
[1713] Entering Code
[1714] The user uploads the source code to be analyzed into the system's interface, which provides a file selection dialog and drag-and-drop functionality.
[1715] Receive and save the code
[1716] The server receives the uploaded code file and saves it in a local directory. Specifically, it receives an HTTP POST request and saves the file on the server side.
[1717] Code Analysis
[1718] The server analyzes the code using the following techniques:
[1719] Parsing: Split the uploaded code into tokens and generate an Abstract Syntax Tree (AST). Use the Python ast module and the ast.parse function to generate an AST.
[1720] Static analysis: Using tools such as pylint, potential problems in the code are identified.
[1721] Dynamic analysis: Running unit tests to verify that the code behaves as expected.
[1722] Emotion recognition
[1723] The server uses an emotion engine to recognize the user's emotional state, using the Google Cloud Natural Language API and IBM Watson Tone Analyzer, to assess the user's current stress level, satisfaction, excitement, etc. based on the code entered by the user and past interaction data.
[1724] Comment Generation
[1725] The server generates a natural language comment based on the analysis results, using a generative AI model (e.g., GPT-3). The prompt for comment generation is set as follows:
[1726] "Generate polite comments for the following code:"
[1727] The analyzed code content is entered following the prompt statement to query the AI model.
[1728] Inserting comments
[1729] The server inserts the generated comment into the original source code at the appropriate position. When inserting the comment, it places it in the correct position based on the abstract syntax tree and formats it using Python's autopep8. For example, if the generated comment is "This function is for adding two numbers," it will be inserted just before the function definition.
[1730] Provides commented code
[1731] The server generates source code with the added comments and sends it to the user's terminal.
[1732] Presenting to the user
[1733] The device displays the commented source code to the user, who can then view it in a web browser or dedicated application, with highlighting features to help users easily identify emotionally charged comments.
[1734] Specific examples
[1735] As an example, consider the case where a user uploads the following Python code to the system:
[1736] python
[1737] def add_numbers(a, b):
[1738] return a + b
[1739] result = add_numbers(5, 3)
[1740] print(result)
[1741] The server analyzes this code, uses an emotion engine to recognize the user's emotional state, and then generates and inserts a comment like this:
[1742] python
[1743] Hello! This function adds two numbers.
[1744] def add_numbers(a, b):
[1745] return a + b
[1746] Use the add_numbers function to add 5 and 3 and assign the result to result.
[1747] result = add_numbers(5, 3)
[1748] Finally, print the results.
[1749] print(result)
[1750] The terminal displays this commented code to the user to make it easier for the user to understand.
[1751] This system not only allows developers to quickly understand other people's code and significantly reduces the time it takes to learn new frameworks and algorithms, but also provides support that responds to the user's emotions.
[1752] The flow of the identification process in the second embodiment will be described with reference to FIG.
[1753] Step 1:
[1754] The user uploads the source code to be analyzed into the system interface by opening a file selection dialog or dropping the code file into the drag-and-drop area.
[1755] Input: Source code file
[1756] Output: Uploaded source code data
[1757] Step 2:
[1758] The server receives the uploaded source code file and saves it to a local directory. The server receives an HTTP POST request and writes the file.
[1759] Input: Uploaded source code data
[1760] Output: Source code files stored on the server
[1761] Step 3:
[1762] The server uses a parser to split the source code into tokens and generate an Abstract Syntax Tree (AST). Specifically, it uses the Python ast module and the ast.parse function to generate an AST.
[1763] Input: Source code files stored on the server
[1764] Output: Abstract syntax tree (AST)
[1765] Step 4:
[1766] The server analyzes the source code using static analysis tools (e.g., pylint) to determine the structure and functionality of the code. This analysis identifies potential issues and areas for improvement in the source code.
[1767] Input: Abstract Syntax Tree (AST)
[1768] Output: Static analysis result data
[1769] Step 5:
[1770] The server performs dynamic analysis to verify the runtime behavior of the code, specifically by running unit tests to verify that the source code behaves as expected.
[1771] Input: Source code file
[1772] Output: Dynamic analysis result data
[1773] Step 6:
[1774] The server uses an emotion engine to recognize the user's emotional state, using Google Cloud Natural Language API and IBM Watson Tone Analyzer to evaluate the code entered by the user and past interaction data to obtain an emotion score.
[1775] Input: Source code and user interaction data
[1776] Output: User's emotional state data
[1777] Step 7:
[1778] The server generates a natural language comment based on the analysis results and the user's emotional state. Using a generative AI model (e.g., GPT-3), the server queries the AI model by entering the prompt "Please generate a polite comment for the following code."
[1779] Input: Static analysis result data, dynamic analysis result data, user emotional state data
[1780] Output: Generated natural language comment
[1781] Step 8:
[1782] The server inserts the generated comments into the appropriate positions in the source code based on the abstract syntax tree, and then formats the entire code using a formatting tool such as Python's autopep8.
[1783] Input: Source code files, generated natural language comments
[1784] Output: Commented source code
[1785] Step 9:
[1786] The server sends the commented source code to the user's terminal. Specifically, the server returns the commented source code as an HTTP response.
[1787] Input: Commented source code
[1788] Output: Commented source code sent to the user's terminal
[1789] Step 10:
[1790] The device displays the commented source code to the user. Specifically, the code is displayed in a web browser or a dedicated application, and the user can easily check the comments using highlighting functions.
[1791] Input: Commented source code sent to the user's terminal
[1792] Output: Commented source code displayed to the user
[1793] The above is the specific processing flow of this system.
[1794] (Application example 2)
[1795] Next, a description will be given of Application Example 2. In the following description, the data processing device 12 will be referred to as a "server" and the robot 414 will be referred to as a "terminal."
[1796] Factory robot programs are complex, requiring engineers to understand them quickly and accurately. However, engineers often experience stress and difficulty in understanding the programs, resulting in decreased production efficiency and work accuracy. Furthermore, there has been no method to provide real-time support that responds to the engineers' emotions, so a new method to help them understand the programs is needed.
[1797] The specific processing by the specific processing unit 290 of the data processing device 12 in Application Example 2 is realized by the following means. In this invention, the server includes means for inputting code, means for analyzing the code to extract its structure and function, means for generating comments in natural language based on the extracted structure and function, means for adjusting the content of the generated comments based on the user's emotional state, and means for providing the commented code to a display device in real time. This allows the provision of commented code that is adapted to the engineer's emotional state, enabling the engineer to quickly and easily understand the program.
[1798] A "means for inputting code" is an interface or mechanism that allows a technician to upload the program code of a factory robot into the system.
[1799] "Means of analyzing code to extract structure and function" is the process of breaking down code into tokens and parsing it to generate an abstract syntax tree (AST) of the code, identifying its structure and function in detail.
[1800] "Means for generating natural language comments based on extracted structures and functions" is a mechanism that automatically generates natural language explanations for each part of the analyzed code to make it easier to understand.
[1801] "Means for adjusting the content of generated comments based on the emotional state of the user" refers to a process in which the emotional engine recognizes the emotional state of the engineer and adjusts the tone and content of the generated comments accordingly.
[1802] The "means for providing commented code to a display device in real time" is a mechanism for quickly transmitting the generated commented code to a display device such as a head-mounted display worn by the engineer and displaying it in real time.
[1803] To implement this invention, it is necessary to build a system for analyzing factory robot programs and generating comments. This system consists of a server, a terminal, and a user interface. The specific operation of each component and the hardware and software used are described below.
[1804] Server roles and technologies used
[1805] The server initially receives the robot's program code uploaded by the engineer through an input interface that provides a file selection dialog and drag-and-drop functionality.
[1806] To perform the code analysis process, the server first uses a parsing library to split the code into tokens and generate an Abstract Syntax Tree (AST), then uses static and dynamic analysis techniques to identify the code's structure and functionality for further analysis.
[1807] Next, an emotion engine library is used to recognize the technician's emotional state, which is evaluated based on the technician's inputs and interactions, taking into account stress levels, satisfaction, excitement, etc.
[1808] Generate natural language comments based on the analyzed information and emotional state, with the tone and content of the comments tailored based on the specific code analysis results and emotional state.
[1809] The generated comments are inserted into the code at the appropriate point, automatically adjusting indentation and comment positioning, and then the commented code is delivered in real time to the engineer's terminal or head-mounted display (HMD).
[1810] Device role and technology used
[1811] The engineer's terminal, especially the head-mounted display (HMD), displays the commented code sent from the server in real time, allowing the engineer to always check the latest comments and code while working, improving understanding and work efficiency.
[1812] User roles and operating procedures
[1813] The engineer uploads the program code through the system's interface, then inputs the current emotional state into the interface, which the system analyzes with its emotion engine.
[1814] Engineers can use the HMD to view commented code displayed in real time as they work, making it easier to understand the program and allowing them to quickly and accurately modify or create new programs for factory robots.
[1815] Examples of specific examples and prompts
[1816] As a concrete example, consider the case where an engineer uploads the following robot program code:
[1817] python
[1818] def control_robot(speed, direction):
[1819] move_robot(speed, direction)
[1820] check_obstacle()
[1821] return 'Success'
[1822] If the engineer's emotional state is recognized as "Stress: 0.8, Satisfaction: 0.5", the system will generate and insert the following comment:
[1823] python
[1824] Hello! Functions for controlling the speed and direction of a robot.
[1825] def control_robot(speed, direction):
[1826] move_robot(speed, direction)
[1827] Check for obstructions.
[1828] check_obstacle()
[1829] Finally, it returns whether the operation was successful.
[1830] return 'Success'
[1831] This commented code is displayed in real time on the HMD, helping engineers to quickly understand it.
[1832] Prompt Sentence Examples
[1833] "Analyze the robot's operating program code and generate and display comments based on the engineer's emotional state emotion_state."
[1834] In this way, the system of the present invention provides commented code that is adapted to the emotional state of the engineer, thereby promoting understanding of factory robot programs and improving the engineer's work efficiency.
[1835] The flow of the specific processing in the application example 2 will be described with reference to FIG.
[1836] Step 1:
[1837] Users upload factory robot program code through an input interface that provides file selection dialogs and drag-and-drop functionality. The uploaded code is sent to a server and prepared for analysis.
[1838] Step 2:
[1839] The server processes the received program code with a code analysis library, splitting the code into tokens, and then uses a parser to generate an Abstract Syntax Tree (AST). This analysis process extracts the structure and functionality of the code.
[1840] Output: Abstract syntax tree and detailed code structure information
[1841] Step 3:
[1842] The server then performs further analysis of the extracted structural information using static and dynamic analysis: static analysis identifies the code's components, and dynamic analysis examines the code's behavior at runtime, providing a complete understanding of the code's functionality and behavior.
[1843] Output: Detailed code functionality and behavior information
[1844] Step 4:
[1845] The user inputs their current emotional state into the input interface. The emotional state is input as numerical data such as stress level, satisfaction level, and excitement level, and is then sent to the server.
[1846] Input: User's emotional state data
[1847] Step 5:
[1848] The server uses an emotion engine to analyze the received emotional state data and evaluate the user's current emotional state, which in turn evaluates the user's stress level, satisfaction, excitement, etc.
[1849] Output: Evaluation result of the user's emotional state
[1850] Step 6:
[1851] The server generates natural language comments based on the analyzed code structure and function information, as well as the emotional state assessment results. The comments are created using a generative AI model and are adjusted in tone and content according to the user's emotional state.
[1852] Output: Tailored natural language comments
[1853] Step 7:
[1854] The server inserts the generated comments into the original program code at the appropriate positions, automatically adjusting indentation and comment positioning to maintain code readability.
[1855] Output: Commented program code
[1856] Step 8:
[1857] The server sends commented program code to the engineer's terminal or head-mounted display (HMD) in real time, and the terminal displays the received commented code in real time, allowing the engineer to quickly understand the content of the code.
[1858] Output: Commented code displayed in real time
[1859] For example, you can use the following prompt to see it in action:
[1860] "Analyze the robot's operating program code and generate and display comments based on the engineer's emotional state emotion_state."
[1861] The specific processing unit 290 transmits the result of the specific processing to the robot 414. In the robot 414, the control unit 46A causes the speaker 240 and the control target 443 to output the result of the specific processing. The microphone 238 acquires voice indicating a user input regarding the result of the specific processing. The control unit 46A transmits voice data indicating the user input acquired by the microphone 238 to the data processing device 12. In the data processing device 12, the specific processing unit 290 acquires the voice data.
[1862] The data generation model 58 is a so-called generative AI (Artificial Intelligence). An example of the data generation model 58 is ChatGPT (Internet Search<URL: https: / / openai.com / blog / chatgpt> ), Gemini (Internet search <url: https: gemini.google.com ?hl="ja">) and other generation AIs. The data generation model 58 is obtained by performing deep learning on a neural network. A prompt including an instruction is input to the data generation model 58, and inference data such as voice data indicating voice, text data indicating text, and image data indicating an image is also input. The data generation model 58 performs inference on the input inference data in accordance with the instruction indicated by the prompt, and outputs the inference result in a data format such as voice data and text data. Here, inference refers to, for example, analysis, classification, prediction, and / or summarization.
[1863] In the above embodiment, an example in which the specific processing is performed by the data processing device 12 has been given, but the technology of the present disclosure is not limited to this, and the specific processing may be performed by the robot 414.
[1864] The emotion identification model 59 as an emotion engine may determine the user's emotion according to a specific mapping. Specifically, the emotion identification model 59 may determine the user's emotion according to an emotion map (see FIG. 9), which is a specific mapping. Similarly, the emotion identification model 59 may determine the robot's emotion, and the identification processing unit 290 may perform identification processing using the robot's emotion.
[1865] FIG. 9 illustrates an emotion map 400 on which multiple emotions are mapped. In the emotion map 400, emotions are arranged in concentric circles radiating from the center. Emotions closer to the center of the concentric circles are more primitive. Emotions representing states and behaviors arising from a state of mind are arranged on the outer edges of the concentric circles. The concept of emotion includes both affect and mental states. Emotions generally generated from reactions occurring in the brain are arranged on the left side of the concentric circles. Emotions generally induced by situational judgment are arranged on the right side of the concentric circles. Emotions generally generated from reactions occurring in the brain and induced by situational judgment are arranged on the upper and lower sides of the concentric circles. Furthermore, the emotion of "pleasure" is arranged on the upper side of the concentric circles, and the emotion of "discomfort" is arranged on the lower side. In this way, in the emotion map 400, multiple emotions are mapped based on the structure by which emotions are generated, and emotions that tend to occur simultaneously are mapped close to each other.
[1866] These emotions are distributed in the 3 o'clock direction on emotion map 400, and typically fluctuate between relief and anxiety. In the right half of emotion map 400, situational awareness dominates over internal sensations, resulting in a sense of calm.
[1867] The inside of emotion map 400 represents what is going on in the mind, and the outside of emotion map 400 represents behavior, so the further you go outside emotion map 400, the more visible the emotions become (the more they are expressed in behavior).
[1868] Human emotions are based on various balances, such as posture and blood sugar levels. When these balances deviate from the ideal, a state of discomfort is indicated, and when they approach the ideal, a state of pleasure is indicated. Emotions can also be created for robots, automobiles, and motorcycles, based on various balances, such as posture and remaining battery life. When these balances deviate from the ideal, a state of discomfort is indicated, and when they approach the ideal, a state of pleasure is indicated. An emotion map can be generated, for example, based on Dr. Mitsuyoshi's emotion map (Research on Voice Emotion Recognition and Emotional Brain Physiological Signal Analysis Systems, Tokushima University, Doctoral Dissertation: https: / / ci.nii.ac.jp / naid / 500000375379). The left half of the emotion map lists emotions belonging to the "reaction" domain, where sensation is dominant. The right half of the emotion map lists emotions belonging to the "situation" domain, where situational awareness is dominant.
[1869] The emotion map defines two emotions that promote learning. One is a negative emotion on the situation side, around the middle of "repentance" or "reflection." In other words, this occurs when the robot experiences negative emotions such as "I never want to feel this way again" or "I don't want to be scolded again." The other is a positive emotion on the response side, around "desire." In other words, this occurs when the robot experiences positive feelings such as "I want more" or "I want to know more."
[1870] The emotion identification model 59 inputs user input into a pre-trained neural network, obtains emotion values indicating each emotion shown in the emotion map 400, and determines the user's emotion. This neural network is pre-trained based on multiple pieces of training data that are combinations of user input and emotion values indicating each emotion shown in the emotion map 400. Furthermore, this neural network is trained so that emotions that are located close to each other have similar values, as in the emotion map 900 shown in FIG. 10. FIG. 10 shows an example in which multiple emotions, "relieved," "calm," and "reassuring," have similar emotion values.
[1871] The system according to the present disclosure has been described above mainly with respect to the functions of the data processing device 12, but the system according to the present disclosure is not necessarily implemented on a server. The system according to the present disclosure may be implemented as a general information processing system. The present disclosure may be implemented, for example, as a software program running on a personal computer or an application running on a smartphone, etc. The method according to the present disclosure may be provided to users in the form of SaaS (Software as a Service).
[1872] In the above embodiment, an example was given in which the specific processing is performed by one computer 22, but the technology of the present disclosure is not limited to this, and the specific processing may be distributed and performed by a plurality of computers including the computer 22. For example, the data generation model 58 may be provided in an external device of the data processing device 12, and data may be generated in the external device in accordance with input data.
[1873] In the above embodiment, an example in which the specific processing program 56 is stored in the storage 32 has been described, but the technology of the present disclosure is not limited to this. For example, the specific processing program 56 may be stored in a portable, computer-readable, non-transitory storage medium such as a USB (Universal Serial Bus) memory. The specific processing program 56 stored in the non-transitory storage medium is installed in the computer 22 of the data processing device 12. The processor 28 executes the specific processing in accordance with the specific processing program 56.
[1874] Alternatively, the specific processing program 56 may be stored in a storage device such as a server connected to the data processing device 12 via the network 54, and the specific processing program 56 may be downloaded and installed on the computer 22 in response to a request from the data processing device 12.
[1875] It is not necessary to store all of the specific processing program 56 in a storage device such as a server connected to the data processing device 12 via the network 54, or to store all of the specific processing program 56 in the storage 32; only a portion of the specific processing program 56 may be stored.
[1876] The hardware resource for executing a specific process can be any of the following processors: An example of a processor is a CPU, which is a general-purpose processor that functions as a hardware resource for executing a specific process by executing software, i.e., a program. Another example of a processor is a dedicated electrical circuit, such as an FPGA (Field-Programmable Gate Array), a PLD (Programmable Logic Device), or an ASIC (Application Specific Integrated Circuit), which is a processor with a circuit configuration designed specifically for executing a specific process. Each processor has built-in or connected memory, and each processor uses the memory to execute the specific process.
[1877] The hardware resource that executes the specific processing may be configured with one of these various processors, or may be configured with a combination of two or more processors of the same or different types (for example, a combination of multiple FPGAs, or a combination of a CPU and an FPGA). Also, the hardware resource that executes the specific processing may be a single processor.
[1878] As an example of a system configured with a single processor, first, one processor is configured by combining one or more CPUs and software, and this processor functions as a hardware resource that executes a specific process. Second, there is a system that uses a processor that realizes the functions of an entire system including multiple hardware resources that execute a specific process on a single IC chip, as typified by SoC (System-on-a-chip). In this way, a specific process is realized using one or more of the above-mentioned various processors as hardware resources.
[1879] Furthermore, the hardware structure of these various processors can be, more specifically, an electric circuit that combines circuit elements such as semiconductor devices. The specific processing described above is merely an example. Therefore, it goes without saying that unnecessary steps may be deleted, new steps may be added, or the processing order may be rearranged, without departing from the spirit of the invention.
[1880] The above-described description and illustrations are a detailed explanation of the parts related to the technology of the present disclosure and are merely an example of the technology of the present disclosure. For example, the above description of the configuration, functions, actions, and effects is an explanation of an example of the configuration, functions, actions, and effects of the parts related to the technology of the present disclosure. Therefore, it goes without saying that unnecessary parts may be deleted, new elements may be added, or replacements may be made to the above-described description and illustrations within the scope of the gist of the technology of the present disclosure. Furthermore, to avoid confusion and facilitate understanding of the parts related to the technology of the present disclosure, the above-described description and illustrations omit explanations of common technical knowledge that do not require particular explanation to enable the implementation of the technology of the present disclosure.
[1881] All publications, patent applications, and technical standards mentioned in this specification are herein incorporated by reference to the same extent as if each individual publication, patent application, or technical standard was specifically and individually indicated to be incorporated by reference.
[1882] The following is further disclosed regarding the above embodiment.
[1883] (Claim 1)
[1884] [Means for entering the code], and
[1885] [Methods for analyzing code to extract structure and function],
[1886] [Means for generating natural language comments based on the extracted structures and features]; and
[1887] [A means of inserting the generated comments into the appropriate places in the code],
[1888] [Method for providing commented code to users]
[1889] A system including:
[1890] (Claim 2)
[1891] 10. The system of claim 1, further comprising: means for identifying the structure and functionality of the code using static analysis; and means for verifying the run-time behavior of the code using dynamic analysis.
[1892] (Claim 3)
[1893] 2. The system of claim 1, comprising: means for generating an abstract syntax tree of the code; and means for parsing portions of the code based on the generated abstract syntax tree.
[1894]
[1895] "Example 1"
[1896] (Claim 1)
[1897] [Means for entering the code], and
[1898] [Methods for splitting code into tokens and generating abstract syntax trees],
[1899] [Methods for extracting code structure and functionality using static and dynamic analysis], and
[1900] [Means of generating natural language comments using a generative AI model based on the extracted structures and features]; and
[1901] A way to insert generated comments into the code at the correct position, preserving indentation and formatting, and
[1902] [Method for providing commented code to users]
[1903] A system including:
[1904] (Claim 2)
[1905] 10. The system of claim 1, further comprising: means for identifying the structure and functionality of the code using static analysis; and means for verifying the run-time behavior of the code using dynamic analysis.
[1906] (Claim 3)
[1907] 2. The system of claim 1, comprising: means for generating an abstract syntax tree of the code; and means for parsing portions of the code based on the generated abstract syntax tree.
[1908] "Application Example 1"
[1909] (Claim 1)
[1910] [Means for entering the code;
[1911] [Means of analyzing the code to extract structure and function,
[1912] [Means for generating natural language comments based on the extracted structures and features; and
[1913] [Means of inserting the generated comments into the appropriate places in the code, and
[1914] [Means for providing commented code to users, and
[1915] [Means for transmitting the code uploaded to the user terminal to the cloud server;
[1916] [A system including means for performing syntax analysis, AST generation, static analysis, and dynamic analysis on a cloud server.
[1917] (Claim 2)
[1918] 10. The system of claim 1, further comprising: means for identifying the structure and functionality of the code using static analysis; and means for verifying the run-time behavior of the code using dynamic analysis.
[1919] (Claim 3)
[1920] 2. The system of claim 1, comprising: means for generating an abstract syntax tree of the code; and means for parsing portions of the code based on the generated abstract syntax tree.
[1921] "Example 2: Combining Emotion Engines"
[1922] (Claim 1)
[1923] [Means for entering the code;
[1924] [Means of analyzing the code to extract structure and function,
[1925] [Means for generating natural language comments based on the extracted structures and features; and
[1926] [Means of inserting the generated comments into the appropriate places in the code, and
[1927] [Means for providing commented code to users, and
[1928] [Means for recognizing the emotional state of users and adjusting the content of their comments;
[1929] A system including:
[1930] (Claim 2)
[1931] 10. The system of claim 1, further comprising: means for identifying the structure and functionality of the code using static analysis; and means for verifying the run-time behavior of the code using dynamic analysis.
[1932] (Claim 3)
[1933] 2. The system of claim 1, comprising: means for generating an abstract syntax tree of the code; and means for parsing portions of the code based on the generated abstract syntax tree.
[1934] (Claim 4)
[1935] 10. The system of claim 1, comprising: means for recognizing an emotional state of a user using an emotion recognition engine; and means for adjusting the tone of comments based on the emotion recognition engine.
[1936] "Application example 2 when combining emotion engines"
[1937] (Claim 1)
[1938] [Means for entering the code;
[1939] [Means of analyzing the code to extract structure and function,
[1940] [Means for generating natural language comments based on the extracted structures and features; and
[1941] [Means of inserting the generated comments into the appropriate places in the code, and
[1942] [Means for adjusting the content of the generated comments based on the emotional state of the user; and
[1943] [means for providing commented code to a display device in real time;
[1944] A system including:
[1945] (Claim 2)
[1946] 10. The system of claim 1, further comprising: means for identifying the structure and functionality of the code using static analysis; and means for verifying the run-time behavior of the code using dynamic analysis.
[1947] (Claim 3)
[1948] 2. The system of claim 1, comprising: means for generating an abstract syntax tree of the code; and means for parsing portions of the code based on the generated abstract syntax tree. [Explanation of symbols]
[1949] 10, 210, 310, 410 Data Processing Systems 12 Data Processing Device 14 Smart Devices 214 Smart Glasses 314 Headset-type terminal 414 Robot< / url:> < / url:> < / url:> < / url:>
Claims
1. means for entering a code; A means of analyzing the code to extract structure and function; means for generating natural language comments based on the extracted structures and features; A means of inserting the generated comments into the code at the appropriate point; A means to provide commented code to users A system including:
2. The system of claim 1 , further comprising means for using static analysis to identify the structure and functionality of the code and means for using dynamic analysis to determine the run-time behavior of the code.
3. 2. The system of claim 1, further comprising: means for generating an abstract syntax tree of the code; and means for parsing portions of the code based on the generated abstract syntax tree.
Citation Information
Patent Citations
Persona chatbot control method and system
JP2022180282A