A technical debt severity identification method based on multi-source information
Patent Information
- Application Number
- CN202211470595.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-23
- Publication Date
- 2026-09-08
- Estimated Expiration
- 2042-11-23
AI Technical Summary
[0004]在技术债务严重程度识别问题中,已有的研究主要聚焦实证调研,尚缺乏可靠的方法来度量技术债务的严重程度
[0029] 1. Combining different types of information to predict the severity of technical debt in method-level code can effectively mitigate the bias caused by a single piece of information;
Smart Images

Figure CN115994330B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software technology debt management, and in particular to a method for identifying the severity of technology debt based on multi-source information. Background Technology
[0002] Thanks to advancements in technical debt research, numerous efficient tools now exist to help developers automatically identify technical debt in their code. However, a significant amount of technical debt exists during software development and maintenance, and repaying it all is neither possible nor realistic. In practice, due to limited time or resources, developers tend to prioritize repaying technical debt that is more severe. Therefore, identifying the severity of technical debt is a crucial task, enabling developers to make optimal decisions before releasing new software versions.
[0003] Unfortunately, research on measuring the severity of technical debt is relatively limited. Mensah et al. manually analyzed 600,000 code comments, extracting textual features to distinguish between severe and non-severe technical debt. They found that in four projects—ArgoUML, Chromium, Eclipse, and Apache—severe technical debt accounted for 14%, 55%, 14%, and 17%, respectively. Through a survey of software in the Hibernate ecosystem, Limahe et al. found a direct relationship between the time required to eliminate technical debt and its severity; that is, higher-severity technical debt requires longer time and greater effort. Furthermore, over 50% of software with high-severity technical debt tends to increase in quantity over time.
[0004] Existing research on the severity of technical debt mainly focuses on empirical surveys, lacking reliable methods to measure its severity. Therefore, this invention proposes a method for identifying the severity of technical debt based on multi-source information. This method simultaneously considers the semantic and structured information of the technical debt method codes, enabling accurate prediction of the severity of technical debt. Summary of the Invention
[0005] To effectively identify the severity of technical debt, this invention provides a method for identifying the severity of technical debt based on multi-source information. By combining the semantic and structural information of the code, it can effectively improve prediction performance.
[0006] The specific technical solution adopted in this invention is as follows:
[0007] Step 1. Obtain the data needed to identify the severity of technical debt:
[0008] First, obtain project data from open-source software repositories and filter out the Java files, all of which end with ".java".
[0009] Secondly, use JavaParser to extract all methods from the Java file, along with the start and end line information for each method, and form a quadruple mt =<file,method,start,end> Where file represents the filename, method represents the method-level code, start represents the starting line number of the method, and end represents the ending line number of the method; all the quadruples form the set MT = (mt1, mt2, ..., mt... l1 ), where l1 represents the number of quadruplets.
[0010] Then, SonarQube is used to scan the Java files to obtain all statement-level technical debt instances, each consisting of a triple dt =<file,line,severity> Here, `line` represents the line number of the code, and `severity` represents the severity of technical debt. The `severity` here is based on a metric provided by SonarQube and has been manually checked to correct false positives. All triples form the set DT = (dt1, dt2, ..., dt...). l2 ), where l2 represents the number of triples.
[0011] Finally, for a quadruple in MT and a triple in DT, if their files are the same, line ≥ start and line ≤ end, then they are paired to generate a sample.<method,severity> This represents instances of method-level technical debt. During the pairing process, severity is used as the severity of a method-level technical debt sample only if all statement-level technical debts have the same severity; otherwise, pairing fails and no new sample is generated. All samples form a set S = (sample1, sample2, ..., sample...). l3 l3 represents the number of samples.
[0012] Step 2. Use the srcML tool to obtain the XML file of the Java source code and extract its structured information:
[0013] First, the method is measured in three aspects: size, complexity, and coupling. Size is mainly measured by the number of statements and lines of code (LOC); complexity is measured by cyclomatic complexity, number of parameters, number of comments, number of expressions, number of variable declarations, and number of identifiers; coupling is measured by the number of method calls.
[0014] Then, the metrics are normalized to prevent extreme values from affecting model learning. For each metric x in the metric X, the normalization formula is:
[0015]
[0016] Where, x min and x max These are the minimum and maximum values of all measures in X, respectively.
[0017] Finally, the method in each sample is transformed into a vector structuralV = [size, complexity, coupling], which represents the structured information of the method code. All structuralVs form a set STV = (structuralV1, structuralV2, ..., structuralV2). l3 ).
[0018] Step 3. Use JavaParser to process each sample. i The methods in (o = 1, 2, ..., l3) are transformed into an Abstract Syntax Tree (AST) and semantic information is extracted:
[0019] First, for each method, extract the distinct paths between all nodes in its corresponding AST tree. The start and end nodes of each path p, along with the path itself, form a triple ct = ... <x s ,p,x t >, where x s and x t Representing the start and end node values, all cts form a set CT = (ct1, ct2, ..., ct2). l4 ), l4 represents the number of paths in the AST.
[0020] Then, the word embedding technique CBOW is used to train all cts to obtain each ct. i Vector representation of (i = 1, 2, ..., l4)
[0021] Finally, use the attention mechanism to combine them. Aggregate into a vector Semantic information used to represent method code, where α i For vectors The attention weights are given by the set SEV = (semanticV1, semanticV2, ..., semanticV2). l3 ).
[0022] Step 4. Concatenate the structuralV and semanticV corresponding to the method in each sample to obtain the final vector representation of the method, methodV. Each dimension of methodV represents a feature value. At this point, each sample can be represented as sample =<methodV,severity> .
[0023] Step 5. Use the Chi-Square Test method to calculate the correlation score between the category and the feature, and select the top K percent of features by score.
[0024] Step 6. Data Augmentation. For a minority class sample in the set... a Calculate the Euclidean distance between the sample and all samples of the same class, select the k nearest neighbors as a candidate set, and then randomly select a sample from the candidate set. b Based on sample a and sample b Generate a new sample using interpolation. c and sample c Add to the sample set. c The generation process is as follows:
[0025] sample c =sample a +rand(0,1)×(sample b -sample a )
[0026] Here, rand(0,1) represents a random value between 0 and 1. This process is repeated until the number of minority class samples equals the number of majority class samples. This method effectively increases the diversity of the sample set, effectively avoids overfitting, and improves model performance.
[0027] Step 7. Using stratified sampling, divide the dataset into ten equal parts, with nine parts used as the training set and one part as the test set. Train a classifier based on XGBoost (eXtreme Gradient Boosting). For new samples, use the trained classifier to predict their severity.
[0028] This invention provides a method for identifying the severity of technical debt based on multi-source information. Compared with existing technologies, the advantages of this invention are as follows:
[0029] 1. Combining different types of information to predict the severity of technical debt in method-level code can effectively mitigate the bias caused by a single piece of information;
[0030] 2. By selecting features from the feature set, the algorithm's running time can be effectively reduced and its performance improved.
[0031] 3. Data augmentation was used to increase the number of minority class samples, which effectively solved the class imbalance problem. Attached Figure Description
[0032] Figure 1 This is a flowchart of the technical debt severity identification method based on multi-source information according to the present invention. Detailed Implementation
[0033] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0034] Data Source Acquisition: The original dataset used in this experiment comes from the open-source software repositories GitHub and SourceForge.net. This dataset includes 9 Java projects, containing 9,791 source code files and 1,051,692 lines of code.
[0035] The following is in conjunction with the appendix Figure 1 This invention patent provides a detailed description of a method for identifying the severity of technical debt based on multi-source information, which includes the following steps:
[0036] Step 1. Obtain the data needed to identify the severity of technical debt:
[0037] First, the source code of nine projects—Ant, ArgoUML, Columba, Hibernate, JEdit, JFreeChart, JMeter, JRuby, and Squirrel—was obtained from the open-source software repositories SourceForge.net and Github. All Java files in these projects were then selected, and all of them ended with ".java".
[0038] Secondly, use JavaParser to extract all methods from the Java file, along with the start and end line information for each method, and form a quadruple mt =<file,method,start,end> Where file represents the filename, method represents the method-level code, start represents the starting line number of the method, and end represents the ending line number of the method; all the quadruples form the set MT = (mt1, mt2, ..., mt... l1 ), where l1 represents the number of quadruplets;
[0039] Then, SonarQube is used to scan the Java files to obtain all statement-level technical debt instances, each consisting of a triple dt =<file,line,severity> This indicates that, where `line` represents the line number and `severity` represents the severity of technical debt. The `severity` here is based on a metric provided by SonarQube and has been manually checked to correct false positives. All triples form the set DT = (dt1, dt2, ..., dt...). l2 ), where l2 represents the number of triples;
[0040] Finally, for a quadruple in MT and a triple in DT, they are paired according to the following formula to generate a sample: sample =<method,severity> , used to represent instances of method-level technical debt.
[0041] mt i (i = 1, 2, ..., l1) ∈ MT
[0042] dt j (j=1,2,…,l2)∈DT
[0043] mt i· file=dt j· file
[0044] dt j· line≥mt i· start
[0045] dt j· line≤mt i· end
[0046] During the pairing process, severity is used as the severity of method-level technical debt samples only if all statement-level technical debts have the same severity; otherwise, pairing fails and no new samples are generated. After pairing, all samples form a set S = (sample1, sample2, ..., sample...). l3l3 represents the number of samples.
[0047] Step 2. Use the srcML tool to obtain the XML file of the Java source code and extract its structured information:
[0048] First, the method is measured in three aspects: size, complexity, and coupling. Size is mainly measured by the number of statements and lines of code (LOC); complexity is measured by cyclomatic complexity, number of parameters, number of comments, number of expressions, number of variable declarations, and number of identifiers; coupling is measured by the number of method calls.
[0049] Then, the metrics are normalized to prevent extreme values from affecting model learning. For each metric x in the metric X, the normalization formula is:
[0050]
[0051] Where, x min and x max These are the minimum and maximum values of all measures in X, respectively.
[0052] Finally, the method in each sample is transformed into a vector structuralV = [size, complexity, coupling], which represents the structured information of the method code. All structuralVs form a set STV = (structuralV1, structuralV2, ..., structuralV2). l3 ).
[0053] Step 3. Use JavaParser to process each sample. i The methods in (i = 1, 2, ..., l3) are transformed into an Abstract Syntax Tree (AST) and semantic information is extracted:
[0054] First, for each method, extract the distinct paths between all nodes in its corresponding AST tree. The start and end nodes of each path p, along with the path itself, form a triple ct = ... <x s ,p,x t >, where x s and x t Representing the start and end node values, all cts form a set CT = (ct1, ct2, ..., ct2). l4 ), l4 represents the number of paths in the AST;
[0055] Secondly, two matrices are obtained using the word embedding technique CBOW. and Use value_vocab on x s and x t Word embedding is performed using path_vocab on p. Here, l5 is the number of nodes in the AST, and d = 300 is the manually configurable word embedding size.
[0056] Then, ct i The embedding values of the three parts (i = 1, 2, ..., l4) are concatenated to obtain the vectorized representation c. i And use a fully connected layer to handle c i To merge;
[0057]
[0058] in, This is the fused vector representation. It is the weight matrix learned during training, and tanh is the activation function;
[0059] Finally, use the attention mechanism to combine them. Aggregate into a vector Semantic information used to represent method code, where α i For vectors The attention weights are given by the set SEV = (semanticV1, semanticV2, ..., semanticV2). l3 ).
[0060] Step 4. Concatenate the structuralV and semanticV corresponding to the method in each sample to obtain the final vector representation of the method, methodV. Each dimension of methodV represents the value of a feature. At this point, each sample can be represented as sample =<methodV,severity> .
[0061] Step 5. Use the Chi-Square Test to calculate the relevance score between the category and the feature, and select the top K percent of features by score. Assume C i Categories representing the severity of technical debt, characterized by w j and C i The formula for calculating the relevance score is as follows:
[0062]
[0063] Where A is the feature w j And belongs to class Ci The number of samples, B is the number of features w. j But it does not belong to class C. i The number of samples, C belongs to class C. i But does not include feature w j The number of samples, D, is the number of samples that does not include feature w. j It does not belong to class C. i The number of samples.
[0064] Get CHI(w) j C i Then, the feature w can be calculated according to the following formula. j The chi-square score, where P(C) i ) represents category C i The probability of occurrence in the sample set.
[0065] CHI(w j )=∑P(C i CHI(w) j C i )
[0066] At this point, each sample can be represented as sample = [w1, w2, ..., w l6 ], w i l represents its i-th feature, and l6 represents the number of features selected.
[0067] Step 6. Data Augmentation. For a minority class sample in the set... a Calculate the Euclidean distance between this sample and all samples of the same class. Select sample a The k nearest neighbors are used as a candidate set, and then a sample is randomly selected from the candidate set. b Based on sample a and sample b Generate a new sample using interpolation. c and sample c Add to the sample set. c The generation process is as follows:
[0068] sample c =sample a +rand(0,1)×(sample b -sample a )
[0069] Here, rand(0,1) represents a random value between 0 and 1. This process is repeated until the number of minority class samples equals the number of majority class samples. This method can effectively increase the diversity of the sample set and effectively avoid overfitting, thus improving the method's performance.
[0070] Step 7. Using stratified sampling, divide the dataset into ten equal parts, with nine parts used as the training set and one part as the test set. Based on the XGBoost (eXtreme Gradient Boosting) model, on the training set T = {(Sample...} j ,y j A classifier is trained on a dataset (j = 1, 2, ..., l7), where l7 is the number of samples in the training set. j and y j Let represent the sample and its corresponding label, respectively. The severity of the j-th sample can be calculated using the following formula:
[0071]
[0072] Where l8 represents the number of regression trees, F = {f(x) = ω} q(x)}(q:R s →T,ω∈R T Let ) denote a function space representing regression trees, i.e., all possible regression trees, and q denote the structure of each tree, which stores each sample. j Mapping to the corresponding leaf nodes, T represents the number of leaf nodes in a regression tree, and ω represents the weight of each leaf.
Claims
1. A method for identifying the severity of technical debt based on multi-source information, characterized in that, Includes the following steps: Step 1. Obtain the data needed to identify the severity of technical debt; Sub-step 1-1: Obtain project data from the open-source software repository and filter out the Java files; Sub-steps 1-2 involve using JavaParser to extract all methods from the Java file, along with the start and end line information for each method, forming a quadruple. ,in Indicates the file name. This represents method-level code. Indicates the starting line number of the method. The method ends with a line number; all quadruples form a set. ,in Represents the number of quadruplets; Sub-steps 1-3 use SonarQube to scan Java files to obtain all statement-level technical debt instances, each consisting of a triple. express, Indicates the line number of the code. Indicates the severity of technical debt; All triples form a set ,in Represents the number of triples; Sub-steps 1-4, for a quadruple in MT and a triple in DT, if its same, and Then they are paired to generate a sample. , used to represent instances of method-level technical debt; During the pairing process, a pairing is performed only if all statement-level technical debts have the same severity. As a measure of the severity of technical debt samples at the method level, otherwise pairing fails and no new samples are generated; All samples form a set , Represents the number of samples; Step 2. Use the srcML tool to obtain the XML file of the Java source code, and process each sample... The method in Structured information is extracted to obtain vectors. And collection STV; Step 3. Use JavaParser to process each sample The method in The process involves transforming the data into an abstract syntax tree and extracting semantic information to obtain an aggregate vector. and set SEV; Step 4. For each sample, assign the method corresponding to... and By concatenating the vectors, we obtain the final vector representation of the method. Each sample can be represented as Each dimension of the vector represents the value of a feature; Step 5. Use the chi-square test to calculate the correlation score between the category and the feature, and select the top M percent of features with the highest scores, where the category is the category of technical debt severity; Step 6. Perform data augmentation on the minority class samples in the sample set; Step 7. Using stratified sampling, divide the dataset into ten equal parts, with nine parts serving as the training set and one part as the test set. Train a classifier based on XGBoost and use the trained classifier to identify the severity of technical debt.
2. The method for identifying the severity of technical debt based on multi-source information according to claim 1, characterized in that, Step 2 includes the following sub-steps: Sub-step 2-1: Use the srcML tool to obtain the XML file of the Java source code and determine the method size. Complexity and coupling degree Measured from three aspects; Size is measured by the number of statements and the number of lines of code; Complexity metrics include: cyclomatic complexity, number of parameters, number of comments, number of expressions, number of variable declarations, and number of identifiers; Coupling is measured by the number of method calls; Sub-step 2-2 involves normalizing the metric values to prevent extreme values from affecting model learning. Each metric in The normalization formula is: in, and These are the minimum and maximum values among all the metrics of V, respectively; Sub-steps 2-3 involve processing each sample... Transform into a vector Its representative method code's structured information, all Form a set ;in Represents the number of samples.
3. The method for identifying the severity of technical debt based on multi-source information according to claim 1, characterized in that, Step 3 includes the following sub-steps: Sub-step 3-1: Extract the different paths between all nodes in the AST tree corresponding to each method; For path Triples exist ,in and Indicates the start and end node values, all Form a set , Represents the number of paths in the AST; Sub-step 3-2, using the word embedding technique CBOW to analyze all... Training to obtain each vector representation ; Sub-step 3-3: Use the attention mechanism to process all... Aggregate into a vector , used to represent semantic information of method code, where For vectors Attention weights, all Form a set ;in Represents the number of samples.
4. The method for identifying the severity of technical debt based on multi-source information according to claim 2, characterized in that, Step 5 includes: set up Categories representing the severity of technical debt, characteristics and The formula for calculating the relevance score is as follows: in, A is the total number of samples, and A is the number of features included. And belong to class The number of samples, B is the number of features. But it does not belong to the class The number of samples, C is the class. But does not include features The number of samples, D, is the number of samples that does not contain features. It does not belong to the class The number of samples; get Then the features can be calculated according to the following formula. The chi-square score, of which Representative category Probability of occurrence in the sample set: Each sample can be represented as , Indicates its first One characteristic, This represents the number of features selected.
5. The method for identifying the severity of technical debt based on multi-source information according to claim 1, characterized in that, Step 6 includes: Calculate minority class samples Euclidean distance between and samples of the same class, select of The nearest neighbor samples are used as the candidate set, and a sample is randomly selected from the candidate set. ;based on and Generate a new sample using interpolation. and will Add to the sample set; The generation process is as follows: in, This represents a random value between 0 and 1. This process is repeated until the number of minority class samples equals the number of majority class samples.
6. The method for identifying the severity of technical debt based on multi-source information according to claim 1, characterized in that, Step 7 includes: Suppose the training set contains Sample and corresponding tags Then the training set can be represented as The predicted value for the j-th sample is calculated using the following formula: in, Indicates the number of regression trees. Let represent a function space that characterizes regression trees, i.e., all possible regression trees. This represents the structure of each tree, which will store each sample Mapped to the corresponding leaf node. This represents the number of leaf nodes in a regression tree. This represents the weight of each leaf.
Citation Information
Patent Citations
Code bad smell detection method and device
CN112764758A