Function feature-oriented code map construction method and system
By extracting the functional features and code links of the code base, abstracting the shallow module into a deep module, building a code map for functional features, solving the problem that existing technology is difficult to show the overall construction framework of the code base, and improving the developers' understanding of the code base efficiency.
Patent Information
- Application Number
- CN202510246230.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-04
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2045-03-04
AI Technical Summary
Existing code map applications pay attention to code details and are difficult to show the overall construction framework of the code base, resulting in inefficient developers' understanding.
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, visually displaying, and building a code map for functional features.
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.
Smart Images

Figure CN119718276A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer software technology and relates to a method and system for constructing a code map oriented to functional features. Background Art
[0002] Code map is a method and technology that displays the structure of software code in a graphical way to help developers understand and navigate complex code bases. Existing code map applications mainly focus on correlation analysis of code information of software projects, such as drawing flowcharts and call graphs that control a single file after analyzing the control flow and call relationship of the file; or listing the functions and symbols in all project files and then associating them with each other. These code maps focus too much on code details and fail to grasp the overall construction framework of the code base, resulting in inefficient understanding of the code base by developers. During the project development process, in order to facilitate maintenance, large code files are layered and 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 architecture of the project.
[0003] In order to help developers understand complex code bases comprehensively, deeply, and layer by layer, and reduce the cognitive load during the understanding process, it is necessary to propose a code map construction method 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 the code library by inputting the source code file of the code library, and design a corresponding code link extraction algorithm to extract the links of fine-grained functional points, and after the links are basically divided according to the specifications in project development, shallow modules such as classes and methods are abstracted into deep modules for visual display, so as to gradually master the code library. Among them, shallow modules refer to modules with relatively complex interfaces relative to the small functions provided.
[0005] To achieve the above objectives, the technical solution of the present invention includes the following contents.
[0006] A method for constructing a code map oriented to functional features, the method comprising: 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 for the functional feature is obtained based on the subgraph; Render the code links oriented to functional features to obtain a code map.
[0007] Furthermore, the functional features of the software project are extracted, 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.
[0008] Further 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.
[0009] Furthermore, obtaining a code link for the functional feature 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; Expanding forward based on the backend code link to obtain a frontend code link; Find the interface file of the front-end and back-end code links related to database operations, and based on the SQL statements of the interface file, expand the front-end and back-end code links related to database operations to the database table to obtain the code link for the functional feature.
[0010] Further, 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; The interface API file of the backend code link is extended forward to obtain the frontend code link.
[0011] Furthermore, find the interface files of the front-end and back-end code links related to database operations, including: 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, the interface files related to database operations in the front-end and back-end code links are found.
[0012] Furthermore, rendering the code link for the functional feature 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.
[0013] A code map construction system oriented to functional features, the system comprising: 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, 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 for the functional features based on the subgraph; The code link rendering module is used to render the code link oriented to functional features to obtain a code map.
[0014] An 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 described in any one of the above items is implemented.
[0015] A computer-readable storage medium having computer program instructions stored thereon, wherein the computer program instructions, when executed by a processor, implement any of the above-mentioned function-feature-oriented code map construction methods.
[0016] Compared with the prior art, the present invention has at least the following beneficial effects.
[0017] Users use the project's source code files as input to the tool, first extracting the functional features of the project code from the global to the local, and then from the local to the global, gradually mastering the code base by understanding fine-grained functional points, thereby helping developers to fully and deeply understand complex code bases while reducing the cognitive load on developers' understanding of project codes. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 It is the overall implementation framework of the present invention.
[0019] Figure 2 The functional features extracted for the present invention.
[0020] Figure 3 The code link for the fine-grained functions obtained by the present invention. DETAILED DESCRIPTION
[0021] The present invention is further described in detail below in conjunction with the accompanying drawings. The examples given are only used to explain the present invention but not to limit the scope of the present invention.
[0022] The present invention first constructs a file-function tree based on the file directory of the project and in combination with a large language model to interactively obtain the functional features of the project; then, by statically analyzing the code files, relevant nodes and relationships are extracted to construct a knowledge graph; and then, 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.
[0023] like Figure 1 As shown, the function-feature-oriented code map of the present invention is constructed through the following steps.
[0024] Step 1: Extract the functional characteristics of the software project.
[0025] The present invention first constructs a file tree based on the code files of the software project to be analyzed, wherein the root node is the project root directory and the leaf node is a single code file. Then, each node in the file tree is summarized layer by layer from bottom to top to obtain a file-function tree. The large language model interactively extracts the functional features of the project based on the file-function tree.
[0026] Step 2: Build a knowledge graph for the software project.
[0027] Static analysis is performed on the software project file to construct a knowledge graph. Static analysis is performed on the back-end file, and the entities obtained include files, classes / interfaces, and methods. 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 calling relationship of the method to the method. In addition, a summary is generated for each entity as the attribute of the entity. The front-end file is analyzed, and the entities obtained include vue files, js files, and html files. The relationship types include the vue file importing the relevant functions in the js file; the js file listening to the elements in the html file; the vue file importing and reusing the elements in the vue file (such as the input box); the js file importing the relevant functions in the js file. In addition, a summary is generated for each entity as the attribute of the node.
[0028] Step 3: According to the functional features, the description attributes of the nodes are used to match the relevant nodes in the knowledge graph to obtain a subgraph, and the code link for the functional features is obtained based on the subgraph.
[0029] Step 3.1: Retrieve and match relevant nodes in the knowledge graph using the description attributes of the nodes based on the fine-grained functional features to obtain a subgraph. The subgraph is then expanded by the large language model to obtain the backend code link related to the fine-grained functional features.
[0030] Step 3.2: Expand forward based on the backend code link to obtain the frontend code link.
[0031] The front end generally needs to use Ajax technology to request dynamic resources from the server (back end). In the js file, use axios related functions and specify the request path to send requests to the server (back end). The server (back end) needs to specify the request path by adding annotations such as @controller and @RequestMapping in the .java file. By comparing the request path using the large language model technology, the interface API file of the back end code link can be identified, and the back end code link can be extended to the front end code link.
[0032] Step 3.3: Find the interface file of the front-end and back-end code links related to database operations, and based on the SQL statements of the interface file, expand the front-end and back-end code links related to database operations to the database table to obtain the code link for the functional feature.
[0033] There are two ways to operate the database on the server side (backend). The first one requires the use of the configuration file xml. The sql statement encapsulated in the xml file will use the mapper tag, which indicates the scope of the statement. The interface file of the backend code link can be found through the scope. The second one is to directly embed the sql statement in the server side (backend) interface file through the annotation @Mapper and a series of operation annotations. The interface file of the backend code link can be found through semantic analysis of the large language model. After obtaining the interface file, by viewing its sql statement, it can be expanded to a specific database table, thereby obtaining the code link for the functional feature.
[0034] Step 4: Render the code links oriented to functional features to obtain a code map.
[0035] Step 4.1: Break down the overall code link.
[0036] In order to reduce the cognitive load of developers in understanding the code base, the present invention subdivides the backend code chain, including: the interface API files identified in step 3.2 and the interfaces / classes and methods therein are aggregated into the control layer (Controller) in the three-layer architecture, whose function is to accept requests and respond to data; the interface files identified in step 3.3 and the interfaces / classes and methods therein are aggregated into the persistence layer (Dao), whose function is data operation (addition, deletion, modification and query); the code files in the remaining backend code chain and the interfaces / classes and methods therein are aggregated into the business logic layer (Service), whose function is to process specific business logic.
[0037] Step 4.2: Render based on the segmentation results to obtain a code map.
[0038] 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, building a file-function tree can help us better understand and manage the 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 functions at the highest level and gradually refining them to specific sub-functions. In this way, we can clearly see all the functional features of the project, including the relationships and hierarchies between them. Specifically, by analyzing the project files, we can identify the key functions of the project and build a function tree based on them. This helps project managers and team members have a comprehensive understanding of the project, so as to plan, execute and monitor the project more effectively.
[0039] The present invention also discloses a code link mining algorithm oriented to functional features. In the process of 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, each step of it in the code can be traced, starting from the initial call to the end of the final execution. This method helps to understand the logic of complex code, diagnose and solve problems in programming, and optimize and refactor code.
[0040] The present invention abstracts shallow modules into a visual design of deep modules. When designing software or systems, some superficial and simple functional modules are analyzed and summarized to extract deeper and more abstract modules, and the relationship and structure between these modules are intuitively displayed in a graphical way. This helps to better understand the internal structure of the system, making the design clearer and easier to manage.
[0041] In order to verify the effect of the present invention, four Java language software projects related to personal blog systems were selected for experimental verification, all of which were high-star open source projects on GitHub. Figure 2 Shows the functional features extracted from a blog system. Figure 3 This shows the code link after the breakdown of a fine-grained function (user login).
[0042] Although the specific embodiments of the present invention are disclosed for the purpose of illustration, the purpose is to help understand the content of the present invention and implement it accordingly, those skilled in the art will understand that various substitutions, changes and modifications are possible without departing from the spirit and scope of the present invention and the appended claims. Therefore, the present invention should not be limited to the content disclosed in the best embodiment, and the scope of the present invention is subject to the scope defined in 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 features, 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 features is obtained based on the subgraph; Render the code links oriented to functional features 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. The method according to claim 1, characterized in that Acquiring a code link for the functional feature 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; Expanding forward based on the backend code link to obtain a frontend code link; Find the interface file of the front-end and back-end code links related to database operations, and based on the SQL statements of the interface file, expand the front-end and back-end code links related to database operations to the database table to obtain the code link for the functional feature.
5. The method according to claim 4, characterized in that 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; The interface API file of the backend code link is extended forward to obtain the frontend code link.
6. The method according to claim 5, characterized in that Find the interface files of the front-end and back-end code links related to database operations, including: 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, the interface files related to database operations in the front-end and back-end code links are found.
7. The method according to claim 6, characterized in that The rendering of the code link for the functional feature 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.
8. 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, used to match relevant nodes in the knowledge graph using the description attributes of the nodes according to the functional features, obtain a subgraph, and obtain a code link oriented to the functional features based on the subgraph; The code link rendering module is used to render the code link oriented to functional features to obtain a code map.
9. 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 7 is implemented.
10. 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 7 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
Method and device for constructing interactive low-code knowledge graph
CN116595191A
Calling link generation method based on Java static code analysis
CN118312250A
Method and equipment for generating code map for project and storage medium
CN119512531A