Code repository analysis method and system for high-value code extraction
By combining multidimensional feature extraction and machine learning models with dynamic optimization, this method solves the problems of one-sidedness and low efficiency in the identification of high-value code in existing technologies, realizes the automated identification and extraction of high-value code, improves the identification accuracy and coverage, and is suitable for continuous integration environments.
Patent Information
- Application Number
- CN202510965120.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-14
- Publication Date
- 2025-10-31
AI Technical Summary
Existing technologies for identifying and extracting high-value codes suffer from several problems, including reliance on a single indicator leading to bias, high costs of dynamic analysis, low efficiency of manual annotation, and weak cross-warehouse correlation. These issues make it difficult to automatically identify and prioritize the extraction of high-value codes.
By employing multidimensional feature extraction, machine learning models, dynamic optimization, and visualization techniques, the value of code is quantified through static code features, evolutionary history features, and cross-project reuse features. The model is adjusted in real time to adapt to changes in the code ecosystem, providing visualization results and support for code extraction and reuse.
It improved the accuracy of high-value code identification by 30%, enhanced the analysis coverage across code repositories by 50%, and supports incremental analysis in continuous integration environments.
Smart Images

Figure CN120872407A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software development technology, specifically to a code repository analysis method and system for extracting high-value code. Background Technology
[0002] As code repositories grow in size, the challenge becomes how to quickly identify high-value code (such as core technical logic, highly reusable functions, and potential intellectual property protection objects) from massive amounts of code.
[0003] The existing technology has the following drawbacks:
[0004] Static analysis is too simplistic: Traditional methods rely on single metrics such as code complexity and call frequency, which easily overlook code semantics and contextual dependencies;
[0005] Dynamic analysis is costly: runtime behavior analysis requires the deployment of a complete environment, making it difficult to apply to ultra-large-scale warehouses;
[0006] Manual annotation is inefficient: Existing tools rely on manually defined rules and lack the ability to adapt to emerging code patterns.
[0007] Weak cross-repository coherence: Failure to consider code references and reuse across projects leads to a one-sided value assessment.
[0008] How to automatically identify and prioritize the extraction of high-value code is a technical problem that needs to be solved. Summary of the Invention
[0009] The technical objective of this invention is to address the above-mentioned shortcomings by providing a code repository analysis method and system for extracting high-value code, thereby solving the technical problem of how to automatically identify and prioritize the extraction of high-value code.
[0010] In a first aspect, the present invention provides a code repository analysis method for extracting high-value code, comprising the following steps:
[0011] Multidimensional feature extraction: Extract multidimensional features from the code repository, including static code features for static analysis, evolutionary history features for evolutionary history analysis, and cross-project reuse features for cross-project reuse analysis.
[0012] Value scoring: Quantifies code value by integrating multi-dimensional features through machine learning models;
[0013] Dynamic priority adjustment: Real-time optimization of model and feature weights to adapt to changes in the code ecosystem;
[0014] Visualization and Output: Visualize the code analysis results and provide code extraction and reuse.
[0015] As preferred methods, static feature analysis is used to extract code structure complexity and API dependency chains, evolution history analysis is used to count code modification frequency, number of maintainers, and bug fixing history, and cross-project reuse analysis is used to build a reuse network of code modules in multiple repositories and calculate reuse weights.
[0016] As a preferred method, value scoring includes the following steps:
[0017] The static complexity, evolution history, and reusability features are normalized into an N-dimensional vector.
[0018] XGBoost / LightGBM is used to process structured features, code features are classified and DNN layers are stacked to process text features;
[0019] Key features are determined using SHAP values, which include reuse weight and the number of defect associations.
[0020] Utilize online learning and adjust model parameters based on real-time user feedback;
[0021] Output a score within a predetermined range and provide an interpretable report.
[0022] As a preferred approach, when dynamically prioritizing, high-value or low-value misjudged samples are marked through a visual interface, and the feedback data is stored in the annotation database to trigger incremental model training. In the early stages of optimizing the model and feature weights, a rule engine is used to assist in annotation, which is gradually replaced by model-driven training.
[0023] Preferably, the visualization of the analysis results includes heatmaps, dependency maps, and historical evolution trend maps.
[0024] Secondly, the present invention provides a code repository analysis system for extracting high-value code, comprising a multi-dimensional feature extraction module, a value scoring module, a dynamic priority adjustment module, and a visualization and output module.
[0025] The multidimensional feature extraction module is used to perform the following operations: extract multidimensional features from the code repository, including static code features for static analysis, evolutionary history features for evolutionary history analysis, and cross-project reuse features for cross-project reuse analysis;
[0026] The value scoring module performs the following operation: quantifies the value of code by integrating multi-dimensional features through a machine learning model;
[0027] The dynamic priority adjustment module is used to perform the following operations: real-time optimization of model and feature weights to adapt to changes in the code ecosystem;
[0028] The visualization and output module is used to perform the following operations: visualize the code analysis results and provide code extraction and reuse.
[0029] As preferred methods, static feature analysis is used to extract code structure complexity and API dependency chains, evolution history analysis is used to count code modification frequency, number of maintainers, and bug fixing history, and cross-project reuse analysis is used to build a reuse network of code modules in multiple repositories and calculate reuse weights.
[0030] As a preferred option, the value scoring module is used to perform the following operations:
[0031] The static complexity, evolution history, and reusability features are normalized into an N-dimensional vector.
[0032] XGBoost / LightGBM is used to process structured features, code features are classified and DNN layers are stacked to process text features;
[0033] Key features are determined using SHAP values, which include reuse weight and the number of defect associations.
[0034] Utilize online learning and adjust model parameters based on real-time user feedback;
[0035] Output a score within a predetermined range and provide an interpretable report.
[0036] As a preferred option, the dynamic priority adjustment module is used to mark high-value or low-value misjudged samples through a visual interface, and the feedback data is stored in the annotation database to trigger incremental training of the model. In the early stage of optimizing the model and feature weights, the rule engine is used to assist in annotation, and gradually the model takes the lead.
[0037] Preferably, the visualization of the analysis results includes heatmaps, dependency maps, and historical evolution trend maps.
[0038] The code repository analysis method and system for extracting high-value code of the present invention have the following advantages:
[0039] 1. Accuracy improved by 30% (compared to traditional static analysis methods);
[0040] 2. Cross-code repository analysis coverage increased by 50%;
[0041] 3. Supports incremental analysis, suitable for continuous integration environments. Attached Figure Description
[0042] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the 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.
[0043] The invention will be further described below with reference to the accompanying drawings.
[0044] Figure 1 This is a flowchart of a code repository analysis method for extracting high-value code, as described in Example 1. Detailed Implementation
[0045] The present invention will be further described below with reference to the accompanying drawings and specific embodiments, so that those skilled in the art can better understand and implement the present invention. However, the embodiments are not intended to limit the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments can be combined with each other.
[0046] This invention provides a code repository analysis method and system for extracting high-value code, which addresses the technical problem of how to automatically identify and prioritize the extraction of high-value code.
[0047] Example 1:
[0048] This invention provides a code repository analysis method for extracting high-value code, comprising four steps: multi-dimensional feature extraction, value scoring, dynamic priority adjustment, and visualization and output.
[0049] Multidimensional feature extraction: Extract multidimensional features from the code repository. These multidimensional features include static code features for static analysis, evolutionary history features for evolutionary history analysis, and cross-project reuse features for cross-project reuse analysis.
[0050] Among them, multidimensional feature extraction extracts multidimensional features from the code repository, including static code features, evolutionary history features, and cross-project reuse features, including static feature analysis, evolutionary history analysis, and cross-project reuse analysis.
[0051] In this embodiment, static feature analysis is used to extract code structural complexity (such as cyclomatic complexity) and API dependency chains. Evolutionary history analysis is used to statistically analyze code modification frequency, number of maintainers, and bug fixing history. Cross-project reuse analysis is used to construct a reuse network for code modules across multiple repositories and calculate reuse weights.
[0052] Value scoring: Quantifying code value by integrating multi-dimensional features through machine learning models.
[0053] As a specific implementation of value scoring, this step includes the following operations:
[0054] (1) Normalize the static complexity, evolution history, and reusability features into an N-dimensional vector (e.g., 20 key features);
[0055] (2) Use XGBoost / LightGBM to process structured features, classify code features (high value / low value) and stack DNN layers (such as fully connected networks) to process text features (such as annotation semantics);
[0056] (3) Use SHAP (Shapley Additive Explanation) values to determine key features, including reuse weight and number of defect associations;
[0057] (4) Employ online learning and adjust model parameters based on real-time user feedback (such as developers marking "misjudged samples");
[0058] (5) Output a score within a predetermined range and provide an interpretability report. The score output range is a normalized value of 0 to 1. The threshold is configurable (e.g., >0.75 is high value) and an interpretability report is provided (e.g., "This module has a high score because it has been reused by 5 projects and has no historical defects").
[0059] Dynamic priority adjustment: Real-time optimization of model and feature weights to adapt to changes in the code ecosystem.
[0060] During dynamic priority adjustments, the model and feature weights are optimized in real time to adapt to changes in the code ecosystem. Developers use a visual interface to label "high-value misclassifications" or "low-value misclassifications" samples, and the feedback data is stored in the annotation database, triggering incremental model training (e.g., batch updates every night). Initially, a rule engine (e.g., "reuse count > 3 and complexity < 10") is used to assist in annotation, which is gradually replaced by model-driven annotation.
[0061] Visualization and Output: Visualize the code analysis results and provide code extraction and reuse.
[0062] This embodiment presents the analysis results in a visual format, supporting code extraction and reuse. Visualizations include heatmaps (distributing value scores by code directory, with red indicating high value), dependency graphs (showing the call relationships and cross-project reference networks of high-value code), and historical evolution trend charts (curves depicting how code value changes over time, such as a module's score increasing due to improved reusability). It supports exporting to reusable code packages or API documentation.
[0063] An evaluation system is constructed by hybrid analysis of static code complexity, cross-project reusable networks, and evolutionary history features. A fusion model of XGBoost and DNN is used to quantify and score code value. Dynamic optimization is achieved through SHAP interpretability analysis and online learning. High-value modules are visualized using heatmaps and dependency graphs. This method improves identification accuracy by 30%, cross-project coverage by 50%, supports incremental analysis in continuous integration environments, and effectively extracts highly reusable and stable core technology modules.
[0064] Example 2:
[0065] This invention provides a code repository analysis system for extracting high-value code, comprising a multi-dimensional feature extraction module, a value scoring module, a dynamic priority adjustment module, and a visualization and output module.
[0066] The multidimensional feature extraction module is used to perform the following operations: extract multidimensional features from the code repository, including static code features for static code analysis, evolutionary history features for evolutionary history analysis, and cross-project reuse features for cross-project reuse analysis.
[0067] Among them, multidimensional feature extraction extracts multidimensional features from the code repository, including static code features, evolutionary history features, and cross-project reuse features, including static feature analysis, evolutionary history analysis, and cross-project reuse analysis.
[0068] In this embodiment, static feature analysis is used to extract code structural complexity (such as cyclomatic complexity) and API dependency chains. Evolutionary history analysis is used to statistically analyze code modification frequency, number of maintainers, and bug fixing history. Cross-project reuse analysis is used to construct a reuse network for code modules across multiple repositories and calculate reuse weights.
[0069] The value scoring module is used to perform the following operations: quantify the value of code by integrating multi-dimensional features through a machine learning model.
[0070] As a specific implementation of the value scoring module, this module is used to perform the following operations:
[0071] (1) Normalize the static complexity, evolution history, and reusability features into an N-dimensional vector (e.g., 20 key features);
[0072] (2) Use XGBoost / LightGBM to process structured features, classify code features (high value / low value) and stack DNN layers (such as fully connected networks) to process text features (such as annotation semantics);
[0073] (3) Use SHAP (Shapley Additive Explanation) values to determine key features, including reuse weight and number of defect associations;
[0074] (4) Employ online learning and adjust model parameters based on real-time user feedback (such as developers marking "misjudged samples");
[0075] (5) Output a score within a predetermined range and provide an interpretability report. The score output range is a normalized value of 0 to 1. The threshold is configurable (e.g., >0.75 is high value) and an interpretability report is provided (e.g., "This module has a high score because it has been reused by 5 projects and has no historical defects").
[0076] The dynamic priority adjustment module is used to perform the following operations: real-time optimization of model and feature weights to adapt to changes in the code ecosystem.
[0077] As a specific implementation of the dynamic priority adjustment module, this module optimizes the model and feature weights in real time to adapt to changes in the code ecosystem. Developers use a visual interface to label "high-value misclassification" or "low-value misclassification" samples, and the feedback data is stored in the annotation database, triggering incremental model training (e.g., batch updates every night). Initially, a rule engine (e.g., "reuse count > 3 and complexity < 10") is used to assist in annotation, which is gradually replaced by model-driven annotation.
[0078] The visualization and output module is used to perform the following operations: visualize the code analysis results and provide code extraction and reuse.
[0079] This embodiment's visualization and output module is used to display analysis results in a visual format, supporting code extraction and reuse. Visualization formats include heatmaps (showing the distribution of value scores by code directory, with red indicating high value), dependency graphs (displaying the call relationships and cross-project reference networks of high-value code), and historical evolution trend graphs (curves showing how code value changes over time, such as a module's score increasing due to improved reusability). It supports exporting to reusable code packages or API documentation.
[0080] The code repository analysis method and system for extracting high-value code provided by this invention have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this invention. Therefore, the content of this specification should not be construed as a limitation of this invention.
Claims
1. A code repository analysis method for extracting high-value code, characterized in that, Includes the following steps: Multidimensional feature extraction: Extract multidimensional features from the code repository, including static code features for static analysis, evolutionary history features for evolutionary history analysis, and cross-project reuse features for cross-project reuse analysis. Value scoring: Quantifies code value by integrating multi-dimensional features through machine learning models; Dynamic priority adjustment: Real-time optimization of model and feature weights to adapt to changes in the code ecosystem; Visualization and Output: Visualize the code analysis results and provide code extraction and reuse.
2. The code repository analysis method for extracting high-value code according to claim 1, characterized in that, Static feature analysis is used to extract code structure complexity and API dependency chains, evolution history analysis is used to count code modification frequency, number of maintainers, and bug fixing history, and cross-project reuse analysis is used to build a reuse network of code modules in multiple repositories and calculate reuse weights.
3. The code repository analysis method for extracting high-value code according to claim 1, characterized in that, Value rating includes the following steps: The static complexity, evolution history, and reusability features are normalized into an N-dimensional vector. XGBoost / LightGBM is used to process structured features, code features are classified and DNN layers are stacked to process text features; Key features are determined using SHAP values, which include reuse weight and the number of defect associations. Utilize online learning and adjust model parameters based on real-time user feedback; Output a score within a predetermined range and provide an interpretable report.
4. The code repository analysis method for extracting high-value code according to claim 1, characterized in that, When dynamically adjusting priorities, high-value or low-value misjudged samples are marked through a visual interface, and the feedback data is stored in the annotation database to trigger incremental training of the model. In the early stages of optimizing the model and feature weights, a rule engine is used to assist in annotation, which is gradually replaced by model-driven training.
5. The code repository analysis method for extracting high-value code according to claim 1, characterized in that, The visualizations of the analysis results include heatmaps, dependency maps, and historical evolution trend maps.
6. A code repository analysis system for extracting high-value code, characterized in that, It includes a multi-dimensional feature extraction module, a value scoring module, a dynamic priority adjustment module, and a visualization and output module; The multidimensional feature extraction module is used to perform the following operations: extract multidimensional features from the code repository, including static code features for static analysis, evolutionary history features for evolutionary history analysis, and cross-project reuse features for cross-project reuse analysis; The value scoring module performs the following operation: quantifies the value of code by integrating multi-dimensional features through a machine learning model; The dynamic priority adjustment module is used to perform the following operations: real-time optimization of model and feature weights to adapt to changes in the code ecosystem; The visualization and output module is used to perform the following operations: visualize the code analysis results and provide code extraction and reuse.
7. The code repository analysis system for extracting high-value code according to claim 6, characterized in that, Static feature analysis is used to extract code structure complexity and API dependency chains, evolution history analysis is used to count code modification frequency, number of maintainers, and bug fixing history, and cross-project reuse analysis is used to build a reuse network of code modules in multiple repositories and calculate reuse weights.
8. The code repository analysis system for extracting high-value code according to claim 6, characterized in that, The value scoring module is used to perform the following operations: The static complexity, evolution history, and reusability features are normalized into an N-dimensional vector. XGBoost / LightGBM is used to process structured features, code features are classified and DNN layers are stacked to process text features; Key features are determined using SHAP values, which include reuse weight and the number of defect associations. Utilize online learning and adjust model parameters based on real-time user feedback; Output a score within a predetermined range and provide an interpretable report.
9. The code repository analysis system for extracting high-value code according to claim 6, characterized in that, The dynamic priority adjustment module is used to mark high-value or low-value misjudged samples through a visual interface. The feedback data is stored in the annotation database, triggering incremental training of the model. In the early stage of optimizing the model and feature weights, a rule engine is used to assist in annotation, which is gradually replaced by model-driven training.
10. The code repository analysis system for extracting high-value code according to claim 6, characterized in that, The visualizations of the analysis results include heatmaps, dependency maps, and historical evolution trend maps.
