A method and apparatus for reviewing and recommending opinions from an open-source community.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-20
- Publication Date
- 2026-08-14
AI Technical Summary
[0008]鉴于上述的分析,本发明实施例旨在提供一种开源社区的评审意见推荐方法和装置,用以解决将代码直接作为文本进行处理,不能有效提取代码改动中丰富的语法结构和语义信息,使得评审意见自动化推荐不准确的问题
[0017]基于上述装置的进一步改进,每个贡献请求包括代码部分和文本描述部分,所述贡献请求向量生成模块用于基于所述每个贡献请求中的文本描述部分生成所述贡献请求文本向量;以及基于所述每个贡献请求中的代码部分生成所述贡献请求代码向量。
Smart Images

Figure CN116009930B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of review result prediction technology, and in particular to a method for recommending review comments in an open-source community. Background Technology
[0002] Open source communities, also known as open-source code communities, are platforms where developers release software source code according to appropriate open-source software license agreements. GitHub is an open source community and a hosting platform for both open-source and private software projects. On GitHub, developers collaborate in a distributed manner on their respective branches through a contribution request mechanism, modifying and improving the project, and packaging their detailed code changes into contribution requests (which include both code and text descriptions). However, due to varying skill levels and programming habits among developers, not all contribution requests meet the management standards of open-source projects. Therefore, reviewers are needed to select compliant contribution requests through code review mechanisms and merge them into the source code repository. For contribution requests that do not meet the standards, developers can be guided to iterate and modify them until they comply with project standards, thereby ensuring the overall quality of the open-source software project.
[0003] With the popularity and rapid development of the open-source community, the growth rate of contribution requests far exceeds the expansion rate of review teams. This discrepancy in quantity means that some contribution requests cannot be reviewed in a timely manner, which not only affects the project's development speed but also dampens developers' enthusiasm for contributing. Meanwhile, code reviews are detailed and complex, requiring reviewers to spend a significant amount of time reviewing contribution requests and guiding contributors in iterative modifications. This also leads to long review times and low contribution aggregation efficiency in open-source communities. Therefore, an automated review comment recommendation method is needed. After a developer submits a contribution request, it can automatically recommend corresponding review comments, providing a reference for reviewers to write their comments and quickly guiding developers in iterative modifications, thereby improving code review efficiency.
[0004] The key to automated review comment recommendations lies in extracting the code modification information from contribution requests. These modifications represent the most direct changes developers make to open-source projects and are the primary focus of reviewers. Current technologies often treat these code modifications directly as natural language text. While simple and convenient, this approach fails to effectively extract syntactic structure and semantic information from the code modifications at the syntactic level, thus hindering the accuracy of review comment recommendations. Furthermore, reviewers consider other textual features of contribution requests, such as the title, description, and submission details. Failure to comprehensively consider these features also reduces the effectiveness of automated review comment recommendations.
[0005] In summary, existing research indicates that long code review cycles can dampen developer enthusiasm, and writing numerous review comments requires reviewers to expend a significant amount of time and effort. Furthermore, effectively extracting change information from code modifications is crucial for delivering effective review recommendations. Therefore, current research exhibits the following shortcomings: 1. There is a lack of an automated method for recommending review comments. This method should automatically recommend review comments after a developer submits a contribution request, which can assist or replace reviewers in writing review comments, thereby quickly guiding developers to iterate and modify contribution requests.
[0006] 2. Existing technologies are not accurate enough in generating vectors for code changes. They lack a more comprehensive preprocessing procedure for code changes and treat the code directly as text. This fails to effectively extract the rich syntactic structure and semantic information from the code changes, resulting in inaccurate automated review recommendations.
[0007] 3. Existing technologies lack reference and measurement of other characteristic information of contribution requests, cannot effectively extract all the modification content of contribution requests, and differ from the information referenced by reviewers during actual review. Summary of the Invention
[0008] Based on the above analysis, the embodiments of the present invention aim to provide a method and apparatus for recommending review comments in open source communities, in order to solve the problem that processing code directly as text cannot effectively extract the rich syntactic structure and semantic information in code modifications, resulting in inaccurate automated review comment recommendations.
[0009] On one hand, embodiments of the present invention provide a method for recommending review comments in an open-source community, comprising: obtaining multiple contribution requests that have completed the code review process from the open-source community and obtaining multiple review comments contained in each contribution request; generating a contribution request vector based on each contribution request, wherein the contribution request vector includes a contribution request text vector and a contribution request code vector; generating a review comment vector based on the multiple review comments contained in each contribution request; establishing a bidirectional long short-term memory network (Bi-LSTM) model, training the Bi-LSTM model using the contribution request vector and the review comment vector to obtain a review comment recommendation model; and obtaining contribution requests to be tested uploaded to the open-source community and generating a contribution request vector to be tested based on the contribution requests to be tested, and then using the review comment recommendation model to calculate the matching value between the contribution request vector to be tested and all review comment vectors of the multiple review comments, so as to recommend the 5 review comments with the highest matching value.
[0010] The beneficial effects of the above technical solution are as follows: The contribution request vector includes both the contribution request text vector and the contribution request code vector, which can more effectively extract the syntactic structure and semantic information of code changes, providing technical support for automated review comment recommendation. The review comment recommendation model calculates the matching value between the contribution request vector to be tested and the review comment vectors of multiple reviews, recommending the five reviews with the highest matching values. These recommended reviews can assist or replace reviewers in writing genuine review comments, saving reviewers' time; they can also quickly guide developers to iteratively modify contribution requests, improving code review efficiency and enhancing the open-source ecosystem. Based on a further improvement of the above method, each contribution request includes a code portion and a text description portion, wherein generating a contribution request vector based on each of the plurality of contribution requests further includes: generating the contribution request text vector based on the text description portion of each contribution request; and generating the contribution request code vector based on the code portion of each contribution request.
[0011] A further improvement to the above method, generating the contribution request text vector based on the text description portion of each contribution request, includes: extracting text features of the contribution request from the text description portion of each contribution request; performing natural language preprocessing on the text features of the contribution request using a natural language toolkit, wherein the natural language preprocessing includes word segmentation, stemming, and stop word removal; and converting the preprocessed text features of the contribution request into the contribution request text vector using the TF-IDF method.
[0012] Based on further improvements to the above method, the text features of the contribution request include: contribution request title, contribution request description body, submitting author, submission information, submitting author's age, submitting author's historical submission count, submitting author's historical submission information, tool execution result, tool execution report, and modified file path name.
[0013] A further improvement to the above method, generating the contribution request code vector based on the code portion of each contribution request, further includes: preprocessing the code modifications of the code portion using the pygments tool, wherein the code preprocessing includes removing comments, removing email addresses and signatures, replacing hyperlinks, replacing numbers and version numbers, and splitting complex variable names; and extracting code features of the contribution request from the code modifications of the preprocessed code portion and generating the contribution request code vector based on the code features, wherein the code features of the contribution request include: character-level code modification sequences, word-level code modification sequences, abstract syntax-level code modification sequences, the number of lines added by code modifications, and the number of lines deleted by code modifications.
[0014] Further improvements to the above method include extracting code features of contribution requests from code changes in the preprocessed code portion and generating code vectors of contribution requests based on the code features. This further includes: splitting the code changes in the preprocessed code portion into character-level code change sequences in character form to extract semantic features of the code changes; and converting the split character-level code change sequences into character-level code change vectors using OneHot encoding. Further improvements to the above method include extracting code features of contribution requests from code changes in the preprocessed code portion and generating code vectors of contribution requests based on the code features. This further includes: splitting the code changes in the preprocessed code portion into word-level code change sequences in word form to extract the syntactic structure of the code changes; and converting the split word-level code change sequences into word-level code change vectors using the Word2Vec embedding method.
[0015] Further improvements to the above method, generating a review comment vector based on the multiple review comments contained in each contribution request, further include: splitting the multiple review comments contained in each contribution request into a character-level review comment sequence in character form, and converting it into a character-level review comment vector through OneHot encoding; and splitting the multiple review comments contained in each contribution request into a word-level review comment sequence in word form, and converting it into a word-level review comment vector through the Word2Vec embedding method.
[0016] On the other hand, embodiments of the present invention provide a review comment recommendation device for an open-source community, comprising: a data acquisition module, configured to acquire multiple contribution requests that have completed the code review process from the open-source community and acquire multiple review comments contained in each contribution request, and acquire contribution requests to be tested uploaded to the open-source community; a contribution request vector generation module, configured to generate a contribution request vector based on each contribution request and generate a contribution request vector to be tested based on the contribution request to be tested, wherein the contribution request vector includes a contribution request text vector and a contribution request code vector; a review comment vector generation module, configured to generate a review comment vector based on the multiple review comments contained in each contribution request; a review comment recommendation model, configured to establish a bidirectional long short-term memory network (Bi-LSTM) model, train the Bi-LSTM model using the contribution request vector and the review comment vector to obtain the review comment recommendation model; and a recommendation module, configured to use the review comment recommendation model to calculate the matching value between the contribution request vector to be tested and the review comment vectors of the multiple review comments, so as to recommend the five review comments with the highest matching value.
[0017] Based on a further improvement of the above-mentioned device, each contribution request includes a code portion and a text description portion. The contribution request vector generation module is used to generate the contribution request text vector based on the text description portion of each contribution request; and to generate the contribution request code vector based on the code portion of each contribution request.
[0018] Compared with the prior art, the present invention can achieve at least one of the following beneficial effects: 1. This invention extracts data features from 15 contribution requests from both textual and code attributes, effectively extracting modification information from contribution requests, generating contribution request feature vectors, and fully extracting the feature information contained in contribution requests.
[0019] 2. At the same time, a more complete code modification preprocessing method is proposed. Based on the abstract syntax tree, a multi-level embedded code modification vector generation method is designed. Compared with treating the code directly as text, this method can more effectively extract the syntactic structure and semantic information of the code modification, providing technical support for the automated recommendation of review comments.
[0020] 3. Construct a clear and reasonable code review dataset based on the characteristics of contribution requests and review comments, and train the matching value between contribution requests and review comments based on the Bi-LSTM (Bi-directional LSTM) sequence algorithm.
[0021] 4. For a newly created contribution request, select the most matching review comments for recommendation, thus automating the review comment recommendation process. The recommended review comments can assist or replace reviewers in writing genuine review comments, saving reviewers' time; they can also quickly guide developers to iterate and modify contribution requests, improving code review efficiency and the open-source ecosystem.
[0022] In this invention, the above-described technical solutions can be combined with each other to achieve more preferred combinations. Other features and advantages of this invention will be set forth in the following description, and some advantages may become apparent from the description or be learned by practicing the invention. The objects and other advantages of this invention can be realized and obtained from what is particularly pointed out in the description and drawings. Attached Figure Description
[0023] The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. Throughout the drawings, the same reference numerals denote the same parts.
[0024] Figure 1 This is a flowchart illustrating the open-source community's review and recommendation method according to an embodiment of the present invention.
[0025] Figure 2A This is a diagram illustrating the abstract syntax modification tree according to an embodiment of the present invention; Figure 2B For the reason Figure 2A The diagram shows the sequence of nodes in the abstract syntax modification tree transformed by depth-first traversal.
[0026] Figure 3 A diagram illustrating the ASTReview model for automated recommendation of review comments in the open-source community according to an embodiment of the present invention.
[0027] Figure 4 This is an illustration of code modification feature extraction according to an embodiment of the present invention.
[0028] Figure 5 This is a diagram illustrating the review comments recommended according to an embodiment of the present invention.
[0029] Figure 6 This is a diagram illustrating an open-source community review and recommendation device according to an embodiment of the present invention. Detailed Implementation
[0030] Preferred embodiments of the present invention will now be described in detail with reference to the accompanying drawings, which form part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not intended to limit the scope of the present invention.
[0031] One specific embodiment of the present invention discloses a method for review and recommendation comments from an open-source community. (See references) Figure 1 The open-source community's method for recommending review opinions includes: in step S102, obtaining multiple contribution requests that have completed the code review process from the open-source community and obtaining multiple review opinions contained in each contribution request; in step S104, generating a contribution request vector based on each contribution request, wherein the contribution request vector includes a contribution request text vector and a contribution request code vector; in step S106, generating a review opinion vector based on the multiple review opinions contained in each contribution request; in step S108, establishing a bidirectional long short-term memory network (Bi-LSTM) model, training the Bi-LSTM model using the contribution request vector and the review opinion vector to obtain a review opinion recommendation model; and in step S110, obtaining the contribution requests to be tested uploaded to the open-source community and generating a contribution request vector to be tested based on the contribution requests to be tested, then using the review opinion recommendation model to calculate the matching value between the contribution request vector to be tested and the review opinion vectors of multiple review opinions, and recommending the 5 review opinions with the highest matching value.
[0032] Compared with existing technologies, the open-source community review comment recommendation method provided in this embodiment uses a contribution request vector that includes both a contribution request text vector and a contribution request code vector. This allows for more effective extraction of the syntactic structure and semantic information of code modifications, providing technical support for automated review comment recommendation. The review comment recommendation model calculates the matching value between the contribution request vector to be tested and the review comment vectors of multiple reviews, and then recommends the five reviews with the highest matching values.
[0033] The following text will refer to Figure 1 Steps S102 to S110 of the method for recommending the review comments from the open source community are described in detail.
[0034] In step S102, multiple contribution requests that have completed the code review process are obtained from the open-source community, and multiple review comments are obtained for each contribution request. Specifically, each contribution request has multiple review comments, where each review comment corresponds to a code change. Specifically, the review comments include what problems exist in the code and how to fix those problems. The research object of this invention is historical review data of real projects on the GitHub platform. By crawling code review data of real projects using the GitHub API, it was found that reviewers focus on the code changes and other relevant text information in the contribution requests when completing code reviews and writing review comments.
[0035] In step S104, a contribution request vector is generated based on each contribution request. This vector includes a contribution request text vector and a contribution request code vector. Each contribution request includes a code portion and a text description portion. Generating a contribution request vector based on each of the multiple contribution requests further includes: generating a contribution request text vector based on the text description portion of each contribution request; and generating a contribution request code vector based on the code portion of each contribution request. Specifically, generating a contribution request text vector based on the text description portion of each contribution request includes: extracting text features of the contribution request from the text description portion of each contribution request; performing natural language preprocessing on the text features of the contribution request using a natural language toolkit, where natural language preprocessing includes word segmentation, stemming, and stop word removal; and converting the preprocessed text features of the contribution request into a contribution request text vector using the TF-IDF method. The text features of the contribution request include: contribution request title, contribution request description body, submitting author, submission information, submitting author's age, number of historical submissions by the submitting author, historical submission information of the submitting author, tool execution result, tool execution report, and modified file path name.
[0036] Generating a contribution request code vector based on the code portion of each contribution request further includes: preprocessing the code changes in the code portion using the pygments tool, wherein the code preprocessing includes removing comments, removing email addresses and signatures, replacing hyperlinks, replacing numbers and version numbers, and splitting complex variable names; and extracting code features of the contribution request from the code changes in the preprocessed code portion and generating a contribution request code vector based on the code features, wherein the code features of the contribution request include: character-level code change sequence, word-level code change sequence, abstract syntax-level code change sequence, number of lines added by code changes, and number of lines deleted by code changes.
[0037] Extracting code features from the code changes in the preprocessed code portion and generating code vectors for the contribution requests based on these features further includes: splitting the code changes in the preprocessed code portion into character-level code change sequences in character form to extract semantic features of the code changes; and converting the split character-level code change sequences into character-level code change vectors using OneHot encoding. Extracting code features from the code changes in the preprocessed code portion and generating code vectors for the contribution requests based on these features further includes: splitting the code changes in the preprocessed code portion into word-level code change sequences in word form to extract syntactic structure of the code changes; and converting the split word-level code change sequences into word-level code change vectors using the Word2Vec embedding method.
[0038] In step S106, a review comment vector is generated based on the multiple review comments contained in each contribution request. Generating the review comment vector based on the multiple review comments contained in each contribution request further includes: splitting the multiple review comments contained in each contribution request into a character-level review comment sequence in character form, and converting it into a character-level review comment vector using OneHot encoding; and splitting the multiple review comments contained in each contribution request into a word-level review comment sequence in word form, and converting it into a word-level review comment vector using the Word2Vec word embedding method.
[0039] In step S108, a bidirectional long short-term memory (Bi-LSTM) network model is established. The Bi-LSTM model is trained using contribution request vectors and review comment vectors to obtain a review comment recommendation model. Specifically, the code change features in sequence form are sequentially input into the Bi-LSTM sequence model, including character-level and word-level generated sequences and abstract syntax node sequences. These three sequence features are trained through three Bi-LSTM layers to generate three context vectors, representing the syntactic and semantic information of the code changes. These context vectors are then fused with the added and deleted lines of the code changes through a fully connected layer to form a single code change vector, generating a contribution request code vector containing valid information.
[0040] In step S110, the contribution request to be tested uploaded to the open source community is obtained and a contribution request vector to be tested is generated based on the contribution request to be tested. Then, the matching value between the contribution request vector to be tested and the review opinion vectors of multiple review opinions is calculated using the review opinion recommendation model, and the 5 review opinions with the highest matching value are recommended.
[0041] Another specific embodiment of the present invention discloses a device for recommending review comments from an open-source community. (See reference) Figure 6 The open-source community review and recommendation device includes: a data acquisition module 602, used to acquire multiple contribution requests that have completed the code review process from the open-source community and acquire multiple review comments contained in each contribution request, as well as to acquire contribution requests to be tested uploaded to the open-source community; and a contribution request vector generation module 604, used to generate a contribution request vector based on each contribution request and to generate a contribution request vector to be tested based on the contribution requests to be tested, wherein the contribution request vector includes a contribution request text vector and a contribution request code vector; each contribution request includes a code part and a text description part, and the contribution request vector generation module 604 is used to generate a contribution request text vector based on the text description part in each contribution request; and to generate a contribution request code vector based on the code part in each contribution request. The review comment vector generation module 606 is used to generate a review comment vector based on the multiple review comments contained in each contribution request; the review comment recommendation model 608 is used to establish a bidirectional long short-term memory network (Bi-LSTM) model, train the Bi-LSTM model using the contribution request vector and the review comment vector to obtain the review comment recommendation model; and the recommendation module 610 is used to calculate the matching value between the contribution request vector to be tested and the review comment vectors of multiple review comments using the review comment recommendation model, so as to recommend the 5 review comments with the highest matching value.
[0042] The following text will refer to Figures 1 to 5 The following describes in detail the review comments and recommendations from the open-source community according to embodiments of the present invention, using specific examples.
[0043] Based on the above analysis, this invention studies code review activities between developers and reviewers using real review data from open-source communities. It designs an automated review comment recommendation method that automatically recommends suitable review comments for newly created contribution requests based on the correlation between the contribution request and the review comments. Simultaneously, a code change vector generation method is designed based on abstract syntax trees and multi-level embedding methods. This method effectively extracts code change information from contribution requests and constructs code change vectors, serving as a crucial basis for model recommendations. The effectiveness of the proposed review comment recommendation method is then validated using massive amounts of data. Finally, an application system is implemented based on this method to support code review in open-source software communities.
[0044] The research object of this invention is historical review data of real projects on the GitHub platform. Utilizing... By crawling code review data from real projects using the GitHub API, it was found that reviewers focus on code changes and other relevant textual information in contribution requests when completing code reviews and writing review comments. Therefore, this invention extracts 15 effective features from contribution requests from both textual and code attributes as a basis for matching with review comments. Among these, code features are the most critical, representing the most important information reviewed by the reviewer. This invention designs a comprehensive code change preprocessing workflow and proposes a multi-level embedding method for generating code change vectors based on abstract syntax trees, which can effectively extract the syntactic structure and semantic information of code changes. Combined with the textual features of contribution requests, this fully expresses the change information of the contribution request. Subsequently, a review comment recommendation model, AstReview, is designed based on the Bi-LSTM sequence algorithm and trained to generate matching relationships between contribution requests and review comments. For a newly created contribution request, the model can construct relevant features based on the change information of the contribution request and automatically recommend the most matching review comments, serving as a reference for reviewers when reviewing contribution requests or providing timely review feedback to developers.
[0045] The beneficial effects of the above technical solution are as follows: (1) This invention extracts data features of 15 contribution requests from two aspects: text attributes and code attributes. It can effectively extract the modification information in the contribution request and generate the contribution request feature vector. At the same time, it proposes a more complete code modification preprocessing method and designs a multi-level embedded code modification vector generation method based on abstract syntax tree. It can effectively extract the syntactic structure and semantic information of code modification and provide technical support for automated recommendation of review opinions. (2) Based on the contribution request features and review opinions, a clear and reasonable code review dataset is constructed. The matching value between contribution requests and review opinions is trained based on the Bi-LSTM (Bidirectional Long Short Memory Network) sequence algorithm. (3) For a newly created contribution request, the review opinion that best matches it is selected for recommendation to realize automated recommendation of review opinions. The recommended review opinions can assist or replace the reviewer in writing real review opinions, saving the reviewer's time; it can also quickly guide the developer to iterate and modify the contribution request, improve the efficiency of code review, and improve the open source ecosystem.
[0046] (1) Generate contribution request feature vector Specifically, this invention extracts data features of 15 contribution requests from two aspects: text attributes and code attributes.
[0047] a. Generate feature vectors of text attributes Based on a further improvement of the above method, the text attribute of the issue refers to the natural language text manually written by the developer when creating the contribution request. This text describes the specific functionality or fixes implemented by the code changes in the contribution request, facilitating reviewers' quick understanding of the modifications. This invention extracts 10 text data features from the text attribute, including the contribution request title, contribution request description, submitting author, submission information, submitting author's age, the submitting author's historical submission count, the submitting author's historical submission information, tool execution results, tool execution report, and modified file path name.
[0048] Specifically, the contribution request title is the title written by the developer when creating the contribution request. It is the most concise description of the contribution request's functionality, and each contribution request uniquely corresponds to one contribution request title. The contribution request description is a detailed description of the contribution request written by the developer when creating the contribution request. Each contribution request uniquely corresponds to one contribution request description. A contribution request can contain multiple commits, each of which is the minimum set of modifications made by the developer in their local packaging. The commit author is the username of the developer who completed this commit, the commit information is a brief description of the commit written by the developer when packaging and submitting, the commit author's age is the total number of days since the developer registered, the commit author's historical commit count is the total number of all historical commits by the developer, and the historical commit information is the collection of commit information from all historical commits by the developer. After the developer creates a contribution request, the project will automatically execute pre-configured tools, such as quality checks and continuous integration tools, to perform automated testing on the contribution request and return tool execution results and tool execution reports. The execution results and reports of all tools are integrated into the tool execution results and tool execution report of the contribution request. The modified file path name refers to the file location of the specific modified files in the open-source project. The term frequency–inverse document frequency (TF-IDF) method is used to convert the above contribution request text attribute data into word vectors, generating contribution request text vectors.
[0049] The specific formula for TF-IDF is as follows:
[0050] in, tf pr,s To contribute the frequency of word 's' occurrence in the requested data, df s It is the frequency of the word 's' in all documents. NT This represents the total number of documents.
[0051] b. Generate feature vectors for code attributes Based on further improvements to the above method, the code attributes of the problem are the main content of the contribution request and a key reference for reviewers, representing the direct modifications made by the developer to the open-source software. These code changes consist of added lines, deleted lines, source code, and modification locations, corresponding to specific additions, deletions, or other modifications made to a file within the open-source software. This invention extracts five code data features from the code attributes of contribution requests: character-level code change sequences, word-level code change sequences, abstract syntax-level code change sequences, the number of lines added due to code changes, and the number of lines deleted due to code changes.
[0052] Specifically, the code changes in the contribution request are first preprocessed using the pygments tool, including removing comments, removing emails and signatures, replacing hyperlinks, replacing numeric version numbers, and splitting complex variable names.
[0053] The code modifications include the removal of comments. Comments are typically natural language descriptions of the code. Since this invention primarily extracts the language information and syntactic structure of the modified code, and comments can interfere with the extraction of syntactic structure, all comments in the code modifications are removed. For example, comments such as " / / …" and " / *…..* / " are deleted.
[0054] Email addresses and signatures have been removed. Some open-source projects require the author's username and email address to be added at the end of the submission instructions or review comments. However, this information is not particularly relevant to code review; therefore, this project has removed the email address and signature. For example, usernames or email addresses such as "@helloxx" or "liuzhengxxx@xx.com" have been removed.
[0055] Replace hyperlinks with fixed words. <url>During the review process, reviewers and contributor request authors sometimes cite links to software documentation, manuals, open-source community issues, or other contributor requests to aid explanation. However, hyperlinks, being relatively infrequent words, can contaminate the training of word representation models. Therefore, this project replaces all hyperlinks with a single, specific word. <url>For example, in the phrase "Add a error message base on github.com / xxx / xxx / pull / discussion_xxx", the last word is a hyperlink and will be replaced by "Add a errormessage base on". <url>".
[0056] Replace the numbers, commit ID, and version number with the fixed word. <number> ’、‘ <commitid> ’、‘ <version>Contribution requests and review comments often contain specific numbers, commit IDs, and version numbers to uniquely identify a commit. These elements are usually project-specific and serve only as unique identifiers, lacking inherent meaning and having little relevance to the code review process. Therefore, they will be uniformly replaced with fixed words. For example, numbers like "95527" will be replaced with the fixed word. <number>Commit numbers with a specific format, such as "68cbb7291a9cb0d736ceea64caa50fd8c001xxx", will be replaced with a fixed word. <commitid>".
[0057] This project decomposes complex variable names in code modifications. Code modifications often include many user-defined variable or method names, most of which are composed of multiple words, such as "tcpMd5SigMaxKeyLen". Since this invention builds a vocabulary and generates vector representations based on individual words, it is difficult for machines to learn the semantic information and generate effective vector representations for such complex words with low frequency. Therefore, this project uses the NLTK and StackOverflow vocabulary libraries. Words not found in these libraries are marked as complex variable names. These complex variable names are then simplified by vocabulary matching, breaking them down into as many known words from the vocabulary as possible, or by using underscores ('_') as delimiters to obtain multiple simpler words from the vocabulary. For example, the above example "tcpMd5SigMaxKeyLen" will be broken down into five words: "tcp, md5sig, max, key, len", thus better extracting information from the variable name.
[0058] The above preprocessing is performed mainly because these words appear infrequently and do not contain much useful information, making it difficult to learn their specific meanings and convert them into accurate vector forms. Therefore, they are replaced with a fixed word to reduce the noise impact on the overall sequence.
[0059] Specifically, after completing the preprocessing of the code changes, this invention designs a multi-level code change vector embedding method based on an abstract syntax tree to convert the above-mentioned contribution request code changes into vector form and generate contribution request code vectors.
[0060] Specifically, code modification vector representations are generated through embedding at three dimensions: character level, word level, and abstract syntax tree level. At the character level, code modifications are processed as text, splitting them character by character. For example, "int a = 0;" will be split into a sequence of "['i', 'n', 't', ' ', a, ' ', =, ' ', 0]". Character-level embedding effectively extracts the semantic features of code modifications and learns vector representations of complex variable names. At the word level, the code modifications are lexically analyzed and segmented using the pygments library. For example, "int a = 0;" will be split into a sequence of "['int', 'a', '=', '0']", which better extracts lexical information from the code modifications. At the abstract syntax tree level, the code modifications are transformed into an abstract syntax tree, generated through maximum point matching. Each node in an abstract syntax tree (AST) consists of a category and a label. The category refers to the syntax type of the node, such as an identifier or expression, while the label represents the specific syntax content. This invention defines the modification types of abstract syntax nodes: update, deletion, move, insertion, and no modification. To address the problem of excessively large and deep ASTs, the resulting AST is transformed into a sequence of nodes using a depth-first traversal. Depth-first traversal is a method for traversing and searching a tree or graph. Starting from a vertex, it sequentially visits all unvisited child nodes of that vertex, transforming the tree structure of the AST into a linear structure of node sequences based on the order of visits. Figure 2A and Figure 2B This is an example of transforming a tree into a sequence of modified tree nodes, where Figure 2A For an example of an abstract grammar change tree, transform it into a depth-first traversal order. Figure 2B The modified tree node sequence is shown.
[0061] Specifically, this invention identifies five types of changes to abstract syntax nodes. An updated node refers to two nodes whose parent nodes match, or two nodes match but whose type or label changes. A deleted node refers to a node in the modified abstract syntax tree that is no longer present in the original abstract syntax tree. A moved node refers to matching nodes in different positions, determined primarily by the parent node and the node's depth, recording the movement method. An inserted node refers to the addition of a node in the modified abstract syntax tree that was not present in the original abstract syntax tree. An unmodified node refers to two matching nodes with identical types, labels, and parent nodes. Since unmodified nodes do not belong to the code modification part, to reduce their interference with information extraction, all subtrees containing only unmodified nodes will be deleted.
[0062] Specifically, the code modification features in sequence form are fed into a Bi-LSTM sequence model, including character-level and word-level generated sequences as well as abstract syntax node sequences. These three sequence features are trained through three Bi-LSTM layers to generate three context vectors, representing the syntactic and semantic information of the code modification. These context vectors are then fused with the added and deleted lines in the code modification through a fully connected layer to form a single overall code modification vector, generating a contribution request code vector containing valid information.
[0063] Based on the further improvement of the above method, the contribution request text vector and contribution request code vector are fused together through a fully connected layer to generate a whole contribution request vector P (Pull Request), which can effectively express the modification information and content of the contribution request.
[0064] (2) Matching value between training contribution requests and review comments Further improvements to the above method involve sequentially inputting the sequence-based review comment features into a Bi-LSTM sequence model, including both character-level and word-level sequence formats. The two sequence features are trained through two separate Bi-LSTM layers to generate two context vectors representing the review information. These vectors are then fused into a single, unified review comment vector R(Review) through a fully connected layer.
[0065] Based on the further improvement of the above method, the obtained contribution request vector P and review opinion vector R are input into the model to train and generate the matching value Rel(P,R) between contribution requests and review opinions. This is a value between -1 and 1, and the larger the value, the better the match between the two.
[0066] Specifically, during training, a matching label value Rel(P, R) is first added to the data. For a pair of real contribution requests and review comments, Rel(P, R) is set to 1, indicating that the two are matched. However, since training requires constructing negative samples, i.e., mismatched data, this invention randomly selects 3 other review comments and contribution requests from all contribution requests in the training set to construct negative sample data, and sets Rel(P, R) to -1, indicating that the two are not matched.
[0067] (3) Automated recommendation of review comments Based on further improvements to the above method, after model training, for a newly created contribution request, the matching value between it and all review comments is calculated. The five review comments with the highest matching values are selected as the review comment recommendation list. This list is automatically recommended to developers and reviewers, assisting reviewers in writing authentic review comments and quickly providing developers with review references, effectively improving the code review process in open-source communities.
[0068] A specific embodiment of the present invention discloses an automated recommendation model for review comments in the open-source community. The framework of the AstReview model is as follows: Figure 3 As shown.
[0069] The methods for recommending review opinions in the open source community include: (1) crawling real code review data of open source projects from the GitHub open source community, and constructing a code review dataset after data preprocessing and feature extraction. (2) selecting features from two dimensions: text attributes and code attributes, and determining a total of 15 effective features. Designing a multi-level embedding method for code changes based on abstract syntax trees, which can effectively extract the syntactic structure and semantic information of code changes. (3) inputting the code changes of contribution requests in sequence and the review opinions in sequence into the Bi-LSTM model to train and generate contribution request code vectors and review opinion vectors. Then, combining the contribution request text vectors to train the matching value between contribution requests and review opinions. (4) for a newly created contribution request, the matching value between it and all review opinions is calculated by the model, and the 5 review opinions with the highest matching value are selected as the review opinion recommendation list and automatically recommended to developers and reviewers.
[0070] (1) Crawling and constructing a code review dataset Specifically, we crawled real historical data from the GitHub open-source community via the GitHub API. On the GitHub platform, reviewers who write comments are often core members of the project team. To ensure the quantity and quality of contribution requests and review comments, this project prioritized projects on GitHub with a sufficient number of contribution requests and high star counts. The number of stars represents the number of likes a project receives; a high number of stars indicates a high level of recognition for the project, and suggests high code and review quality.
[0071] The system crawls contribution requests that have completed code review processes from open-source projects using the URL "https: / / api.github.com / repos / :owner / :repo / pulls?state=closed", where ":owner" represents the project owner and ":repo" represents the project name. It retrieves the contribution request ID and basic information about each request. Then, it crawls the review comments included in each contribution request using the URL "https: / / api.github.com / repos / :owner / :repo / pulls / :pull_id / comments", where ":pull_id" represents the contribution request ID. The crawled content is in JSON format, where the "body" field contains the review comments and the "diff_hunk" field represents the corresponding code changes.
[0072] (2) Extracting contribution request features from text attributes and code attributes Based on the further advancement of the above implementation plan, after crawling all code review data, 15 valid features of contribution requests and corresponding review comments are extracted from text attributes and code attributes.
[0073] Specifically, 10 effective features were extracted from the perspective of text attributes, including contribution request title, contribution request description body, submitter, submission information, submitter's age, submitter's historical commit count, submitter's historical commit information, tool execution result, tool execution report, and modified file path name. The contribution request title is the title written by the developer when creating the contribution request; it is the most concise description of the contribution request's function, and each contribution request uniquely corresponds to one title. The contribution request description is a detailed description of the contribution request written by the developer when creating the contribution request; each unique contribution request corresponds to one description. A contribution request can contain multiple commits, each commit being the minimum set of modifications the developer made during local packaging. The submitter's author is the username of the developer who completed this commit; the submission information is a brief description of the commit written by the developer during packaging; the submitter's age is the total number of days since the developer registered; the submitter's historical commit count is the total number of all historical commits by the developer; and the historical commit information is the collection of submission information for all historical commits by the developer. After a developer creates a contribution request, the project automatically executes pre-configured tools, such as quality checks and continuous integration tools, to perform automated tests on the contribution request and return tool execution results and reports. The tool execution results and reports for the contribution request are a collection of returns from all tools. Modifying a file path name refers to the location of the specific file in the open-source project that was modified.
[0074] First, the NLTK tool is used to perform natural language preprocessing on the text features of contribution requests, including word segmentation, stemming, and stop word removal, transforming the text words into a simpler form. Word segmentation divides a piece of text into multiple word forms; stemming obtains the prototype of each word, removing plural or tense forms; stop word removal mainly removes words without specific meaning or that do not affect the semantics of the text. Then, the term frequency–inverse document frequency (TF-IDF) method is used to convert the contribution request text attribute data into word vectors, generating contribution request text vectors.
[0075] Specifically, this invention designs a multi-level code change vector embedding method based on an abstract syntax tree, which extracts five code data features of contribution requests from code attributes, including character-level code change sequences, word-level code change sequences, abstract syntax-level code change sequences, number of lines added by code changes, and number of lines deleted by code changes.
[0076] Figure 4 This is an example of feature extraction from code changes. The left image shows a piece of code that has been modified, and the right image shows the five data features extracted from the code changes.
[0077] First, the code preprocessing of contribution requests is performed using the pygments tool, including removing comments, replacing hyperlinks, replacing numbers and version numbers, and splitting complex variable names.
[0078] Then, code change vector representations are generated by embedding at three dimensions: character level, word level, and abstract syntax level.
[0079] Character-level embedding processes code changes as text, breaking them down character by character. For example, "int a = 0;" will be split into a sequence of "['i', 'n', 't', ' ', a, ' ', =, ' ', 0]". Character-level embedding effectively extracts semantic features of code changes and learns vector representations of complex variable names. Due to the limited number of character types, after word segmentation... OneHot encoding is converted into vector form. OneHot uses N bits to encode N states, with each state represented by an independent bit, and only one bit is valid at any given time. For example, if this invention includes N characters, then the vector representation of all characters contains N bits, and the vector representation of the first character 'a' is "10000…0", the vector representation of the second character 'b' is "01000…0", and the vector representation of the Nth character is "00000…1".
[0080] Word-level code modifications are analyzed and segmented using the pygments library. For example, "int a= 0;" will be split into a sequence of "['int', 'a', '=', '0']", which better extracts the lexical information of the code changes. Due to the large number of word types and the vast vocabulary, using OneHot encoding vectors would be too sparse. Therefore, this invention uses the Word2Vec word embedding method to convert word-level code modifications into vector form. Word2Vec is a pre-trained neural network model that takes a large text corpus as input and typically generates a vector representation space with hundreds of dimensions. Word2Vec trains the vector representation of each word based on the context information of each word in the corpus, ensuring that words with similar context information have similar vector representations. Finally, a corresponding vector representation is assigned to each word in the corpus within the vector space.
[0081] The abstract syntax tree (AST) level transforms code changes into an abstract syntax tree format. Maximum point matching is used to generate an AST from the code changes. Each node in the AST consists of a category and a label. The category refers to the syntax type of the node, such as an identifier or expression, while the label represents the specific syntax content. This invention defines the change types for AST nodes as: update, deletion, move, insertion, and no change. To address the issue of excessively large and deep ASTs, the resulting AST is transformed into a sequence of AST nodes using a depth-first traversal.
[0082] (3) Matching value of contribution requests and review comments based on Bi-LSTM training The code change features in sequence are then fed into a Bi-LSTM sequence model, including character-level and word-level generated sequences and abstract syntax node sequences. These three sequence features are trained through three Bi-LSTM layers to generate three context vectors, representing the syntactic and semantic information of the code changes. These context vectors are then fused with the added and deleted lines in a fully connected layer to form a single code change vector, generating a contribution request code vector containing valid information.
[0083] Specifically, Bi-LSTM, also known as a bidirectional long short-term memory model, is a commonly used model for processing time-series data. Bi-LSTM is an improvement on LSTM, consisting of a forward LSTM and a backward LSTM. The forward LSTM receives sequence features in their normal order, while the backward LSTM receives them in their reverse order. In a unidirectional LSTM, the model can only model sequence features from beginning to end, and during learning, it can only use contextual information, not contextual information. Therefore, this invention uses Bi-LSTM, which can extract richer and more effective sequence information compared to a unidirectional LSTM.
[0084] Specifically, a fully connected layer is a flat structure composed of multiple neurons that can weight and process multiple features, thereby achieving dimensionality reduction and fusion of multiple input vectors. Here, the present invention uses a fully connected layer to fuse the sequence feature vectors at three levels, the number of rows added, and the number of rows deleted into a single code change vector.
[0085] Based on the further advancement of the above implementation scheme, the obtained contribution request text vector and contribution request code vector are fused together through a fully connected layer to generate a unified contribution request vector P (Pull Request).
[0086] Further advancements based on the aforementioned implementation plan involve sequentially inputting the sequence-based review comment features into a Bi-LSTM sequence model, including character-level and word-level generated sequences. The two sequence features are trained through two separate Bi-LSTM layers to generate two context vectors representing the review information of the comments. These vectors are then fused into a single, unified review comment vector R(Review) through a fully connected layer.
[0087] Based on the further development of the above implementation scheme, matching values between contribution requests and review comments are trained and generated according to the obtained contribution request vector and review comment vector.
[0088] Specifically, the obtained contribution request vector P and review comment vector R are transformed into input matrices and fed into the model. Before training, a matching label value Rel(P, R) is added to the data. For real contribution request and review comment data pairs, Rel(P, R) is set to 1, indicating that the two are matched. However, since training also requires constructing negative samples, i.e., mismatched data, this invention randomly selects three other review comments from all contribution requests in the training set to construct negative sample data with the contribution requests, and sets Rel(P, R) to -1, representing that the two are mismatched. Finally, the matching value Rel(P, R) between contribution requests and review comments is generated during training. This is a value between -1 and 1, with a larger value indicating a better match.
[0089] (4) Automated recommendation of review comments for contribution requests. Furthermore, after model training is complete, for a newly created contribution request, relevant features are extracted from text and code attributes in the same manner to generate a contribution request vector. The constructed model calculates the matching value between this contribution request and all review comments, and selects the five review comments with the highest matching values as a review comment recommendation list. This recommendation list serves as the final review comment recommendation result, automatically recommended to developers and reviewers, assisting reviewers in writing authentic review comments and quickly providing them to developers for review reference, thus completing the automated recommendation of review comments.
[0090] As shown in the figure below, Figure 5 As an example of a reviewer's recommendation, to evaluate the effectiveness of the model's recommendation, this invention mixes real reviewers' comments into the reviewer's comment matching set to see if the model can find and recommend real reviewers' comments within the matching set. The left image shows the real code changes and real reviewers' comments. Here, the developer submitted a call to the `latch1` method. The reviewer felt that the `latch1` method name did not meet project requirements and did not clearly show the method's function, therefore suggesting the developer change `latch1` to `request1ConnectStart`. The right image shows the list of reviewers' comments recommended by the method designed in this invention, containing 5 reviewers' comments and a corresponding matching value `Rel` for each comment. The matching value is a value between -1 and 1, with higher values indicating a stronger match. It can be seen that the method designed in this invention can correctly recommend real reviewers' comments.
[0091] Compared with the prior art, the present invention can achieve at least one of the following beneficial effects: 1. A method for recommending review comments in an open-source community, which builds a deep learning prediction model based on code review data and Bi-LSTM algorithm training. It can effectively extract code change information and review information, automatically recommend review comments during review, assist or replace reviewers in writing review comments, and greatly improve the efficiency of code review.
[0092] 2. By employing web scraping technology, we acquire more comprehensive real-world code review data from open-source communities. We construct more complete contribution request features using text and code attributes, generating contribution request vector representations that express changes. Simultaneously, based on the NLTK and pygments libraries, we perform data mining, feature extraction, and data preprocessing of review comments and code changes, effectively alleviating the problem of complex and difficult-to-represent code change vocabulary, and providing data support for training and building a review comment recommendation model.
[0093] 3. A code modification vector representation method based on abstract syntax tree and multi-level embedding can effectively extract the semantic information and syntactic structure of code modifications, significantly improve the accuracy of review comments and recommendations, and provide technical support for training and building a review comment recommendation model.
[0094] Those skilled in the art will understand that all or part of the processes of the methods described in the above embodiments can be implemented by a computer program instructing related hardware, and the program can be stored in a computer-readable storage medium. The computer-readable storage medium may be a disk, optical disk, read-only memory, or random access memory, etc.
[0095] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the scope of protection of the present invention.< / commitid> < / number> < / version> < / commitid> < / number> < / url> < / url> < / url>
Claims
1. A method for recommending reviews in an open-source community, characterized in that, include: Obtain multiple contribution requests that have completed the code review process from the open-source community and obtain multiple review comments contained in each contribution request; A contribution request vector is generated based on each contribution request, wherein the contribution request vector includes a contribution request text vector and a contribution request code vector, and each contribution request includes a code portion and a text description portion; A review comment vector is generated based on the multiple review comments contained in each contribution request; A bidirectional long short-term memory (Bi-LSTM) network model is established, and the Bi-LSTM model is trained using the contribution request vector and the review opinion vector to obtain a review opinion recommendation model; and The system retrieves the contribution requests to be tested uploaded to the open-source community and generates a contribution request vector to be tested based on the contribution requests. Then, it uses the reviewer recommendation model to calculate the matching value between the contribution request vector to be tested and the reviewer vectors of the multiple reviewers, and recommends the 5 reviewers with the highest matching values. The step of generating a contribution request vector based on each of the plurality of contribution requests further includes: generating a contribution request text vector based on the text description portion of each contribution request, wherein text features of the contribution request are extracted from the text description portion of each contribution request; and generating a contribution request code vector based on the code portion of each contribution request, wherein code features of the contribution request are extracted from the code modifications in the preprocessed code portion and the code vector of the contribution request is generated based on the code features. The code characteristics of the contribution request include: character-level code change sequence, word-level code change sequence, abstract syntax tree-level code change sequence, number of lines added by code changes, and number of lines deleted by code changes. The abstract syntax tree level is the transformation of code changes into an abstract syntax tree. The change types of the abstract syntax tree nodes include update, deletion, move, insertion, no change, and the abstract syntax tree node sequence is transformed into an abstract syntax tree node sequence in depth-first traversal order. The textual features of the contribution request include: contribution request title, contribution request description body, submitting author, submission information, submitting author's age, submitting author's historical submission count, submitting author's historical submission information, tool execution result, tool execution report, and modified file path name.
2. The open-source community review and recommendation method according to claim 1, characterized in that, Generating the contribution request text vector based on the text description portion of each contribution request further includes: Natural language preprocessing is performed on the text features of the contribution request using a natural language toolkit, wherein the natural language preprocessing includes word segmentation, stemming, and stop word removal; and The TF-IDF method is used to convert the preprocessed text features of the contribution request into the contribution request text vector.
3. The open-source community review and recommendation method according to claim 1, characterized in that, Generating the contribution request code vector based on the code portion in each contribution request further includes: The code modifications to the code section are preprocessed using the pygments tool. The code preprocessing includes removing comments, removing email addresses and signatures, replacing hyperlinks, replacing numbers and version numbers, and splitting complex variable names.
4. The open-source community review and recommendation method according to claim 1, characterized in that, Extracting code features of contribution requests from the code changes in the preprocessed code portion and generating code vectors for the contribution requests based on the code features further includes: The preprocessed code changes are broken down into character-level sequences to extract semantic features of the code changes; and The split character-level code change sequence is converted into a character-level code change vector using OneHot encoding.
5. The method for recommending open-source community reviews according to claim 1, characterized in that, Extracting code features of contribution requests from the code changes in the preprocessed code portion and generating code vectors for the contribution requests based on the code features further includes: The code changes in the preprocessed code section are broken down into word-level sequences to extract the syntactic structure of the code changes; and The split word-level code change sequences are transformed into word-level code change vectors using the Word2Vec embedding method.
6. The open-source community review and recommendation method according to claim 1, characterized in that, Generating a review comment vector based on the multiple review comments contained in each contribution request further includes: The multiple review comments contained in each contribution request are split into character-level review comment sequences in character form, and then converted into character-level review comment vectors using OneHot encoding; and The multiple review comments contained in each contribution request are split into word-level review comment sequences in word form, and then transformed into word-level review comment vectors using the Word2Vec embedding method.
7. A review and recommendation device for an open-source community, characterized in that, include: The data acquisition module is used to acquire multiple contribution requests that have completed the code review process from the open source community, acquire multiple review comments contained in each contribution request, and acquire contribution requests to be tested uploaded to the open source community. A contribution request vector generation module is used to generate a contribution request vector based on each contribution request and to generate a contribution request vector to be tested based on the contribution request to be tested. The contribution request vector includes a contribution request text vector and a contribution request code vector. Each contribution request includes a code portion and a text description portion. The contribution request vector generation module is used to generate the contribution request text vector based on the text description portion of each contribution request; and to generate the contribution request code vector based on the code portion of each contribution request. The review opinion vector generation module is used to generate a review opinion vector based on the multiple review opinions contained in each contribution request; The review opinion recommendation model is used to establish a bidirectional long short-term memory (Bi-LSTM) network model. The Bi-LSTM model is trained using the contribution request vector and the review opinion vector to obtain the review opinion recommendation model. The recommendation module is used to calculate the matching value between the contribution request vector to be tested and all the review opinion vectors of the multiple review opinions using the review opinion recommendation model, so as to recommend the 5 review opinions with the highest matching value. The contribution request vector generation module is further configured to: generate a contribution request text vector based on the text description portion of each contribution request, wherein text features of the contribution request are extracted from the text description portion of each contribution request; and generate a contribution request code vector based on the code portion of each contribution request, wherein code features of the contribution request are extracted from the code modifications in the preprocessed code portion and the code vector of the contribution request is generated based on the code features. The code characteristics of the contribution request include: character-level code change sequence, word-level code change sequence, abstract syntax tree-level code change sequence, number of lines added by code changes, and number of lines deleted by code changes. The abstract syntax tree level is the transformation of code changes into an abstract syntax tree. The change types of the abstract syntax tree nodes include update, deletion, move, insertion, no change, and the abstract syntax tree node sequence is transformed into an abstract syntax tree node sequence in depth-first traversal order. The textual features of the contribution request include: contribution request title, contribution request description body, submitting author, submission information, submitting author's age, submitting author's historical submission count, submitting author's historical submission information, tool execution result, tool execution report, and modified file path name.
Citation Information
Patent Citations
A user comment recommendation method based on a code cloning technology
CN109683946A
Method and device for reviewing codes based on configuration model, and computer equipment
CN110297656A