# US 2024/0201984 A1 · Deep learning-based java program internal annotation generation method and syste

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2024/0201984 A1
- Document ID: US20240201984A1
- Status: Published application
- Kind: A1
- Application number: 18/554,899
- Filed: 2021-04-26
- Published: 2024-06-20
- Earliest claimed: 2021-04-25
- Assignees: Nanjing University
- Applicants: Nanjing University
- Inventors: Lin CHEN; Zhi WANG; Yanhui LI
- Web page: https://patentgrep.com/patent/US20240201984A1

## CPC

- G06F 8/73: Program documentation
- G06F 8/75: Structural analysis for program understanding
- G06F 8/71: Version control (security arrangements therefor G06F21/57); Configuration management
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A deep learning-based Java program internal annotation generation method and system is provided. The method includes acquiring items with a Stars number ranked in the top, and extracting corresponding internal annotations and method statement lists; obtaining an <annotation, target code> pair; selecting an annotation in a Verb-dobj form; obtaining a code context associated with a target code segment; preprocessing the annotation, the target code, and the context to obtain a triplet dataset; randomly dividing the constructed dataset into a training set, a validation set, and a test set, and constructing an encoder-decoder network at the same time; enabling the training set in division to be used for model training, performing evaluation on the validation set to obtain a model with the best effect on the validation set as a target model; and predicting data in the test set with the obtained target model to generate a predicted annotation.

## Claims

### Claim 1

A deep learning-based Java program internal annotation generation method, comprising the following steps:
step SS1: acquiring items with a Stars number ranked in the top from GitHub, then extracting method information in a Java source code with a static analysis tool JDT, then recognizing corresponding method information, and extracting corresponding internal annotations and method statement lists;
step SS2: traversing statements in the method information according to positions of the annotations, obtaining a statement list corresponding to the annotations through position information and data flow information, and obtaining an <annotation, target code> pair;
step SS3: performing filtration according to a type of the annotations and selecting an annotation in a Verb-dobj form;
step SS4: analyzing the data flow information implemented within the method information, and obtaining a code context associated with a target code segment according to a definition use relationship between variables;
step SS5: preprocessing the annotation, the target code, and the context, the preprocessing process comprising word segmentation, identifier splitting, and word lowercasing; and
completing final processing to obtain a triplet dataset including <annotation, target code, code context>;
step SS6: randomly dividing the constructed dataset into a training set, a validation set, and a test set, and constructing an encoder-decoder network at the same time;
step SS7: enabling the training set in division in step SS6 to be used for model training, and performing evaluation on the validation set to obtain a model with the best effect on the validation set as a target model; and
step SS8: predicting data in the test set with the target model obtained in step SS7 to generate a predicted annotation.

### Claim 2 (depends on 1)

The deep learning-based Java program internal annotation generation method according to claim 1, wherein step SS1 specifically comprises: acquiring Java items with the Stars number ranked in the top from GitHub to obtain 5281 items, downloading the items to local, and then extracting information in a Java method with the static analysis tool JDT, and extracting a code and annotations, each piece of annotation information comprises a unique path, annotation text, type, start line, end line, statement list; the unique path comprises file name+class name+method name+parameter name, the type comprises line annotations or block annotations), and the start line and the end line, comprising a start line and an end line of a single-line annotation, are same.

### Claim 3 (depends on 1)

The deep learning-based Java program internal annotation generation method according to claim 1, wherein step SS2 specifically comprises: processing the data in step SS1, and determining a target code of the annotation according to positions of the annotation and the code and a relationship between the annotation and the code; firstly, determining that an initial target statement list for the annotation is all statements from a next line of the annotation to a statement segmented by a blank line or ended with a code block; then, more accurately selecting a target statement list corresponding to the annotation through definition use dependence of variables, semantic similarity dependence of the code, and code-annotation dependence; each data table entry is: <annotation information, target statement list, method statement list>.

### Claim 4 (depends on 1)

The deep learning-based Java program internal annotation generation method according to claim 1, wherein step SS3 specifically comprises: processing the annotations in step SS2, performing part-of-speech tagging and dependency parsing on the annotations by a Stanford coreNLP toolset, selecting an annotation starting with a verb and comprising a dobj direct object structure, and further removing comprised annotated codes and technical debts.

### Claim 5 (depends on 1)

The deep learning-based Java program internal annotation generation method according to claim 1, wherein step SS4 specifically comprises: based on the target statement list and the method statement list in step SS3, extracting a variable definition use relationship and a use definition relationship of variables in the target statement list and the method statement list through data flow analysis, and constructing a context statement list; and finally, each data table entry is: <annotation information, target statement list, context statement list>.

### Claim 6 (depends on 1)

The deep learning-based Java program internal annotation generation method according to claim 1, wherein step SS5 specifically comprises: processing the data in step SS4, firstly splitting identifiers in a statement by Camel-Case, and completing the processing process of the identifiers through regular expression design; then, splitting a Java code through punctuations and converting the code into a sequence of words that can be recognized by a deep learning model; meanwhile, performing word segmentation on an English annotation spaced by punctuations and spaces, and finally, converting the annotation and code to lowercase, and a presentation form of each piece of data is: <annotation, target code, context code>.

### Claim 7 (depends on 1)

The deep learning-based Java program internal annotation generation method according to claim 1, wherein step SS6 specifically comprises: randomly dividing the dataset obtained in step SS5 in a proportion of 80%: 10%: 10%, with the training set comprising 336457 pieces of data, and the validation set and the test set each comprising 42056 pieces of data; meanwhile, an entire model is of an encoder-decoder structure; an encoder CodeBERT uses bimodal data instances as an input for training in a pretraining stage, and a decoder employs 6 Transformer decoding layers to stack to construct an entire network.

### Claim 8 (depends on 1)

The deep learning-based Java program internal annotation generation method according to claim 1, wherein step SS7 specifically comprises: enabling the training set in step SS6 to be used as a model input for training and optimization, performing training by setting a target code length to be 100, a context code length to be 300, and an annotation length to be 30, performing model selection through the validation set, and selecting a model with the best performance on the validation set as the target model.

### Claim 9 (depends on 1)

The deep learning-based Java program internal annotation generation method according to claim 1, wherein step SS8 specifically comprises: generating a target annotation finally by using the remaining 10% of the test set in step SS6 as an input of the target model in step SS7.

### Claim 10

A deep learning-based Java program internal annotation generation system, comprising:
an annotation list extraction module, configured to: acquire items with a Stars number ranked in the top from GitHub, then extract method information in a Java source code with a static analysis tool JDT, then recognize corresponding method information, and extract corresponding internal annotations and method statement lists;
an annotation-code pair extraction module, configured to: traverse statements in the method information according to positions of the annotations, obtain a statement list corresponding to the annotations through position information and data flow information, and obtain an <annotation, target code> pair;
an annotation type filter module, configured to: perform filtration according to a type of the annotations and select an annotation in a Verb-dobj form;
a code context generation module, configured to: analyze the data flow information implemented within the method information, and obtain a code context associated with a target code segment according to a definition use relationship between variables;
a preprocessing module, configured to: preprocess the annotation, the target code, and the context, the preprocessing process comprising word segmentation, identifier splitting, and word lowercasing; and complete final processing to obtain a triplet dataset including <annotation, target code, code context>;
a dataset dividing module, configured to: randomly divide the constructed dataset into a training set, a validation set, and a test set, and construct an encoder-decoder network at the same time;
a model training module, configures to; enable the training set in division of the dataset dividing module to be used for model training, and perform evaluation on the validation set to obtain a model with the best effect on the validation set as a target model; and
a predicted annotation generation module, configured to: predict data in the test set with the target model obtained by the model training module to generate a predicted annotation.
