A graph neural network-based architecture recovery method and architecture recovery device

By combining graph neural networks with semantic information and dependency relationships, the problem of inaccurate software architecture recovery in existing technologies is solved, and more comprehensive software architecture recovery is achieved.

CN116821734BActive Publication Date: 2025-09-19NANJING UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310559130.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-18
Publication Date
2025-09-19
Estimated Expiration
2043-05-18

AI Technical Summary

Technical Problem

Existing software architecture recovery algorithms fail to utilize both the knowledge and structural information of the software, resulting in inaccurate and incomplete recovery.

Method used

A graph neural network-based method is adopted, combined with the semantic information and dependency relationships in the software system, trained through the graph neural network model GCN, and the unsupervised learning clustering algorithm K-means is used to perform node clustering to obtain the software architecture.

Benefits of technology

It more accurately restores the architecture of the software system, taking into account both structural and knowledge information, and improves the accuracy and comprehensiveness of the recovery.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116821734B_ABST
    Figure CN116821734B_ABST
Patent Text Reader

Abstract

The present invention discloses an architecture recovery method and an architecture recovery device based on a graph neural network. The method comprises steps S1: inputting semantic information in each file of a software system; S2: inputting dependency relationships between files of the software system; S3: integrating the software information obtained by S1 and S2 into a graph data structure; S4: using an unsupervised graph neural network algorithm to train the graph data structure obtained by S3 to obtain a vector expression of each node; and S5: using an unsupervised clustering algorithm K-means algorithm to cluster the vector expressions of the nodes in the graph data obtained by step S4, dividing the nodes into K categories according to a set K value, and obtaining a specific category of each file node. Each node represents a certain category of the software architecture, and together constitutes a software architecture.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to automated software architecture recovery, and in particular to an architecture recovery method and an architecture recovery device based on a graph neural network. Background Art

[0002] Software architecture recovery is the use of automated technology to recover software architecture, primarily using software clustering technology, which aims to map software entities such as files, functions, and classes into meaningful modules. Software architecture recovery algorithms typically use knowledge and structural information to cluster software modules. Currently, most architecture recovery algorithm technologies do not simultaneously utilize both software knowledge and structural information, i.e., the dependencies between program semantics and file entities. The graph neural network-based software architecture recovery device proposed in this invention can simultaneously take into account both the structural information and knowledge information of the software system, thereby obtaining more accurate and comprehensive software architecture information. Summary of the Invention

[0003] The problem to be solved by the present invention is to perform automatic architecture recovery on a software system.

[0004] To solve the above problems, the present invention adopts the following solution: a graph neural network-based architecture recovery method, which analyzes entities in the software system, such as software files. Specifically, the method combines semantic information extracted from the files with dependency information extracted from the files, trains the graph neural network model GCN to obtain the vector representation of each node in the graph, and clusters the nodes using the unsupervised learning clustering algorithm Kmeans to obtain the software architecture of the software system. The method specifically includes the following steps:

[0005] S1: input semantic information in each file of the software system;

[0006] The semantic information in the file is a collection of words in the source code file of the software product, including common macros, variable names and function names, as well as words appearing in comments;

[0007] S2: Dependencies between input software system files;

[0008] The dependency relationship refers to the calling relationship between the source code files of the software product, including include dependency, function dependency, symbol dependency, etc., which can be obtained using static analysis and dynamic analysis;

[0009] S3: Integrate the software information obtained by S1 and S2 into a graph data structure, including the following steps:

[0010] S31: Use the data structure in the pyg.data library to represent the graph data. First, vectorize the semantic words obtained in S1. Each bit in the vector represents whether the word appears in the file. A bit of 1 indicates that the word appears in the file, and a bit of 0 indicates that the word does not appear in the file.

[0011] S32: Use the adjacency matrix to represent the dependency edges of the graph obtained in S2, assign the file vector in S31 to pyg.data.x, and assign the adjacency matrix to pyg.data.edge as the edge information of the graph.

[0012] S4: Use an unsupervised graph neural network algorithm to train the graph data structure obtained in S3 to obtain a vector representation of each node, including the following steps:

[0013] S41: Initialize the graph neural network model GCN as a two-layer model. The unit of the first layer model is half of the maximum dimension of the input graph vector, and the unit of the second layer model is the dimension of the output vector expression. Manually select the number of categories K to be clustered, and set the loss function to the neighbor node similarity as the loss function;

[0014] S42: Train the data in the GCN model, stop training after the loss function converges, and obtain the low-dimensional representation of the node;

[0015] S5: Use the unsupervised clustering algorithm K-means algorithm to cluster the vector expressions of the nodes in the graph data obtained in step S4, and divide the nodes into K categories according to the set K value to obtain the specific category of each file node. Each node represents a certain category of software architecture, and together they constitute a software architecture.

[0016] Based on the same principle, the present invention also discloses an architecture recovery device based on a graph neural network, which is characterized by including the following modules:

[0017] M1: Used to input semantic information in each file of the software system;

[0018] The semantic information in the file is a collection of words in the source code file of the software product, including common macros, variable names and function names, as well as words appearing in comments;

[0019] The semantic information in the file is text data extracted by program semantic analysis tools such as clang / llvm;

[0020] M2: used to input the dependency relationship between software system files;

[0021] The dependency relationship refers to the calling relationship between the source code files of the software product, including include dependency, function dependency, symbol dependency, etc., which can be obtained using static analysis and dynamic analysis;

[0022] M3: Used to integrate the software information obtained by M1 and M2 into a graph data structure, including the following modules:

[0023] M31: Uses the data structure in the pyg.data library to represent graph data. First, the semantic words obtained in M1 are vectorized. Each bit in the vector represents whether the word appears in the file. A bit of 1 indicates that the word appears in the file, and a bit of 0 indicates that the word does not appear in the file.

[0024] M32: Used to: represent the dependency edges of the graph obtained by M2 using the adjacency matrix, assign the file vector in M31 to pyg.data.x, and assign the adjacency matrix to pyg.data.edge as the edge information of the graph.

[0025] M4: Used to: Use the unsupervised graph neural network algorithm to train the graph data structure obtained by M3 to obtain the vector expression of each node, including the following modules:

[0026] M41: Used to initialize the graph neural network model GCN as a two-layer model. The units of the first layer model are half of the maximum dimension of the input graph vector, and the units of the second layer model are the dimension of the output vector expression. The number of categories K to be clustered is manually selected, and the loss function is set to the neighbor node similarity as the loss function;

[0027] M42: Used to train the data in the GCN model, stop training after the loss function converges, and obtain the low-dimensional representation of the node;

[0028] M5: Uses the unsupervised K-means clustering algorithm to cluster the vector representations of nodes in the graph data obtained by the M4 module. The nodes are divided into K categories according to the set K value to obtain the specific category of each file node. Each node represents a certain category of the software architecture, and together they constitute a software architecture.

[0029] The technical effects of the present invention are as follows: The present invention uses a software architecture recovery device based on a graph neural network, taking into account both the structural information and the knowledge information of the software system, and obtaining the software architecture more accurately and comprehensively. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 Schematic diagram of the training process based on a graph neural network according to an embodiment of the present invention.

[0031] Figure 2 A schematic diagram of the node clustering process according to an embodiment of the present invention. DETAILED DESCRIPTION

[0032] The present invention will be further described in detail below with reference to the accompanying drawings.

[0033] This paper presents a software architecture recovery method based on a graph neural network. This method analyzes entities in a software system, such as software files. Specifically, it combines semantic information extracted from the files with dependency information extracted from the files. This method then trains a graph neural network model (GCN) to obtain a vector representation of each node in the graph. The nodes are then clustered using the unsupervised learning clustering algorithm Kmeans to retrieve the software architecture of the software system. This method primarily involves two steps: training the graph neural network to obtain representations of graph nodes and clustering the nodes.

[0034] S1: input semantic information in each file of the software system;

[0035] The semantic information in the file is a collection of words in the source code file of the software product, including common macros, variable names and function names, as well as words appearing in comments;

[0036] S2: Dependencies between input software system files;

[0037] The dependency relationship refers to the calling relationship between the source code files of the software product, including include dependency, function dependency, symbol dependency, etc., which can be obtained using static analysis and dynamic analysis;

[0038] S3: Integrate the software information obtained by S1 and S2 into a graph data structure, including the following steps:

[0039] S31: Use the data structure in the pyg.data library to represent the graph data. First, vectorize the semantic words obtained in S1. Each bit in the vector represents whether the word appears in the file. A bit of 1 indicates that the word appears in the file, and a bit of 0 indicates that the word does not appear in the file.

[0040] S32: Use the adjacency matrix to represent the dependency edges of the graph obtained in S2, assign the file vector in S31 to pyg.data.x, and assign the adjacency matrix to pyg.data.edge as the edge information of the graph.

[0041] S4: Use an unsupervised graph neural network algorithm to train the graph data structure obtained in S3 to obtain a vector representation of each node, including the following steps:

[0042] S41: Initialize the graph neural network model GCN as a two-layer model. The unit of the first layer model is half of the maximum dimension of the input graph vector, and the unit of the second layer model is the dimension of the output vector expression. Manually select the number of categories K to be clustered, and set the loss function to the neighbor node similarity as the loss function;

[0043] S42: Figure 1 , train the graph data in the GCN model, stop training after the loss function converges, and obtain the low-dimensional representation of the nodes;

[0044] S5: If Figure 2 ,Use the unsupervised clustering algorithm K-means algorithm to cluster the vector expressions of the nodes in the graph data obtained in step S4, and divide the nodes into K categories according to the set K value to obtain the specific category of each file node. Each node represents a certain category of software architecture, and together constitute a software architecture.

[0045] The above description is merely a preferred embodiment of the present invention. The specific embodiments described herein are intended only to explain the present invention and are not intended to limit the present invention. Any simple modifications, equivalent variations, and modifications made to the above embodiments by any person skilled in the art, without departing from the principles and spirit of the present invention, in accordance with the technical essence of the present invention, shall be included within the scope of protection of the present invention.

Claims

1. A graph neural network-based architecture recovery method, characterized in that: The steps include: S1: input semantic information in each file of the software system; The semantic information in the file is a collection of words in the source code file of the software product, including macros, variable names, function names, and words appearing in comments; The semantic information in the file is text data extracted by the clang or llvm program semantic analysis tool; S2: Dependencies between input software system files; The dependency relationship refers to the calling relationship between the source code files of the software product, including include dependency, function dependency, symbol dependency, obtained using static analysis and dynamic analysis; S3: Integrate the software information obtained by S1 and S2 into a graph data structure; this specifically includes the following steps: S31: Use the data structure in the pyg.data library to represent the graph data. First, vectorize the semantic words obtained in S1. Each bit in the vector represents whether the word appears in the file. A bit of 1 indicates that the word appears in the file, and a bit of 0 indicates that the word does not appear in the file. S32: Use the adjacency matrix to represent the dependency edges of the graph obtained in S2, assign the file vector in S31 to pyg.data.x, and assign the adjacency matrix to pyg.data.edge as the edge information of the graph; S4: Use an unsupervised graph neural network algorithm to train the graph data structure obtained in S3 to obtain a vector representation of each node; S5: Use the K-means algorithm to cluster the vector expressions of the nodes in the graph data obtained in step S4. According to the set K value, the nodes are divided into K categories to obtain the specific category of each file node. Each node represents a certain category of software architecture, and together they constitute a software architecture.

2. The architecture recovery method based on graph neural network according to claim 1, characterized in that In the step S4, it specifically includes the following steps: S41: Initialize the graph neural network model GCN as a two-layer model. The units of the first layer model are half of the maximum dimension of the input graph vector, and the units of the second layer model are the dimension of the output vector expression. The number of cluster categories K is manually selected, and the function of the similarity of neighbor nodes is set as the loss function. S42: Train the data in the GCN model, stop training after the loss function converges, and obtain the low-dimensional representation of the node.

3. An architecture recovery device based on graph neural network, characterized in that: Includes the following modules: M1: Used to input semantic information in each file of the software system; The semantic information in the file is a collection of words in the source code file of the software product, including macros, variable names, function names, and words appearing in comments; The semantic information in the file is text data extracted by the clang or llvm program semantic analysis tool; M2: used to input the dependency relationship between software system files; The dependency relationship refers to the calling relationship between the source code files of the software product, including include dependency, function dependency, symbol dependency, obtained using static analysis and dynamic analysis; M3: is used to integrate the software information obtained by M1 and M2 into a graph data structure; it specifically includes the following submodules: M31: Uses the data structure in the pyg.data library to represent graph data. First, the semantic words obtained in M1 are vectorized. Each bit in the vector represents whether the word appears in the file. A bit of 1 indicates that the word appears in the file, and a bit of 0 indicates that the word does not appear in the file. M32: Used to represent the dependency edges of the graph obtained by M2 using the adjacency matrix, assign the file vector in M31 to pyg.data.x, and assign the adjacency matrix to pyg.data.edge as the edge information of the graph; M4: Used to: Use the unsupervised graph neural network algorithm to train the graph data structure obtained by M3 to obtain the vector expression of each node; M5: Used to: Use the K-means algorithm to cluster the vector expressions of the nodes in the graph data obtained by the M4 module, divide the nodes into K categories according to the set K value, and obtain the specific category of each file node. Each node represents a certain category of the software architecture, and together constitute a software architecture.

4. The architecture recovery device based on graph neural network according to claim 3 is characterized in that The module M4 specifically includes the following submodules: M41: Used to initialize the graph neural network model GCN as a two-layer model. The units of the first layer model are half of the maximum dimension of the input graph vector, and the units of the second layer model are the dimension of the output vector expression. The number of categories K to be clustered is manually selected, and the loss function is set to the neighbor node similarity as the loss function; M42: Used to train the data in the GCN model, stop training after the loss function converges, and obtain the low-dimensional representation of the node.

Citation Information

Patent Citations

  • Method for identifying key classes in software system based on graph neural network

    CN111913702A

  • Code vulnerability detection method

    CN116108452A