Software system core class identification method

By combining the forward and backward recommendation mechanisms in the software system, the core classes of the software system are identified, and the problem of insufficient identification caused by only considering forward recommendations in the existing technology is solved, and the recognition performance and explanatory nature of the core classes are improved. sex.

CN119065714APending Publication Date: 2024-12-03JINLING INST OF TECH
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411148382.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-20
Publication Date
2024-12-03

AI Technical Summary

Technical Problem

The existing PageRank algorithm only considers forward recommendation in the core class identification of software system, resulting in insufficient backward recommendation mechanism and it is difficult to accurately identify core classes with high degree but low degree in software-dependent networks.

Method used

A core class recognition method for software system is proposed, by extracting project source code, building abstract syntax tree, extracting dependency instances, generating directed powered dependency edges, and simplifying class-level software-dependent networks, and combining forward and backward recommendation mechanisms The PageRank algorithm calculates the importance of classes and displays the most important classes as core classes.

Benefits of technology

It improves the recognition performance of the core class of the system, overcomes the problem of singleness of existing PageRank recommendations, simplifies the operation process, and has good interpretability and recognition effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119065714A_ABST
    Figure CN119065714A_ABST
Patent Text Reader

Abstract

The invention relates to the field of program understanding, in particular to a software system core class identification method. According to the software system core class identification method provided by the invention, the problem of singleness of existing PageRank recommendation is solved by integrating forward and backward recommendation mechanisms under the condition of not changing the existing PageRank framework, and the identification performance of the system core class is improved. The method further provides software network reduction rules, namely reduction based on maximum connected subgraphs and reduction based on in-degree and out-degree, and the rules are simple, easy to operate and good in interpretability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of program understanding, and in particular to a method for identifying core classes of a software system. Background Art

[0002] As software scale and complexity grow, the cost of software maintenance is getting higher and higher. Code understanding, as the core link of the maintenance process, has an important impact on software modification and updating. Maintenance engineers usually need to devote 30% to 60% of their total workload to analyzing and understanding the internal structure of the software system. Although the importance of software maintenance is becoming increasingly prominent, facing large-scale and complex software systems, especially when maintenance personnel are unfamiliar with the system, software analysis and understanding face many difficulties. Practice shows that starting with the core class (also known as the key class or important class) to understand and analyze helps to quickly become familiar with the core functions of the software system, thereby helping to control and reduce software maintenance costs. Among the core class identification methods, the PageRank algorithm based on the software dependency network has become an important solution. However, the existing PageRank algorithm only considers voting for outbound neighbor nodes (forward recommendation), resulting in the inbound neighbor nodes not being able to obtain the due votes (backward recommendation), making it difficult to identify the core class that plays a control and management role. The core class node usually has only a high out-degree in the software dependency network. Summary of the invention

[0003] In order to solve the above technical problems, the present invention proposes a method for identifying core classes of a software system, comprising the following steps:

[0004] S1: Extract the source code of the project to be parsed;

[0005] S2: Convert each source file in the project source code into a corresponding abstract syntax tree;

[0006] S3: Extract dependency instances of each dependency type from the abstract syntax tree to obtain DepInstances, where DepInstances is a collection of all dependency instances; each dependency instance includes a dependency source class, a dependency target class, and its corresponding dependency type and dependency frequency; where dependency types include: global variable relationship, implementation relationship, inheritance relationship, local variable relationship, method call relationship, method parameter relationship, and return type relationship;

[0007] S4: traverse each dependency instance in DepInstances, accumulate the dependency frequencies in the dependency instances with the same dependency source class and dependency target class, obtain the corresponding accumulated frequencies, and then form directed weighted dependency edges. Each directed weighted dependency edge includes the dependency source class, the dependency target class and the corresponding accumulated frequencies; generate a class-level software dependency network G based on all directed weighted dependency edges;

[0008] S5: Use heuristic rules to simplify G and obtain the simplified class-level software dependency network G′;

[0009] S6: Calculate the importance of each class in G′;

[0010] S7: According to user needs, display the k most important classes as the core classes of the system, where k is a natural number.

[0011] Preferably, the method of simplifying G using heuristic rules is:

[0012] S5.1: traverse all maximal connected components in G; if the number of nodes of a maximal connected component is less than 1% of the total number of nodes of G, delete the maximal connected component and finally obtain the intermediate result network G*;

[0013] S5.2: Traverse each class node in G*. If the class node satisfies indegree = 0 and outdegree = 1, or indegree = 1 and outdegree = 0, delete the class node and its connected edges, and finally obtain G′.

[0014] Preferably, methods for calculating the importance of a class include HIndex, Coreness, PageRank, ElementRank, PageRankLike or PageRankFBR, wherein PageRankFBR specifically refers to a PageRank method using a forward and backward recommendation mechanism.

[0015] Preferably, the specific implementation method of PageRankFBR is to use the PR value of the class node to evaluate the importance of the corresponding class. The larger the PR value, the more important the corresponding class is. The steps of obtaining the PR value of each class node are:

[0016] S6.1: For a class node v in G′, initially, the forward PR value and backward PR value of all class nodes v are:

[0017] PR1(v)=1 / N

[0018] PR2(v)=1 / N

[0019] Among them, PR1(v) represents the forward PR value of class node v;

[0020] PR2(v) represents the backward PR value of class node v;

[0021] N represents the total number of class nodes in G′;

[0022] S6.2: Perform iterative calculations on all class nodes v in G′. In each iteration, use the following formula to update the forward PR value and backward PR value for each class node v:

[0023]

[0024] Among them, d is the damping coefficient, F is the backward recommendation coefficient;

[0025] inDegree(v) is the in-degree of class node v, and outDegree(v) is the out-degree of class node v;

[0026] wInDegree(v) is the weighted in-degree of class node v, wOutDegree(v) is the weighted out-degree of class node v;

[0027] inDegreeSum is the sum of the in-degrees of all class nodes; outDegreeSum is the sum of the out-degrees of all class nodes;

[0028] wInDegreeSum is the weighted in-degree sum of all class nodes; wOutDegreeSum is the weighted out-degree sum of all class nodes;

[0029] fwdContribution(v) is the forward contribution value of class node v; bwdContribution(v) is the backward contribution value of class node v;

[0030] IN(v) is the set of incoming neighbor nodes of class node v; ON(v) is the set of outgoing neighbor nodes of class node v;

[0031] fwdContribution(v) is the forward contribution value of class node v; bwdContribution(v) is the backward contribution value of class node v;

[0032] w(x, y) represents the weight of the directed edge x→y;

[0033] After the iteration reaches the preset convergence condition, stop the iteration and use the following formula to calculate the PR value of each class node v:

[0034] PR(v)=(1-F)×PR1(v)+F×PR2(v)

[0035] Among them, PR(v) represents the PR value of class node v.

[0036] Preferably, the preset convergence condition is: the number of iterations is greater than the iteration number threshold or the sum of the iteration difference values ​​of all class nodes v is less than the difference value threshold;

[0037] The formula for calculating the iterative difference value of class node v is:

[0038] Change(v)=(1-F)×|PR1(v)-backPR1(v)|+F×|PR2(v)-backPR2(v)|

[0039] Among them, Change(v) represents the iterative difference value of class node v;

[0040] backPR1(v) represents the PR1(v) value at the previous iteration;

[0041] backPR2(v) represents the PR2(v) value at the previous iteration.

[0042] Beneficial effects: Compared with the prior art, the present invention has the following advantages:

[0043] (1) This technology proposes a method for identifying the core classes of a software system. This method overcomes the existing PageRank recommendation singleness problem without changing the existing PageRank framework by integrating forward and backward recommendation mechanisms, and improves the recognition performance of the system core classes.

[0044] (2) The software network simplification rules proposed in the present invention, namely "simplification based on maximal connected subgraph" and "simplification based on in-degree-out-degree", have simple rules, easy operation and good interpretability. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 It is the software that relies on the network construction process;

[0046] Figure 2 This is the Precision result on Ant-1.6.1;

[0047] Figure 3 This is the Precision result on Javaclient-2.0;

[0048] Figure 4 This is the recall result on Ant-1.6.1;

[0049] Figure 5 This is the recall result on Javaclient-2.0;

[0050] Figure 6 This is the F1 result on Ant-1.6.1

[0051] Figure 7 The F1 result on Javaclient-2.0 DETAILED DESCRIPTION

[0052] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described below 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.

[0053] like Figure 1 As shown, a method for identifying core classes of a software system comprises the following steps:

[0054] S1: Extract the source code of the project to be parsed;

[0055] In this embodiment, the Git version libraries of the Ant and Javaclient projects are downloaded from https: / / ant.apache.org / and https: / / github.com / appium / java-client websites respectively, and the Ant-1.6.1 and Javaclient-2.0 source codes are extracted respectively using the tool JGit (https: / / www.eclipse.org / jgit / ) and stored in the locally specified path. Ant-1.6.1 contains 654 classes, of which 10 classes are core classes, and Javaclient-2.0 contains 214 classes, of which 57 classes are core classes. The above two projects were selected for verification for the following reasons: (1) Existing studies have already labeled the core classes in the projects, making performance comparison and analysis more convenient; (2) The software networks of projects Ant-1.6.1 and Javaclient-2.0 have different characteristics, i.e., Ant-1.6.1 contains three maximal connected subgraphs but no core classes with in-degree 0, while Javaclient-2.0 contains only one maximal connected subgraph (i.e., the project itself) but has five core classes with in-degree 0; and (3) The fields and scales they belong to are different.

[0056] S2: Convert each source file in the project source code into a corresponding abstract syntax tree (Abstract Syntatic Tree, AST); in this embodiment, the project to be parsed is a Java project, so the Java Development Toolkit (Java Development Tools, JDT) is used to convert the source code into the corresponding abstract syntax tree;

[0057] S3: Extract dependency instances of each dependency type from the abstract syntax tree to obtain DepInstances, where DepInstances is a collection of all dependency instances; each dependency instance includes a dependency source class (source), a dependency target class (target) and its corresponding dependency type (type) and dependency frequency (frequency); wherein dependency types include: global variable relationship, implementation relationship, inheritance relationship, local variable relationship, method call relationship, method parameter relationship, and return type relationship; in this embodiment, the dependency target class only comes from the project source code, and does not consider the top-level class of the same file as the member class dependency;

[0058] S4: traverse each dependency instance in DepInstances, accumulate the dependency frequencies in the dependency instances with the same dependency source class and dependency target class, obtain the corresponding accumulated frequencies, and then form directed weighted dependency edges, each directed weighted dependency edge includes a dependency source class, a dependency target class and the corresponding accumulated frequencies; generate a class-level software dependency network G according to all directed weighted dependency edges; in this embodiment, the process of generating a class-level software dependency network G according to all directed weighted dependency edges is implemented using the JGraphT tool;

[0059] S5: Use heuristic rules to simplify G and obtain the simplified class-level software dependency network G′;

[0060] In this embodiment, the method of simplifying G using heuristic rules is:

[0061] S5.1: traverse all maximal connected components in G; if the number of nodes of a maximal connected component is less than 1% of the total number of nodes of G, delete the maximal connected component and finally obtain the intermediate result network G*;

[0062] S5.2: Traverse each class node in G*. If the class node satisfies inDegree = 0 and outDegree = 1, or inDegree = 1 and outDegree = 0, delete the class node and its connected edges, and finally get G′;

[0063] S6: Calculate the importance of each class in G′; methods for calculating the importance of a class include HIndex, Coreness, PageRank, ElementRank, PageRankLike or PageRankFBR, wherein PageRankFBR specifically refers to a PageRank method with forward and backward recommendation mechanisms;

[0064] There are many possible implementations of PageRankFBR. In this embodiment, the specific implementation is to use the PR value of the class node to evaluate the importance of the corresponding class. The larger the PR value, the more important the corresponding class. The steps for obtaining the PR value of each class node are:

[0065] S6.1: For a class node v in G′, initially, the forward PR value and backward PR value of all class nodes v are:

[0066] PR1(v)=1 / N

[0067] PR2(v)=1 / N

[0068] Among them, PR1(v) represents the forward PR value of class node v;

[0069] PR2(v) represents the backward PR value of class node v;

[0070] N represents the total number of class nodes in G′;

[0071] S6.2: Perform iterative calculations on all class nodes v in G′. In each iteration, use the following formula to update the forward PR value and backward PR value for each class node v:

[0072]

[0073] Wherein, d is the damping coefficient, and in this embodiment, the value is 0.85;

[0074] F is the backward recommendation coefficient, and in this embodiment, the value is 0.5;

[0075] inDegree(v) is the in-degree of class node v, and outDegree(v) is the out-degree of class node v;

[0076] wInDegree(v) is the weighted in-degree of class node v, wOutDegree(v) is the weighted out-degree of class node v;

[0077] inDegreeSum is the sum of the in-degrees of all class nodes; outDegreeSum is the sum of the out-degrees of all class nodes;

[0078] wInDegreeSum is the weighted in-degree sum of all class nodes; wOutDegreeSum is the weighted out-degree sum of all class nodes;

[0079] fwdContribution(v) is the forward contribution value of class node v; bwdContribution(v) is the backward contribution value of class node v;

[0080] IN(v) is the set of incoming neighbor nodes of class node v; ON(v) is the set of outgoing neighbor nodes of class node v;

[0081] fwdContribution(v) is the forward contribution value of class node v; bwdContribution(v) is the backward contribution value of class node v;

[0082] w(x, y) represents the weight of the directed edge x→y;

[0083] After the iteration reaches the preset convergence condition, stop the iteration and use the following formula to calculate the PR value of each class node v:

[0084] PR(v)=(1-F)×PR1(v)+F×PR2(v)

[0085] Among them, PR(v) represents the PR value of class node v;

[0086] In this embodiment, the preset convergence condition is: the number of iterations is greater than the iteration number threshold or the sum of the iteration difference values ​​of all class nodes v is less than the difference value threshold;

[0087] The formula for calculating the iterative difference value of class node v is:

[0088] Change(v)=(1-F)×|PR1(v)-backPR1(v)|+F×|PR2(v)-backPR2(v)|

[0089] Among them, Change(v) represents the iterative difference value of class node v;

[0090] backPR1(v) represents the PR1(v) value at the previous iteration;

[0091] backPR2(v) represents the PR2(v) value at the previous iteration;

[0092] S7: According to user needs, display the k most important classes as the core classes of the system, where k is a natural number.

[0093] The performance of using different algorithms to evaluate the importance of a class in step S6 of the present invention is evaluated below:

[0094] First, the algorithm existing in the prior art used in step S6 is introduced:

[0095] (1) HIndex: HIndex was proposed by JE Hirsch in 2005 to objectively evaluate the academic achievements of scholars. In the field of software engineering, HIndex is used to identify key classes. By constructing a dependency graph between classes and calculating the HIndex index value of each class to evaluate the importance of the class, it provides scientific guidance for the understanding and maintenance of the system structure.

[0096] (2) Coreness: Coreness analysis is an important method to reveal the structural characteristics of a network by identifying the core nodes in the network. These core nodes play a vital role in information dissemination, resource allocation, and network stability. Through coreness analysis, we can effectively identify the centers of influence, hubs, and potential vulnerabilities in the network.

[0097] (3) PageRank: The classic PageRank algorithm was invented by Larry Page, the founder of Google, to calculate the importance of a website. Similarly, the algorithm can also be used to calculate the importance of class nodes in software networks.

[0098] (4) ElementRank: ElementRank is an emerging software system analysis method that abstracts software projects into multi-layer software networks and implements weighted evaluation of class importance at the class and application levels. This method first uses the weighted PageRank algorithm to quantify the importance of classes at each level in the network, and then uses the hierarchical analysis method to comprehensively analyze the importance scores of each level, thereby obtaining a comprehensive importance evaluation of the classes in the entire multi-layer software network.

[0099] (5) PageRankLike: PageRankLike uses degree and weighted degree to improve the probability of random access, and uses simple filtering rules to improve the recognition performance of core categories.

[0100] Experimental evaluation indicators use precision, recall, and F1-Score to evaluate the key class recognition performance. Table 1 describes the calculation method and corresponding explanation of each indicator in detail, where a true positive (TP) refers to a class that is predicted as a core class and is also marked as a core class in the dataset; a false positive (FP) refers to a class that is predicted as a core class but is marked as a non-core class in the dataset; a false negative (FN) refers to a class that is predicted as a non-core class but is marked as a core class in the dataset; a true negative (TN) refers to a class that is predicted as a non-core class and is also marked as a non-core class in the dataset.

[0101] Table 1 Core category recognition performance evaluation indicators

[0102]

[0103] Figure 2-Figure 7 The following is the performance of PageRankFBR and existing benchmark algorithms on projects Ant-1.6.1 and Javaclient-2.0. It can be seen that PageRankFBR is significantly better than existing benchmark algorithms in terms of Precision, Recall, and F1 performance indicators.

[0104] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A method for identifying core classes of a software system, characterized in that: The following steps are involved: S1: Extract the source code of the project to be parsed; S2: Convert each source file in the project source code into a corresponding abstract syntax tree; S3: Extract dependency instances of each dependency type from the abstract syntax tree to obtain DepInstances, where DepInstances is a collection of all dependency instances; each dependency instance includes a dependency source class, a dependency target class, and its corresponding dependency type and dependency frequency; where dependency types include: global variable relationship, implementation relationship, inheritance relationship, local variable relationship, method call relationship, method parameter relationship, and return type relationship; S4: traverse each dependency instance in DepInstances, accumulate the dependency frequencies in the dependency instances with the same dependency source class and dependency target class, obtain the corresponding accumulated frequencies, and then form directed weighted dependency edges. Each directed weighted dependency edge includes the dependency source class, the dependency target class and the corresponding accumulated frequencies; generate a class-level software dependency network G based on all directed weighted dependency edges; S5: Use heuristic rules to simplify G and obtain the simplified class-level software dependency network G′; S6: Calculate the importance of each class in G′; S7: According to user needs, display the k most important classes as the core classes of the system, where k is a natural number.

2. A method for identifying core classes of a software system according to claim 1, characterized in that: The method of simplifying G using heuristic rules is: S5.1: traverse all maximal connected components in G; if the number of nodes of a maximal connected component is less than 1% of the total number of nodes of G, delete the maximal connected component and finally obtain the intermediate result network G*; S5.2: Traverse each class node in G*. If the class node satisfies indegree = 0 and outdegree = 1, or indegree = 1 and outdegree = 0, delete the class node and its connected edges, and finally obtain G′.

3. A method for identifying core classes of a software system according to claim 1, characterized in that: Methods for calculating the importance of a class include HIndex, Coreness, PageRank, ElementRank, PageRankLike or PageRankFBR, where PageRankFBR specifically refers to the PageRank method with forward and backward recommendation mechanisms.

4. A method for identifying core classes of a software system according to claim 3, characterized in that: The specific implementation method of PageRankFBR is to use the PR value of the class node to evaluate the importance of the corresponding class. The larger the PR value, the more important the corresponding class is. The steps to obtain the PR value of each class node are: S6.1: For a class node v in G′, initially, the forward PR value and backward PR value of all class nodes v are: PR1(v)=1 / N PR2(v)=1 / N Among them, PR1(v) represents the forward PR value of class node v; PR2(v) represents the backward PR value of class node v; N represents the total number of class nodes in G′; S6.2: Perform iterative calculations on all class nodes v in G′. In each iteration, use the following formula to update the forward PR value and backward PR value for each class node v: Among them, d is the damping coefficient, F is the backward recommendation coefficient; inDegree(v) is the in-degree of class node v, and outDegree(v) is the out-degree of class node v; wInDegree(v) is the weighted in-degree of class node v, wOutDegree(v) is the weighted out-degree of class node v; inDegreeSum is the sum of the in-degrees of all class nodes; outDegreeSum is the sum of the out-degrees of all class nodes; wInDegreeSum is the weighted in-degree sum of all class nodes; wOutDegreeSum is the weighted out-degree sum of all class nodes; fwdContribution(v) is the forward contribution value of class node v; bwdContribution(v) is the backward contribution value of class node v; IN(v) is the set of incoming neighbor nodes of class node v; ON(v) is the set of outgoing neighbor nodes of class node v; fwdContribution(v) is the forward contribution value of class node v; bwdContribution(v) is the backward contribution value of class node v; w(x, y) represents the weight of the directed edge x→y; After the iteration reaches the preset convergence condition, stop the iteration and use the following formula to calculate the PR value of each class node v: PR(v)=(1-F)×PR1(v)+F×PR2(v) Among them, PR(v) represents the PR value of class node v.

5. A method for identifying core classes of a software system according to claim 4, characterized in that: The preset convergence condition is: the number of iterations is greater than the iteration number threshold or the sum of the iteration difference values ​​of all class nodes v is less than the difference value threshold; The formula for calculating the iterative difference value of class node v is: Change(v)=(1-F)×|PR1(v)-backPR1(v)|+F×|PR2(v)-backPR2(v)| Among them, Change(v) represents the iterative difference value of class node v; backPR1(v) represents the PR1(v) value at the previous iteration; backPR2(v) represents the PR2(v) value at the previous iteration.

Citation Information

Cited By

  • Important software identification method based on software dependency graph

    CN117009239A

  • A method for identifying important software based on a software dependency graph

    CN117009239B