Code quality adaptive evaluation and optimization method, system, equipment and medium

By cleaning up and standardizing the code to generate an abstract syntax tree, and using deep learning and neural networks to analyze dependencies and automatically generate optimization suggestions, the problem of low efficiency in existing code quality assessment and optimization is solved, achieving efficient and accurate code quality improvement.

CN121210282APending Publication Date: 2025-12-26浪潮智慧科技有限公司 +2
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202511046400.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-29
Publication Date
2025-12-26

AI Technical Summary

Technical Problem

Existing code quality assessment methods are inefficient, inaccurate, and unable to adapt to the personalized coding standards of different projects. Traditional optimization methods rely on human experience and are costly. The evaluation and optimization processes are disconnected, resulting in low efficiency in code quality improvement.

Method used

By cleaning up and standardizing redundant information in the original code, an abstract syntax tree is generated. Semantic vectors are extracted using a deep learning model, and dependencies are analyzed using a neural network. Optimization suggestions are automatically generated, and the model and algorithm are iteratively optimized based on feedback.

Benefits of technology

It enables automated evaluation and optimization of code quality, improves code readability and maintainability, reduces development costs and risks, enhances development efficiency and team collaboration, and adapts to the personalized needs of different projects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121210282A_ABST
    Figure CN121210282A_ABST
Patent Text Reader

Abstract

The invention provides a code quality adaptive evaluation and optimization method, system and device and a medium, and belongs to the technical field of computers. The method comprises the following steps: performing redundant information cleaning and standardization processing on an original code; selecting an adaptive parser to convert the processed code into an abstract syntax tree, and optimizing the abstract syntax tree; performing embedding processing on each node of the abstract syntax tree by using a pre-trained deep learning model to generate a node semantic vector, and performing aggregation, feature extraction and vector normalization operation to obtain a semantic vector representing code semantic features; extracting a dependency relationship from the abstract syntax tree to construct a program dependency graph, extracting node features by using a neural network model, and generating a dependency relationship analysis result; based on the semantic vector and the dependency analysis result, identifying a code potential problem by using an optimization algorithm and generating an optimization suggestion; codes are automatically modified according to optimization suggestions, the optimization effect is re-evaluated, and related models and algorithms are iteratively optimized according to feedback information.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer technology, and more specifically relates to a method, system, device and medium for adaptive evaluation and optimization of code quality. Background Technology

[0002] In modern software development, code quality, as a core indicator for measuring the reliability, maintainability, and scalability of a software system, directly impacts project development efficiency, operational costs, and the competitiveness of the final product. With the continuous expansion of software scale and the increasing complexity of its architecture, the nesting levels of code logic deepen, and the coupling relationships between modules become increasingly complex. Traditional code quality assurance methods are no longer sufficient to meet the demands of rapid iterative development. How to efficiently and accurately assess code quality and achieve targeted optimization has become a critical problem that urgently needs to be solved in the field of software engineering. Among existing code quality assessment methods, manual review remains a core tool relied upon by many teams. This approach depends on the accumulated experience of senior developers, identifying potential problems through code walkthroughs, review meetings, and other means. However, manual review has significant limitations: firstly, it is extremely inefficient; for large projects with millions of lines of code, a comprehensive review often takes weeks or even months, severely lagging behind the development schedule; secondly, the assessment results are greatly influenced by subjective factors, as different developers have different understandings of coding standards, making it difficult to unify quality standards and easily overlooking hidden logical flaws or performance vulnerabilities. The emergence of static analysis tools has alleviated the pressure of manual review to some extent. By automating code scanning through preset rules, they can quickly identify explicit issues such as syntax errors, non-standard naming, and potential null pointers. However, these tools also have significant drawbacks: First, their rule bases are fixed and lack flexibility, failing to adapt to the personalized coding standards of different projects, leading to a large number of false positives or false negatives. Second, they can only perform surface-level analysis based on code structure, and are powerless to address deeper, implicit issues such as logical coupling, inefficient algorithms, and lack of exception handling.

[0003] In the code optimization phase, traditional optimization methods heavily rely on developers' personal experience, requiring engineers to manually refactor identified problems using domain knowledge. This demands not only strong programming skills and architectural design abilities from developers but also a significant investment of time in verifying solutions. For small to medium-sized teams or inexperienced developers, this approach not only increases labor costs but may also introduce new code risks due to inappropriate optimization solutions. Furthermore, existing evaluation and optimization processes are often disconnected, preventing evaluation results from being directly translated into actionable optimization strategies, further reducing the efficiency of code quality improvement. Summary of the Invention

[0004] To address the above problems, the present invention aims to provide a method, system, device, and medium for adaptive code quality assessment and optimization, which can automatically assess code quality and adaptively optimize the code based on the assessment results. This not only improves the readability and maintainability of the code but also reduces development costs and risks.

[0005] To achieve the above objectives, the present invention employs the following technical solution: In a first aspect, embodiments of this application provide a method for adaptive code quality assessment and optimization, including: The original code undergoes redundancy cleanup and standardization to generate processed code. Select the appropriate parser to convert the processed code into an abstract syntax tree, and optimize the abstract syntax tree; Using a pre-trained deep learning model, the nodes of the abstract syntax tree are embedded to generate node semantic vectors. Through aggregation, feature extraction and vector normalization operations, semantic vectors representing the semantic features of the code are obtained. Dependencies are extracted from the abstract syntax tree to construct a program dependency graph. A neural network model is used to extract node features to identify critical paths, circular dependencies, redundant code, and potential security vulnerabilities in the code, generating dependency analysis results. Based on the semantic vector and dependency analysis results, optimization algorithms are used to identify potential code problems and generate optimization suggestions. The code is automatically modified based on optimization suggestions, the optimization effect is re-evaluated, and the relevant models and algorithms are iteratively optimized based on feedback information.

[0006] In an optional implementation, the process of cleaning up and standardizing redundant information in the original code includes: Remove all comments from the original code; Format the original code to a uniform style, and standardize the use of indentation and spaces in the original code. Break the code down into logically independent code segments.

[0007] In an optional implementation, the selected parser converts the processed code into an abstract syntax tree and optimizes the abstract syntax tree, including: Select a suitable parser based on the programming language corresponding to the original code, and use the parser to convert the processed code into an abstract syntax tree; The generated abstract syntax tree is optimized by removing irrelevant nodes and merging similar nodes to obtain an optimized abstract syntax tree.

[0008] In an optional implementation, the step of using a pre-trained deep learning model to embed nodes of the abstract syntax tree to generate node semantic vectors, and obtaining semantic vectors representing the semantic features of the code through aggregation, feature extraction, and vector normalization operations, includes: Select a pre-trained deep learning model and input the abstract syntax tree into the deep learning model; The deep learning model is used to embed each node of the abstract syntax tree to generate a node semantic vector. The semantic vectors of all nodes are aggregated using averaging, weighted averaging, or pooling operations to generate a semantic representation of the code snippet; The semantic representation of the code snippet is subjected to feature extraction and vector normalization to generate a semantic vector that represents the semantic features of the code. By calculating the similarity of semantic vectors of different code fragments, repetitive or similar logic in the code can be identified.

[0009] In an optional implementation, the step of extracting dependencies from the abstract syntax tree to construct a program dependency graph, and using a neural network model to extract node features to identify critical paths, circular dependencies, redundant code, and potential security vulnerabilities in the code, generating dependency analysis results, includes: Extract variable definition and usage relationships, function call relationships, and control flow statement dependencies from the abstract syntax tree; A program dependency graph is constructed based on the extracted dependencies; where nodes in the program dependency graph represent code elements and edges represent dependencies between elements. Optimize the program dependency graph by removing redundant edges. Choose either the GraphSAGE model or the GAT model as the graph structure analysis model; The training set constructed from the historical program dependency graph is used to input the graph structure analysis model for model training, in order to learn the dependencies between nodes and the topology of the graph; The program dependency graph is input into the trained graph structure analysis model to extract features including node type, semantic vectors and dependency relationships. This identifies critical paths, circular dependencies, redundant code and potential security vulnerabilities in the code and generates dependency analysis results.

[0010] In an optional implementation, the step of identifying potential code problems and generating optimization suggestions based on the semantic vectors and dependency analysis results includes: Based on the semantic vector and dependency analysis results, an optimization algorithm is used to identify potential problems in the code and generate optimization suggestions including code refactoring, performance optimization, and security improvement. By combining code function descriptions, parameter lists, and contextual information with a natural language generation model, optimization suggestions are converted into human-readable text.

[0011] In one optional implementation, the step of automatically modifying the code based on optimization suggestions, re-evaluating the optimization effect, and iteratively optimizing the relevant models and algorithms based on feedback information includes: The code is automatically modified based on optimization suggestions, the quality of the optimized code is evaluated, and dependency analysis results are generated. Receive feedback from developers on the optimization results; if developers manually modify the code, input the modification results into the system. The deep learning model, graph structure analysis model, and optimization algorithm are iteratively optimized based on feedback information.

[0012] Secondly, embodiments of this application also provide a code quality adaptive evaluation and optimization system, including: The code preprocessing module is used to clean up redundant information and standardize the original code, generating processed code. The Abstract Syntax Tree (ABS) building module is used to select the appropriate parser to convert the processed code into an ABS and optimize the ABS. The semantic analysis module is used to embed nodes of the abstract syntax tree using a pre-trained deep learning model to generate node semantic vectors. Through aggregation, feature extraction and vector normalization operations, semantic vectors representing the semantic features of the code are obtained. The dependency analysis module is used to extract dependencies from the abstract syntax tree to construct the program dependency graph, and to use a neural network model to extract node features to identify critical paths, circular dependencies, redundant code and potential security vulnerabilities in the code, and generate dependency analysis results. The optimization suggestion generation module is used to identify potential problems in the code and generate optimization suggestions based on the semantic vector and dependency analysis results; The iterative optimization module is used to automatically modify the code based on optimization suggestions, re-evaluate the optimization effect, and iteratively optimize the relevant models and algorithms based on feedback information.

[0013] Thirdly, embodiments of this application also provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the code quality adaptive evaluation and optimization method as described in any of the above.

[0014] Fourthly, embodiments of this application also provide a storage medium storing a computer program thereon, wherein the computer program, when executed by a processor, implements the steps of the code quality adaptive evaluation and optimization method as described in any of the above.

[0015] As can be seen from the above technical solutions, the present invention has the following advantages: The adaptive code quality assessment and optimization method provided in this application first extracts the changed code and constructs its Abstract Syntax Tree (AST). A deep learning model is then used to perform semantic analysis on the code, generating semantic vector representations. Next, a Program Dependency Graph (PDG) is constructed, and a Graph Neural Network (GNN) is used to analyze the dependencies between code elements. Combining the results of semantic analysis and graph structure analysis, a natural language generation model automatically generates optimization suggestions to help developers improve code quality. The newly generated optimization suggestions are reviewed by a quality assessment module to ensure their accuracy and readability. Finally, the optimization suggestions are integrated into the codebase through integration and deployment steps, thereby achieving automated maintenance and optimization of code quality. The entire process involves multiple advanced technologies such as deep learning, natural language processing, and graph structure analysis to improve code readability and maintainability.

[0016] This application standardizes the original code, unifying indentation, spaces, and other formatting specifications, and decomposes the code into logically independent segments, making the code structure clearer. Simultaneously, optimization suggestions generated through semantic analysis can specifically improve code logic. Combined with readable text generated from natural language, this makes it easier for developers to understand the code's functionality and design principles, significantly reducing the understanding cost during subsequent maintenance and substantially improving code readability and long-term maintainability.

[0017] This application leverages pre-trained deep learning and graph neural network models to not only identify explicit problems in code but also uncover deeper, hidden defects such as logical coupling, algorithmic inefficiency, and security vulnerabilities. Through automated evaluation and optimization, it effectively reduces redundant code and circular dependencies. Furthermore, the optimization suggestions cover both performance and security improvements, enhancing code reliability from multiple dimensions and systematically improving code quality.

[0018] This application replaces traditional manual inspection and optimization with an automated process, saving a significant amount of time and cost associated with manual review and code walkthrough. For large projects, it eliminates the need for extensive manpower for comprehensive inspection, and the optimization process reduces repetitive modifications caused by insufficient human experience, thereby lowering manpower and time consumption, significantly reducing quality assurance costs in the development cycle, and effectively reducing development costs.

[0019] This application frees developers from spending time and energy on basic issues such as code formatting and simple logical flaws, allowing them to focus more on business logic design and core functionality implementation. The automated evaluation and optimization process quickly provides feedback on issues and offers improvement solutions, reducing developers' repeated attempts at quality debugging, accelerating development iterations, and significantly improving overall development efficiency.

[0020] This application generates objective code quality reports and optimization suggestions based on unified evaluation standards, avoiding subjective differences in manual evaluation and providing a consistent quality reference framework for team members. Clear optimization suggestions enable the team to have clear goals during code reviews, reducing communication disagreements. At the same time, standardized code format and structure ensure a more consistent coding style among different developers, enhancing the smoothness of team collaboration.

[0021] This application continuously iterates and optimizes its evaluation algorithm and model by receiving feedback from developers, enabling it to adapt to the personalized needs and technological evolution of different projects. As data accumulates and the model is upgraded during use, the accuracy of the evaluation and the relevance of the optimization suggestions gradually improve, forming a virtuous cycle of "evaluation-optimization-feedback-iteration." This continuously improves the system's performance and provides more efficient support for long-term code quality enhancement. Attached Figure Description

[0022] To more clearly illustrate the technical solution of the present invention, the accompanying drawings used in the description will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0023] Figure 1 A flowchart illustrating the adaptive evaluation and optimization method for code quality provided in this application.

[0024] Figure 2 A schematic diagram of the structure of the code quality adaptive evaluation and optimization system provided in this application.

[0025] Figure 3 A schematic diagram of the structure of the electronic device provided in this application. Detailed Implementation

[0026] The various embodiments of this disclosure will be described more fully in the detailed steps of the adaptive code quality assessment and optimization method described below. This disclosure may have various embodiments, and adjustments and changes may be made therein. However, it should be understood that there is no intention to limit the various embodiments of this disclosure to the specific embodiments disclosed herein, but rather this disclosure should be understood to cover all adjustments, equivalents, and / or alternatives falling within the spirit and scope of the various embodiments of this disclosure.

[0027] In the following, the terms “comprising” or “may include”, which may be used in various embodiments of this disclosure, indicate the presence of the disclosed functions, operations, or elements, and do not limit the addition of one or more functions, operations, or elements. Furthermore, as used in various embodiments of this disclosure, the terms “comprising,” “having,” and their cognates are intended only to indicate a particular feature, number, step, operation, element, component, or combination of the foregoing, and should not be construed as primarily excluding the presence of one or more other features, numbers, steps, operations, elements, components, or combinations of the foregoing, or the possibility of adding one or more combinations of the foregoing.

[0028] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0029] Please see Figure 1 The diagram shows a flowchart of a code quality adaptive evaluation and optimization method in a specific embodiment. The method includes: S1: Clean up and standardize redundant information in the original code to generate processed code.

[0030] In a specific implementation, the original code is first scanned to identify and remove all types of comments (such as line comments and multi-line comments starting with # in Python, and single-line comments and multi-line comments in Java). Although comments help with code readability, they do not affect the actual execution logic of the code, so they are removed in the preprocessing stage to simplify the subsequent processing flow.

[0031] Next, format the code to a consistent style. For example, for Python code, stipulate that four spaces should be used as the indentation unit, instead of mixing tabs and spaces; for Java code, specify the rules for using curly braces (e.g., the left curly brace must be at the end of the line, and the right curly brace must be at the beginning of the next line and aligned with the left curly brace of the previous line). Also, standardize the use of spaces, such as adding a space between keywords (e.g., if, for, etc.) and parentheses, and on both sides of operators (e.g., +, -, =, etc.) to ensure consistent code style.

[0032] Finally, the entire code is broken down into logically independent segments, such as functions, classes, and modules. For example, in Python, the `def` keyword is used to determine the start of a function, and the `class` keyword is used to define the scope of a class; in Java, keywords such as `public class` and `private function` are used to segment the code into segments so that these independent segments can be analyzed separately later.

[0033] S2: Select an appropriate parser to convert the processed code into an abstract syntax tree and optimize the abstract syntax tree.

[0034] In specific implementations, the appropriate parser is first selected based on the programming language of the code. For example, for Python code, the built-in ast module of Python is used as the parser; for Java code, the ANTLR parser is used. These parsers can accurately identify and parse the syntactic structure of the corresponding language.

[0035] The preprocessed code is then fed into the selected parser. The parser performs lexical and syntactic analysis on the code, transforming it into an Abstract Syntax Tree (AST). An AST is a tree-like data structure where each node represents a syntactic construct in the code, such as a variable declaration node, a function call node, or a control flow statement node (e.g., if statement, for statement, etc.). For example, in Python, the `ast.parse()` function can parse code into an AST, and the structural information of the code can be obtained by traversing the nodes of the AST.

[0036] Finally, the generated AST is optimized. Specifically, this includes: removing irrelevant nodes, such as nodes containing only formatting information, which, although formatted during preprocessing, may still contain redundant representations in the AST; and merging similar nodes, for example, merging consecutive variable declaration statements into a single node to simplify the AST structure and improve the efficiency of subsequent processing.

[0037] S3: Using a pre-trained deep learning model, embedding is performed on each node of the abstract syntax tree to generate node semantic vectors. Through aggregation, feature extraction and vector normalization operations, semantic vectors representing the semantic features of the code are obtained.

[0038] In a specific implementation, the specific process of this step is as follows: S301: Select a deep learning model. Choose a suitable model for code semantic analysis from among the many pre-trained deep learning models, such as CodeBERT or GraphCodeBERT. These models have been pre-trained on large amounts of code data and have a good understanding of code semantics. For example, CodeBERT is a pre-trained model based on the Transformer architecture, which can capture semantic information and contextual relationships in the code.

[0039] S302: Embedding AST Nodes. The optimized AST is input into the selected deep learning model. The model embeds each node of the AST, converting it into a high-dimensional semantic vector. This semantic vector can characterize the semantic features of the code segment represented by the node. For example, the semantic vector of a function call node can reflect the function's purpose, parameter meanings, and other semantic information.

[0040] S303: Aggregate Semantic Vectors. A specific method is used to aggregate the semantic vectors of all nodes to generate a semantic representation of the entire code snippet. This can be achieved using a simple averaging method, averaging the semantic vectors of all nodes along each dimension; a weighted averaging method can be used, assigning different weights to nodes based on their importance in the code (e.g., function nodes have higher weights than ordinary variable nodes); or more complex pooling operations, such as max pooling or min pooling, can be used to extract key features from the semantic vectors.

[0041] S304: Feature Extraction and Vector Normalization. Key features are extracted from the aggregated semantic representation. These features highlight the semantic information of the code. For example, principal component analysis (PCA) and other dimensionality reduction methods are used to extract the main feature components. Next, the extracted feature vectors are normalized to a length of 1. This eliminates differences in the magnitude of different semantic vectors, ensuring comparability in subsequent similarity calculations and other operations.

[0042] S305: Semantic Similarity Calculation. This calculates the similarity between the semantic vectors of different code segments. Cosine similarity can be used to measure the cosine of the angle between two semantic vectors; the closer the value is to 1, the more similar the semantics. This method can identify parts of the code that contain repetitive or similar logic, providing a basis for subsequent optimization (such as eliminating redundant code).

[0043] S4: Extract dependencies from the abstract syntax tree to construct a program dependency graph, and use a neural network model to extract node features to identify critical paths, circular dependencies, redundant code, and potential security vulnerabilities in the code, generating dependency analysis results.

[0044] In a specific implementation, the specific process of this step includes: S401: Extract Dependencies. Extract various dependencies from the AST (Abstract Syntax Tree). First, the definition and usage relationships of variables; for example, finding where a variable is defined and all locations referencing it in the code. Second, the function call relationships, including the function call hierarchy (e.g., function A calls function B, and function B calls function C). Third, the dependencies of control flow statements, such as the dependency between the condition and execution branch of an if statement, and the dependency between the loop variable and the loop body of a for statement.

[0045] S402: Constructing a Program Dependency Graph (PDG). The PDG is constructed based on the extracted dependencies. In the PDG, nodes represent individual elements in the code (such as variables, functions, control flow statements, etc.), and edges represent the dependencies between elements. For example, a variable definition node points to a node that uses that variable, representing a usage dependency; a function call node points to a node that calls the function, representing a call dependency. In this way, the structure and dependencies of the code are visually represented in the form of a graph.

[0046] S403: Optimize PDG. Optimize the constructed PDG by removing redundant edges. For example, if there is an indirect dependency path (such as node A depending on node B, node B depending on node C, and node A also directly depending on node C), redundant direct dependency edges can be removed to simplify the PDG structure and improve the efficiency of subsequent analysis.

[0047] S404: Select a Graph Neural Network (GNN) model. Choose a suitable GNN model for graph structure analysis from among the many available, such as GraphSAGE or GAT. These models can handle graph structure data and delve into the complex relationships between nodes. For example, GraphSAGE learns the embedding representation of nodes by sampling and aggregating the features of neighboring nodes; GAT, on the other hand, uses an attention mechanism to dynamically assign different weights to neighboring nodes, highlighting the influence of important neighboring nodes.

[0048] S405: Model Training and Dependency Analysis. The training set constructed from historical PDGs is input into the selected GNN model for training. During training, the model learns the dependencies between nodes and the topological features of the graph. After training, the PDG to be analyzed is input into the trained GNN model to extract node features (including node type, semantic vectors, and dependencies). By analyzing the model's output, critical paths in the code (such as critical computation paths in loops and critical decision paths in conditional branches), circular dependencies (such as circular dependencies formed by mutual function calls), redundant code (such as meaningless variable assignment operations), and potential security vulnerabilities (such as code injection vulnerabilities caused by improper handling of user input) can be identified, ultimately generating detailed dependency analysis results.

[0049] S5: Based on the semantic vector and dependency analysis results, use optimization algorithms to identify potential code problems and generate optimization suggestions.

[0050] In a specific implementation, firstly, based on the semantic vectors obtained in step S3 and the dependency analysis results in step S4, optimization algorithms are used to identify potential problems in the code. For example, by analyzing the similarity of semantic vectors, multiple redundant function implementations are found in the code, thus identifying redundant code issues; by analyzing circular dependencies in the PDG, code sections that may cause deadlocks or performance degradation during program execution are identified. Based on these problems, corresponding optimization suggestions are generated, such as merging redundant code and refactoring circular dependencies. These optimization suggestions cover multiple aspects, including code refactoring, performance optimization, and security improvements.

[0051] Then, a Natural Language Generation (NLG) model is used to convert the generated optimization suggestions into human-readable text. During training, the NLG model learns a large number of code-comment pairs, understanding the mapping between code semantics and natural language descriptions. When generating optimization suggestions, the model combines functional descriptions of the code (such as function comments, class usage descriptions, etc.), parameter lists (such as function input and output parameters), and contextual information (such as the business logic implied by variable names and method names) to generate detailed, accurate, and easy-to-understand optimization suggestion text. For example, for a performance bottleneck problem, the NLG model can generate optimization suggestions such as "In the function `compute`, nested loops cause excessive time complexity; it is recommended to optimize the loops, such as replacing nested loops with vectorized operations."

[0052] Meanwhile, the system's rule engine standardizes the style and content of optimization suggestions based on programming experience and community best practices. For example, it stipulates that the text of optimization suggestions should use concise and clear language and be organized according to the structure of "problem description - cause analysis - improvement suggestions"; for suggestions on security improvements, it should emphasize the possible risk level and the urgency of the fix, to ensure the quality and usability of the optimization suggestions.

[0053] S6: Automatically modify the code based on optimization suggestions, re-evaluate the optimization effect, and iteratively optimize the relevant models and algorithms based on feedback information.

[0054] In a specific implementation, the code is first automatically modified based on the optimization suggestions generated in step S5. For example, redundant code snippets mentioned in the suggestions are automatically deleted or merged; for performance optimization suggestions, the code structure or algorithm implementation is automatically adjusted. The modified code then goes through the processing flow of steps S1 to S4 again for quality assessment, and dependency analysis results are regenerated to verify whether the optimization effect has achieved the expected results.

[0055] Then, the system receives feedback from developers regarding the optimization results. Developers can review the optimized code and submit feedback through the interface in their Integrated Development Environment (IDE) or Continuous Integration / Continuous Deployment (CI / CD) workflow. If developers are not satisfied with the automatically optimized code, they can manually modify it and re-enter the modified code into the system.

[0056] Finally, based on the feedback provided by the developers, the deep learning model, graph structure analysis model, and optimization algorithm are iteratively optimized. For example, if a developer reports that an optimization suggestion is not applicable or causes new problems, the feedback can be analyzed to adjust the parameters of the deep learning model, enabling it to more accurately understand the code in subsequent semantic analysis; or the training strategy of the GNN model can be improved to enhance its ability to analyze code structure and dependencies; the rules and parameters of the algorithm can also be optimized to generate more reasonable optimization suggestions, thereby continuously improving the performance and accuracy of the entire code quality adaptive evaluation and optimization method.

[0057] In this embodiment, by performing redundancy cleanup and standardization on the original code, generating and optimizing the abstract syntax tree with the help of an adapting parser, extracting semantic vectors using a pre-trained deep learning model to capture code semantics, and combining program dependency graphs and neural network models such as GraphSAGE and GAT to analyze dependencies and identify critical paths, vulnerabilities, and other issues, an optimization algorithm generates understandable optimization suggestions. Based on these suggestions, the code is automatically modified, and the model and algorithm are iteratively optimized based on developer feedback. This achieves comprehensiveness and accuracy in code quality assessment, improves the efficiency and targeting of code optimization, and continuously enhances the maintainability, security, and performance of the code through adaptive iteration, thus achieving the beneficial effect of efficiently improving code quality.

[0058] like Figure 2 As shown, the following are embodiments of the code quality adaptive evaluation and optimization system provided in this disclosure. This system and the code quality adaptive evaluation and optimization methods in the above embodiments belong to the same inventive concept. For details not described in detail in the embodiments of the code quality adaptive evaluation and optimization system, please refer to the embodiments of the above code quality adaptive evaluation and optimization methods.

[0059] An adaptive code quality assessment and optimization system, comprising: The code preprocessing module is used to clean up redundant information and standardize the original code, generating processed code.

[0060] The Abstract Syntax Tree (AST) building module is used to select an appropriate parser to convert the processed code into an AST and optimize the AST.

[0061] The semantic analysis module uses a pre-trained deep learning model to embed nodes of the abstract syntax tree to generate node semantic vectors. Through aggregation, feature extraction, and vector normalization operations, semantic vectors representing the semantic features of the code are obtained.

[0062] The dependency analysis module is used to extract dependencies from the abstract syntax tree to construct the program dependency graph, and to use a neural network model to extract node features to identify critical paths, circular dependencies, redundant code and potential security vulnerabilities in the code, and generate dependency analysis results.

[0063] The optimization suggestion generation module is used to identify potential problems in the code and generate optimization suggestions based on the semantic vector and dependency analysis results.

[0064] The iterative optimization module is used to automatically modify the code based on optimization suggestions, re-evaluate the optimization effect, and iteratively optimize the relevant models and algorithms based on feedback information.

[0065] It is important to note that the adaptive code quality assessment and optimization system provided in this embodiment can be integrated into existing development environments, such as IDEs or CI / CD workflows. Specifically, the system integrates with IDEs or CI / CD tools via API to automate the code quality assessment and optimization process. Developers can automatically trigger the execution of adaptive code quality assessment and optimization methods through IDEs or CI / CD workflows to achieve continuous improvement in code quality.

[0066] The system can automatically implement adaptive code quality assessment and optimization methods to achieve continuous code quality improvement. Specifically, the system monitors all commit actions in the code repository through hooks in version control systems (such as Git), including post-commit or pre-push hooks. Whenever a developer commits an update to the code repository, the corresponding hook triggers an automated script. This script calls the system API to automatically trigger the code quality assessment and optimization process. The optimized code is then reassessed to ensure the effectiveness of the optimization.

[0067] The code quality adaptive assessment and optimization system provided in this embodiment cleans up redundancy and standardizes the original code, generates and optimizes the abstract syntax tree using an adapter parser, extracts semantic vectors using a pre-trained deep learning model, analyzes dependencies based on program dependency graphs and neural network models to identify critical paths, vulnerabilities, and other issues, and then generates suggestions and automatically modifies the code through optimization algorithms. It can also iteratively optimize the model and algorithm based on feedback. This system not only efficiently cleans up redundant information, accurately extracts code semantics and dependencies, and comprehensively identifies potential problems, but also automatically generates optimization suggestions and dynamically iterates and optimizes, thereby significantly improving the accuracy and efficiency of code quality assessment and enhancing code maintainability, security, and performance.

[0068] Figure 3 A schematic diagram of the hardware structure of an electronic device for implementing various embodiments of the present invention.

[0069] The code quality adaptive evaluation and optimization method provided in this application can be applied to electronic devices. Those skilled in the art will understand that the electronic device structure involved in the embodiments of this invention does not constitute a limitation on the electronic device. An electronic device may include more or fewer components than illustrated, or combine certain components, or have different component arrangements. In the embodiments of this invention, the electronic device includes, but is not limited to, laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the embodiments of this application described and / or claimed herein.

[0070] Electronic devices may include processors, external memory interfaces, internal memory, universal serial bus (USB) interfaces, charging management modules, power management modules, batteries, wireless communication modules, audio modules, speakers, microphones, sensor modules, buttons, cameras, displays, and SIM card interfaces, etc.

[0071] A processor may include one or more processing units, such as: a central processing unit (CPU), an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU). Different processing units may be independent devices or integrated into one or more processors.

[0072] The processor can serve as the nerve center and command center of an electronic device. The controller can generate operation control signals based on the instruction opcode and timing signals to control the fetching and execution of instructions.

[0073] The processor may also include memory for storing instructions and data. In some embodiments, the memory in the processor is a cache memory. This memory can store instructions or data that the processor has just used or that are used repeatedly. If the processor needs to use the instruction or data again, it can retrieve it directly from this memory. This avoids repeated accesses, reduces processor latency, and thus improves system efficiency.

[0074] An external storage interface (ESI) can be used to connect external memory cards, such as microSD cards, to expand the storage capacity of electronic devices. The external memory card communicates with the processor through the ESI to perform data storage functions, such as saving music and video files on the external memory card.

[0075] Internal memory can be used to store computer executable program code, which includes instructions. The processor executes various functional applications and data processing of electronic devices by running the instructions stored in internal memory. Internal memory can include a program storage area and a data storage area. Internal memory can include high-speed random access memory, and can also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.

[0076] Wireless communication functionality in electronic devices can be achieved through antennas, wireless communication modules, modem processors, and baseband processors.

[0077] Wireless communication modules can provide solutions for wireless communication applications in electronic devices, including wireless local area networks (WLANs) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies.

[0078] Electronic devices can implement audio functions through audio modules, speakers, receivers, microphones, headphone jacks, and application processors.

[0079] Electronic devices can achieve shooting functions through ISPs, cameras, video codecs, GPUs, displays, and application processors.

[0080] Electronic devices can achieve display functions through GPUs, displays, and application processors.

[0081] A GPU is a microprocessor for image processing, connected to the display screen and application processor. GPUs are used to perform mathematical and geometric calculations for graphics rendering. A processor may include one or more GPUs, which execute program instructions to generate or modify display information.

[0082] A display screen is used to display images, videos, etc. A display screen includes a display panel.

[0083] The aforementioned electronic device implements the adaptive code quality assessment and optimization method of this application. By cleaning up redundancy and standardizing the original code, generating and optimizing the abstract syntax tree in conjunction with the adapter parser, extracting semantic vectors using a pre-trained deep learning model, analyzing dependencies based on the program dependency graph and neural network model, generating suggestions and automatically modifying the code with the help of optimization algorithms, and iteratively optimizing the model and algorithm based on feedback, the method achieves the beneficial effects of improving the accuracy and efficiency of code quality assessment, and enhancing code maintainability, security and performance.

[0084] The storage medium provided in this application stores a program product capable of implementing an adaptive code quality assessment and optimization method.

[0085] Adaptive code quality assessment and optimization methods include: The original code undergoes redundancy cleanup and standardization to generate processed code. Select the appropriate parser to convert the processed code into an abstract syntax tree, and optimize the abstract syntax tree; Using a pre-trained deep learning model, the nodes of the abstract syntax tree are embedded to generate node semantic vectors. Through aggregation, feature extraction and vector normalization operations, semantic vectors representing the semantic features of the code are obtained. Dependencies are extracted from the abstract syntax tree to construct a program dependency graph. A neural network model is used to extract node features to identify critical paths, circular dependencies, redundant code, and potential security vulnerabilities in the code, generating dependency analysis results. Based on the semantic vector and dependency analysis results, optimization algorithms are used to identify potential code problems and generate optimization suggestions. The code is automatically modified based on optimization suggestions, the optimization effect is re-evaluated, and the relevant models and algorithms are iteratively optimized based on feedback information.

[0086] In some possible implementations, the code quality adaptive evaluation and optimization method of this disclosure can be implemented as a program product comprising program code that, when the program product is run on a terminal device, causes the terminal device to perform the steps described in the "Exemplary Methods" section of this specification according to various exemplary embodiments of this disclosure.

[0087] The storage medium disclosed herein may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof.

[0088] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for adaptive evaluation and optimization of code quality, characterized in that, The method comprises the following steps: cleaning and standardizing the original code to generate processed code; selecting an appropriate parser to convert the processed code into an abstract syntax tree and optimizing the abstract syntax tree; using a pre-trained deep learning model to embed each node of the abstract syntax tree to generate a node semantic vector, aggregating all node semantic vectors by using an average, weighted average or pooling operation to generate a semantic representation of the code segment, and performing feature extraction and vector normalization on the semantic representation of the code segment to generate a semantic vector representing the semantic features of the code; extracting dependency relationships from the abstract syntax tree to construct a program dependency graph, using a neural network model to extract node features to identify key paths, circular dependencies, redundant code and potential security vulnerabilities in the code, and generating a dependency analysis result; based on the semantic vector and the dependency analysis result, using an optimization algorithm to identify potential problems in the code and generate optimization suggestions; automatically modifying the code according to the optimization suggestions, re-evaluating the optimization effect, and iterating the related models and algorithms according to the feedback information.

2. The method of code quality adaptive evaluation and optimization of claim 1, wherein, The cleaning and standardizing of the original code comprises the following steps: deleting all comments in the original code; formatting the original code into a unified style, and unifying the indentation and space usage specifications of the original code; decomposing the code into logically independent code segments.

3. The method of code quality adaptive evaluation and optimization of claim 2, wherein, The selection of an appropriate parser to convert the processed code into an abstract syntax tree and the optimization of the abstract syntax tree comprise the following steps: selecting an appropriate parser according to the programming language corresponding to the original code, and converting the processed code into an abstract syntax tree through the parser; optimizing the generated abstract syntax tree to remove irrelevant nodes and combine similar nodes, thereby obtaining an optimized abstract syntax tree.

4. The method of code quality adaptive evaluation and optimization of claim 3, wherein, The use of a pre-trained deep learning model to embed each node of the abstract syntax tree to generate a node semantic vector, and the aggregation, feature extraction and vector normalization operations comprise the following steps: selecting a pre-trained deep learning model and inputting the abstract syntax tree into the deep learning model; embedding each node of the abstract syntax tree through the deep learning model to generate a node semantic vector; aggregating all node semantic vectors by using an average, weighted average or pooling operation to generate a semantic representation of the code segment; performing feature extraction and vector normalization on the semantic representation of the code segment to generate a semantic vector representing the semantic features of the code; identifying repeated or similar logic in the code by calculating the similarity of different code segment semantic vectors.

5. The method of code quality adaptive evaluation and optimization of claim 4, wherein, The extraction of dependency relationships from the abstract syntax tree to construct a program dependency graph, and the use of a neural network model to extract node features to identify key paths, circular dependencies, redundant code and potential security vulnerabilities in the code, and the generation of a dependency analysis result comprise the following steps: extracting variable definition and usage relationships, function call relationships and control flow statement dependency relationships from the abstract syntax tree; constructing a program dependency graph based on the extracted dependency relationships; wherein the nodes of the program dependency graph represent code elements, and the edges represent the dependency relationships between the elements; optimizing the program dependency graph to remove redundant edges in the graph; selecting a GraphSAGE model or a GAT model as a graph structure analysis model; The training set constructed from the historical program dependency graph is input into a graph structure analysis model for model training to learn the dependency relationship between nodes and the topology of the graph; The program dependency graph is input into the trained graph structure analysis model to extract features including node types, semantic vectors, and dependency relationships, identify key paths, circular dependencies, redundant code, and potential security vulnerabilities in the code, and generate dependency relationship analysis results.

6. The method of code quality adaptive evaluation and optimization of claim 5, wherein, Based on the semantic vectors and dependency relationship analysis results, an optimization algorithm is used to identify potential problems in the code and generate optimization suggestions, including: Based on the semantic vectors and dependency relationship analysis results, an optimization algorithm is used to identify potential problems in the code and generate optimization suggestions including code refactoring, performance optimization, and security improvement; The optimization suggestions are converted into human-readable text by a natural language generation model combined with code function descriptions, parameter lists, and context information.

7. The method of code quality adaptive evaluation and optimization of claim 6, wherein, The code is automatically modified based on the optimization suggestions, the optimization effect is re-evaluated, and the related models and algorithms are iteratively optimized based on feedback information, including: The code is automatically modified based on the optimization suggestions, the optimization effect is re-evaluated, and the related models and algorithms are iteratively optimized based on feedback information, including: The system uses the code quality adaptive evaluation and optimization method of any one of claims 1 to 7; The system includes:

8. A code quality adaptive evaluation and optimization system, characterized by, A code preprocessing module for cleaning and standardizing the original code to generate processed code; An abstract syntax tree construction module for converting the processed code into an abstract syntax tree using an appropriate parser and optimizing the abstract syntax tree; A semantic analysis module for embedding each node of the abstract syntax tree using a pre-trained deep learning model to generate a node semantic vector, and obtaining a semantic vector representing the semantic features of the code through aggregation, feature extraction, and vector normalization operations; A dependency relationship analysis module for extracting dependency relationships from the abstract syntax tree to construct a program dependency graph, using a neural network model to extract node features to identify key paths, circular dependencies, redundant code, and potential security vulnerabilities in the code, and generate dependency relationship analysis results; An optimization suggestion generation module for identifying potential problems in the code using an optimization algorithm based on the semantic vectors and dependency relationship analysis results and generating optimization suggestions; An iterative optimization module for automatically modifying the code based on the optimization suggestions, re-evaluating the optimization effect, and iteratively optimizing the related models and algorithms based on feedback information. The processor executes the program to implement the steps of the code quality adaptive evaluation and optimization method of any one of claims 1 to 7. The computer program is executed by the processor to implement the steps of the code quality adaptive evaluation and optimization method of any one of claims 1 to 7.

9. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, ​ 10. A storage medium having stored thereon a computer program, characterized in that ​

Citation Information

Cited By

  • Script grammar analysis method and system based on machine learning

    CN121807314A

  • Machine Learning-Based Script Syntax Parsing Method and System

    CN121807314B

  • Semantic analysis and attention combined code sequence compression method, device and equipment

    CN122285016A

  • Historical engineering code parsing optimization method and device, equipment and storage medium

    CN122387506A