Method and System for Constructing a Code Map Oriented to Functional Features

By extracting the functional features of the code base and designing the code link extraction algorithm, the problem that code maps in the existing technology are difficult to show the overall construction framework of the code base, and the effect of helping developers to deeply understand the code base is achieved.

CN119718276BActive Publication Date: 2025-06-03PEKING UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510246230.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-04
Publication Date
2025-06-03
Estimated Expiration
2045-03-04

AI Technical Summary

Technical Problem

Existing code map applications focus on code details, making it difficult for developers to understand the overall construction framework of the code base, resulting in inefficient developers' understanding of the code base.

Method used

By extracting the functional features of the code base, designing code link extraction algorithms, abstract classes, methods and other shallow modules are used as deep modules, and visually display them to achieve a gradual mastery of the code base.

Benefits of technology

Help developers to fully and in-depth understanding of complex code bases, reduce the cognitive load during the understanding process, and improve the efficiency of code base understanding.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718276B_ABST
    Figure CN119718276B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for constructing a code map oriented to functional features, belonging to the technical field of computer software. The method includes: extracting the functional features of a software project; constructing a knowledge graph of the software project; matching relevant nodes in the knowledge graph according to the functional features by using the description attributes of the nodes to obtain a subgraph, and obtaining a code link oriented to the functional features based on the subgraph; rendering the code link oriented to the functional features to obtain a code map. The present invention can abstract shallow modules such as classes and methods into deep modules for visual display, and gradually master the code library.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of computer software, and relates to a method and system for constructing a code map oriented to functional features. Background Art

[0002] A code map is a method and technology for graphically displaying the software code structure to help developers understand and navigate complex code libraries. Existing code map applications mainly focus on the correlation analysis of the code information of software projects. For example, after performing control flow and call relationship analysis on a single file, a flow chart, call graph, etc. that control the file are drawn; or the functions and symbols in all project files are listed and then correlated with each other. These code maps focus too much on code details and cannot grasp the overall construction framework of the code library, resulting in low efficiency for developers to understand the code library. During the project development process, in order to facilitate maintenance, large code files are hierarchically decoupled, resulting in a large number of methods, classes, or modules. However, the existing code maps with methods and classes as basic units have too many details, making it difficult for developers to understand the overall functions and architectures of the project.

[0003] In order to help developers comprehensively and deeply understand complex code libraries layer by layer and reduce the cognitive load during the understanding process, it is necessary to propose a method for constructing a code map oriented to functional features. Summary of the Invention

[0004] The present invention provides a method and system for constructing a code map oriented to functional features, which can extract the functional features of a code library by inputting the source code files of the code library, design a corresponding code link extraction algorithm to extract the links of fine-grained function points, and after basically dividing the links according to the specifications in project development, abstract shallow modules such as classes and methods into deep modules for visual display, so as to gradually master the code library. Among them, a shallow module refers to a module with relatively complex interfaces compared to the provided small functions.

[0005] To achieve the above object, the technical solution of the present invention includes the following content.

[0006] A method for constructing a code map oriented to functional features, the method comprising:

[0007] Extracting the functional features of a software project;

[0008] Constructing a knowledge graph of the software project;

[0009] Matching relevant nodes in the knowledge graph according to the functional features by using the description attributes of the nodes to obtain a subgraph, and obtaining a code link oriented to the functional feature based on the subgraph;

[0010] Rendering the code link oriented to the functional feature to obtain a code map.

[0011] Further, extract the functional features of the software project, including:

[0012] Construct a file tree based on the code files of the software project; wherein, the root node of the file tree is the project root directory, and the leaf nodes of the file tree are individual code files;

[0013] Perform functional analysis on each node in the file tree to obtain a file - function tree;

[0014] The large - language model interactively extracts the functional features of the software project according to the file - function tree.

[0015] Further construct the knowledge graph of the software project, including:

[0016] Perform static analysis on the backend files to obtain the relationships between the first entities, and use the descriptions of the first entities as the attributes of the first entities; wherein, the first entities include: code file entities, class / interface entities, and method entities, and the relationship types between the first entities include: the inclusion relationship of code file entities to method entities, the inheritance relationship of class / interface entities to class / interface entities, the reference relationship of class / interface entities to method entities, and the call relationship of method entities to method entities;

[0017] Analyze the frontend files to obtain the relationships between the second entities, and use the descriptions of the second entities as the attributes of the second entities; wherein, the second entities include: vue file entities, js file entities, and html file entities, and the relationship types between the second entities include: vue file entities import relevant functions in js file entities, js file entities listen to elements in html file entities, vue file entities import and reuse elements in vue file entities, and js file entities import relevant functions in js file entities;

[0018] Generate the knowledge graph of the software project based on the first entities, the relationships between the first entities, the second entities, and the relationships between the second entities.

[0019] Further, obtain the code link for the functional feature based on the sub - graph, including:

[0020] The large - language model extends the sub - graph to obtain the backend code link for the fine - grained functional feature;

[0021] Based on the backend code link, extend forward to obtain the frontend code link;

[0022] Find the interface files of the front-end and back-end code links related to database operations, and based on the SQL statements in the interface files, extend the front-end and back-end code links related to database operations to the database tables to obtain the code links for this functional feature.

[0023] Further, based on the forward extension of the back-end code link, obtain the front-end code link, including:

[0024] Specify the request path;

[0025] Make the back-end aware of the request path by adding annotations in the.java file;

[0026] Use axios-related functions in the js file and send a request to the back-end based on the request path;

[0027] Use the large language model to compare the request path known by the back-end with the request path corresponding to the request to obtain the interface API file of the back-end code link;

[0028] Based on the interface API file of the back-end code link, perform forward extension to obtain the front-end code link.

[0029] Further, find the interface files of the front-end and back-end code links related to database operations, including:

[0030] Based on the SQL statements in the xml file, obtain the mapper tags, and according to the statement scope prompted by the mapper tags, obtain the interface files of the front-end and back-end code links related to database operations;

[0031] Or,

[0032] Through semantic analysis of the large language model, find the interface files related to database operations in the front-end and back-end code links.

[0033] Further, render the code link for this functional feature to obtain a code map, including:

[0034] Subdivide the code link for this functional feature; among them, the subdivision includes:

[0035] Aggregate the interface API files connecting the front-end code link and the interfaces / classes and methods in the interface API files into the control layer;

[0036] Aggregate the interface files related to database operations and the interfaces / classes and methods in the interface files into the persistence layer;

[0037] The remaining code files in the code link for this functional feature and the interfaces / classes and methods of the code files are aggregated into the business logic layer;

[0038] Render based on the segmentation result to obtain a code map.

[0039] A code map construction system for functional features, the system includes:

[0040] A functional feature extraction module for extracting the functional features of a software project;

[0041] A knowledge graph construction module for constructing the knowledge graph of the software project;

[0042] A code link generation module for matching relevant nodes in the knowledge graph according to the functional features by using the description attributes of the nodes to obtain a sub-graph, and obtaining a code link for the functional feature based on the sub-graph;

[0043] A code link rendering module for rendering the code link for the functional feature to obtain a code map.

[0044] An electronic device, the electronic device includes: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the code map construction method for functional features described in any one of the above is implemented.

[0045] A computer-readable storage medium, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the code map construction method for functional features described in any one of the above is implemented.

[0046] Compared with the prior art, the present invention has at least the following beneficial effects.

[0047] The user uses the source code file of the project as the input of the tool, extracts the functional features of the project code from the global to the local first, and then from the local to the global, gradually masters the code library by understanding the fine-grained function points, so as to help developers comprehensively and deeply understand the complex code library while reducing the cognitive load of developers' understanding of the project code. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 Is the overall implementation framework of the present invention.

[0049] Figure 2 Are the functional features extracted by the present invention.

[0050] Figure 3 Is the code link of the fine-grained function obtained by the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0051] The present invention will be further described in detail below with reference to the accompanying drawings. The examples given are only for explaining the present invention and are not intended to limit the scope of the present invention.

[0052] The present invention first constructs a file - function tree based on the project's file directory in combination with a large - language model to interactively obtain the functional features of the project; then, through static analysis of code files, relevant nodes and relationships are extracted to construct a knowledge graph; furthermore, a code link mining algorithm oriented to functional features is used to obtain and subdivide the entire code link for developers to understand; finally, the code link is rendered visually on the front - end.

[0053] As Figure 1 shown, the code map oriented to functional features of the present invention is constructed through the following steps.

[0054] Step 1: Extract the functional features of the software project.

[0055] According to the code files of the software project to be analyzed, the present invention first constructs its file tree, with the root node being the project root directory and the leaf nodes being individual code files. Then, each node in the file tree is summarized layer by layer from bottom to top to obtain the file - function tree. The large - language model interactively extracts the functional features of the project based on the file - function tree.

[0056] Step 2: Construct the knowledge graph of the software project.

[0057] Static analysis is performed on the software project files to construct a knowledge graph. For the back - end files, the entities obtained through static analysis include files, classes / interfaces, and methods, and the relationship types include the inclusion relationship of the code file to the class / interface; the inclusion relationship of the code file to the method; the inheritance relationship of the class / interface entity to the class / interface entity; the reference relationship of the class / interface entity to the method; the call relationship of the method to the method. In addition, a summary is generated for each entity as a description of the entity's attribute. For the front - end files, the entities obtained through analysis include vue files, js files, and html files, and the relationship types include the vue file importing relevant functions in the js file; the js file listening to elements in the html file; the vue file importing and reusing elements (such as input boxes) in the vue file; the js file importing relevant functions in the js file. In addition, a summary is generated for each entity as a description of the node's attribute.

[0058] Step 3: Match relevant nodes in the knowledge graph according to the functional features using the description attributes of the nodes to obtain a sub - graph, and obtain the code link oriented to the functional feature based on the sub - graph.

[0059] Step 3.1: Retrieve and match relevant nodes in the knowledge graph according to the fine - grained functional features using the description attributes of the nodes to obtain a sub - graph, and then the large - language model expands the sub - graph to obtain the back - end code link related to the fine - grained functional features.

[0060] Step 3.2: Expand forward based on the backend code link to obtain the frontend code link.

[0061] Generally, to implement the request for dynamic resources from the frontend to the server side (backend), Ajax technology is usually required. In the js file, relevant axios functions are used and the request path is specified to send a request to the server side (backend). The server side (backend) needs to specify the request path through annotations such as @controller and @RequestMapping in the.java file. By using the large language model technology to compare the request paths, the interface API file of the backend code link can be identified, realizing the expansion of the backend code link to the frontend code link.

[0062] Step 3.3: Locate the interface files of the frontend and backend code links related to database operations, and based on the sql statements in the interface files, expand the frontend and backend code links related to database operations to the database tables to obtain the code link for this functional feature.

[0063] There are two ways for the server side (backend) to implement database operations. The first way requires using a configuration file xml. The sql statements encapsulated in the xml file will use the mapper tag, and the scope of the statement is prompted in this tag. Through the scope, the interface file of the backend code link can be found. The second way is to directly embed the sql statements through annotations such as @Mapper and a series of operation annotations in the interface file of the server side (backend). Through semantic analysis using the large language model, the interface file of the backend code link can be found. After obtaining the interface file, by viewing its sql statements, it can be extended to specific database tables, thereby obtaining the code link for this functional feature.

[0064] Step 4: Render the code link for the functional feature to obtain the code map.

[0065] Step 4.1: Subdivide the overall code link.

[0066] To reduce the cognitive load of developers in understanding the code library, the present invention subdivides the backend code link, including: the interface API file identified in Step 3.2 and the interfaces / classes and methods therein are aggregated into the control layer (Controller) in the three-tier architecture, whose function is to accept requests and respond with data; the interface file identified in Step 3.3 and the interfaces / classes and methods therein are aggregated into the persistence layer (Dao), whose function is data operation (insert, delete, update, query); the code files in the remaining backend code link and the interfaces / classes and methods therein are aggregated into the business logic layer (Service), whose function is to process specific business logics.

[0067] Step 4.2: Render based on the subdivision result to obtain a code map.

[0068] In summary, the present invention first discloses a method for extracting functional features based on a project file - function tree. When dealing with complex projects, constructing a file - function tree can help us better understand and manage various parts of the project. The file - function tree is a graphical tool that displays the functions of the project according to the file hierarchy structure, starting from the overall function at the highest level and gradually refining to specific sub - functions. Through this method, we can clearly see all the functional features of the project, including their relationships and hierarchies. Specifically, by analyzing project files, we can identify the key functions of the project and construct a function tree based on them. This helps project managers and team members have a comprehensive understanding of the project, thereby planning, executing, and monitoring the project more effectively.

[0069] The present invention also discloses an algorithm for mining code links oriented to functional features. During software development and maintenance, developers may need to understand how a specific function in the code is implemented and its running path in the entire system. By identifying and analyzing this functional feature, every step of it in the code can be traced, starting from the initial call until the final execution ends. This method helps understand the logic of complex code, diagnose and solve programming problems, and optimize and refactor the code.

[0070] The present invention visualizes the design of forming deep modules from shallow modules. When designing software or a system, some surface - level and simple functional modules are analyzed and summarized to extract deeper - level and more abstract modules, and the relationships and structures between these modules are intuitively displayed in a graphical way. This helps better understand the internal structure of the system, making the design clearer and easier to manage.

[0071] To verify the effectiveness of the present invention, 4 software projects related to personal blog systems in the Java language were selected for experimental verification, all of which are high - star open - source projects on GitHub. Figure 2 Shows the functional features extracted from a blog system. Figure 3 Illustrates the subdivided code link of a fine - grained function (user login).

[0072] Although specific embodiments of the present invention are disclosed for illustrative purposes, aiming to help understand the content of the present invention and implement it accordingly, those skilled in the art can understand that: without departing from the spirit and scope of the present invention and the appended claims, various substitutions, changes, and modifications are possible. Therefore, the present invention should not be limited to the content disclosed in the best embodiments, and the scope of protection required by the present invention is defined by the scope of the claims.

Claims

1. A method for constructing a code map oriented to functional features, characterized in that: The method comprises: Extract functional features of software projects; Constructing a knowledge graph of the software project; According to the functional feature, the relevant nodes are matched in the knowledge graph using the description attributes of the nodes to obtain a subgraph, and a code link oriented to the functional feature is obtained based on the subgraph; wherein the code link oriented to the functional feature is obtained based on the subgraph, including: Expand the subgraph from the large language model to obtain the backend code link related to the fine-grained functional features; Based on the forward expansion of the backend code link, a frontend code link is obtained; wherein, based on the forward expansion of the backend code link, a frontend code link is obtained, including: Specify the request path; By adding annotations in the .java file, the backend is informed of the request path; Use axios related functions in the js file and send requests to the backend based on the request path; Use the large language model to compare the request path learned by the backend with the request path corresponding to the request, and obtain the interface API file of the backend code link; Expand forward according to the interface API file of the backend code link to obtain the frontend code link; Find the interface file of the front-end and back-end code link related to the database operation, and expand the front-end and back-end code link related to the database operation to the database table based on the SQL statement of the interface file to obtain the code link for the functional feature; wherein, finding the interface file of the front-end and back-end code link related to the database operation includes: Get the mapper tag based on the SQL statement in the XML file, and get the interface file of the front-end and back-end code links related to the database operation according to the statement scope prompted by the mapper tag; or, Through semantic analysis of the large language model, find the interface files related to database operations in the front-end and back-end code links; Rendering the functional feature-oriented code link to obtain a code map; wherein rendering the functional feature-oriented code link to obtain a code map includes: The code link for the functional feature is subdivided; wherein the subdivision includes: Aggregate the interface API file that connects the front-end code link and the interfaces / classes and methods in the interface API file into a control layer; Aggregate the interface files related to database operations and the interfaces / classes and methods in the interface files into a persistence layer; The remaining code files in the code link for the functional feature and the interfaces / classes and methods of the code files are aggregated into a business logic layer; Rendering is performed based on the segmentation results to obtain a code map.

2. The method according to claim 1, characterized in that Extract the functional characteristics of the software project, including: Construct a file tree according to the code files of the software project; wherein the root node of the file tree is the project root directory, and the leaf nodes of the file tree are single code files; Perform function analysis on each node in the file tree to obtain a file-function tree; The large language model interactively extracts the functional features of the software project based on the file-function tree.

3. The method according to claim 1, characterized in that Constructing the knowledge graph of the software project includes: Static analysis is performed on the backend file to obtain the relationship between the first entity and the first entity, and the description of the first entity is used as the attribute of the first entity; wherein the first entity includes: code file entity, class / interface entity and method entity, and the relationship types between the first entities include: inclusion relationship between code file entity and method entity, inheritance relationship between class / interface entity and class / interface entity, reference relationship between class / interface entity and method entity, and calling relationship between method entity and method entity; Analyze the front-end file to obtain the relationship between the second entity and the second entity, and use the description of the second entity as the attribute of the second entity; wherein the second entity includes: vue file entity, js file entity and html file entity, and the relationship types between the second entities include: vue file entity imports relevant functions in js file entity, js file entity listens to elements in html file entity, vue file entity imports and reuses elements in vue file entity, and js file entity imports relevant functions in js file entity; A knowledge graph of the software project is generated based on the first entity, the relationship between the first entities, the second entity, and the relationship between the second entities.

4. A code map construction system oriented to functional features, characterized in that: The system comprises: Functional feature extraction module, used to extract functional features of software projects; A knowledge graph construction module, used to construct a knowledge graph of the software project; A code link generation module is used to match relevant nodes in the knowledge graph using the description attributes of the nodes according to the functional features to obtain a subgraph, and obtain a code link oriented to the functional features based on the subgraph; wherein obtaining a code link oriented to the functional features based on the subgraph includes: Expand the subgraph from the large language model to obtain the backend code link related to the fine-grained functional features; Based on the forward expansion of the backend code link, a frontend code link is obtained; wherein, based on the forward expansion of the backend code link, a frontend code link is obtained, including: Specify the request path; By adding annotations in the .java file, the backend is informed of the request path; Use axios related functions in the js file and send requests to the backend based on the request path; Use the large language model to compare the request path learned by the backend with the request path corresponding to the request, and obtain the interface API file of the backend code link; Expand forward according to the interface API file of the backend code link to obtain the frontend code link; Find the interface file of the front-end and back-end code link related to the database operation, and expand the front-end and back-end code link related to the database operation to the database table based on the SQL statement of the interface file to obtain the code link for the functional feature; wherein, finding the interface file of the front-end and back-end code link related to the database operation includes: Get the mapper tag based on the SQL statement in the XML file, and get the interface file of the front-end and back-end code links related to the database operation according to the statement scope prompted by the mapper tag; or, Through semantic analysis of the large language model, find the interface files related to database operations in the front-end and back-end code links; The code link rendering module is used to render the code link oriented to the functional features to obtain a code map; wherein the rendering of the code link oriented to the functional features to obtain the code map includes: The code link for the functional feature is subdivided; wherein the subdivision includes: Aggregate the interface API file that connects the front-end code link and the interfaces / classes and methods in the interface API file into a control layer; Aggregate the interface files related to database operations and the interfaces / classes and methods in the interface files into a persistence layer; The remaining code files in the code link for the functional feature and the interfaces / classes and methods of the code files are aggregated into a business logic layer; Rendering is performed based on the segmentation results to obtain a code map.

5. An electronic device, characterized in that: The electronic device comprises: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the function-feature-oriented code map construction method as described in any one of claims 1 to 3 is implemented.

6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the method for constructing a code map oriented to functional features as described in any one of claims 1 to 3 is implemented.

Citation Information

Patent Citations

  • Vulnerability code graph construction and code vulnerability detection method based on knowledge graph

    CN114692155A

  • Software knowledge graph incremental updating method based on code submission

    CN115543402A