Software defect positioning method based on context-aware code translation and feature fusion

By constructing the fusion of traditional information retrieval, shallow semantics and deep semantic matching modules, combined with context-aware code translation technology, the problem of insufficient deep mining of source file information in the existing technology is solved, and the accuracy and model of software defect positioning are improved stability.

CN118916263AActive Publication Date: 2024-11-08XIAN SANREN ELECTRONIC TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202410879574.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-02
Publication Date
2024-11-08
Estimated Expiration
2044-07-02

AI Technical Summary

Technical Problem

The existing software defect positioning technology lacks in-depth mining in capturing source file information, resulting in limited positioning accuracy, especially traditional information retrieval methods rely on vocabulary matching to deal with different writing methods of code logic and vocabulary mismatch in natural language texts.

Method used

Using a method based on context-aware code translation and feature fusion, traditional information retrieval, shallow semantic and deep semantic matching modules are constructed. Through the fully connected network correlation characteristics of dense blocks and transition blocks, combined with information retrieval and semantic information, the fusion matching results are combined with Improve the accuracy of defect positioning.

Benefits of technology

Through the supplementation and feature fusion of deep semantic information, the lack of feature representation and information loss of traditional methods are overcome, the accuracy of defect positioning and model stability are improved, and the understanding of source files is enhanced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916263A_ABST
    Figure CN118916263A_ABST
Patent Text Reader

Abstract

The invention discloses a software defect positioning method based on context-aware code translation and feature fusion. The method comprises the following steps: firstly, extracting different types of information retrieval features from a defect report and a source file, and associating different features of information retrieval by utilizing a linear model containing a dense block and a transition block; then constructing a shallow semantic information and defect report matching module of the source file and a deep semantic information and defect report matching module of the source file, converting codes of the source file into natural language description as deep semantics of the source file, and performing semantic matching by utilizing the deep semantics and the defect report; and finally, constructing a fusion module to fuse the results of the modules to obtain a final positioning result. According to the method, the limitation that insufficient features are used for representing the source file in the defect positioning technology at the present stage is overcome, the feature expression ability of the source file is enriched, the model is helped to better understand the source file, and therefore the final prediction accuracy of defect positioning is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of software defect location, and in particular relates to a software defect location method based on context-aware code translation and feature fusion. Background Art

[0002] As technology advances and the demand for software increases, the size and complexity of software is also rising. Software is becoming more and more uncontrollable, and defects in software can cause the software to not run as expected. The development team spends a lot of manpower and time on software maintenance. Defect location is an important part of the software maintenance process. Only after the defects are located can the subsequent repairs and other links be completed. Manual defect location has the following shortcomings: First, it takes a lot of time. A survey pointed out that program debugging and fault location may take up 50% of the developer's working time; second, it depends on the developer's experience and expertise. In order to reduce the cost of maintaining software and reduce the time to solve problems, researchers have proposed automated software defect location technology.

[0003] Among the existing technologies, a mainstream technology can rank source files according to the correlation between source files and defect reports, thereby helping developers automatically find source files that may have defects. This software defect location technology can be roughly divided into two categories. One is defect location based on information retrieval. This method of defect location uses the keyword matching between defect reports and source files. Another type is defect location based on deep learning. This method of defect location encodes defect reports and source files into embedded representations and then calculates the similarity between vectors. Traditional defect location based on information retrieval regards both defect reports and source files as plain text, and the similarity between keywords in the text is the main basis for location. Therefore, there are the following disadvantages in completing defect location in this way: there is a vocabulary mismatch between the natural language text in the defect report and the programming language in the source file; it is sensitive to code changes, and the same code logic can be written in different ways. Different writing methods mean that there are text differences, which affects the accuracy of location. Benefiting from the development of deep learning, researchers have set their sights on deep learning. Defect localization based on deep learning converts the text of defect reports and source files into corresponding vectors using word embedding technology, then inputs the vectors into the deep learning model to obtain vectors representing their respective semantics, and finally calculates the similarity between the vectors. Compared with traditional information retrieval, the biggest advantage of deep learning is that it can capture semantic information through the model. Recent work has also proved that deep learning technology can effectively improve the accuracy of defect localization. These works try various methods to capture the semantics of defect reports and source files as much as possible.

[0004] Although deep learning models are superior to traditional methods in obtaining the semantics of defect reports and source files, most of the current related work focuses on information at the text level of source files. For example, the inventor’s previous patent CN202310441116.8, although its defect positioning is reasonable and can solve the problem of vocabulary mismatch between defect reports and source files, it still lacks deeper mining of source file information, which results in the performance of the model still being limited. Summary of the invention

[0005] The purpose of the present invention is to address the deficiencies in the prior art and propose a software defect localization method based on context-aware code translation and feature fusion. The method requires the construction of an information retrieval feature and defect report matching module, a source file text (called the shallow semantics of the source file) and a defect report matching module, and a natural language description of the code in the source file (called the deep semantics of the source file) and a defect report matching module. Finally, the matching results of the three modules are integrated to improve the accuracy of defect localization.

[0006] In a first aspect, the present invention provides a software defect localization method based on context-aware code translation and feature fusion, which specifically comprises the following steps:

[0007] Step 1: Get the defect report and source file;

[0008] Step 2: Build a traditional information retrieval and defect report matching module:

[0009] Step 2.1, based on the professional knowledge in the field of software engineering, extract the traditional information retrieval features of the defect report and source file in step 1, wherein the features include rVSM (Vector Space Model) score, collaborative filtering score, stack trace score, cyclomatic complexity, defect repair recency, and defect repair frequency;

[0010] Step 2.2, input the traditional information retrieval features obtained in step 2.1 into the fully connected network DenseNet to obtain the matching score wide_score between the source file and the defect report at the traditional information retrieval level; the fully connected network DenseNet includes a dense block and a transition block, the dense block is composed of multiple layers, the output dimension of each layer is the same, and in the forward propagation, the output of each layer is used as the input of the subsequent layer; the transition block is used to control the complexity of the model;

[0011] Step 3: Build a shallow semantic information and defect report matching module for source files

[0012] Step 3.1: Get summary and description information from the defect report, and get program information and snippets information from the source file. The program information includes four types of structural information: class name, method name, attribute name, and local variable name. The snippets information is the various snippets divided after the text preprocessing of the source file.

[0013] Preferably, the preprocessing includes text normalization, stop word removal and stemming.

[0014] Step 3.2, match the summary and description of the defect report with the program information and snippet information of the source file in pairs, and calculate the matching scores of summary-program information (summary_infos), summary-snippet information (summary_snps), description-program information (desc_infos), and description-snippet information (desc_snps), which are used as the shallow semantic score shallow_semantic;

[0015] Step 4: Build deep semantic information of source files and defect report matching module

[0016] Step 4.1: Use a compiler and a decompiler to convert the text in the source file into a sequence of code instructions;

[0017] Step 4.2: Use context-aware code translation technology to translate the instruction sequence into a natural language description, which is the deep semantic information of the source file (s trans );

[0018] Specifically, step 4.2 includes the following process:

[0019] Step 4.2.1, construct translation rules, and then divide the instruction sequence into four categories according to the interaction between the instruction sequence and the local variable array or operand stack:

[0020] Instructions that interact only with the operand stack, instructions that interact only with the local variable array, instructions that interact with both the operand stack and the local variable array, instructions that interact with neither the operand stack nor the local variable array;

[0021] Step 4.2.2, statically traverse the instruction sequence from top to bottom:

[0022] Starting from the entry point of the code, each instruction is traversed statically step by step downward to simulate the execution process of the instruction; during the traversal process, each instruction is converted into the corresponding translation result according to the constructed translation rules;

[0023] Step 4.2.3, during the traversal process, different context information is collected according to the category to which each instruction belongs; the context information includes constants, local variables, and data and control dependencies with other instructions; the collected context information is used to update the translation rules of the current or other related instructions;

[0024] Step 4.2.4: After traversing all instructions, the conversion result generated by the instruction sequence is obtained. This conversion result can reflect the deep semantic information of the source code.

[0025] Step 4.3, after matching the summary and description of the defect report in step 3.1 with the deep semantic information of the source file, two matching scores, summary-instruction information (summary_trans) and description-instruction information (desc_trans), are calculated as the deep semantic score deep_semantic;

[0026] Step 5: Fusion matching module results:

[0027] Step 5.1, concatenate shallow_semantic and deep_semantic, and put the concatenated result into the fully connected layer to obtain the total semantic score semantic_score;

[0028] Step 5.2: The total semantic score semantic_score obtained in step 5.1 is combined with the matching score wide_score of the source file and the bug report at the traditional information retrieval level obtained in step 2.2 to obtain the final similarity score between the bug report and the source file;

[0029] Step 6: Sort the source files in descending order according to the final similarity scores, and then recommend the sorted source file list to the developer to assist in defect location.

[0030] In a second aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the above method.

[0031] Compared with the prior art, the present invention has the following beneficial effects:

[0032] 1. Most of the current defect location technologies focus on the information at the source file text level, lacking deeper mining of source file information, which results in the performance of the model being limited. In contrast, the present invention uses context-aware code translation technology to translate the instruction sequence of the source file into a natural language description as a supplement to the semantic information of the source file, thus overcoming the limitation of the current defect location technology that uses insufficient features to represent the source file.

[0033] 2. A linear model consisting of dense blocks and transition blocks is used to associate different features of information retrieval. The output of each layer is connected to the subsequent layer. This allows the low-level features in the network to be directly passed to higher layers, thus avoiding feature loss and information bottleneck problems. This feature reuse helps to enhance the propagation of gradients and improve the stability of the model.

[0034] 3. The present invention takes into account both the traditional information retrieval features of the source file and the semantic features of the source file. These two features complement each other, and the fusion of these two features enriches the feature expression ability of the source file, helps the model to better understand the source file, and thus improves the accuracy of the final prediction of defect location. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 The flowchart of the software defect localization method based on context-aware code translation and feature fusion is shown;

[0036] Figure 2 This is a dense block structure diagram of the present invention;

[0037] Figure 3 This is the architecture diagram of the fully connected network DenseNet of the present invention;

[0038] Figure 4 Matching module architecture diagrams for shallow semantic information of source files and defect reports;

[0039] Figure 5 Classify the results for the instructions;

[0040] Figure 6 Flowchart of instruction translation algorithm;

[0041] Figure 7 Matching module architecture diagrams for deep semantic information of source files and defect reports. DETAILED DESCRIPTION

[0042] The present invention will be further explained below with reference to the accompanying drawings;

[0043] like Figure 1 As shown, a software defect localization method based on context-aware code translation and feature fusion takes defect reports and as input. Specifically, it includes the following steps:

[0044] Step 1: Get the defect report and source file;

[0045] Step 2: Build a traditional information retrieval and defect report matching module

[0046] Step 2.1: Based on the domain knowledge in software engineering, extract six types of features: rVSM score, collaborative filtering score, stack trace score, cyclomatic complexity, defect repair recency, and defect repair frequency. The calculation process of their corresponding scores is as follows:

[0047] rVSM score

[0048] The rVSM score represents bug reports and source files as vectors of term weights. The weight w of each term t in document d is i Calculated based on term frequency (TF) and inverse document frequency (IDF), the calculation formula is as follows

[0049]

[0050] In the formula, f t,d represents the number of times word t appears in document d, #docs refers to the total number of documents in the corpus, d t is the total number of documents containing word t. After obtaining the weight of each word, we can use the following formula to express the vector corresponding to document d.

[0051]

[0052] Cosine similarity is used to measure the similarity score between the bug report r and the source file s.

[0053]

[0054] We also need to combine the length score of the source file with the result of cosine similarity. The following formula is used to calculate the length score of the source file:

[0055]

[0056] The #term represents the number of words in each source file, which is input into the normalization function Nor(x). Assume that there is an array A = {a1, a2, …, a n}, the minimum and maximum values ​​in array A are a mi n and a max , the normalization function Nor(x) is as follows:

[0057]

[0058] Finally, the rVSM scores of defect report r and source file s are as follows:

[0059] rVSM(r,s)=cos(r,s)*lengthScore(#term) (6)

[0060] Collaborative filtering score

[0061] Given a current bug report r and a source file s, before(r,s) represents the set of bug reports before r and related to s. The collaborative filtering score cf(r,s) calculates the text similarity between the text of r and the summaries of all bug reports in before(r,s), and the formula is as follows:

[0062] cf(r,s)=cos(r,before,s)) (7)

[0063] Cyclomatic complexity

[0064] Cyclomatic complexity measures the complexity of code. In this work, cyclomatic complexity cc(s) is calculated using the lizard tool. The calculation formula is as follows:

[0065] cc(s)=E-N+2 (8)

[0066] Where E and N represent the number of edges and nodes in CFG respectively.

[0067] Stack trace

[0068] Some bug reports record stack trace information of code execution errors, which is used in this work. We use regular expressions to extract valid stack information and use the following formula to get the score st(r,s) related to the stack trace:

[0069]

[0070] The most recent time the bug was fixed

[0071] last(r,s) represents the most recently repaired defect and last(r,s)∈before(r,s). The following formula is used to obtain the time-related score fr(r,s) of the most recent defect repair:

[0072]

[0073] Where r.month represents the month when defect report r was generated, and s.month represents the month when source file s was last fixed before defect report r was created.

[0074] Frequency of bug fixes

[0075] Because frequently modified source files are more likely to contain defects, the defect repair frequency is used in this work. We use the following formula to express the defect repair frequency ff(r,s):

[0076] ff(r,s)=|before(r,s)| (11)

[0077] Step 2.2: After obtaining the six software-specific information retrieval feature scores, we concatenate them to get the input vector and input it into the fully connected network DenseNet. The output result of the fully connected network DenseNet is the matching score wide_score between the source file and the defect report at the traditional information retrieval level.

[0078] IR_features(r,s)=[rVSM(r,s); cf(r,s); cc(s); st(r,s); fr(r,s); ff(r,s)] (12)

[0079] wide_score=DenseNet(IR_features(r,s)) (13)

[0080] The six features are combined in the network using dense blocks and transition blocks. A dense block consists of multiple layers, and each layer uses a consistent number of output sizes (the output dimension of each layer is the same), f(x i ) represents the i-th layer, x i is the input of the i-th layer. In the forward propagation, the output of each layer is used as the input of the subsequent layer. Therefore, for the n-th layer, its input is as follows, and the architecture of the dense block is as follows Figure 2 shown.

[0081] x n =f(x n-1 )+x n-1 (14)

[0082] Each layer implements a linear transformation and activation function as shown in Formula 15.

[0083] f n (x n )=ReLu(FC(x n )) (15)

[0084] Each dense block will increase the output size. Suppose a dense block with 10 layers and an output size of 2 for each layer is defined. When the input size of the dense block is 2, the final output size is 2+2*10=22. Therefore, using too many dense blocks will make the model complicated, so the transition block is introduced to control the complexity of the model. The transition block is represented by TransitionBlock(x), where x represents the input of the transition block. The transition block consists of a fully connected layer and a ReLu layer, as shown in Formula 16.

[0085] TransitionBlock(x)=ReLu(FC(x)) (16)

[0086] The overall architecture of the fully connected network DenseNet used is as follows Figure 3 As shown; the fully connected network DenseNet includes dense blocks and transition blocks connected in sequence, and the number of the dense blocks and the transition blocks is equal. In this embodiment, the fully connected network DenseNet includes 3 dense blocks and 3 transition blocks.

[0087] Step 3: Build a shallow semantic information and defect report matching module for source files.

[0088] Step 3.1, for the defect report, the content of its summary and description part is used; for the source file, the entire content including code and comments is used. This application also considers the structured information of the source file in the work. The four types of structured program information in the source file, namely class name, method name, attribute name and local variable, are obtained by AST parsing. In the data preprocessing stage, all texts are divided into words, and then the words are filtered. In this operation, punctuation marks, numbers, stop words and keywords in the programming language are filtered out. It should be noted that there are compound words with specific meanings in the word sequence, such as getMax. In the process of data preprocessing, such compound words will be split into forms such as 'get' and 'max', and the original words will be retained. Each source file will be split into fragments of the same size. Before entering the model, the words will be converted into vectors. In this work, the word2vec model with skip-gram is used to convert words into vectors.

[0089] Step 3.2: In this step, four combinations of scores are obtained. These four groups are summary and program information, summary and snippet information, description and program information, and description and snippet information. Their scores are represented by summary_infos, summary_snps, decs_infos, and desc_snps, respectively. The specific architecture of the shallow semantic information and defect report matching module is as follows: Figure 4 As shown in the figure, we take the example of matching the summary of the defect report with the program information and snippet of the source file. The word embeddings in the program information and snippet information are average-pooled to obtain their respective vector representations. are vector representations of class names, method names, attribute names, and local variable names in the code, respectively. is the vector representation of n fragments of the source file, are the vector representations of the bug report summary and description, respectively.

[0090] For the combination of summary and program information, we need to make the model pay more attention to helpful program information, so we introduce the attention mechanism. We use the following formula to achieve this goal.

[0091]

[0092] in is the scaled point score of each program information relative to the summary, is the vector obtained by weighting all program information based on the scaled click score. The program information-aware bug report summary encoding is calculated by the following equation, and finally the fully connected layer calculates the matching score between the summary and the program information.

[0093]

[0094] For the combination of summary and fragment information, we choose TextCNN as the extraction of text features. It is input into TextCNN, and k convolution kernels are set to capture different n-gram features in the text. After convolution and pooling, the feature vector corresponding to each convolution kernel is output. Finally, the feature vector corresponding to each convolution kernel is Splice them together, the spliced ​​vector The vector representing the fragment is the vector output by TextCNN. We calculate the vector With vector The cosine similarity of is used to obtain the matching score between the summary and the fragment information.

[0095]

[0096] The calculation method for the combination of description and program information is the same as the calculation method for the combination of summary and program information, and the calculation method for the combination of description and fragment information is the same as the calculation method for the combination of summary and fragment information. Finally, the scores of the four combinations are obtained, namely the shallow semantic score shallow_sematic.

[0097] shallow_sematic=[summary_infos; summary_snps; desc_infos; desc_snps] (24)

[0098] Step 4: Build the deep semantic information of the source file and the defect report matching module.

[0099] Step 4.1: The deep semantic information of the source file is described in natural language extracted from the source file code. The natural language description is obtained through context-aware code translation technology. Context-aware code translation technology consists of translation rules and translation algorithms. Because code translation technology needs to be applied to the machine instructions of the code, the machine instructions need to be obtained first. For some codes, the program compiler cannot get the instructions of the entire code because the necessary dependency libraries need to be introduced before the code can be compiled. However, we need to use different versions of code in defect location. If the corresponding dependency libraries are introduced for each version of the code, the work will become complicated. The JCoffee tool is a static program analysis tool. It can supplement the missing classes, functions, and definitions for the code snippet according to the error information fed back by the compiler during the iteration process, so that the code snippet can pass the compilation. We first use the Spoon tool to extract the function snippet from the source file code, and then use the JCoffee tool to perform static analysis on the function snippet. The function snippet after static analysis uses the compiler and decompiler to obtain the instruction sequence of the function snippet.

[0100] Step 4.2: The translation rules in the code translation technology are manually constructed based on the instruction specifications. In order to make the natural language of the instructions brief and accurate, the context-aware code translation technology manually organizes the corresponding translation for each instruction. The basic idea of ​​the translation algorithm is to simulate the execution of instructions by statically traversing the instruction sequence from top to bottom. Based on the specific role of each instruction, the code translation technology divides the instructions into four categories according to whether the instructions interact with the local variable array or the operand stack. These four categories are instructions that only interact with the operand stack, instructions that only interact with the local variable array, instructions that interact with both the operand stack and the local variable array, and instructions that do not interact with either the operand stack or the local variable array. During the traversal process, the algorithm first converts each instruction sequence into the corresponding translation result according to the translation rules. Then extract the operands in each instruction, which are used to update the placeholders of the translation results in the subsequent process. Next, according to the above-mentioned instruction classification, different processing is performed on the operands and placeholders. After traversing all the instructions, the algorithm outputs the final natural language description.

[0101] Step 4.2 includes the following process:

[0102] Step 4.2.1, construct translation rules:

[0103] The JAVA virtual machine specification describes in detail how instructions interact with local variables and the operand stack. Based on this, the context-aware code translation technology manually constructs a short and accurate description for each instruction. For example, the instruction "istore_2" is translated into "store int [ps] into local variable [pv]". The [ps] and [pv] in the description represent placeholders, which will be filled in the subsequent context traversal.

[0104] Step 4.2.2, instruction translation:

[0105] First, the instructions are divided into four categories according to whether they interact with the local variable array or the operand stack, namely: instructions that only interact with the operand stack Instructions that interact only with local variable arrays Instructions that interact with both the operand stack and the local variable array Instructions that do not interact with either the operand stack or the local variable array The classification results are as follows Figure 5 shown.

[0106] Starting from the entry point of the code, it traverses each instruction step by step and simulates the execution process of the instruction. During the traversal, different context information is collected according to the category of each instruction. The context consists of constants, local variables, and data and control dependencies with other instructions. These contexts will be used to update the short description of the current or other related instructions. The process of instruction translation is as follows: Figure 6 shown.

[0107] Step 4.2.3: After traversing all instructions, the conversion result generated by the instruction sequence is obtained. This conversion result can reflect the deep semantic information of the source code.

[0108] Step 4.3: We use the data preprocessing method described in step 3.1 to obtain the preprocessed natural language description. In this step, we can obtain two combinations of scores, namely summary and natural language description and description and natural language description. Their scores are represented by summary_trans,desc_trans. The specific architecture of the deep semantic information and defect report matching module is as follows: Figure 7 As shown in the figure, this example is based on the matching of the summary of the defect report and the natural language description of the source file. The score calculation method for these two combinations is the same as the calculation method of description and fragment information and summary and fragment information in step 2.2. Finally, the score of the two combinations of deep semantic information of the source file and the defect report matching module is obtained, that is, the deep semantic score deep_semantic.

[0109] deep_semantic=[summary_trans;desc_trans] (25)

[0110] Step 5: Fusion the results of the above three matching modules

[0111] Step 5.1, concatenate shallow_semantic and deep_semantic, and put the concatenated result into the fully connected layer to get the total semantic score semantic_score, the formula is as follows:

[0112] semantic_score=FC([shallow_semantic; deep_semantic]) (26)

[0113] Step 5.2: The semantic score in step 5.1 is finally fused with the wide score obtained in step 2.2. The final similarity score fusion_score (r, s) between the defect report r and the source file s is calculated using the following formula.

[0114] fusion_score=FC([wide_score; semantic_score]) (27)

[0115] Step 6: Defect localization can be considered as a sorting problem, that is, calculating the similarity score between the defect report and the source file, and then sorting the source files in descending order according to the score. The higher the ranking of the source file, the greater the possibility that it contains defects. Therefore, the hinge loss function is used to train the model. The formula of the loss function is as follows:

[0116] (r,s + ,s - ,θ)=max(0,1-fusion_score(r,s + )+fusion_score(r,s - )) (28)

[0117] Where θ is all the parameters in the model, s + Represents the source file associated with the defect report, s - represents source files that are not relevant to the defect report.

Claims

1. A software defect localization method based on context-aware code translation and feature fusion, comprising the following steps: Step 1: Get the defect report and source file; Step 2: Build a traditional information retrieval and defect report matching module: Step 2.1, based on the professional knowledge in the field of software engineering, extract the traditional information retrieval features of the defect report and source file in step 1, wherein the features include rVSM score, collaborative filtering score, stack trace score, cyclomatic complexity, defect repair recency, and defect repair frequency; Step 2.2: Input the traditional information retrieval features obtained in step 2.1 into the fully connected network DenseNet to obtain the matching score wide_score between the source file and the defect report at the traditional information retrieval level; Characterized in that the method further comprises the following steps: Step 3: Build the shallow semantic information of the source file and the defect report matching module: Step 3.1, obtain summary information and description information from the defect report in step 1, and obtain program information and fragment information from the source file in step 1; Step 3.2, match the summary information and description information of the defect report with the program information and fragment information of the source file in pairs, and calculate the four matching scores of summary-program information, summary-fragment information, description-program information, and description-fragment information as the shallow semantic score shallow_semantic; Step 4: Build the deep semantic information of source files and the defect report matching module: Step 4.1, using a compiler and a decompiler to convert the text in the source file in step 1 into a code instruction sequence; Step 4.2: Use context-aware code translation technology to translate the instruction sequence into a natural language description, where the natural language description is the deep semantic information of the source file; Step 4.3, match the summary information and description information of the defect report in step 3.1 with the natural language description of the source file, and calculate two matching scores of summary-instruction information and description-instruction information as the deep semantic score deep_semantic; Step 5: Fusion matching module results: Step 5.1, concatenate shallow_semantic and deep_semantic, and put the concatenated result into the fully connected layer to obtain the total semantic score semantic_score; Step 5.2, the total semantic score semantic_score obtained in step 5.1, the matching score of the defect report obtained in step 2.2, and the matching score wide_score in the traditional information retrieval and defect report matching module are merged to obtain the final similarity score between the defect report and the source file; Step 6: Sort the source files in descending order according to the final similarity scores, and then recommend the sorted source file list to the developer to assist in defect location.

2. According to claim 1, a method for locating software defects based on context-aware code translation and feature fusion, characterized in that: The fully connected network DenseNet includes an input layer, N dense blocks, N transition blocks and an output layer, N is a positive integer, and the dense blocks and the transition blocks are set at intervals.

3. According to claim 2, a method for locating software defects based on context-aware code translation and feature fusion, characterized in that: The input layer concatenates the traditional information retrieval features obtained in step 2.1 to obtain an input vector, which is then input into the first dense block: IR_features(r, s)=[rVSM(r, s); cf(r, s); cc(s); st(r, s); fr(r, s); ff(r, s)] (1) Where r is a defect report, s is a source file, rVSMScore(r, s), cfScore(r, s), stScore(r, s), ccScore(r, s), bfrScore(r, s), and bffScore(r, s) represent the VSM similarity, collaborative filtering score, stack trace score, cyclomatic complexity, defect repair recency, and defect repair frequency of the defect report and source file, respectively; The output of each dense block is processed by a transition block and then used as the input of the next dense block; The output layer outputs the data of the last dense block after being processed by a transition block as the matching score wide_score between the source file and the defect report at the traditional information retrieval level; wide_score=DenseNet(IR_features(r, s)) (2).

4. According to claim 3, a method for locating software defects based on context-aware code translation and feature fusion, characterized in that: Each of the dense blocks contains multiple layers, where the input of the i-th layer is as follows: x i =f(x i-1 )+x i-1 (3) where x i is the input of the i-th layer, x i-1 is the input of the i-1th layer, f(x i-1 ) is the output of the i-1th layer; Each layer implements a linear transformation and activation function: f i ( x i )=ReLu(FC(x i )) (4) The transition block consists of a fully connected layer and a ReLu layer, and its formula is as follows: TransitionBlock(x)=ReLu(FC(x)) (5) Where x is the input of the transition block.

5. According to claim 1, a method for locating software defects based on context-aware code translation and feature fusion, characterized in that: Step 4.2 includes the following steps: Step 4.2.1, construct translation rules, and then divide the instruction sequence into four categories according to the interaction between the instruction sequence and the local variable array or operand stack: Instructions that interact only with the operand stack, instructions that interact only with the local variable array, instructions that interact with both the operand stack and the local variable array, instructions that interact with neither the operand stack nor the local variable array; Step 4.2.2, statically traverse the instruction sequence from top to bottom: Starting from the entry point of the code, each instruction is traversed statically step by step downward to simulate the execution process of the instruction; during the traversal process, each instruction is converted into the corresponding translation result according to the constructed translation rules; Step 4.2.3, during the traversal process, different context information is collected according to the category to which each instruction belongs; the context information includes constants, local variables, and data and control dependencies with other instructions; the collected context information is used to update the translation rules of the current or other related instructions; Step 4.2.4: After traversing all instructions, the conversion result generated by the instruction sequence is obtained, and the conversion result is the deep semantic information of the source file.

6. The method for locating software defects based on context-aware code translation and feature fusion according to claim 1, characterized in that: Step 4.3 is as follows: summary_trans is used to represent summary-command information, and desc_trans is used to represent description-command information; For summary_trans, select TextCNN as the text feature extraction; is the vector representation of the n natural language description fragments of the source file obtained in step 4.2, is a vector representation of the summary of the bug report; It is input into TextCNN, and k convolution kernels are set to capture different n-gram features in the text. After convolution and pooling, the feature vector corresponding to each convolution kernel is output; finally, the feature vector corresponding to each convolution kernel is Splice them together, the spliced ​​vector The vector representing the fragment is the vector output by TextCNN, and the vector is calculated With vector The cosine similarity of gets the matching score between the summary and the fragment information: desc_trans is calculated in the same way as summary_trans; Finally, we get the deep semantic information of the source file and the scores of the two combinations in the defect report matching module. The combination deep_semantic represents the deep semantics of the source file. deep_semantic=[summary_trans;desc_trans] (9).

7. The method for locating software defects based on context-aware code translation and feature fusion according to claim 1, characterized in that: In step 5.1, the following formula is used for splicing: semantic_score=FC([shallow_semantic; deep_semantic]) (10) Among them, semantic_score is the total semantic score, and FC is the fully connected layer.

8. The method for locating software defects based on context-aware code translation and feature fusion according to claim 1, characterized in that: Step 5.2 uses the following formula: fusion_score(r, s)=FC([wide_score; semantic_score])(11) Where fusion_score(r, s) is the final similarity score, r is the defect report, s is the source file, and FC is the fully connected layer.

9. The method for locating software defects based on context-aware code translation and feature fusion according to claim 1, characterized in that: In step 6, the hinge loss function is used to train the model. The formula of the hinge loss function is as follows: Where θ is all the parameters in the model, r is the defect report, s is the source file, and s + Represents the source file associated with the defect report, s - Represents source files that are not relevant to the defect report.

10. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Software defect positioning method based on similarity integration

    CN112000802A

  • Software defect positioning method based on feature crossing and structural semantic information matching

    CN117851216A

  • Method, electronic device, and computer program product for code defect detection

    US20230128681A1