Software defect prediction method, system, equipment and medium

By converting the software source code into an abstract syntax tree and combining the information of the class-dependent network, the graph node attribute features are generated, which solves the problem of insufficient comprehensive and accurate defect prediction in the existing technology, and improves the accuracy and recognition ability of defect prediction.

CN119149051AInactive Publication Date: 2024-12-17GUANGDONG UNIV OF PETROCHEMICAL TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411621261.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-14
Publication Date
2024-12-17
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing software defect prediction methods are based on a single view, and cannot fully utilize the complementary information between each view, resulting in insufficient comprehensive and accurate defect prediction, and fail to fully utilize the attribute information in the class-dependent network, affecting the accuracy of the prediction model.

Method used

Convert the software source code into an abstract syntax tree, use the master node-first traversal algorithm and convolutional neural network to generate syntax tree features, and build a class-dependent network for embedding, combine code metrics to generate enhanced features, and finally defect through the graph node attribute features predict.

Benefits of technology

By integrating abstract syntax trees, traditional code metrics and class-dependent network information, high-quality graph node attribute features are built, which improves the accuracy and recognition ability of defect prediction and captures more comprehensive code semantics and structural information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149051A_ABST
    Figure CN119149051A_ABST
Patent Text Reader

Abstract

The invention discloses a software defect prediction method, system and device and a medium, and the method comprises the steps: converting a software source code into an abstract syntax tree, processing the abstract syntax tree based on a main node priority traversal algorithm and a convolutional neural network, and generating syntax tree features; establishing a class dependency network according to the dependency relationship in the source code, and embedding the class dependency network by using a graph embedding algorithm to obtain a network embedding vector; then splicing the code metric of the source code with the network embedding vector to generate an enhanced feature; combining the syntax tree features with the enhanced features to obtain graph node attribute features; and finally, performing defect prediction based on the graph node attribute characteristics. According to the method, various view information features are fused, and the accuracy of defect prediction and the defect recognition capability can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of defect prediction in software engineering, and in particular to a software defect prediction method, system, device and medium. Background Art

[0002] Software Defect Prediction (SDP) is dedicated to assisting the testing team in revealing software problems that have not yet been identified. The purpose is to identify the software components that are most likely to contain defects in the early stages of the software development process, and then focus on and prioritize testing these components, thereby assisting the development and testing teams to more effectively fix these defects. The process of software defect prediction usually includes steps such as data collection, data preprocessing, feature selection, model building, model evaluation, and model application.

[0003] Currently, existing software defect prediction methods usually perform feature selection based on a single-view method. However, the prediction model constructed based on the feature data obtained by the single-view method cannot fully utilize the complementary information between the views, resulting in the defect prediction not being more comprehensive and accurate. At the same time, the existing software defect prediction methods ignore more attribute information on each node in the class dependency network when constructing the prediction model. Failure to fully utilize these attributes will result in the prediction model's insufficient representation of code features, thereby affecting the accuracy of defect prediction. Summary of the invention

[0004] The technical problem to be solved by the present invention is to provide a software defect prediction method, system, device and medium, which can improve the accuracy of software defect prediction.

[0005] To solve the above technical problems, an embodiment of the present invention provides a software defect prediction method, comprising: Converting the software source code into an abstract syntax tree, and processing the abstract syntax tree based on a main node-first traversal algorithm and a convolutional neural network to generate syntax tree features; Constructing a class dependency network according to the dependency relationship in the source code, and embedding the class dependency network using a graph embedding algorithm to obtain a network embedding vector; concatenating the code metrics of the source code with the network embedding vector to generate enhanced features; Combining the syntax tree feature with the enhanced feature to obtain a graph node attribute feature; Defect prediction is performed based on the graph node attribute features.

[0006] As an improvement of the above solution, the main node priority based traversal algorithm and convolutional neural network process the abstract syntax tree to generate syntax tree features, including: Extracting the abstract syntax tree based on a main node-first traversal algorithm to obtain a target node sequence; Convert the target node sequence into a word embedding vector; The word embedding vector is processed using a convolutional neural network to generate a grammatical tree feature.

[0007] As an improvement of the above solution, the main node priority-based traversal algorithm extracts the abstract syntax tree to obtain a target node sequence, including: Starting from the root node of the abstract syntax tree, determine whether the node is a target node one by one; If so, add it to the target node sequence; If not, each child node is traversed according to the subtree size of each node's child nodes to return a target node sequence that meets the requirements.

[0008] As an improvement of the above solution, the word embedding vector is processed using a convolutional neural network to generate a syntax tree feature, including: Using a convolutional layer of a convolutional neural network to perform a convolution operation on the word embedding vector to extract convolution features; Pooling the convolutional features through a pooling layer of the convolutional neural network; The pooled features are transformed through the fully connected layer of the convolutional neural network to generate syntax tree features.

[0009] As an improvement of the above solution, the syntax tree feature and the enhanced feature are combined in a manner including at least one of adding, multiplying or concatenating elements of the features.

[0010] As an improvement of the above solution, after generating the enhancement feature, the method further includes: The principal component analysis dimensionality reduction method is used to reduce the dimension of the enhanced features to obtain low-dimensional features.

[0011] As an improvement of the above solution, the defect prediction based on the graph node attribute features includes: Using the graph node attribute features as input to a deep learning model to output defect prediction results; Calculate the loss function according to the prediction result, optimize and train the deep learning model with the goal of minimizing the loss function, and obtain a trained software defect prediction model; Software defect prediction is performed through the trained software defect prediction model.

[0012] To solve the above technical problems, an embodiment of the present invention further provides a software defect prediction system, including: A first feature generation module is used to convert the software source code into an abstract syntax tree, and process the abstract syntax tree based on a main node priority traversal algorithm and a convolutional neural network to generate syntax tree features; A network embedding vector generation module, used to construct a class dependency network according to the dependency relationship in the source code, and embed the class dependency network using a graph embedding algorithm to obtain a network embedding vector; A second feature generation module, configured to concatenate the code metrics of the source code with the network embedding vector to generate an enhanced feature; A third feature generation module, used to combine the syntax tree feature with the enhanced feature to obtain a graph node attribute feature; A defect prediction module is used to perform defect prediction based on the graph node attribute features.

[0013] To solve the above technical problems, an embodiment of the present invention further provides a terminal device, comprising: a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor implements the software defect prediction method as described in any one of the above when executing the computer program.

[0014] To solve the above technical problems, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute any one of the software defect prediction methods described above.

[0015] The embodiments of the present invention provide a software defect prediction method, system, device and medium. The method converts software source code into an abstract syntax tree, processes the abstract syntax tree based on a main node priority traversal algorithm and a convolutional neural network to generate syntax tree features; and constructs a class dependency network according to the dependency relationship in the source code, and embeds the class dependency network using a graph embedding algorithm to obtain a network embedding vector; then concatenates the code metrics of the source code with the network embedding vector to generate enhanced features; then combines the syntax tree features with the enhanced features to obtain graph node attribute features; and finally, performs defect prediction based on the graph node attribute features. The present invention firstly captures syntax tree features through a main node priority traversal algorithm and a convolutional neural network, and can extract deep and defect-related features from the source code; secondly, by embedding the features extracted from the traditional code metrics in the class dependency network, the attribute information of each node is enriched, and the quality of the features is further improved; finally, by fusing the three view information features of the abstract syntax tree, the traditional code metrics and the class dependency network, a high-quality graph node attribute feature is constructed, and based on this feature representation, a software defect prediction model is trained and optimized, which can capture more comprehensive code semantics and structural information, learn a more comprehensive feature representation, and thus improve the accuracy of defect prediction and defect recognition capabilities. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solution of the present invention, the drawings used in the implementation mode will be briefly introduced below. Obviously, the drawings described below are only some implementation modes of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0017] Figure 1 is a flowchart of a software defect prediction method provided by an embodiment of the present invention; Figure 2 It is a flow chart of generating syntax tree features of a software defect prediction method provided by an embodiment of the present invention; Figure 3 is a schematic diagram of a network structure used in a software defect prediction method provided by an embodiment of the present invention; Figure 4 is a structural block diagram of a software defect prediction system provided by an embodiment of the present invention; Figure 5 It is a structural block diagram of a terminal device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0018] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0019] See also Figure 1 , is a flowchart of a software defect prediction method provided by an embodiment of the present invention, the method comprising steps S1 to S5: S1. Convert the software source code into an abstract syntax tree, and process the abstract syntax tree based on a main node priority traversal algorithm and a convolutional neural network to generate syntax tree features; It should be noted that the Abstract Syntax Tree (AST) is a data structure used to represent the syntax structure of source code. By analyzing the source code and building the AST, complex code logic can be converted into a structured model, making the understanding and analysis of the code clearer. Each node of the abstract syntax tree represents a syntax structure of the source code, such as a function, variable, conditional statement, etc.

[0020] Specifically, the main node priority based traversal algorithm and convolutional neural network process the abstract syntax tree to generate syntax tree features, including: Extracting the abstract syntax tree based on a main node-first traversal algorithm to obtain a target node sequence; Convert the target node sequence into a word embedding vector; The word embedding vector is processed using a convolutional neural network to generate a grammatical tree feature.

[0021] Specifically, the main node-first traversal algorithm extracts the abstract syntax tree to obtain a target node sequence, including: Starting from the root node of the abstract syntax tree, determining whether a node is a target node one by one; If so, add it to the target node sequence; If not, each child node is traversed according to the subtree size of each node's child nodes to send back a target node sequence that meets the requirements.

[0022] It is worth noting that, in order to improve the performance of the defect prediction model, the embodiment of the present invention constructs the source code as an abstract syntax tree to extract features. In order to extract the node sequence containing important semantic information (i.e., the target node sequence) from the abstract syntax tree, the embodiment of the present invention proposes a traversal algorithm based on primary node priority (Primary Node Priority Traversal Algorithm), and the method is referred to as the PNPT algorithm.

[0023] More specifically, for the PNPT algorithm, in one implementation, the specific steps are as follows: Step 1: Initialize the token sequence (tokenSequence) to an empty list; Step 2: Initialize the stack and push the root node of the AST into the stack; Step 3: When the stack is not empty, do the following: Step 3.1: First pop the stack node; Step 3.2: Determine whether the node is a target node (i.e., whether it contains important semantic information). If it is a target node (true), add the node's token to the token sequence (tokenSequence). If it is not a target node (false), skip this step (3.2); Step 3.3: Initialize the subtree size list (childSizes) to an empty list; Step 3.4: Loop through each child node of the node, calculate the subtree size of the child node, and add it to the subtree size list (childSizes); Step 3.5: Sort the subtrees in descending order (from large to small) according to their size; Step 3.6: Push the sorted child nodes (from largest to smallest) into the stack in sequence; Step 3.7: After step 3.6, the maximum length (MaxSize) of the token sequence (tokensequence) is determined. If it exceeds the maximum length (MaxSize), the entire loop of step 3 is jumped out. If it does not exceed the maximum length (MaxSize), continue to execute step 3; Step 4: Return the generated token sequence (tokenSequence).

[0024] It is worth noting that, compared with the traditional depth first search (DFS) algorithm, the master node first traversal algorithm provided by the embodiment of the present invention has the following advantages: (1) The DFS algorithm traverses nodes in a fixed order, which may cause important nodes to be truncated and lost. The main node priority traversal algorithm introduces the concept of the main node. During the traversal process, the algorithm calculates the size of the subtree and prioritizes the node with the largest subtree. This ensures that as much important semantic information as possible is retained in the generated token sequence, reducing the possibility of information loss.

[0025] (2) When processing complex ASTs, the DFS algorithm cannot dynamically adjust according to the importance of the nodes. The main node priority traversal algorithm can dynamically adjust the traversal order according to the size of the subtree, flexibly adapt to code structures of different complexities, and ensure that key nodes are processed first.

[0026] (3) The master node priority traversal algorithm significantly reduces the information loss caused by sequence length limitation through the master node priority strategy, thereby improving the quality and representativeness of the generated sequence.

[0027] (4) For token sequences that exceed the maximum length, the main node priority traversal algorithm can intelligently prioritize the retention of key nodes, thereby avoiding the loss of important information due to truncation.

[0028] In one implementation, the processing of the word embedding vector using a convolutional neural network to generate a syntax tree feature includes: Using a convolutional layer of a convolutional neural network to perform a convolution operation on the word embedding vector to extract convolution features; Pooling the convolutional features through a pooling layer of the convolutional neural network; The pooled features are transformed through the fully connected layer of the convolutional neural network to generate syntax tree features.

[0029] S2. constructing a dependency network according to the dependency relationship in the source code, and embedding the class dependency network using a graph embedding algorithm to obtain a network embedding vector; Preferably, the dependency relationship includes at least one of inheritance or interface implementation, aggregation and method parameters.

[0030] It should be noted that in the field of software engineering, especially in the research of software defect prediction and software maintenance, the class dependency network (CDN) is a key concept. It shows the dependency relationship between classes in the form of a graph, including inheritance, interface implementation, aggregation or method call, etc. Therefore, when constructing the class dependency network, the embodiment of the present invention considers the following dependencies between class nodes: 1. Inheritance or interface implementation: class Inherited from Or implement the interface , forming a directed edge ; 2. Aggregation: Class Contains class As an attribute, form a directed edge ; 3. Method parameters: class The method calls the class The method forms a directed edge .

[0031] Preferably, the graph embedding algorithm is a node2vec algorithm. The embodiment of the present invention uses the node2vec algorithm to embed the class dependency network to capture the structural and semantic information in the network, and generates an embedding vector for each node in the class dependency network.

[0032] S3, concatenating the code metrics of the source code with the network embedding vector to generate enhanced features; Specifically, the traditional software engineering feature vector, that is, the code metrics of the source code, such as code complexity, coupling degree, etc., is normalized; the normalized feature vector is concatenated with the above-mentioned network embedding vector to form an enhanced feature.

[0033] S4, combining the syntax tree feature with the enhanced feature to obtain a graph node attribute feature; Preferably, the syntax tree feature and the enhanced feature are combined in a manner including at least one of adding, multiplying or concatenating elements of the features.

[0034] In one embodiment, after generating the enhanced features, the method further includes: The principal component analysis dimensionality reduction method is used to reduce the dimension of the enhanced features to obtain low-dimensional features.

[0035] Furthermore, the low-dimensional features may be combined with the syntax tree features to obtain graph node attribute features.

[0036] It is worth noting that in order to further reduce the dimension of the feature and retain the most important information, the implementation of the present invention can also use the principal component analysis dimensionality reduction technology to transform the original features into a new coordinate system through linear transformation, so that the data variance on the first coordinate axis of the new coordinate system is the largest, and each subsequent coordinate axis is orthogonal to the previous coordinate axis and has the largest variance. In this way, a low-dimensional feature representation can be obtained.

[0037] S5. Defect prediction is performed based on the graph node attribute features.

[0038] In one implementation, the defect prediction based on the graph node attribute features includes: Using the graph node attribute features as input to a deep learning model to output defect prediction results; Calculate the loss function according to the prediction result, optimize and train the deep learning model with the goal of minimizing the loss function, and obtain a trained software defect prediction model; Software defect prediction is performed through the trained software defect prediction model.

[0039] In order to make the technical solutions of the embodiments of the present invention more clear to those skilled in the art, Figure 2~3 A software defect prediction method provided by an embodiment of the present invention is described in detail.

[0040] See also Figure 2 , is a flowchart of a method for predicting software defects according to an embodiment of the present invention for generating syntax tree features. For example, assuming a project named P, which contains n Java source files, denoted as The source code file can then be parsed into a grammatical structure using grammar rules, and the parsed grammatical structure can be converted into an abstract syntax tree.

[0041] Furthermore, the abstract syntax tree is processed by the main node priority traversal algorithm to generate the target node Token sequence to extract a series of tokens, which are recorded as a set It should be noted that after generating the target node Token sequence, each source file is converted into a set of tokens. In order to input the data into the convolutional neural network, the token set needs to be mapped, and each token is mapped to an integer, so that each source code file is converted into an integer vector. Considering that the length of the tokens generated by each file is different, it is necessary to fill the shorter vectors with zeros to ensure that the length of the vectors generated by each file is consistent.

[0042] For example, let the input word index sequence (Token sequence) be , where n represents the sequence length. Assume that the embedding matrix is , where V represents the vocabulary size, d represents the word embedding dimension, is a real-valued matrix. Then the output of the embedding layer is The calculation is as follows: (1); in Expressive words The corresponding word embedding vector, assuming that the input embedding vector sequence is ,in represents the word embedding vector. Let the convolution kernel be , where k represents the size of the convolution kernel and c represents the number of convolution kernels or the number of output channels. The output of the convolution layer The calculation is as follows: (2); in, represents the segment from the i-th word to the i+k-1-th word in the input sequence, b represents the bias vector, and ReLU() represents the linear rectifier unit activation function.

[0043] For each feature map , take the feature value after the maximum pooling , after pooling, the feature vector is , the pooled feature vector is transformed through the fully connected layer, and finally the syntax tree feature is obtained : (3); Furthermore, in the modeling of the class dependency network, the embodiment of the present invention first uses the node2vec algorithm to embed the class dependency network to capture the structural and semantic information in the network. The node2vec algorithm explores the local and global structures in the network by adjusting two parameters p and q in the random walk. In the embodiment of the invention, p=2 and q=0.15 are set to balance the homogeneity and structural role of the nodes in order to better reveal the similarities and differences between the nodes. In this way, an embedding vector is generated for each node in the class dependency network (CDN).

[0044] (4); Next, the traditional software engineering features, i.e., code metrics, such as code complexity and coupling, are normalized to eliminate the impact of different dimensions. Normalization can be performed using formula (5): (5); in, is the i-th feature in the original feature vector, is the i-th feature in the normalized feature vector. Normalization ensures that all feature values ​​are in the range of 0 to 1. Afterwards, the normalized traditional feature vector is concatenated with the network embedding vector to form an enhanced feature representation .

[0045] Preferably, principal component analysis dimensionality reduction technology is used to reduce the dimension of the enhanced features to obtain a low-dimensional feature representation Finally, the above features Abstract syntax tree features Combination, you can get the graph node attribute characteristics , as shown in formula (6). Considering the different contributions from the two features, the embodiment of the present invention also provides another combination method with a weight parameter version, as shown in formula (7).

[0046] (6); (7); Among them, Combine is a combination method. In the embodiment of the present invention, three methods are selected: element-wise addition (add), element-wise multiplication (multiply) and concatenation (concat).

[0047] Using the above obtained graph node attribute feature matrix , as the input of the deep learning model, in the embodiment of the present invention, taking the graph convolutional network as an example, the final output result can be calculated by formula (8). In this formula, is the weight between the hidden layer and the input layer, H represents the number of hidden layer units, C represents the feature dimension, is the weight coefficient between the hidden layer and the output layer, is the preprocessed adjacency matrix, output feature matrix The dimension is , ReLU() function is the nonlinear activation function in the network. The output of the graph convolutional network is shown in formula (8): (8); The final prediction output of the network is: (9); Among them, the calculation formula of the loss function is: (10); Among them, Y is the true label and Z is the predicted probability after the softmax function of the prediction layer.

[0048] Finally, the deep learning model is optimized and trained by calculating the loss function and minimizing the loss function to obtain a trained software defect prediction model; Software defect prediction is performed through the trained software defect prediction model.

[0049] In summary, see Figure 3 , is a schematic diagram of a network structure used in a software defect prediction method provided in an embodiment of the present invention, such as Figure 3 As shown, the source code is first converted into an abstract syntax tree (AST), and then processed through a convolutional neural network (CNN) to obtain syntax tree features; at the same time, a class dependency network (CDN) is constructed according to the dependency relationship of the source code, and the network is embedded through a graph embedding algorithm to obtain a network embedding vector, and the normalized code metrics are spliced ​​with the network embedding vector to obtain enhanced features; the above-mentioned syntax tree features are then combined with the enhanced features to obtain graph node attribute features (including node initial attributes); the graph node attribute features are input into the input layer of the graph convolutional neural network, through a series of processing operations such as the hidden layer, and finally the features and prediction results are output through the output layer, and the graph convolutional network model is optimized and trained according to the prediction results to obtain the final software defect prediction model.

[0050] It should be noted that in the embodiment of the present invention, since the software is predicted for defects by integrating the three view information of the abstract syntax tree (AST), traditional features and class dependency network (CDN), a software defect prediction method provided by the embodiment of the present invention is named ATC2Defect (AST, Traditional Features, and Class Dependency Network-based Defect Prediction Method). The defect prediction model obtained by this method is the ATC2Defect defect prediction model.

[0051] In the specific implementation, the inventors conducted a comprehensive evaluation of the obtained software defect prediction model to characterize the performance of the model in two different application scenarios: intra-version prediction and cross-version prediction.

[0052] Take the project test on Apache software (Apache HTTP Server, an open source web server of the Apache Software Foundation) as an example. See Table 1 and Table 2. Table 1 is the test result of the ATC2Defect defect prediction model provided by the embodiment of the present invention in the software version test task, and Table 2 is the test result of the ATC2Defect defect prediction model provided by the embodiment of the present invention in the software cross-version test task. The test projects include Ant, Camel, jEdit, Lucene, POI, Velocity, and Xalan. The evaluation indicators include F1 value, AUC value, and the average value of F1 value and AUC value.

[0053] Table 1 Test results of ATC2Dfect prediction within the software version Table 2 Test results of ATC2Dfect in software cross-version prediction It should be noted that Ant, camel, jedit, lucene, poi, velocity, and xalan in Table 1 and Table 2 are all important open source projects of Apache software. The following is a detailed introduction to each project: Ant is a Java-based build tool designed to automate the build process, including compilation, packaging, testing and other steps; Camel is an open source integration framework that provides a routing and rule-based programming model to help developers easily integrate different systems and applications; jEdit is an open source text editor for Java with powerful functions and extensibility for a variety of programming tasks; Lucene is a high-performance, full-featured text search engine library that provides powerful search and indexing capabilities and is widely used in search engines and data retrieval applications; POI is a Java library for operating Microsoft Office documents, including Excel, Word and PowerPoint files; Velocity is a Java-based template engine that allows developers to combine templates with data to generate dynamic content; Xalan is a Java-implemented XSLT processor for converting XML documents to other formats, such as HTML or text.

[0054] It should be noted that the F1 value in Table 1 and Table 2 is the harmonic mean of precision and recall, which strikes a balance between the two. When both precision and recall are high, the F1 value will also be high. Among them, precision measures the proportion of samples that are actually positive among those predicted by the model as positive; recall, also known as true positive rate or sensitivity, measures how many of all samples that are actually positive are correctly predicted by the model, which reflects the model's ability to capture positive samples. The AUC value (Area Under the Curve) is a commonly used indicator for evaluating model performance. In machine learning and statistics, AUC is used to measure the prediction accuracy of the model. AUC represents the area under the receiver operating characteristic (ROC) curve. The ROC curve can show the true positive rate (True Positive Rate) and false positive rate (False Positive Rate) of the model at different thresholds. The value range of AUC is between 0 and 1. The closer to 1, the better the performance of the model, and the closer to 0.5, the weaker the prediction ability of the model.

[0055] Therefore, Tables 1 and 2 present the situation of each project in three different software versions, where v1, v2 and v3 correspond to increasing version levels respectively (for example, in the ant project, v1 represents version 1.4 of the ant project, v2 represents its version 1.6, and v3 represents its version 1.7) to comprehensively evaluate the software defect prediction model ATC2Defect proposed in the embodiment of the present invention.

[0056] It can be seen from the test results in Table 1 that for predictions within software versions, the embodiments of the present invention show extremely high prediction accuracy. In all projects, the F1 value generally exceeds 0.7, indicating that the model has excellent performance in both precision and recall, and can effectively identify potential defects. In most cases, the F1 value even reaches above 0.8, and the highest value reaches 0.89. Similarly, the AUC value of the model also performs well, all above 0.8, and the highest value reaches 0.89, which further confirms the high ability of the model in distinguishing positive and negative samples. In the scenario of cross-version prediction, although the performance of the model has declined to a certain extent. But the F1 value can still reach above 0.5 in most cases.

[0057] It is worth noting that the above test results also show that the method of the present invention is more suitable for intra-version defect prediction tasks. This phenomenon of performance differences between intra-version prediction and cross-version prediction may be related to the changes that occur in software projects as versions evolve. With the iteration of project versions, the total number of source files, dependency architecture, coding style, and defect patterns may all undergo significant changes, which pose a challenge to the generalization ability of the model. In particular, when the difference between two versions is large, the prediction accuracy of the model on the new version may be affected. For example, in the camel project, the changes in the number of files, dependencies, and defect rates between different versions are very significant, and these factors work together to lead to a decline in the cross-version prediction effect. In contrast, projects with high structural similarity perform relatively well in cross-version prediction, which shows that the structural stability of the project is an important consideration when predicting across versions.

[0058] See also Figure 4 , is a structural block diagram of a software defect prediction system provided by an embodiment of the present invention, the software defect prediction system comprising: A first feature generation module 21 is used to convert the software source code into an abstract syntax tree, and process the abstract syntax tree based on a main node priority traversal algorithm and a convolutional neural network to generate syntax tree features; A network embedding vector generating module 22, configured to construct a class dependency network according to the dependency relationship in the source code, and embed the class dependency network using a graph embedding algorithm to obtain a network embedding vector; A second feature generation module 23, configured to concatenate the code metrics of the source code with the network embedding vector to generate an enhanced feature; A third feature generating module 24, configured to combine the syntax tree feature with the enhanced feature to obtain a graph node attribute feature; The defect prediction module 25 is used to perform defect prediction based on the graph node attribute features.

[0059] Specifically, the first feature generation module 21 includes: A target node sequence generating unit, used for extracting the abstract syntax tree based on a main node priority traversal algorithm to obtain a target node sequence; A word embedding vector conversion unit, used to convert the target node sequence into a word embedding vector; The convolution unit is used to process the word embedding vector using a convolutional neural network to generate a grammar tree feature.

[0060] Specifically, the target node sequence generation unit is specifically used for: Starting from the root node of the abstract syntax tree, determine whether the node is a target node one by one; If so, add it to the target node sequence; If not, each child node is traversed according to the subtree size of each node's child nodes to return a target node sequence that meets the requirements.

[0061] Specifically, the convolution unit is specifically used for: Using a convolutional layer of a convolutional neural network to perform a convolution operation on the word embedding vector to extract convolution features; Pooling the convolutional features through a pooling layer of the convolutional neural network; The pooled features are transformed through the fully connected layer of the convolutional neural network to generate syntax tree features.

[0062] Preferably, in the software defect prediction method, the second feature generation module 23 further includes: The low-dimensional feature generating unit is used to reduce the dimension of the enhanced feature by adopting the principal component analysis dimensionality reduction method to obtain the low-dimensional feature.

[0063] In one implementation, the defect prediction module 25 is specifically configured to: Using the graph node attribute features as input to a deep learning model to output defect prediction results; Calculate the loss function according to the prediction result, optimize and train the deep learning model with the goal of minimizing the loss function, and obtain a trained software defect prediction model; Software defect prediction is performed through the trained software defect prediction model.

[0064] It should be noted that a software defect prediction system provided in an embodiment of the present invention is used to execute all process steps of a software defect prediction method in the above embodiment, and the working principles and beneficial effects of the two correspond one to one, so they will not be repeated here.

[0065] The embodiment of the present invention also provides a terminal device, such as Figure 5 , which is a structural block diagram of a preferred embodiment of a terminal device provided by the present invention. The terminal device includes a processor 31, a memory 32, and a computer program stored in the memory 32 and configured to be executed by the processor 31, and the processor 31 implements the software defect prediction method described in any of the above embodiments when executing the computer program.

[0066] In addition, an embodiment of the present invention further provides a computer-readable storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the software defect prediction method described in any of the above embodiments.

[0067] When the processor 31 executes the computer program, the steps in the above software defect prediction method embodiment are implemented, for example: Figure 1 Alternatively, when the processor 31 executes the computer program, the functions of each module in the above software defect prediction system embodiment are realized, for example Figure 4 The functions of each module of the software defect prediction system are shown.

[0068] Preferably, the computer program can be divided into one or more modules / units, which are stored in the memory 32 and executed by the processor 31 to implement the present invention. The one or more modules / units can be a series of computer program instruction segments that can implement specific functions, and the instruction segments are used to describe the execution process of the computer program in the terminal device.

[0069] The processor 31 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor, or the processor 31 may be any conventional processor. The processor 31 is the control center of the terminal device, and various parts of the terminal device are connected using various interfaces and lines.

[0070] The memory 32 mainly includes a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function, etc., and the data storage area can store related data, etc. In addition, the memory 32 can be a high-speed random access memory, or a non-volatile memory, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, and a flash card (Flash Card), etc., or the memory 32 can also be other volatile solid-state storage devices.

[0071] It should be noted that the above terminal device may include, but is not limited to, a processor and a memory. Those skilled in the art will understand that Figure 5The structural block diagram shown is only a structural example of the above-mentioned terminal device and does not constitute a structural limitation of the above-mentioned terminal device. The above-mentioned terminal device may include more or fewer components than shown in the figure, or combine certain components, or different components.

[0072] In summary, the embodiments of the present invention provide a software defect prediction method, system, device and medium. The method converts the software source code into an abstract syntax tree, processes the abstract syntax tree based on a main node-first traversal algorithm and a convolutional neural network to generate syntax tree features; and constructs a class dependency network according to the dependency relationship in the source code, and embeds the class dependency network using a graph embedding algorithm to obtain a network embedding vector; then concatenates the code metrics of the source code with the network embedding vector to generate enhanced features; then combines the syntax tree features with the enhanced features to obtain graph node attribute features; and finally, performs defect prediction based on the graph node attribute features. The present invention firstly captures syntax tree features through a main node priority traversal algorithm and a convolutional neural network, and can extract deep and defect-related features from the source code; secondly, by embedding the features extracted from the traditional code metrics in the class dependency network, the attribute information of each node is enriched, and the quality of the features is further improved; finally, by fusing the three view information features of the abstract syntax tree, the traditional code metrics and the class dependency network, a high-quality graph node attribute feature is constructed, and based on this feature representation, a software defect prediction model is trained and optimized, which can capture more comprehensive code semantics and structural information, learn a more comprehensive feature representation, and thus improve the accuracy of defect prediction and defect recognition capabilities.

[0073] The above is a preferred embodiment of the present invention. It should be pointed out that a person skilled in the art can make several improvements and modifications without departing from the principle of the present invention. These improvements and modifications are also considered to be within the scope of protection of the present invention.

Claims

1. A software defect prediction method, characterized in that: include: Converting the software source code into an abstract syntax tree, and processing the abstract syntax tree based on a main node-first traversal algorithm and a convolutional neural network to generate syntax tree features; Constructing a class dependency network according to the dependency relationship in the source code, and embedding the class dependency network using a graph embedding algorithm to obtain a network embedding vector; concatenating the code metrics of the source code with the network embedding vector to generate enhanced features; Combining the syntax tree feature with the enhanced feature to obtain a graph node attribute feature; Defect prediction is performed based on the graph node attribute features.

2. The software defect prediction method according to claim 1, characterized in that: The main node priority based traversal algorithm and convolutional neural network process the abstract syntax tree to generate syntax tree features, including: Extracting the abstract syntax tree based on a main node-first traversal algorithm to obtain a target node sequence; Convert the target node sequence into a word embedding vector; The word embedding vector is processed using a convolutional neural network to generate a grammatical tree feature.

3. The software defect prediction method according to claim 2, characterized in that: The main node priority-based traversal algorithm extracts the abstract syntax tree to obtain a target node sequence, including: Starting from the root node of the abstract syntax tree, determine whether the node is a target node one by one; If so, add it to the target node sequence; If not, each child node is traversed according to the subtree size of each node's child nodes to return a target node sequence that meets the requirements.

4. The software defect prediction method according to claim 2, characterized in that: The process of processing the word embedding vector using a convolutional neural network to generate a syntax tree feature includes: Using a convolutional layer of a convolutional neural network to perform a convolution operation on the word embedding vector to extract convolution features; Pooling the convolutional features through a pooling layer of the convolutional neural network; The pooled features are transformed through the fully connected layer of the convolutional neural network to generate syntax tree features.

5. The method according to claim 1, characterized in that The manner of combining the syntax tree feature and the enhanced feature includes at least one of adding, multiplying or concatenating elements of the features.

6. The software defect prediction method according to claim 1, characterized in that: After generating the enhanced features, the method further includes: The principal component analysis dimensionality reduction method is used to reduce the dimension of the enhanced features to obtain low-dimensional features.

7. The method according to claim 1, characterized in that The defect prediction based on the graph node attribute features includes: Using the graph node attribute features as input to a deep learning model to output defect prediction results; Calculate the loss function according to the prediction result, optimize and train the deep learning model with the goal of minimizing the loss function, and obtain a trained software defect prediction model; Software defect prediction is performed through the trained software defect prediction model.

8. A software defect prediction system, characterized in that: include: A first feature generation module is used to convert the software source code into an abstract syntax tree, and process the abstract syntax tree based on a main node priority traversal algorithm and a convolutional neural network to generate syntax tree features; A network embedding vector generation module, used to construct a class dependency network according to the dependency relationship in the source code, and embed the class dependency network using a graph embedding algorithm to obtain a network embedding vector; A second feature generation module, configured to concatenate the code metrics of the source code with the network embedding vector to generate an enhanced feature; A third feature generation module, used to combine the syntax tree feature with the enhanced feature to obtain a graph node attribute feature; A defect prediction module is used to perform defect prediction based on the graph node attribute features.

9. A terminal device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor implements the software defect prediction method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the software defect prediction method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Software defect prediction method and system based on heterogeneous class relation graph neural network

    CN117290238A

  • Software defect prediction method and model, terminal and storage medium

    CN118245373A