Intelligent auxiliary method and system for software development
By building dependency graphs and using deep learning models to evaluate the functional coverage and importance of code snippets, and dynamically adjusting the recommendation strategy in combination with the situational analysis model, the shortcomings in code snippet management and evaluation in the existing technology are solved, and efficient classification of code snippets is achieved and recommendations, improve code reuse rate and system stability.
Patent Information
- Application Number
- CN202411188385.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-28
- Publication Date
- 2024-12-17
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing technology cannot effectively evaluate and manage the dependencies and functional coverage of code snippets, making it difficult to guarantee code quality and project stability, and lacks a systematic approach to improve the independence and reusability of code snippets.
By parsing the abstract syntax tree of code snippets, building multi-level dependency graphs and timing dependency graphs, calculating Laplace matrix and performing spectral decomposition, obtaining eigenvalues and eigenvectors, evaluating the functional coverage and importance of code snippets, and using The deep learning model captures the syntax and semantic features of the code, dynamically adjusts the code snippet recommendation strategy in combination with the situational analysis model, and applies an unsupervised learning algorithm for clustering and classification.
It significantly improves the accuracy of the classification, clustering and similarity calculation of code snippets, improves code reuse rate and system stability, optimizes the development process, reduces development and maintenance costs, and ensures the efficient and stable operation of the system.
Smart Images

Figure CN119149045A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software development assistance, and more specifically, to a software development intelligent assistance method and system. Background Art
[0002] In the software development process, the reusability and stability of code snippets are key factors in improving development efficiency and reducing maintenance costs. Code snippets that developers frequently write and modify in their daily work usually contain rich business logic and implementation details. The management and evaluation of these code snippets are crucial to the success of software projects. However, as the code base expands and versions evolve, the dependencies between code snippets become more complex.
[0003] In the prior art, code snippets are usually analyzed based on their usage frequency, which is an obvious shortcoming. Frequency analysis cannot fully capture the dependencies and functional coverage of code snippets, and ignores the importance and independence of code snippets in different functional modules. In addition, frequency analysis cannot effectively evaluate the reusability and stability of code snippets, making it difficult to provide a scientific basis for the optimization and management of code snippets, resulting in difficulty in ensuring code quality and project stability.
[0004] In order to solve the above problems, a technical solution is now provided. Summary of the invention
[0005] In order to overcome the above-mentioned defects of the prior art, the embodiments of the present invention provide a software development intelligent auxiliary method and system, which improves the independence, integrity and functional coverage of code snippets through a systematic method. First, the abstract syntax tree of the code snippet is parsed, a multi-level dependency graph and a temporal dependency graph are constructed, the Laplacian matrix of the dependency graph is calculated and spectral decomposition is performed, the eigenvalues and eigenvectors are obtained, and the coverage and importance of the code snippet in the functional module are evaluated, thereby calculating the warning isolation and functional functional rate. The functional coverage potential coefficient is calculated by the weighted logarithmic harmonic mean formula, and compared with the functional coverage potential threshold to judge the availability of the code snippet. Secondly, the code snippet is converted into a high-dimensional vector representation using a deep learning model, and the syntax and semantic features of the code are captured through model training to achieve a comprehensive characterization of the code function and structure. In addition, the context information of the developer's current code writing is collected and preprocessed, and a situational analysis model is constructed and trained to understand the developer's intentions and needs in real time, and the code snippet recommendation strategy is dynamically adjusted. Combined with the feature embedding and situational analysis results, unsupervised learning algorithms such as K-means are applied to cluster and classify the code snippets to form a semantically similar and functionally related code snippet library. It significantly improves the accuracy of classification, clustering and similarity calculation of code snippets, effectively supports code search and recommendation systems, optimizes development processes, improves code reuse and system stability, reduces development and maintenance costs, and ensures efficient and stable operation of the system to solve the problems raised in the above background technology.
[0006] To achieve the above object, the present invention provides the following technical solutions:
[0007] S1. Automatically collect code snippets written by developers through the code repository hook, pre-process the collected code snippets, and build a code snippet library to be analyzed;
[0008] S2. For each code snippet in the code snippet library, we construct a multi-level dependency graph and a timing dependency graph, calculate the maximum flow and minimum cut to quantify the warning isolation of the code snippet, and use the spectral graph theory to evaluate the functional coverage and diversity of the code snippet, calculate the functional rate, and comprehensively screen out the basic code snippets based on the warning isolation and functional rate to build a basic code snippet library;
[0009] S3. Using a deep learning model, convert the code snippets filtered in step S2 into high-dimensional vector representations. Through model training, the grammatical and semantic features of the code are captured to generate embeddings that can represent the function and structure of the code.
[0010] S4. Combined with the context of the developer's current code writing, the situational analysis model is used to understand the developer's intentions and needs, and the recommended strategy of the code snippet is adjusted in real time;
[0011] S5. Based on the feature embedding and context analysis results, an unsupervised learning algorithm is applied to cluster and classify the code snippets to form a library of semantically similar and functionally related code snippets.
[0012] In a preferred embodiment, step S1 includes the following contents:
[0013] S1.1, configure the repository hook script so that it is automatically called every time the code is submitted. The hook script extracts the submitted code snippets and stores them in a temporary database;
[0014] S1.2, use the gitdif command to compare the differences between the latest submission and the previous version, and extract the newly added or modified code snippets from the differences;
[0015] S1.3, generate a hash value for each extracted code snippet, check whether there is already a code snippet with the same hash value in the temporary database, and skip it if it exists;
[0016] S1.4, remove comments and extra whitespace characters in code snippets to unify the code style;
[0017] S1.5, extract metadata information from the submission log, associate the metadata with the code snippet, and store it in a temporary database;
[0018] S1.6, storing the preprocessed code snippets in a code snippet library to be analyzed.
[0019] In a preferred embodiment, step S2 includes the following contents:
[0020] The functional coverage potential coefficient is obtained by comprehensive calculation using the warning isolation degree and functional functional rate.
[0021] Compare the function coverage potential coefficient with the function coverage potential threshold. If the function coverage potential coefficient is greater than or equal to the function coverage potential threshold, it means that the independence and multifunctional coverage capabilities of the code snippet in the system have reached or exceeded the expected standards, and it is suitable as a basic code snippet, and its optimization and reuse should be given priority to generate an available signal. On the contrary, if the function coverage potential coefficient is less than the function coverage potential threshold, it means that the independence and multifunctional coverage capabilities of the code snippet in realizing the function have not reached the expected standards, and it is not suitable as a basic code snippet, and an unavailable signal is generated.
[0022] For the code snippets that generate usable signals, statistics are collected and summarized to build a basic code snippet library.
[0023] In a preferred embodiment, the logic for obtaining the warning isolation degree is as follows:
[0024] S2.1.1, parse the abstract syntax tree of the code snippet, identify direct dependencies and indirect dependencies, and build dependency graphs at different levels;
[0025] S2.1.2, analyze the code execution path and build a timing dependency graph to represent the dependencies between code snippets at different time points;
[0026] S2.1.3, merge the multi-level dependency graph and the temporal dependency graph to form a comprehensive dependency graph;
[0027] S2.1.4, assign different capacities to each edge in a multi-level dependency graph, where the capacity value is based on the strength of the dependency and the tightness of the timing dependency;
[0028] S2.1.5, set the source node s and sink node t of the comprehensive dependency graph, the source node represents the starting point of the code fragment, and the sink node represents the end point of the code fragment;
[0029] S2.1.6, use the hierarchical maximum flow algorithm to calculate the maximum flow on different levels of the dependency graph;
[0030] S2.1.7, merge the maximum flow results at different levels to form a comprehensive maximum flow;
[0031] S2.1.8, based on the maximum flow results, find the minimum cut on the comprehensive dependency graph and determine the multi-level minimum cut edge set;
[0032] S2.1.9, calculate the total capacity of the multi-level minimum cut edge set to reflect the strength of the comprehensive dependence;
[0033] S2.1.10, calculate the total capacity of the minimum cut edge set, that is, the sum of the capacities of all cut edges. The warning isolation is defined as the inverse of the minimum cut capacity, and the formula is: Among them, e represents an edge in the comprehensive dependency graph, and the edge represents the dependency relationship between variables and functions in the code snippet; C represents the minimum cut edge set, which is the edge set that separates the source node s and the sink node t in the comprehensive dependency graph; c(e) represents the capacity of edge e, and the capacity value is based on the strength of the dependency and the closeness of the timing dependency.
[0034] In a preferred embodiment, the logic for obtaining the functional rate is as follows:
[0035] S2.2.1, by parsing the abstract syntax tree of the code snippet, extracting dependencies based on the grammatical structure of the code, and constructing a dependency graph;
[0036] S2.2.2, the Laplacian matrix is used to represent the structural characteristics of the graph. By calculating the adjacency matrix A and the degree matrix D, the Laplacian matrix L is obtained;
[0037] S2.2.3, spectral decomposition is used to calculate the eigenvalues and eigenvectors of the Laplacian matrix, and the connectivity and clustering characteristics of the graph are obtained by analyzing the eigenvalues and eigenvectors;
[0038] S2.2.4, evaluate the coverage and importance of the code snippets in the functional modules by analyzing the eigenvalues and eigenvectors, and select the first k smallest non-zero eigenvalues and their corresponding eigenvectors to represent the important subgroups in the graph;
[0039] S2.2.5, the functional rate is calculated by analyzing the eigenvalues and eigenvectors to comprehensively calculate the coverage and importance of the code snippets in the functional modules. The functional rate formula is: Among them, v i Indicates the position and connection relationship of the node in the graph; i Represents the connectivity properties of a graph.
[0040] In a preferred embodiment, step S3 includes the following contents:
[0041] S3.1, collect and annotate a large number of code snippet samples, covering multiple programming languages and functional modules, tokenize or mark the preprocessed code snippets, and convert them into an input format that can be processed by the model;
[0042] S3.2, based on the preprocessed code snippets, build a vocabulary, count all code tokens, and assign a unique index ID;
[0043] S3.3, based on the selected deep learning model architecture, define the model’s input layer, input the token sequence into the model, generate the corresponding embedding vector; build the model’s encoder layer; add the attention mechanism;
[0044] S3.4, define the loss function and use the labeled dataset for model training;
[0045] S3.5, using the trained model, inputting the code snippet into the model, generating a corresponding high-dimensional vector representation, normalizing the generated high-dimensional vector, and storing the generated high-dimensional vector in a vector database;
[0046] S3.6, utilizes the encoder layer and attention mechanism of the model to capture the syntactic and semantic features of the code snippet.
[0047] In a preferred embodiment, step S4 includes the following contents:
[0048] S4.1, obtain the code snippet, cursor position, and editing history context information in the current development environment, and use the IDE plug-in to generate the context information of the developer's current code;
[0049] S4.2, preprocess the collected context information, parse the abstract syntax tree of the current code snippet, extract the code structure and syntax information, and identify the developer's current editing intention and potential requirements based on the cursor position and editing history;
[0050] S4.3, based on the selected context analysis model, inputs the preprocessed context information to capture the contextual relationship of the code and the editing habits of the developer;
[0051] The input layer of the context analysis model receives the preprocessed context information, and the encoding layer captures the context dependencies and grammatical structure features of the code snippet;
[0052] S4.4, training a situational analysis model using annotated datasets;
[0053] S4.5, deploys the trained situational analysis model to the development environment, receives and analyzes the developer's contextual information in real time, understands the developer's intentions and needs, dynamically adjusts the code snippet recommendation strategy based on the analysis results, generates code snippet recommendations that best suit the current development situation, and uses the model's prediction results to update the recommendation list in real time.
[0054] In a preferred embodiment, step S5 includes the following contents:
[0055] Collect feature embedding and context analysis results of all code snippets;
[0056] Train an unsupervised learning model based on the selected algorithm;
[0057] For K-means, determine the number of clusters K, initialize the cluster centers, and iteratively update the center points until convergence;
[0058] Use the trained model to cluster and classify code snippets;
[0059] For each code snippet, calculate its distance from all cluster centers and assign it to the nearest cluster center;
[0060] According to the clustering and classification results, a library of semantically similar and functionally related code snippets is constructed, and the code snippets in the same cluster are grouped together to form a collection of code snippets with similar semantics and functions.
[0061] A software development intelligent auxiliary system, comprising: a fragment collection module, a dependency parsing module, a feature embedding module, a context analysis module and a clustering classification module;
[0062] The snippet collection module automatically collects the code snippets written by developers each time the code is submitted by configuring the code repository hook, preprocesses the collected code snippets, including removing comments, standardizing indentation and format, building a library of code snippets to be analyzed, and passing the preprocessed code snippet data to the dependency resolution module;
[0063] The dependency parsing module constructs a multi-level dependency graph and a timing dependency graph for each code snippet in the code snippet library to calculate the maximum flow and minimum cut to quantify the warning isolation of the code snippet. At the same time, it uses the spectral graph theory to evaluate the functional coverage and diversity of the code snippet, calculates the functional functional rate, and comprehensively screens out basic code snippets based on the warning isolation and functional functional rate, builds a basic code snippet library, and passes the screened basic code snippet data to the feature embedding module;
[0064] The feature embedding module uses a deep learning model to convert the selected basic code snippets into high-dimensional vector representations. Through model training, it captures the grammatical and semantic features of the code, generates embedding vectors that can represent the function and structure of the code, forms a feature embedding library, and passes the generated high-dimensional vector data to the context analysis module and the clustering classification module.
[0065] The situational analysis module combines the context of the developer's current code writing, uses the situational analysis model to understand the developer's intentions and needs, adjusts the recommended strategy of the code snippet in real time, and sends the situational analysis results to the clustering and classification module;
[0066] The clustering and classification module uses an unsupervised learning algorithm to cluster and classify code snippets based on feature embedding and context analysis results, forming a library of semantically similar and functionally related code snippets.
[0067] The technical effects and advantages of the software development intelligent auxiliary method and system of the present invention are as follows:
[0068] 1. The present invention quantifies the independence and integrity of code snippets and the coverage of functional modules through a systematic method, specifically including parsing the abstract syntax tree (AST) of the code snippet, constructing a multi-level dependency graph and a timing dependency graph, calculating the Laplace matrix of the dependency graph, performing spectral decomposition to obtain eigenvalues and eigenvectors, evaluating the coverage and importance of the code snippet in the functional module, and using this information to calculate the warning isolation and functional functional rate. Finally, the functional coverage potential coefficient is calculated by the weighted logarithmic harmonic mean formula, and it is compared with the functional coverage potential threshold to determine the availability of the code snippet. Then, through a systematic and quantitative method, the independence, integrity and functional coverage capabilities of the code snippet are efficiently evaluated, high-value basic code snippets are identified, code reuse rate and system stability are improved, code management and development processes are optimized, development and maintenance costs are reduced, and efficient and stable operation of the system is ensured.
[0069] 2. The present invention uses a deep learning model to convert code snippets into high-dimensional vector representations, captures the grammatical and semantic features of the code through model training, and achieves a comprehensive characterization of the code function and structure. Specifically, it includes the steps of data preparation and preprocessing, building a vocabulary and embedding matrix, designing a deep learning model, model training, high-dimensional vector generation, grammatical and semantic feature capture, and application of embedded vectors. Furthermore, through the application of deep learning models, the grammatical and semantic understanding capabilities of code snippets are improved, the accuracy of code snippet classification, clustering, and similarity calculation is enhanced, and code search and recommendation systems are effectively supported, helping developers quickly find relevant code snippets and reuse them, thereby significantly improving development efficiency and code quality, reducing maintenance costs, and promoting efficient management and optimization of code.
[0070] 3. The present invention collects and preprocesses the context information of the developer's current code writing, builds and trains a context analysis model, understands the developer's intentions and needs in real time, and dynamically adjusts the code snippet recommendation strategy. Technical features include collecting context information such as code snippets, cursor positions, editing history, parsing the abstract syntax tree (AST) of the code snippet, designing a context analysis model, using annotated data sets for model training, deploying the model to analyze the context in real time and adjust the recommendation strategy, collecting feedback and continuously optimizing the model. The beneficial effect of the present invention is to understand the developer's intentions and needs in real time through the context analysis model, improve the accuracy and practicality of the code snippet recommendation, ensure that the recommendation results are highly matched with the developer's needs, help developers quickly find relevant code snippets, reduce duplication of work, and optimize the development process, thereby significantly improving development efficiency and code quality.
[0071] 4. The present invention collects and preprocesses code snippet data, combines feature embedding and context analysis results, and applies unsupervised learning algorithms such as K-means to cluster and classify code snippets to form a library of semantically similar and functionally related code snippets. Technical features include using an unsupervised learning algorithm to train a model, calculating the distance between code snippets, evaluating the effect based on clustering results, and building and continuously optimizing the code snippet library. The beneficial effect of the present invention is that, through an automated clustering and classification process, code snippets can be efficiently organized and managed, the workload of manual annotation can be significantly reduced, the efficiency of code snippet retrieval and reuse can be improved, and the development team can be helped to quickly locate high-quality code snippets, optimize the development process, and improve the maintainability and reusability of the code. BRIEF DESCRIPTION OF THE DRAWINGS
[0072] Figure 1 A flowchart of an intelligent auxiliary method for software development according to the present invention;
[0073] Figure 2 The present invention is a structural diagram of a software development intelligent auxiliary system. DETAILED DESCRIPTION
[0074] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0075] Example 1
[0076] Figure 1 The present invention provides a software development intelligent auxiliary method, comprising:
[0077] S1. Automatically collect code snippets written by developers through the code repository hook, pre-process the collected code snippets, and build a code snippet library to be analyzed;
[0078] S2. For each code snippet in the code snippet library, we construct a multi-level dependency graph and a timing dependency graph, calculate the maximum flow and minimum cut to quantify the warning isolation of the code snippet, and use the spectral graph theory to evaluate the functional coverage and diversity of the code snippet, calculate the functional rate, and comprehensively screen out the basic code snippets based on the warning isolation and functional rate to build a basic code snippet library;
[0079] S3. Using a deep learning model, convert the code snippets filtered in step S2 into high-dimensional vector representations. Through model training, the grammatical and semantic features of the code are captured to generate embeddings that can represent the function and structure of the code.
[0080] S4. Combined with the context of the developer's current code writing, the situational analysis model is used to understand the developer's intentions and needs, and the recommended strategy of the code snippet is adjusted in real time;
[0081] S5. Based on the results of feature embedding and context analysis, an unsupervised learning algorithm is applied to cluster and classify the code snippets to form a library of semantically similar and functionally related code snippets.
[0082] In the process of modern software development, with the continuous expansion of code bases and the growing development team, efficient management and utilization of code snippets have become a key task. When developers write and maintain code on a daily basis, the frequently generated code snippets contain a large amount of business logic and implementation details. The effective management of these snippets is of great significance for improving code reuse, improving development efficiency, and reducing duplication of work. However, with the expansion of code size and the frequent version updates, it has become increasingly difficult to manually manage these code snippets, and they often face the following challenges: First, the real-time and comprehensiveness of code snippets are difficult to guarantee, and manual collection is often delayed and incomplete; second, the degree of standardization of code snippets is not high, and the styles and formats vary, which affects subsequent analysis and use; third, it is difficult to remove duplicates and identify uniqueness of code snippets, which is prone to a large number of redundant snippets, increasing storage and management costs; finally, the lack of systematic metadata annotation and management leads to low efficiency in the classification and retrieval of code snippets. In response to these problems, there is an urgent need for an efficient and automated method to collect, standardize and store code snippets written by developers in real time, so as to build an efficient and available code snippet library to be analyzed to support subsequent intelligent analysis and recommendation. Solving this requirement will significantly improve the work efficiency of the development team and promote efficient code reuse and knowledge sharing.
[0083] Step S1 includes the following contents:
[0084] S1.1, every time the code is committed or pushed, the code repository hook is triggered to automatically capture code snippets to ensure the real-time and comprehensive collection of code snippets.
[0085] Configure the repository hook script to be automatically called each time the code is submitted; the hook script extracts the submitted code snippet and stores it in a temporary database.
[0086] Ensure code snippets are collected instantly when submitted to avoid omissions.
[0087] S1.2, use the differential algorithm (diff) to extract only the newly submitted code snippets to avoid repeated collection and storage.
[0088] Use the git iff command to compare the latest submission with the previous version and extract the new or modified code snippets from the difference.
[0089] By accurately capturing code changes, it ensures that the collected code snippets are the latest modified content.
[0090] S1.3, apply a hash algorithm (such as SHA-256) to generate a unique identifier for each code snippet to ensure the uniqueness of the code snippet.
[0091] Generate a hash value for each extracted code snippet; check whether there is already a code snippet with the same hash value in the temporary database, and skip it if it exists.
[0092] By generating and verifying unique identifiers, repeated storage of the same code snippets can be prevented, improving storage efficiency.
[0093] S1.4, standardize the code format and unify the style to improve the consistency and accuracy of subsequent analysis.
[0094] Remove comments and extra whitespace characters in code snippets; unify code style, such as indentation, bracket position, etc., and use code formatting tools (such as Prettier, clang-format).
[0095] Through standardization operations, we ensure that the format and style of all code snippets are consistent, which is convenient for subsequent processing and analysis.
[0096] S1.5, automatically annotate the metadata of code snippets (such as author, submission time, and module to which they belong) to facilitate subsequent analysis and management.
[0097] Extract metadata information from the commit log, such as author, commit time, commit information, etc.; associate the metadata with the code snippet and store it in a temporary database.
[0098] By adding metadata, the information dimension of code snippets is enriched to facilitate classification and management.
[0099] S1.6, use efficient data storage structures (such as NoSQL databases, graph databases) to facilitate subsequent rapid retrieval and analysis.
[0100] Store the preprocessed code snippets in the code snippet library to be analyzed; ensure the efficiency and scalability of data storage, and choose appropriate database technology (such as MongoDB, Neo4j).
[0101] By building an efficient storage structure, a solid data foundation is provided for subsequent code snippet analysis and processing.
[0102] Step S2 includes the following contents:
[0103] The code snippets that developers frequently write and modify in their daily work usually contain rich business logic and implementation details. The management and evaluation of these code snippets are crucial to the success of software projects. However, with the expansion of the code base and the evolution of versions, the dependencies between code snippets become more and more complex. Manually evaluating the independence and integrity of these snippets is not only time-consuming and laborious, but also prone to omissions and misjudgments. Therefore, there is an urgent need for a systematic method to quantify the independence and integrity of code snippets, so as to provide a scientific basis for the reuse and optimization of code snippets. As an indicator to measure the independence and integrity of code snippets, the warning isolation degree systematically evaluates the internal and external dependencies of code snippets by constructing a multi-level dependency graph and applying the minimum cut algorithm, thereby providing clear guidance for developers. This method not only helps to improve the reusability and portability of code snippets, but also significantly improves code quality and the overall stability of the project. The calculation and analysis of the warning isolation degree will lay a solid foundation for the subsequent screening and management of code snippets, and help development teams achieve more efficient code management and optimization in complex software development environments.
[0104] The logic for obtaining the warning isolation degree is as follows:
[0105] S2.1.1, parse the abstract syntax tree (AST) of the code snippet, identify direct dependencies and indirect dependencies, and build dependency graphs at different levels respectively;
[0106] By parsing the abstract syntax tree (AST) of the code snippet, the dependency relationship is extracted based on the grammatical structure of the code, and a direct dependency graph and an indirect dependency graph are constructed. The direct dependency graph shows the direct call relationship between functions and variables, and the indirect dependency graph shows the dependency relationship passed through intermediary functions or variables.
[0107] S2.1.2, analyze the code execution path and build a timing dependency graph to represent the dependencies between code snippets at different time points;
[0108] Through static analysis and dynamic analysis techniques, the execution path and call stack of the code are identified, and a timing dependency graph is constructed. Static analysis is used to identify possible execution paths, dynamic analysis is used to monitor the call sequence during actual runtime, and the timing dependency graph shows the dependencies of code snippets at different time points.
[0109] S2.1.3, merge the multi-level dependency graph and the temporal dependency graph to form a comprehensive dependency graph;
[0110] Through static analysis and dynamic analysis techniques, the execution path and call stack of the code are identified, and a timing dependency graph is constructed. Static analysis is used to identify possible execution paths, dynamic analysis is used to monitor the call sequence during actual runtime, and the timing dependency graph shows the dependencies of code snippets at different time points.
[0111] S2.1.4, assign different capacities to each edge in a multi-level dependency graph, where the capacity value is based on the strength of the dependency and the tightness of the timing dependency;
[0112] Use quantitative indicators to indicate the strength of dependency relationships, such as the number of calls for direct dependency strength, the frequency of variable usage for indirect dependency strength, and the closeness of the call sequence for temporal dependency strength. The capacity value of an edge reflects the strength of a dependency relationship.
[0113] S2.1.5, set the source node s and sink node t of the comprehensive dependency graph, the source node represents the starting point of the code fragment, and the sink node represents the end point of the code fragment;
[0114] By analyzing the execution flow of the code snippet, the starting point and the end point are determined to ensure the rationality of the flow network. The source node and the sink node represent the starting point and the end point of the code snippet.
[0115] S2.1.6, use the hierarchical maximum flow algorithm to calculate the maximum flow on different levels of the dependency graph;
[0116] Use breadth-first search (BFS) to find augmenting paths and calculate the flow on each path until no augmenting path is found. The maximum flow algorithm calculates the maximum flow on the direct dependency graph, indirect dependency graph, and temporal dependency graph respectively.
[0117] S2.1.7, merge the maximum flow results at different levels to form a comprehensive maximum flow;
[0118] By comprehensively calculating the multi-level flow results, the overall maximum flow is obtained, which reflects the overall dependency strength of the code snippets. The merging process can adopt weighted average.
[0119] S2.1.8, based on the maximum flow results, find the minimum cut on the comprehensive dependency graph and determine the multi-level minimum cut edge set;
[0120] Through the construction of the residual network, all nodes reachable by the source node are marked to form a cut set. The minimum cut divides the graph into two parts, so that the source node and the sink node are separated, and the cut edge set reflects the strength of the comprehensive dependency.
[0121] S2.1.9, calculate the total capacity of the multi-level minimum cut edge set to reflect the strength of the comprehensive dependence;
[0122] The sum of the edge capacities indicates the difficulty of the cut. The smaller the cut, the more independent the code snippet. The total capacity of the minimum cut edge set is calculated. The sum of the edge capacities reflects the independence of the code snippet.
[0123] S2.1.10, define the warning isolation using the total capacity of the multi-level minimum cut edge set;
[0124] Calculate the total capacity of the minimum cut edge set, which is the sum of the capacities of all cut edges. The warning isolation is defined as the inverse of the minimum cut capacity, and the formula is:
[0125] Among them, e represents an edge in the comprehensive dependency graph, and the edge represents the dependency relationship between variables and functions in the code snippet;
[0126] C represents the minimum cut edge set, which is the edge set that separates the source node s and the sink node t in the comprehensive dependency graph;
[0127] c(e) represents the capacity of edge e, and the capacity value is based on the strength of the dependency and the closeness of the timing dependency.
[0128] Warning isolation is used to represent and reflect the independence and integrity of a code snippet. The greater the warning isolation, the tighter the internal dependencies of the code snippet, the less external dependencies, the stronger the independence and integrity, the easier it is to reuse in different environments, and the higher the portability and stability. On the contrary, the smaller the warning isolation, the less tight the internal dependencies of the code snippet, the more dependencies on external modules or libraries, the poorer the independence and integrity, the greater the difficulty of reuse and transplantation, and the more likely problems to occur in different environments. Therefore, as a key indicator, warning isolation helps evaluate the adaptability and reliability of code snippets in various development and operation environments by quantifying their dependency characteristics.
[0129] As the complexity and scale of projects continue to increase, the reusability and influence of code snippets in different functional modules have become key considerations. Functional rate is an indicator to measure the coverage and importance of code snippets in functional modules. By quantifying the role of code snippets in multiple modules, it helps developers identify those code snippets that have a significant impact in implementing key functions. The calculation and analysis of functional rate helps development teams optimize code structure, improve code reuse and maintainability, and thus reduce development time and cost. However, traditional methods make it difficult to systematically evaluate the importance and coverage of code snippets in functional modules, resulting in a lack of scientific basis for code optimization and management. By introducing the functional rate indicator, the performance of code snippets in functional implementation can be comprehensively and systematically analyzed, helping development teams identify high-value code snippets in a huge code base, thereby giving priority to their optimization and reuse, and providing a solid foundation for the sustainable development of the project. The calculation of functional rate is not limited to a single dimension, but is combined with the multi-level dependencies and function calls of code snippets. Through spectral graph theory and other advanced algorithms, in-depth analysis is performed to ensure the accuracy and practicality of the evaluation results, laying the foundation for subsequent code snippet screening and management.
[0130] The logic for obtaining the functional rate is as follows:
[0131] S2.2.1, by parsing the abstract syntax tree (AST) of the code snippet, extracting dependencies based on the grammatical structure of the code, and constructing a dependency graph. The nodes in the dependency graph represent the variables and functions in the code snippet, and the edges represent the dependencies between variables and functions. External dependencies are also represented as special external nodes, and corresponding edges are added to the dependency graph to fully display the internal structure and dependencies of the code snippet.
[0132] S2.2.2, Laplace matrix is used to represent the structural characteristics of the graph. By calculating the adjacency matrix A and the degree matrix D, the Laplace matrix L is obtained. The adjacency matrix represents the connection relationship between nodes, and the degree matrix represents the degree of each node. The calculation formula of the Laplace matrix is L=DA, which is used to analyze the connectivity and clustering characteristics of the graph.
[0133] S2.2.3, spectral decomposition is used to calculate the eigenvalues and eigenvectors of the Laplacian matrix. By analyzing the eigenvalues and eigenvectors, the connectivity and clustering characteristics of the graph are obtained. Eigenvalue λ i Reflecting the connectivity of the graph, the eigenvector v i Indicates the position and connection relationship of the node in the graph. The spectral decomposition equation is Lvi = λivi.
[0134] S2.2.4, evaluate the coverage and importance of the code snippet in the functional module by analyzing the eigenvalues and eigenvectors. Select the first k smallest non-zero eigenvalues and their corresponding eigenvectors to represent the important subgroups in the graph. The larger the value of the eigenvector, the more important the node is in the functional implementation, reflecting the functional coverage of the code snippet.
[0135] S2.2.5, the functional rate is calculated by analyzing the eigenvalues and eigenvectors to comprehensively calculate the coverage and importance of the code snippets in the functional modules. The functional rate formula is
[0136]
[0137] Among them, v i Indicates the position and connection relationship of nodes in the graph;
[0138] λ i Represents the connectivity properties of a graph.
[0139] The functional rate is normalized by this formula to comprehensively evaluate the functional implementation efficiency and stability of the code snippet.
[0140] Functional rate is used to represent and reflect the coverage and importance of code snippets in functional modules. The larger the functional rate, the higher the coverage and influence of the code snippet in multiple functional modules, indicating that the code snippet plays a key role in realizing these functions and has higher functional diversity and reuse value. On the contrary, the smaller the functional rate, the lower the coverage and influence of the code snippet in the functional module, indicating that its role in realizing functions is relatively limited, and its functional diversity and reuse value are low. In software development scenarios, by evaluating the functional rate of code snippets, we can identify those code snippets that play an important role in multiple functional modules, so as to give priority to their optimization and reuse to improve development efficiency and code quality.
[0141] The functional coverage potential coefficient can be obtained by comprehensive calculation using the warning isolation degree and the functional functional rate. For example, the following calculation formula can be used:
[0142]
[0143] Among them, FCP is the functional coverage potential coefficient; ID norm and FCR norm are the normalized warning isolation degree and functional rate, respectively; α and β are weight parameters, which are used to adjust the relative importance of warning isolation degree and functional rate in the comprehensive score.
[0144] The normalized warning isolation degree and functional rate are processed using a logarithmic function to make the changes of indicators smoother and avoid excessive fluctuations.
[0145] The weighted log harmonic mean combines the logarithmic function and the weighted average to ensure that both indicators have a significant impact on the overall score.
[0146] The functional coverage potential coefficient is used to represent and reflect the independence and multifunctional coverage capabilities of a code snippet in a system. The larger the coefficient, the higher the independence of the code snippet in implementing a specific function, the less dependent on external modules and functions, and the higher coverage and influence in multiple functional modules, indicating that the code snippet has a higher reuse value and stability. On the contrary, the smaller the functional coverage potential coefficient, the more dependent on external modules and functions the code snippet is in implementing the function, the lower its independence, and the lower its coverage and influence in multiple functional modules, indicating that the reuse value and stability of the code snippet are poor. In software development scenarios, by calculating the functional coverage potential coefficient, we can effectively identify high-value code snippets that have both high independence and can cover multifunctional modules, so as to give priority to their optimization and reuse, improve code quality and development efficiency, reduce maintenance costs, and achieve efficient and stable operation of the system.
[0147] Compare the function coverage potential coefficient with the function coverage potential threshold. If the function coverage potential coefficient is greater than or equal to the function coverage potential threshold, it means that the independence and multi-functional coverage capabilities of the code snippet in the system have met or exceeded the expected standards, and it has high reuse value and stability. It is suitable as a basic code snippet and its optimization and reuse should be prioritized to generate an available signal. On the contrary, if the function coverage potential coefficient is less than the function coverage potential threshold, it means that the independence and multi-functional coverage capabilities of the code snippet in implementing the function have not met the expected standards, and its reuse value and stability are low. It is not suitable as a basic code snippet and an unavailable signal is generated. It needs further optimization or is only used in specific scenarios.
[0148] For the code snippets that generate usable signals, statistics are collected and summarized to build a basic code snippet library.
[0149] The present invention quantifies the independence and integrity of code snippets and the coverage of functional modules through a systematic method, specifically including parsing the abstract syntax tree (AST) of the code snippet, constructing a multi-level dependency graph and a timing dependency graph, calculating the Laplace matrix of the dependency graph, performing spectral decomposition to obtain eigenvalues and eigenvectors, evaluating the coverage and importance of the code snippet in the functional module, and using this information to calculate the warning isolation and functional functional rate. Finally, the functional coverage potential coefficient is calculated by the weighted logarithmic harmonic mean formula, and it is compared with the functional coverage potential threshold to determine the availability of the code snippet. Then, through a systematic and quantitative method, the independence, integrity and functional coverage capabilities of the code snippet are efficiently evaluated, high-value basic code snippets are identified, code reuse rate and system stability are improved, code management and development processes are optimized, development and maintenance costs are reduced, and efficient and stable operation of the system is ensured.
[0150] Traditional code snippet management methods often rely on manual annotation and simple text matching, which cannot fully capture the grammatical and semantic features of the code, resulting in low reusability and maintainability of code snippets. Deep learning models have demonstrated powerful feature extraction capabilities in fields such as natural language processing and image recognition. Applying them to code snippet management can greatly improve the semantic understanding and function recognition capabilities of the code. By converting code snippets into high-dimensional vector representations, deep learning models can capture subtle differences and complex dependencies in the code, and achieve a comprehensive characterization of the code function and structure. This process can not only improve the classification and clustering accuracy of code snippets, but also support more efficient code search and recommendation systems, helping developers quickly find relevant code snippets and reuse them. In this context, using deep learning models to represent code snippets in high-dimensional vectors and capture features has become an inevitable choice for improving code snippet management and optimization, providing a solid foundation for subsequent code snippet screening and optimization.
[0151] Step S3 includes the following contents:
[0152] S3.1, collect and annotate a large number of code snippet samples, covering multiple programming languages and functional modules. Preprocess the code snippets, including removing comments, standardizing indentation, removing redundant whitespace characters, and unifying code formats. Segment or tokenize the preprocessed code snippets and convert them into an input format that the model can process, such as a token sequence.
[0153] S3.2, based on the preprocessed code snippets, build a vocabulary, count all code tokens, and assign a unique index ID. Initialize the embedding matrix, represent each token in the vocabulary as a vector of fixed dimension, using random initialization or pre-trained embedding (such as word2vec).
[0154] S3.3, based on the selected deep learning model architecture, such as Transformer, LSTM, GRU, adapt to the grammatical and semantic feature capture of code snippets. Define the input layer of the model, input the token sequence into the model, and generate the corresponding embedding vector. Build the encoder layer of the model to capture the contextual information and grammatical structure features of the code snippet. The encoder layer usually includes multiple layers of Transformer, bidirectional LSTM or GRU. Add the attention mechanism to improve the model's ability to capture the features of long code snippets.
[0155] S3.4, define the loss function, and select an appropriate loss function according to the task requirements, such as cross entropy loss, mean square error, etc. Use the labeled data set for model training, and select the appropriate optimization algorithm (such as Adam, SGD) and hyperparameters (such as learning rate, batch size). Monitor the training loss and validation loss of the model during training, and perform hyperparameter tuning to avoid overfitting and underfitting. Perform multiple rounds of training until the model converges and achieves the desired performance indicators.
[0156] S3.5, using the trained model, input the code snippet into the model to generate the corresponding high-dimensional vector representation. The generated high-dimensional vector is normalized to ensure that the value range of the vector is consistent, which is convenient for subsequent calculation and comparison. The generated high-dimensional vector is stored in the vector database for fast retrieval and similarity calculation.
[0157] S3.6, using the encoder layer and attention mechanism of the model, captures the grammatical and semantic features of the code snippets. The encoder layer is responsible for extracting the structural information of the code, and the attention mechanism highlights the key code segments and contextual relationships. The captured grammatical and semantic features are integrated to generate an embedding vector that can fully represent the function and structure of the code.
[0158] The present invention utilizes a deep learning model to convert code snippets into high-dimensional vector representations, and captures the grammatical and semantic features of the code through model training to achieve a comprehensive characterization of the code function and structure. Specifically, it includes steps such as data preparation and preprocessing, building a vocabulary and embedding matrix, designing a deep learning model, model training, high-dimensional vector generation, grammatical and semantic feature capture, and application of embedded vectors. Furthermore, through the application of deep learning models, the grammatical and semantic understanding capabilities of code snippets are improved, the accuracy of code snippet classification, clustering, and similarity calculation is enhanced, and code search and recommendation systems are effectively supported, helping developers quickly find relevant code snippets and reuse them, thereby significantly improving development efficiency and code quality, reducing maintenance costs, and promoting efficient management and optimization of code.
[0159] The context environment includes the currently edited code snippet, cursor position, editing history, development tools used, etc. This information can reflect the real-time needs and intentions of developers. However, traditional code snippet recommendation systems often ignore the context information of developers, resulting in the mismatch between the recommended code snippets and the current code writing requirements, which affects development efficiency and code quality. In order to improve the accuracy and practicality of code snippet recommendations, an intelligent system is needed that can analyze the current context environment of developers in real time, understand the intentions and needs of developers through the context analysis model, and dynamically adjust the recommendation strategy of code snippets. This method can not only effectively improve the intelligence level of the recommendation system, but also help developers quickly find code snippets that meet current needs, reduce repetitive work, and optimize the development process. In this context, combining the context information of the developer's current code writing, using the context analysis model to understand the developer's intentions and needs, and adjusting the code snippet recommendation strategy in real time have become key steps to improve the intelligence and practicality of the code snippet recommendation system. This process will provide a scientific basis for subsequent code snippet recommendation and management, ensure that the recommendation results are highly matched with the developer's needs, and significantly improve development efficiency and code quality.
[0160] Step S4 includes the following contents:
[0161] S4.1, obtains contextual information such as code snippets, cursor positions, editing history, etc. in the current development environment, uses IDE plug-ins or APIs to collect these data in real time, generates contextual information of the developer's current code, and ensures the real-time and integrity of the data.
[0162] S4.2, preprocess the collected context information, parse the abstract syntax tree (AST) of the current code snippet, extract the code structure and syntax information, and identify the developer's current editing intention and potential requirements based on the cursor position and editing history.
[0163] S4.3, based on the selected context analysis model, use context information to understand the developer's intentions and needs. Select a suitable model architecture, such as LSTM, Transformer, etc., input preprocessed context information, and capture the contextual relationship of the code and the developer's editing habits. The input layer of the context analysis model receives the preprocessed context information, and the encoding layer captures the contextual dependencies and grammatical structure features of the code snippet.
[0164] S4.4, Use annotated datasets to train the context analysis model. The datasets should contain context information and developer intent in various programming scenarios. Select appropriate loss functions and optimization algorithms, conduct multiple rounds of training, and adjust hyperparameters to ensure that the model has high accuracy in capturing developer intent and requirements. Monitor the loss and accuracy during training to avoid overfitting and underfitting and optimize model performance.
[0165] S4.5 deploys the trained context analysis model to the development environment, receives and analyzes the developer's context information in real time, and understands the developer's intentions and needs. Based on the analysis results, dynamically adjust the code snippet recommendation strategy to generate the code snippet recommendation that best matches the current development context. Using the model's prediction results, update the recommendation list in real time to ensure that the recommended code snippets are highly matched to the developer's current coding needs.
[0166] The present invention collects and preprocesses the context information of the developer's current code writing, builds and trains a context analysis model, understands the developer's intentions and needs in real time, and dynamically adjusts the code snippet recommendation strategy. Technical features include collecting context information such as code snippets, cursor positions, editing history, parsing the abstract syntax tree (AST) of the code snippet, designing a context analysis model, using annotated data sets for model training, deploying the model to analyze the context in real time and adjust the recommendation strategy, collecting feedback and continuously optimizing the model. The beneficial effect of the present invention is to understand the developer's intentions and needs in real time through the context analysis model, improve the accuracy and practicality of the code snippet recommendation, ensure that the recommendation results are highly matched with the developer's needs, help developers quickly find relevant code snippets, reduce duplication of work, and optimize the development process, thereby significantly improving development efficiency and code quality.
[0167] Although deep learning models can capture the grammatical and semantic features of code snippets and generate high-dimensional vector representations, how to further organize and classify these features so that developers can quickly retrieve and reuse related code snippets remains an urgent problem. Unsupervised learning algorithms, such as DBSCAN and K-means, can cluster and classify code snippets by analyzing the feature embedding and context analysis results of code snippets to form a library of semantically similar and functionally related code snippets. This method can not only effectively identify and organize code snippets with similar functions, but also reduce the workload of manual annotation through automated clustering and classification processes, thereby improving the efficiency and accuracy of code snippet management. By clustering and classifying code snippets, development teams can quickly locate and reuse high-quality code snippets, reduce duplication of work, optimize development processes, and improve code maintainability and reusability. Combined with feature embedding and context analysis results, unsupervised learning algorithms are applied to cluster and classify code snippets, laying the foundation for the subsequent construction of code snippet libraries, ensuring the efficiency and practicality of code snippet libraries, and thus achieving more efficient code management and optimization in complex software development environments.
[0168] Step S5 includes the following contents:
[0169] Collect feature embedding and context analysis results of all code snippets, including grammatical features and semantic features. Preprocess code snippet data, unify the format, standardize input, eliminate noise and redundant information, and ensure data consistency and integrity.
[0170] According to the selected algorithm, train the unsupervised learning model. For K-means, determine the number of clusters K, initialize the cluster center, and iteratively update the center point until convergence. For DBSCAN, determine the radius parameter and the minimum number of samples, traverse all points, and classify the points that can be reached by density into one category.
[0171] Use the trained model to cluster and classify the code snippets. For each code snippet, calculate its distance to all cluster centers and assign it to the nearest cluster center. For DBSCAN, classify the code snippets according to density accessibility and identify core points, boundary points, and noise points.
[0172] Evaluate the clustering effect and use internal indicators (such as silhouette coefficient, cluster diameter) and external indicators (such as comparison with existing labels) to measure the clustering quality. According to the evaluation results, adjust the model parameters and training data to optimize the clustering effect and ensure that semantically similar and functionally related code snippets are accurately classified.
[0173] Based on the clustering and classification results, a library of semantically similar and functionally related code snippets is constructed. Code snippets in the same cluster are grouped together to form a collection of code snippets with similar semantics and functions. An efficient data storage and retrieval structure is designed to support fast query and dynamic update.
[0174] Continuously monitor and optimize the code snippet library, collect user feedback, adjust clustering and classification models, and ensure the efficiency and accuracy of the code snippet library. Regularly update the code snippet library, add new code snippets, retrain models, and keep the code snippet library up to date and at optimal performance.
[0175] The present invention collects and preprocesses code snippet data, combines feature embedding and context analysis results, and applies unsupervised learning algorithms such as K-means to cluster and classify code snippets to form a library of semantically similar and functionally related code snippets. Technical features include using an unsupervised learning algorithm to train a model, calculating the distance between code snippets, evaluating the effect based on clustering results, and building and continuously optimizing the code snippet library. The beneficial effect of the present invention is that through an automated clustering and classification process, code snippets can be efficiently organized and managed, the workload of manual annotation can be significantly reduced, the efficiency of code snippet retrieval and reuse can be improved, and the development team can be helped to quickly locate high-quality code snippets, optimize the development process, and improve the maintainability and reusability of the code.
[0176] Example 2
[0177] Figure 2 The present invention provides a software development intelligent auxiliary system, comprising: a fragment collection module, a dependency analysis module, a feature embedding module, a context analysis module and a cluster classification module;
[0178] The snippet collection module automatically collects the code snippets written by developers each time the code is submitted by configuring the code repository hook, preprocesses the collected code snippets, including removing comments, standardizing indentation and format, building a library of code snippets to be analyzed, and passing the preprocessed code snippet data to the dependency resolution module;
[0179] The dependency parsing module constructs a multi-level dependency graph and a timing dependency graph for each code snippet in the code snippet library to calculate the maximum flow and minimum cut to quantify the warning isolation of the code snippet. At the same time, it uses the spectral graph theory to evaluate the functional coverage and diversity of the code snippet, calculates the functional functional rate, and comprehensively screens out basic code snippets based on the warning isolation and functional functional rate, builds a basic code snippet library, and passes the screened basic code snippet data to the feature embedding module;
[0180] The feature embedding module uses a deep learning model to convert the selected basic code snippets into high-dimensional vector representations. Through model training, it captures the grammatical and semantic features of the code, generates embedding vectors that can represent the function and structure of the code, forms a feature embedding library, and passes the generated high-dimensional vector data to the context analysis module and the clustering classification module.
[0181] The situational analysis module combines the context of the developer's current code writing, uses the situational analysis model to understand the developer's intentions and needs, adjusts the recommended strategy of the code snippet in real time, and sends the situational analysis results to the clustering and classification module;
[0182] The clustering and classification module uses an unsupervised learning algorithm to cluster and classify code snippets based on feature embedding and context analysis results, forming a library of semantically similar and functionally related code snippets.
[0183] The above formulas are all dimensionless and numerical calculations. The formula is a formula for the most recent real situation obtained by collecting a large amount of data and performing software simulation. The preset parameters in the formula are set by technicians in this field according to actual conditions.
[0184] The above description is only by way of illustration of certain exemplary embodiments of the present invention. It is undoubted that those skilled in the art can modify the described embodiments in various ways without departing from the spirit and scope of the present invention. Therefore, the above drawings and descriptions are illustrative in nature and should not be construed as limiting the scope of protection of the claims of the present invention.
[0185] It should be noted that, in this article, if there are relational terms such as first and second, etc., they are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "including a..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0186] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A software development intelligent assistance method, characterized in that: Includes steps: S1. Automatically collect code snippets written by developers through the code repository hook, pre-process the collected code snippets, and build a code snippet library to be analyzed; S2. For each code snippet in the code snippet library, we construct a multi-level dependency graph and a timing dependency graph, calculate the maximum flow and minimum cut to quantify the warning isolation of the code snippet, and use the spectral graph theory to evaluate the functional coverage and diversity of the code snippet, calculate the functional rate, and comprehensively screen out the basic code snippets based on the warning isolation and functional rate to build a basic code snippet library; S3. Using a deep learning model, convert the code snippets filtered in step S2 into high-dimensional vector representations. Through model training, the grammatical and semantic features of the code are captured to generate embeddings that can represent the function and structure of the code. S4. Combined with the context of the developer's current code writing, the situational analysis model is used to understand the developer's intentions and needs, and the recommended strategy of the code snippet is adjusted in real time; S5. Based on the results of feature embedding and context analysis, an unsupervised learning algorithm is applied to cluster and classify the code snippets to form a library of semantically similar and functionally related code snippets.
2. The method for intelligently assisting software development according to claim 1, characterized in that: Step S1 includes the following contents: S1.1, configure the repository hook script so that it is automatically called every time the code is submitted. The hook script extracts the submitted code snippets and stores them in a temporary database; S1.2, use the gitdiff command to compare the latest submission with the previous version, and extract the newly added or modified code snippets from the differences; S1.3, generate a hash value for each extracted code snippet, check whether there is already a code snippet with the same hash value in the temporary database, and skip it if it exists; S1.4, remove comments and extra whitespace characters in code snippets to unify the code style; S1.5, extract metadata information from the submission log, associate the metadata with the code snippet, and store it in a temporary database; S1.6, storing the preprocessed code snippets in a code snippet library to be analyzed.
3. The software development intelligent assistance method according to claim 1, characterized in that: Step S2 includes the following contents: The function coverage potential coefficient is calculated by comprehensive processing using the warning isolation degree and the function functional rate, and the function coverage potential coefficient is compared with the function coverage potential threshold. If the function coverage potential coefficient is greater than or equal to the function coverage potential threshold, it means that the independence and multifunctional coverage capabilities of the code fragment in the system have reached or exceeded the expected standards, and it is suitable as a basic code fragment to give priority to its optimization and reuse, and generate an available signal; on the contrary, if the function coverage potential coefficient is less than the function coverage potential threshold, it means that the independence and multifunctional coverage capabilities of the code fragment in realizing the function do not meet the expected standards, and it is not suitable as a basic code fragment, and an unavailable signal is generated; For the code snippets that generate usable signals, statistics are collected and summarized to build a basic code snippet library.
4. The software development intelligent assistance method according to claim 3, characterized in that: The logic for obtaining the warning isolation degree is as follows: S2.1.1, parse the abstract syntax tree of the code snippet, identify direct dependencies and indirect dependencies, and build dependency graphs at different levels; S2.1.2, analyze the code execution path and build a timing dependency graph to represent the dependencies between code snippets at different time points; S2.1.3, merge the multi-level dependency graph and the temporal dependency graph to form a comprehensive dependency graph; S2.1.4, assign different capacities to each edge in a multi-level dependency graph, where the capacity value is based on the strength of the dependency and the tightness of the timing dependency; S2.1.5, set the source node s and sink node t of the comprehensive dependency graph, the source node represents the starting point of the code fragment, and the sink node represents the end point of the code fragment; S2.1.6, use the hierarchical maximum flow algorithm to calculate the maximum flow on different levels of the dependency graph; S2.1.7, merge the maximum flow results at different levels to form a comprehensive maximum flow; S2.1.8, based on the maximum flow results, find the minimum cut on the comprehensive dependency graph and determine the multi-level minimum cut edge set; S2.1.9, calculate the total capacity of the multi-level minimum cut edge set to reflect the strength of the comprehensive dependence; S2.1.10, calculate the total capacity of the minimum cut edge set, that is, the sum of the capacities of all cut edges. The warning isolation is defined as the inverse of the minimum cut capacity, and the formula is: Among them, e represents an edge in the comprehensive dependency graph, and the edge represents the dependency relationship between variables and functions in the code snippet; C represents the minimum cut edge set, which is the edge set that separates the source node s and the sink node t in the comprehensive dependency graph; c(e) represents the capacity of edge e, and the capacity value is based on the strength of the dependency and the closeness of the timing dependency.
5. The software development intelligent assistance method according to claim 3, characterized in that: The logic for obtaining the functional rate is as follows: S2.2.1, by parsing the abstract syntax tree of the code snippet, extracting dependencies based on the grammatical structure of the code, and constructing a dependency graph; S2.2.2, the Laplacian matrix is used to represent the structural characteristics of the graph. By calculating the adjacency matrix A and the degree matrix D, the Laplacian matrix L is obtained; S2.2.3, spectral decomposition is used to calculate the eigenvalues and eigenvectors of the Laplacian matrix, and the connectivity and clustering characteristics of the graph are obtained by analyzing the eigenvalues and eigenvectors; S2.2.4, evaluate the coverage and importance of the code snippets in the functional modules by analyzing the eigenvalues and eigenvectors, and select the first k smallest non-zero eigenvalues and their corresponding eigenvectors to represent the important subgroups in the graph; S2.2.5, the functional rate is calculated by analyzing the eigenvalues and eigenvectors to comprehensively calculate the coverage and importance of the code snippets in the functional modules. The functional rate formula is: Among them, v i Indicates the position and connection relationship of the node in the graph; i Represents the connectivity properties of a graph.
6. The software development intelligent assistance method according to claim 1, characterized in that: Step S3 includes the following contents: S3.1, collect and annotate a large number of code snippet samples, covering multiple programming languages and functional modules, tokenize or mark the preprocessed code snippets, and convert them into an input format that can be processed by the model; S3.2, based on the preprocessed code snippets, build a vocabulary, count all code tokens, and assign a unique index ID; S3.3, based on the selected deep learning model architecture, define the model’s input layer, input the token sequence into the model, generate the corresponding embedding vector; build the model’s encoder layer; add the attention mechanism; S3.4, define the loss function and use the labeled dataset for model training; S3.5, using the trained model, inputting the code snippet into the model, generating a corresponding high-dimensional vector representation, normalizing the generated high-dimensional vector, and storing the generated high-dimensional vector in a vector database; S3.6, utilizes the encoder layer and attention mechanism of the model to capture the syntactic and semantic features of the code snippet.
7. The software development intelligent assistance method according to claim 1, characterized in that: Step S4 includes the following contents: S4.1, obtain the code snippet, cursor position, and editing history context information in the current development environment, and use the IDE plug-in to generate the context information of the developer's current code; S4.2, preprocess the collected context information, parse the abstract syntax tree of the current code snippet, extract the code structure and syntax information, and identify the developer's current editing intention and potential requirements based on the cursor position and editing history; S4.3, based on the selected context analysis model, inputs the preprocessed context information to capture the contextual relationship of the code and the editing habits of the developer; The input layer of the context analysis model receives the preprocessed context information, and the encoding layer captures the context dependencies and grammatical structure features of the code snippet; S4.4, training a situational analysis model using annotated datasets; S4.5, deploys the trained situational analysis model to the development environment, receives and analyzes the developer's contextual information in real time, understands the developer's intentions and needs, dynamically adjusts the code snippet recommendation strategy based on the analysis results, generates code snippet recommendations that best suit the current development situation, and uses the model's prediction results to update the recommendation list in real time.
8. The software development intelligent assistance method according to claim 1, characterized in that: Step S5 includes the following contents: Collect feature embedding and context analysis results of all code snippets; Train an unsupervised learning model based on the selected algorithm; For K-means, determine the number of clusters K, initialize the cluster centers, and iteratively update the center points until convergence; Use the trained model to cluster and classify code snippets; For each code snippet, calculate its distance from all cluster centers and assign it to the nearest cluster center; According to the clustering and classification results, a library of semantically similar and functionally related code snippets is constructed, and the code snippets in the same cluster are grouped together to form a collection of code snippets with similar semantics and functions.
9. A software development intelligent assistance system, used to implement a software development intelligent assistance method according to any one of claims 1 to 8, characterized in that: include: Fragment collection module, dependency parsing module, feature embedding module, context analysis module and clustering classification module; The snippet collection module automatically collects the code snippets written by developers each time the code is submitted by configuring the code repository hook, preprocesses the collected code snippets, including removing comments, standardizing indentation and format, building a library of code snippets to be analyzed, and passing the preprocessed code snippet data to the dependency resolution module; The dependency parsing module constructs a multi-level dependency graph and a timing dependency graph for each code snippet in the code snippet library to calculate the maximum flow and minimum cut to quantify the warning isolation of the code snippet. At the same time, it uses the spectral graph theory to evaluate the functional coverage and diversity of the code snippet, calculates the functional functional rate, and comprehensively screens out basic code snippets based on the warning isolation and functional functional rate, builds a basic code snippet library, and passes the screened basic code snippet data to the feature embedding module; The feature embedding module uses a deep learning model to convert the selected basic code snippets into high-dimensional vector representations. Through model training, it captures the grammatical and semantic features of the code, generates embedding vectors that can represent the function and structure of the code, forms a feature embedding library, and passes the generated high-dimensional vector data to the context analysis module and the clustering classification module. The situational analysis module combines the context of the developer's current code writing, uses the situational analysis model to understand the developer's intentions and needs, adjusts the recommended strategy of the code snippet in real time, and sends the situational analysis results to the clustering and classification module; The clustering and classification module uses an unsupervised learning algorithm to cluster and classify code snippets based on feature embedding and context analysis results, forming a library of semantically similar and functionally related code snippets.
Citation Information
Cited By
Method and system for quickly constructing and multiplexing application framework
CN119576290A
Code management system and method based on software demand design
CN120162034A
Code Management System and Method Based on Software Requirement Design
CN120162034B
Method and system for generating standard drive code based on intention understanding
CN121560301A
