Code maintenance method and device, electronic equipment and storage medium

By collecting data and identifying code relationships in the code base, building a code knowledge graph and extracting metric features, efficient code maintenance is achieved, and the problem of low code maintenance efficiency in the existing technology is solved.

CN119576386APending Publication Date: 2025-03-07CHINA PING AN LIFE INSURANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411756641.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-02
Publication Date
2025-03-07

AI Technical Summary

Technical Problem

The existing code maintenance methods are low in efficiency and are prone to omissions, resulting in complex and time-consuming maintenance processes.

Method used

By collecting data on the preset code base, identifying code coupling relationships, building code knowledge graphs, extracting code metric features, conducting problem detection and maintenance, and reducing manual intervention.

Benefits of technology

It improves the efficiency of code maintenance, reduces the error rate, improves maintenance speed and quality, and reduces the need for manual intervention.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576386A_ABST
    Figure CN119576386A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code maintenance method and device, electronic equipment and a storage medium, belongs to the technical field of development and maintenance, and is suitable for the field of financial science and technology. The method comprises the following steps: performing data collection on a preset code library to obtain source code data; performing code relation identification on the source code data to obtain a code coupling relation; based on the code coupling relationship, performing graph construction on the source code data to obtain a code knowledge graph; performing feature extraction on the code knowledge graph to obtain code measurement features; based on the code measurement features, performing problem detection on the source code data to obtain a code detection log; and performing code maintenance on the source code data based on the code detection log. According to the embodiment of the invention, the code maintenance efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of development and maintenance technology, is applicable to the field of financial technology, and in particular, to a code maintenance method and device, an electronic device, and a storage medium. Background Art

[0002] Code maintenance refers to updating, repairing, and optimizing software source code to ensure its performance, availability, and security, while solving discovered problems and improving code quality. For example, in the financial field, code maintenance of the source code in financial software can ensure the performance, availability, and security of the financial software, thereby ensuring the property safety of users.

[0003] At present, common code maintenance usually involves manually reviewing the source code data of the software or page, and then repairing the source code data based on the review results. However, manual review of source code data is prone to omissions, resulting in low code maintenance efficiency. Therefore, how to improve the efficiency of code maintenance has become a technical problem that needs to be solved urgently. Summary of the invention

[0004] The main purpose of the embodiments of the present application is to provide a code maintenance method and device, an electronic device and a storage medium, aiming to improve the efficiency of code maintenance.

[0005] To achieve the above object, a first aspect of an embodiment of the present application proposes a code maintenance method, the method comprising:

[0006] Collect data from the preset code base to obtain source code data;

[0007] Performing code relationship identification on the source code data to obtain a code coupling relationship;

[0008] Based on the code coupling relationship, a graph is constructed for the source code data to obtain a code knowledge graph;

[0009] Extracting features from the code knowledge graph to obtain code metric features;

[0010] Based on the code metric feature, problem detection is performed on the source code data to obtain a code detection log;

[0011] Based on the code detection log, code maintenance is performed on the source code data.

[0012] In some embodiments, constructing a graph of the source code data based on the code coupling relationship to obtain a code knowledge graph includes:

[0013] Performing element recognition on the source code data to obtain code elements;

[0014] Based on the code coupling relationship and the code elements, construct a code graph database;

[0015] Based on the code elements, construct nodes on the code graph database to obtain graph nodes;

[0016] Based on the code coupling relationship, the code graph database is connected to construct edges to obtain graph connection edges;

[0017] The graph nodes and the graph connection edges are merged to obtain the code knowledge graph.

[0018] In some embodiments, extracting features from the code knowledge graph to obtain code metric features includes:

[0019] Performing community discovery on the code knowledge graph to obtain close nodes, wherein the close nodes are used to represent the graph nodes with similar functions and close dependencies;

[0020] Identify key modules of the code knowledge graph to obtain key nodes;

[0021] Merging the close nodes and the key nodes to obtain a target node;

[0022] Perform node parsing on the target node to obtain the code metric feature.

[0023] In some embodiments, the performing code relationship identification on the source code data to obtain the code coupling relationship includes:

[0024] Performing static code analysis on the source code data to obtain a code static coupling relationship;

[0025] Performing dynamic code parsing on the source code data to obtain a code dynamic coupling relationship;

[0026] The code static coupling relationship and the code dynamic coupling relationship are merged to obtain the code coupling relationship.

[0027] In some embodiments, performing static code parsing on the source code data to obtain a code static coupling relationship includes:

[0028] Performing syntax analysis on the source code data to obtain a code abstract syntax tree;

[0029] Perform node traversal on the code abstract syntax tree to obtain syntax tree nodes;

[0030] Node relationships are identified on the syntax tree nodes to obtain the code static coupling relationship.

[0031] In some embodiments, the performing dynamic code parsing on the source code data to obtain the code dynamic coupling relationship includes:

[0032] Capturing the running log of the source code data to obtain a code running log;

[0033] The code execution log is parsed for execution path to obtain the code dynamic coupling relationship.

[0034] In some embodiments, performing code maintenance on the source code data based on the code detection log includes:

[0035] Perform log analysis on the code detection log to obtain code problems;

[0036] Prioritize the code problems to obtain a problem sequence;

[0037] Based on the problem sequence, the source code data is repaired to obtain a repair code.

[0038] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application proposes a code maintenance device, the device comprising:

[0039] A data acquisition module is used to collect data from a preset code base to obtain source code data;

[0040] A relationship identification module, used to perform code relationship identification on the source code data to obtain a code coupling relationship;

[0041] A graph construction module, used to construct a graph for the source code data based on the code coupling relationship to obtain a code knowledge graph;

[0042] A feature extraction module, used to extract features from the code knowledge graph to obtain code metric features;

[0043] A problem detection module, used to perform problem detection on the source code data based on the code metric features to obtain a code detection log;

[0044] A code maintenance module is used to perform code maintenance on the source code data based on the code detection log.

[0045] To achieve the above objectives, a third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method described in the first aspect is implemented.

[0046] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect is implemented.

[0047] The code maintenance method and device, electronic device and storage medium proposed in the present application automatically collect source code data through a preset code library, then use code relationship recognition technology to detect the code coupling relationship between source code data, and then construct an intuitive code knowledge graph based on the code coupling relationship. Furthermore, code metric features for detecting source code data are extracted from the code knowledge graph, providing a quantitative evaluation basis for code quality. Based on the code metric features, problem detection is performed on the source code data to obtain a code detection log, which can identify potential problems in the code. Finally, code maintenance is performed on the source code data based on the code detection log, thereby reducing the need for manual intervention, reducing the error rate of code maintenance, improving the speed and quality of code maintenance, and effectively improving the efficiency of code maintenance. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 is a flowchart of a code maintenance method provided in an embodiment of the present application;

[0049] Figure 2 yes Figure 1 Flow chart of step S102 in FIG.

[0050] Figure 3 yes Figure 2 Flow chart of step S201 in FIG.

[0051] Figure 4 yes Figure 2 Flow chart of step S202 in FIG.

[0052] Figure 5 yes Figure 1 Flow chart of step S103 in FIG.

[0053] Figure 6 yes Figure 1 Flow chart of step S104 in FIG.

[0054] Figure 7 yes Figure 1 Flow chart of step S106 in FIG.

[0055] Figure 8 It is a structural diagram of a code maintenance device provided in an embodiment of the present application;

[0056] Fig. 9 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0057] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0058] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0059] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0060] First, some nouns involved in this application are analyzed:

[0061] Coupling relationship: Coupling relationship refers to the degree of interdependence between different modules, components or code elements in software engineering. It describes how these elements are related to and influence each other. High coupling means that changes in one module may cause a chain reaction in other modules, while low coupling indicates that the modules are highly independent and changes to one module are unlikely to affect other modules. Ideal software design pursues low coupling and high cohesion to improve the maintainability and scalability of the system.

[0062] Graph database: A graph database is a database system specially designed to store and manage graph-structured data. It uses nodes to represent entities and edges to represent the relationships between entities. It is very suitable for processing complex network analysis, social networks, recommendation systems and other scenarios. It can efficiently perform graph queries and traversal operations, and supports deep correlation analysis between data. Compared with traditional relational databases, it has obvious advantages in processing highly interconnected data.

[0063] Knowledge graph: A knowledge graph is a structured semantic knowledge base that stores the relationships between entities in the form of a graph. Each entity is a node, and the various semantic relationships between entities are edges, thus forming a huge network structure. This structure enables the knowledge graph to effectively represent and process complex data relationships. It is widely used in search engines, recommendation systems, natural language processing and other fields to enhance the cognitive ability of machines and provide more accurate information retrieval services.

[0064] Community algorithms: Community algorithms are a series of methods used to identify community structures in complex networks. A community here refers to a group of nodes in a network that are more closely connected than other nodes. The goal of community discovery algorithms is to divide the nodes in a network into several communities in order to better understand and analyze the structure and function of the network. These algorithms can reveal hidden organizational structures, social groups, and information flow patterns in the network, and are widely used in social network analysis, bioinformatics, financial networks, and other fields. Types of community algorithms include algorithms based on modularity optimization, spectral clustering algorithms based on spectral theory, and so on. Each algorithm has its own specific optimization goals and applicable scenarios, and they use different strategies and mathematical tools to identify community structures in the network. The selection and application of community algorithms depends on the specific characteristics of the network and the needs of the analysis.

[0065] Code maintenance refers to updating, repairing, and optimizing software source code to ensure its performance, availability, and security, while solving discovered problems and improving code quality. For example, in the financial field, code maintenance of the source code in financial software can ensure the performance, availability, and security of the financial software, thereby ensuring the property safety of users.

[0066] At present, common code maintenance usually involves manually reviewing the source code data of the software or page, and then repairing the source code data based on the review results. However, manual review of source code data is prone to omissions, resulting in low code maintenance efficiency. Therefore, how to improve the efficiency of code maintenance has become a technical problem that needs to be solved urgently.

[0067] Based on this, the embodiments of the present application provide a code maintenance method and device, an electronic device, and a storage medium, aiming to improve the efficiency of code maintenance.

[0068] The code maintenance method and device, electronic device and storage medium provided in the embodiments of the present application are specifically described through the following embodiments. First, the code maintenance method in the embodiments of the present application is described.

[0069] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0070] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0071] The code maintenance method provided in the embodiment of the present application relates to the field of development and maintenance technology and is applicable to the field of financial technology. The code maintenance method provided in the embodiment of the present application can be applied to the terminal, can be applied to the server side, and can also be software running in the terminal or the server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, and can also be configured as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the code maintenance method, etc., but is not limited to the above forms.

[0072] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.

[0073] Figure 1 is an optional flowchart of the code maintenance method provided in the embodiment of the present application. Figure 1 The method may include but is not limited to steps S101 to S106.

[0074] Step S101, collecting data from a preset code library to obtain source code data;

[0075] Step S102, performing code relationship identification on source code data to obtain code coupling relationship;

[0076] Step S103, based on the code coupling relationship, construct a graph of the source code data to obtain a code knowledge graph;

[0077] Step S104, extracting features from the code knowledge graph to obtain code metric features;

[0078] Step S105, based on the code metric features, problem detection is performed on the source code data to obtain a code detection log;

[0079] Step S106: performing code maintenance on the source code data based on the code detection log.

[0080] In steps S101 to S106 shown in the embodiment of the present application, data is collected from a preset code base to obtain source code data, and then code relationships are identified on the source code data to obtain code coupling relationships. Further, based on the code coupling relationships, a graph is constructed for the source code data to obtain a code knowledge graph. Next, feature extraction is performed on the code knowledge graph to obtain code metric features. Based on the code metric features, problem detection is performed on the source code data to obtain a code detection log. Finally, code maintenance is performed on the source code data based on the code detection log. Therefore, the present application automatically collects source code data through a preset code library, and then uses code relationship recognition technology to detect the code coupling relationship between source code data, and then constructs an intuitive code knowledge graph based on the code coupling relationship. Furthermore, code measurement features for detecting source code data are extracted from the code knowledge graph, providing a quantitative evaluation basis for code quality. Based on the code measurement features, problem detection is performed on the source code data to obtain a code detection log that can identify potential problems in the code. Finally, based on the code detection log, code maintenance is performed on the source code data, thereby reducing the need for manual intervention, reducing the error rate of code maintenance, improving the speed and quality of code maintenance, and effectively improving the efficiency of code maintenance.

[0081] In step S101 of some embodiments, the code base is a place where software source code data is stored, such as Code Cloud, GitLab, Bitbucket, etc. It should be noted that the code base can be a local file system or a remote server. Source code data is the original code used when writing a program. Source code data is used to define the behavior of the program, such as a script written in Python.

[0082] The present application can obtain the code of the local directory structure by traversing the code of the local directory structure, and then store the code to obtain the source code data.

[0083] In step S102 of some embodiments, the code coupling relationship is used to describe the dependency relationship, calling relationship, reference relationship, etc. between source code data, wherein the source code data may be code elements such as functions, classes, modules, etc. written in code.

[0084] The present application can obtain a static code coupling relationship and a dynamic code coupling relationship by performing static code analysis and dynamic code analysis on source code data, and then obtain a code coupling relationship by combining the static code coupling relationship and the dynamic code coupling relationship.

[0085] For details, see Figure 2 In some embodiments, step S102 may include but is not limited to steps S201 to S205:

[0086] Step S201, performing static code analysis on source code data to obtain a code static coupling relationship;

[0087] Step S202, performing dynamic code analysis on the source code data to obtain a code dynamic coupling relationship;

[0088] Step S203: merge the code static coupling relationship and the code dynamic coupling relationship to obtain a code coupling relationship.

[0089] In step S201 of some embodiments, static code parsing refers to identifying coupling relationships between source code data by parsing the structure and syntax of source code data without running the source code data.

[0090] The present application can construct a code abstract syntax tree by parsing the code elements in the source code data. Furthermore, by analyzing the relationship between the syntax tree nodes in the code abstract syntax tree, the code static coupling relationship between the source code data can be obtained.

[0091] For details, see Figure 3 In some embodiments, step S201 may include but is not limited to steps S301 to S303:

[0092] Step S301, parse the source code data to obtain a code abstract syntax tree;

[0093] Step S302, traversing the code abstract syntax tree to obtain syntax tree nodes;

[0094] Step S303, identifying the node relationship of the syntax tree nodes to obtain the code static coupling relationship.

[0095] In step S301 of some embodiments, the source code data may be lexically parsed to decompose the source code data into a series of tokens, and then the tokens may be combined according to the grammatical rules of the programming language to which the source code data belongs, thereby obtaining a code abstract syntax tree.

[0096] In step S302 of some embodiments, node traversal refers to systematically visiting each node in the code abstract syntax tree.

[0097] The present application can use a depth-first search or a breadth-first search algorithm to traverse the code abstract syntax tree, thereby obtaining information of each node in the code abstract syntax tree and obtaining a syntax tree node.

[0098] In step S303 of some embodiments, the dependency and association relationship between syntax tree nodes can be analyzed to obtain the code static coupling relationship between source code data. For example, if syntax tree node 1 calls syntax tree node 2, then a static coupling relationship exists between syntax tree node 1 and syntax tree node 2. By recording the static coupling relationship, the code static coupling relationship can be obtained.

[0099] In steps S301 to S303 shown in this embodiment, the source code data is parsed to obtain a code abstract syntax tree. Then, the code abstract syntax tree is traversed to obtain syntax tree nodes. Finally, the node relationships of the syntax tree nodes are identified to obtain code static coupling relationships. This can improve the understanding of the code structure, thereby identifying potential quality problems and performance bottlenecks in the code, assisting code refactoring, improving code development efficiency and code readability, and reducing code maintenance costs.

[0100] In step S202 of some embodiments, dynamic code parsing refers to identifying coupling relationships between source code data by monitoring runtime behaviors of source code data when source code data is running.

[0101] The present application can obtain the actual interaction between source code data, that is, the dynamic coupling relationship of the code, by searching the code running log generated when the source code data is running.

[0102] For details, see Figure 4 In some embodiments, step S202 may include but is not limited to steps S401 to S402:

[0103] Step S401, capturing the running log of the source code data to obtain the code running log;

[0104] Step S402: parse the code execution log for the execution path to obtain the code dynamic coupling relationship.

[0105] In step S401 of some embodiments, the local system may obtain an operation log by capturing interactive information of the source code data when the source code data is running. At this time, the operation log is queried to obtain a code operation log.

[0106] In step S402 of some embodiments, execution path parsing refers to parsing data in the code execution log to determine the specific path and logic flow of the source code data execution.

[0107] The present application can obtain the specific path and logical flow of the source code data execution by querying the data describing the source code data execution in the code running log. Furthermore, according to the specific path and logical flow of the source code data execution, the code dynamic coupling relationship between the source code data can be extracted.

[0108] In steps S401 to S402 shown in this embodiment, by capturing the execution log of the source code data to obtain the code execution log, and then performing execution path parsing on the code execution log to obtain the code dynamic coupling relationship, the dynamic interaction and dependency relationship between the source code data can be determined, thereby improving the maintainability and stability of the code.

[0109] In step S203 of some embodiments, a code coupling relationship can be obtained by combining the source code data displayed in the code static coupling relationship with the source code data displayed in the code dynamic coupling relationship. For example, the code static coupling relationship indicates that there is a dependency relationship between source code data A and source code data B, and the code dynamic coupling relationship indicates that there is a calling relationship between source code data A and source code data C. Then, by merging the code static coupling relationship and the code dynamic coupling relationship, a code coupling relationship indicating that there is a dependency relationship between source code data A and source code data B, and a calling relationship between source code data A and source code data C can be obtained.

[0110] In steps S201 to S203 shown in this embodiment, static code parsing is performed on the source code data to obtain a static code coupling relationship. Next, dynamic code parsing is performed on the source code data to obtain a dynamic code coupling relationship. Finally, the static code coupling relationship and the dynamic code coupling relationship are merged to obtain a code coupling relationship. More accurate code coupling information can be obtained, thereby improving the accuracy of code maintenance.

[0111] In step S103 of some embodiments, the code knowledge graph refers to a graphical source code data structure. It should be noted that the code knowledge graph is used to represent the relationship between each source code data. For example, the code knowledge graph can display the inheritance relationship and interaction method between all classes in a software project.

[0112] The present application can identify code elements in source code data, select a code graph database, and then construct nodes and edges of the code graph database according to the above-mentioned code coupling relationship and code elements to obtain a code knowledge graph.

[0113] For details, see Figure 5 In some embodiments, step S103 may include but is not limited to steps S501 to S505:

[0114] Step S501, performing element recognition on source code data to obtain code elements;

[0115] Step S502, constructing a code graph database based on the code coupling relationship and code elements;

[0116] Step S503, constructing nodes in the code graph database based on the code elements to obtain graph nodes;

[0117] Step S504, based on the code coupling relationship, construct connection edges for the code graph database to obtain graph connection edges;

[0118] Step S505, merge the graph nodes and graph connection edges to obtain a code knowledge graph.

[0119] In step S501 of some embodiments, the programming language of the source code data is determined by parsing the source code data, and then various code elements in the source code data, such as variables, functions, classes, etc., can be identified according to the grammatical rules of the programming language.

[0120] In step S502 of some embodiments, the code graph database is a graph database specifically used to store and manage code elements and their relationships, for example, Neo4j.

[0121] The present application can select the type of graph database according to the type of code elements and the code coupling relationship between source code data, and then construct the graph database according to the selected graph database type to obtain a code graph database.

[0122] In step S503 of some embodiments, the nodes of the code graph database can be constructed through the interface and query language provided by the code graph database to obtain the graph nodes.

[0123] It is important to know that graph nodes contain detailed information about code elements, such as the function's documentation string, base classes, parameter names and types, return type, etc.

[0124] In step S504 of some embodiments, the coupling relationship between two graph nodes in the code graph database is identified through the above-mentioned code coupling relationship, and then an edge is created in the code graph database to represent the coupling relationship, thereby obtaining a graph connection edge.

[0125] In step S505 of some embodiments, the above-mentioned graph nodes and graph connection edges are integrated in the code graph database to obtain a code knowledge graph.

[0126] In steps S501 to S505 shown in this embodiment, code elements are obtained by performing element recognition on source code data, and then a code graph database is constructed based on code coupling relationships and code elements. Furthermore, nodes of the code graph database are constructed based on the code elements to obtain graph nodes. Next, connection edges are constructed on the code graph database based on the code coupling relationships to obtain graph connection edges. Finally, graph nodes and graph connection edges are merged to obtain a code knowledge graph, which helps to improve the understanding of the complex structure of the code and the internal connections of the code, thereby improving the accuracy of code maintenance.

[0127] In step S104 of some embodiments, the code metric features refer to features used to evaluate various properties and qualities of the code, such as code dependency, module association, function complexity, etc.

[0128] This application mines special nodes in the code knowledge graph to obtain key graph nodes, and then analyzes the key graph nodes to obtain code metric features.

[0129] For details, see Figure 6 In some embodiments, step S104 may include but is not limited to steps S601 to S604:

[0130] Step S601, performing community discovery on the code knowledge graph to obtain close nodes, wherein the close nodes are used to represent graph nodes with similar functions and close dependencies;

[0131] Step S602, identifying key modules of the code knowledge graph to obtain key nodes;

[0132] Step S603, merging close nodes and key nodes to obtain target nodes;

[0133] Step S604: parse the target node to obtain code metric features.

[0134] In step S601 of some embodiments, community analysis is a graph analysis technology, which aims to divide the graph nodes in the code knowledge graph into several communities or groups, and the connections between the graph nodes in each community are closer than those between the graph nodes in other communities.

[0135] The present application can use a community discovery algorithm to evaluate the density or similarity of edges between graph nodes in a code knowledge graph. Further, based on the density or similarity of edges between graph nodes, the community structure is determined. Then, based on the community structure, several communities are divided from the graph nodes, wherein the graph nodes in each community are close nodes to each other.

[0136] It is important to know that the community discovery algorithm can be a label propagation algorithm, a greedy algorithm based on modularity optimization, or a community discovery algorithm based on edge betweenness, etc.

[0137] In step S602 of some embodiments, key module identification refers to identifying graph nodes that are critical to system functions in the code knowledge graph.

[0138] The present application can identify key graph nodes, i.e., key nodes, in the code knowledge graph by calculating the centrality index of the code knowledge graph, and can also use a graph algorithm to determine the key graph nodes in the code knowledge graph, wherein the graph algorithm can be a Page ranking algorithm or a greedy algorithm based on modularity optimization, etc.

[0139] In step S603 of some embodiments, node merging refers to combining close nodes identified in community discovery and key nodes in key node identification to form a comprehensive node set, namely, a target node.

[0140] The present application marks close nodes and key nodes in the code knowledge graph for easy identification, and further combines the above-marked graph nodes to form a single node, thereby obtaining the target node.

[0141] In step S604 of some embodiments, the code features of the target node can be obtained by reading the attributes of the target node that are helpful in evaluating the code quality, complexity and maintainability. Based on the code features, the code dependency, module association, function complexity and other data of the source code data, i.e., the code metric features, can be calculated.

[0142] In steps S601 to S604 shown in this embodiment, community discovery is performed on the code knowledge graph to obtain close nodes, wherein the close nodes are used to represent graph nodes with similar functions and close dependencies. Furthermore, key modules are identified on the code knowledge graph to obtain key nodes. Next, the close nodes and key nodes are merged to obtain target nodes, thereby simplifying the graph structure of the code knowledge graph, facilitating rapid identification and focusing on graph nodes with similar functions or close dependencies in the code knowledge graph, thereby reducing the complexity of code maintenance. Finally, node parsing is performed on the target node to obtain code metric features, which can increase the speed of locating code problems, thereby improving the efficiency of code maintenance.

[0143] In step S105 of some embodiments, the code metric feature can be compared with a preset code metric feature threshold to determine whether there is a code anomaly in the source code data, and the location and cause of the code anomaly can be recorded to obtain a code detection log, which can reduce manual operations in the source code data detection process and improve the efficiency of code maintenance.

[0144] In step S106 of some embodiments, by querying and parsing the data in the code detection log, abnormal problems occurring in the source code data, i.e., code problems, can be obtained, and the code problems are then arranged to form a problem sequence. Furthermore, the source code data is maintained according to the problem sequence to obtain a repair code.

[0145] For details, see Figure 7 In some embodiments, step S106 may include but is not limited to steps S701 to S703:

[0146] Step S701, parsing the code detection log to obtain code problems;

[0147] Step S702, prioritizing the code issues to obtain an issue sequence;

[0148] Step S703: repair the source code data based on the problem sequence to obtain a repair code.

[0149] In step S701 of some embodiments, log parsing refers to analyzing and processing the code detection log to identify code problems recorded in the code detection log.

[0150] By reading the code detection log, the present application can identify the entry format and entry structure of the code detection log, and then based on the entry format and entry structure, can extract problem information about the source code data, that is, code problems, for example, the error type, error location, possible causes and impacts of the error, etc. of the source code data.

[0151] In step S702 of some embodiments, priority sorting refers to sorting all identified code problems according to the severity, urgency and impact on the system of the code problems.

[0152] The present application can obtain the severity score, urgency score and system impact score of the code problem by performing problem assessment on the code problem, and then perform weighted summation on the severity score, urgency score and system impact score of the above code problem to obtain the priority comprehensive score of the code problem. Furthermore, the code problems are sorted according to the priority comprehensive score to obtain a problem sequence.

[0153] In step S703 of some embodiments, the source code data mentioned in the code problem are modified one by one according to the problem sequence of the code problem, so as to obtain the repair code.

[0154] In steps S701 to S703 shown in this embodiment, code detection logs are parsed to obtain code problems. Then, the code problems are prioritized to obtain a problem sequence. Finally, according to the problem sequence, the source code data is repaired to obtain a repair code, which can reduce rework and thus improve the efficiency of code maintenance.

[0155] The present application automatically collects source code data through a preset code library, and then uses code relationship recognition technology to detect the code coupling relationship between source code data, and then constructs an intuitive code knowledge graph based on the code coupling relationship. Furthermore, code metric features for detecting source code data are extracted from the code knowledge graph, providing a quantitative evaluation basis for code quality. Based on the code metric features, problem detection is performed on the source code data to obtain a code detection log that can identify potential problems in the code. Finally, based on the code detection log, code maintenance is performed on the source code data, thereby reducing the need for manual intervention, reducing the error rate of code maintenance, improving the speed and quality of code maintenance, and effectively improving the efficiency of code maintenance.

[0156] See also Figure 8 The embodiment of the present application also provides a code maintenance device, which can implement the above code maintenance method, and the device includes:

[0157] The data acquisition module 801 is used to collect data from a preset code base to obtain source code data;

[0158] A relationship identification module 802 is used to identify code relationships on source code data to obtain code coupling relationships;

[0159] A graph construction module 803 is used to construct a graph of source code data based on the code coupling relationship to obtain a code knowledge graph;

[0160] The feature extraction module 804 is used to extract features from the code knowledge graph to obtain code metric features;

[0161] A problem detection module 805 is used to perform problem detection on source code data based on code metric features to obtain a code detection log;

[0162] The code maintenance module 806 is used to perform code maintenance on the source code data based on the code detection log.

[0163] The specific implementation of the code maintenance device is substantially the same as the specific implementation of the above-mentioned code maintenance method, and will not be described in detail here.

[0164] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above code maintenance method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.

[0165] See also Fig. 9 , Fig. 9 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:

[0166] The processor 901 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;

[0167] The memory 902 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 902 can store an operating system and other applications. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 902, and the processor 901 calls and executes the code maintenance method of the embodiment of this application;

[0168] Input / output interface 903, used to implement information input and output;

[0169] Communication interface 904, used to realize communication interaction between the device and other devices, which can be realized by wired mode (such as USB, network cable, etc.) or wireless mode (such as mobile network, WIFI, Bluetooth, etc.);

[0170] A bus 905 that transmits information between various components of the device (e.g., the processor 901, the memory 902, the input / output interface 903, and the communication interface 904);

[0171] The processor 901 , the memory 902 , the input / output interface 903 and the communication interface 904 are connected to each other in communication within the device via a bus 905 .

[0172] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned code maintenance method is implemented.

[0173] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0174] The code maintenance method, code maintenance device, electronic device and storage medium provided in the embodiments of the present application automatically collect source code data through a preset code library, then use code relationship recognition technology to detect the code coupling relationship between the source code data, and then construct an intuitive code knowledge graph based on the code coupling relationship. Furthermore, code metric features for detecting source code data are extracted from the code knowledge graph, providing a quantitative evaluation basis for code quality. Based on the code metric features, problem detection is performed on the source code data to obtain a code detection log, which can identify potential problems in the code. Finally, code maintenance is performed on the source code data based on the code detection log, thereby reducing the need for manual intervention, reducing the error rate of code maintenance, improving the speed and quality of code maintenance, and effectively improving the efficiency of code maintenance.

[0175] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0176] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.

[0177] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0178] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.

[0179] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0180] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0181] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. The mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0182] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0183] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0184] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.

[0185] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.

Claims

1. A code maintenance method, characterized in that: The method comprises: Collect data from the preset code base to obtain source code data; Performing code relationship identification on the source code data to obtain a code coupling relationship; Based on the code coupling relationship, a graph is constructed for the source code data to obtain a code knowledge graph; Extracting features from the code knowledge graph to obtain code metric features; Based on the code metric feature, problem detection is performed on the source code data to obtain a code detection log; Based on the code detection log, code maintenance is performed on the source code data.

2. The method according to claim 1, characterized in that The step of constructing a graph of the source code data based on the code coupling relationship to obtain a code knowledge graph includes: Performing element recognition on the source code data to obtain code elements; Based on the code coupling relationship and the code elements, construct a code graph database; Based on the code elements, construct nodes on the code graph database to obtain graph nodes; Based on the code coupling relationship, the code graph database is connected to construct edges to obtain graph connection edges; The graph nodes and the graph connection edges are merged to obtain the code knowledge graph.

3. The method according to claim 2, characterized in that The feature extraction of the code knowledge graph to obtain code metric features includes: Performing community discovery on the code knowledge graph to obtain close nodes, wherein the close nodes are used to represent the graph nodes with similar functions and close dependencies; Identify key modules of the code knowledge graph to obtain key nodes; Merging the close nodes and the key nodes to obtain a target node; Perform node parsing on the target node to obtain the code metric feature.

4. The method according to claim 1, characterized in that: The performing code relationship identification on the source code data to obtain a code coupling relationship includes: Performing static code analysis on the source code data to obtain a code static coupling relationship; Performing dynamic code parsing on the source code data to obtain a code dynamic coupling relationship; The code static coupling relationship and the code dynamic coupling relationship are merged to obtain the code coupling relationship.

5. The method according to claim 4, characterized in that The performing static code analysis on the source code data to obtain a code static coupling relationship includes: Performing syntax analysis on the source code data to obtain a code abstract syntax tree; Perform node traversal on the code abstract syntax tree to obtain syntax tree nodes; Node relationships are identified on the syntax tree nodes to obtain the code static coupling relationship.

6. The method according to claim 4, characterized in that The dynamically parsing the source code data to obtain a code dynamic coupling relationship includes: Capturing the running log of the source code data to obtain a code running log; The code execution log is parsed for execution path to obtain the code dynamic coupling relationship.

7. The method according to any one of claims 1 to 6, characterized in that: The performing code maintenance on the source code data based on the code detection log includes: Perform log analysis on the code detection log to obtain code problems; Prioritize the code problems to obtain a problem sequence; Based on the problem sequence, the source code data is repaired to obtain a repair code.

8. A code maintenance device, characterized in that: The device comprises: A data acquisition module is used to collect data from a preset code base to obtain source code data; A relationship identification module, used to perform code relationship identification on the source code data to obtain a code coupling relationship; A graph construction module, used to construct a graph for the source code data based on the code coupling relationship to obtain a code knowledge graph; A feature extraction module, used to extract features from the code knowledge graph to obtain code metric features; A problem detection module, used to perform problem detection on the source code data based on the code metric features to obtain a code detection log; A code maintenance module is used to perform code maintenance on the source code data based on the code detection log.

9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the code maintenance method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the code maintenance method according to any one of claims 1 to 7 is implemented.