A typical case recommendation method based on weight updating

By using a typical case recommendation method based on weight updates in aerospace software development, combined with a large language model and dynamic weight adjustment, the problems of high missed detection rate and low recommendation accuracy in existing code review are solved, achieving more efficient and accurate code review.

CN122432326APending Publication Date: 2026-07-21BEIJING JINGHANG COMPUTING & COMM RES INST
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING JINGHANG COMPUTING & COMM RES INST
Filing Date
2026-04-15
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

In aerospace software development, existing code review methods rely on human experience and static rule retrieval, resulting in high false negative rates and low review efficiency. Furthermore, case recommendations cannot be optimized and cannot effectively utilize the deep semantic features in code comments, leading to low recommendation accuracy.

Method used

By obtaining code comments from the software source code, semantic parsing is performed using a pre-trained large language model to extract keywords and classification labels. Combined with a case recommendation method with dynamic weight updates, typical cases are recommended based on semantic similarity and label consistency.

Benefits of technology

It improves the accuracy and efficiency of code review, ensures more precise recommendations for typical cases, dynamically adjusts case weights to adapt to actual review scenarios, and enhances code matching accuracy and the practicality of recommendations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122432326A_ABST
    Figure CN122432326A_ABST
Patent Text Reader

Abstract

The present application relates to a kind of typical case recommendation method based on weight update, belong to equipment software testing technical field, solve the problem that the existing space software code review is caused by poor code readability and leads to high rate of missed detection, low review efficiency and case recommendation cannot optimize.For method, the code annotation of each function of the software source code to be reviewed is obtained, and the keyword set therein is extracted;Based on the keyword set of each function, the matching knowledge block is retrieved from the software test typical case knowledge base, and the current weight of each case classification label of each knowledge block is combined to obtain the recommended typical case;Wherein, each knowledge block of software test typical case knowledge base is associated with multiple predefined case classification labels of different categories, and each case classification label has a dynamic weight;The matching degree score of the recommended typical case is obtained, and the weight of each case classification label of the recommended typical case is adjusted based on the matching degree score result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of equipment software testing technology, and in particular to a typical case recommendation method based on weight updates. Background Technology

[0002] In the aerospace software development system, code review is a mandatory and crucial step to ensure high security and reliability. Testers must rigorously review the code according to aerospace software coding standards, design documents, and related specifications. The review focuses on the consistency between the code implementation and the design scheme, the code's compliance with execution standards, the correctness of the code's logical expression, the rationality of the code structure, and the readability of the code. This ensures that aerospace software meets the core requirements for high security and reliability. Through years of engineering practice, aerospace testing experts have analyzed, categorized, and refined typical errors discovered during testing, forming a structured typical case knowledge base containing error patterns, review criteria, and remediation suggestions to guide subsequent testing work. During testing, testers are typically required to ensure that no similar errors already included in the typical case knowledge base are overlooked.

[0003] Currently, review work based on typical case knowledge bases mainly relies on manual experience comparison and static rule retrieval. Manual experience comparison involves testers subjectively associating similar error cases from their memory while reading code, based on their personal technical accumulation and project familiarity. However, in this case, due to varying degrees of familiarity with the project background and business logic among testers, coupled with their varying technical experience, the same code segment may receive inconsistent conclusions from different reviewers. Known errors recorded in the typical case database are easily missed due to insufficient experience, resulting in compromised review coverage. Static rule retrieval uses keyword matching or basic semantic similarity tools to find cases in the knowledge base that are literally or superficially semantically similar to the current code segment. However, existing case recommendations are one-off; regardless of the effectiveness of the recommendation results, they cannot be optimized for subsequent recommendations. A case that is frequently proven effective will not automatically have its recommendation priority increased; a case that is ineffective in certain scenarios will not be demoted in a timely manner, leading to a long-term stagnation in case recommendation accuracy. Summary of the Invention

[0004] Based on the above analysis, the embodiments of the present invention aim to provide a typical case recommendation method based on weight updates, in order to solve the problems of high missed detection rate, low review efficiency, and inability to optimize case recommendation in existing aerospace software code review due to poor code readability.

[0005] The objective of this invention is mainly achieved through the following technical solutions:

[0006] This invention provides a typical case recommendation method based on weight updates, comprising the following steps: Obtain the code comments for each function in the source code of the software to be reviewed and extract the set of keywords from them; Based on the keyword set of each function, matching knowledge blocks are retrieved from the software testing typical case knowledge base, and recommended typical cases are obtained by combining the current weights of each case classification label of each knowledge block; wherein, the software testing typical case knowledge base includes multiple knowledge blocks, each knowledge block corresponds to a typical error case and is associated with a case classification label set; the case classification label set includes multiple predefined case classification labels of different categories, and each case classification label has a dynamic weight; Obtain a matching score for the recommended typical cases, and adjust the weights of each case category label of the recommended typical cases based on the matching score results.

[0007] Furthermore, the keyword set includes a set of annotation keywords and a set of annotation category tags; wherein, The set of annotation keywords is obtained by semantic parsing of the code comments in the source code of the software to be reviewed, and is used to reflect the functional logic and business attributes of the code. The annotation category tag set has the same dimension as the case category tag set of each knowledge block in the software testing typical case knowledge base, and is used to reflect the core features of the code.

[0008] Furthermore, the set of comment keywords is obtained by semantically parsing the code comments of the source code of the software to be reviewed, including: Based on a predefined vocabulary of phrases belonging to the domain of the source code of the software to be reviewed, a first subset of annotation keywords is identified and extracted from the code annotations; The code comments of the source code of the software to be reviewed are semantically parsed using a pre-trained large language model to obtain a second subset of comment keywords; wherein, the pre-trained large language model is fine-tuned based on training data of the domain to which the source code of the software to be reviewed belongs; The set of annotation keywords is obtained by taking the union of the first subset of annotation keywords and the second subset of annotation keywords.

[0009] Furthermore, each annotation category tag in the annotation category tag set corresponds to a predefined case category tag; wherein, the case category tags include software operating environment category tags, software application domain category tags, software functional module category tags, software design attribute category tags, and error type category tags.

[0010] Furthermore, the software operating environment classification labels and the software application domain classification labels are manually specified classification labels; The software function module classification labels, the software design attribute classification labels, and the error type classification labels are corresponding classification labels selected from the predefined candidate label sets corresponding to each label category, based on the code comments of the source code of the software to be reviewed and the set of comment keywords.

[0011] Furthermore, based on the keyword set of each function, matching knowledge blocks are retrieved from the software testing typical case knowledge base, and recommended typical cases are obtained by combining the current weight of each case classification label of each knowledge block, including: for each function in the software source code, the following steps are performed: Based on the annotation classification label set of the current function and the case classification label set of each knowledge block, a label consistency measure is performed to obtain an initial knowledge block candidate set; Calculate the semantic similarity between the set of annotation keywords for the current function and each knowledge block in the initial knowledge block candidate set; For each knowledge block in the initial knowledge block candidate set, a recommendation score for the current function is calculated based on the corresponding semantic relevance, label consistency metric, and the current weight of each case classification label therein. Based on the recommendation scores, typical recommended cases are obtained.

[0012] Furthermore, the label consistency measurement based on the annotation category label set of the current function and the case category label set of each knowledge block includes: the number of consistent category labels in the annotation category label set and the case category label set of each knowledge block among all predefined label categories.

[0013] Furthermore, the calculation of the recommendation score for the current function includes: for each knowledge block, performing the following steps: The label consistency ratio is obtained based on the number of consistent classification labels and the total number of classification labels in the annotation classification label set; Based on the current weights of each case category label in the case category label set, the normalized label weight mean is obtained; The semantic similarity, the label consistency ratio, and the normalized label weight mean are monotonically transformed and then weighted and summed to obtain the recommendation score of the current knowledge block for the current function.

[0014] Furthermore, the adjustment of the weights of each case category label associated with the recommended typical cases based on the matching score includes: The matching score result is mapped to a target weight value within a preset range; Based on the target weight value, the current weight of the case classification label, and the smoothing factor, the adjusted weight of the case classification label is obtained using the following formula: ; in, This represents the adjusted weight of the category label for the i-th case in knowledge block p; This represents the current weight of the category label for the i-th case in knowledge block p; The smoothing factor represents the knowledge block p; This represents the target weight value of knowledge block p; and These represent the lower and upper weight limits, respectively; clip() represents the clipping function.

[0015] Furthermore, the smoothing factor of the knowledge block is calculated based on the number of matching feedbacks corresponding to the knowledge block, and its formula is as follows: ; in, Indicates the initial smoothing factor; Indicates the attenuation parameter; This represents the number of times the matching degree of knowledge block p has been reported.

[0016] Compared with the prior art, the present invention can achieve at least one of the following beneficial effects: 1. This invention associates a dynamic weight with the classification label of each case in the knowledge base, and recommends relevant cases based on the current weight when recommending cases. This makes the recommended cases obtained based on the keywords extracted from the code comments not only rely on fixed text similarity, but also reflect the effectiveness of different error features in actual review scenarios. Cases that have been verified to be effective will be recommended with higher priority, making the recommendation results more accurate and practical.

[0017] 2. This invention uses a large language model finely tuned based on the domain corpus of software source code for deep semantic feature extraction, and combines it with classification tags for hybrid retrieval. This enables accurate parsing of complex domain terms and designs in code comments, improving the accuracy of keyword extraction and making the recommended cases more precise.

[0018] 3. This invention scores the matching degree of recommended typical cases and then updates the weight of the case classification tags of the recommended typical cases. Through dynamic adjustment of the weight, the matching accuracy between typical cases and the code to be reviewed can be improved when recommending cases, and typical cases can be recommended quickly and accurately.

[0019] In this invention, the above-described technical solutions can be combined with each other to achieve more preferred combinations. Other features and advantages of this invention will be set forth in the following description, and some advantages may become apparent from the description or be learned by practicing the invention. The objects and other advantages of this invention can be realized and obtained from what is particularly pointed out in the description and drawings. Attached Figure Description

[0020] The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. Throughout the drawings, the same reference numerals denote the same parts.

[0021] Figure 1 This is a flowchart illustrating a typical case recommendation method based on weight updates in an embodiment of the present invention. Detailed Implementation

[0022] Preferred embodiments of the present invention will now be described in detail with reference to the accompanying drawings, which form part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not intended to limit the scope of the present invention.

[0023] A specific embodiment of the present invention discloses a typical case recommendation method based on weight updates, such as... Figure 1 As shown, it includes the following steps S1-S3: Step S1: Obtain the code comments of each function in the source code of the software to be reviewed and extract the set of keywords from them.

[0024] Step S2: Based on the keyword set of each function, retrieve matching knowledge blocks from the software testing typical case knowledge base, and combine the current weights of each case classification label of each knowledge block to obtain recommended typical cases; wherein, the software testing typical case knowledge base includes multiple knowledge blocks, each knowledge block corresponds to a typical error case and is associated with a case classification label set; the case classification label set includes multiple predefined case classification labels of different categories, and each case classification label has a dynamic weight.

[0025] Step S3: Obtain the matching score of the recommended typical cases, and adjust the weight of each case category label of the recommended typical cases based on the matching score result.

[0026] Specifically, the source code of the software to be reviewed is obtained from the file storage path specified by the software version control system, such as Git or SVN. It usually includes at least one project, and each project includes several source code files (such as .c, .cpp, .h, and .java files).

[0027] The functions in the source code of the software under review refer to code blocks written in a programming language, defined in the source code through a specific syntax structure, performing a specific function, and capable of being independently compiled or analyzed. In this embodiment, they are basic atomic units. The code comments for the functions include function-level code comments and line-level code comments. Function-level code comments are located before the function definition or near the function declaration, used to describe the overall function's functionality, input / output parameters, return value, exception handling, or usage constraints. Line-level code comments are located inside the function body, bound to specific code statements or variables, used to explain the meaning of key variables, branch judgment logic, exception handling mechanisms, or key design intentions. It should be noted that the code comments are obtained solely based on the source code text, without relying on the compilation or execution results of the code.

[0028] More specifically, the process involves traversing all the source code of the software to be reviewed. For each code file, the parser of its corresponding programming language is invoked, performing lexical and syntactic analysis sequentially. Based on the grammatical rules of the programming language, an Abstract Syntax Tree (AST) is constructed. Each node in the tree represents a grammatical construct in the source code, including but not limited to expressions, statements, and declarations. A depth-first or breadth-first search algorithm is used to traverse the AST. Whenever a tree node of type "function definition" is accessed, a function entity to be processed is identified. The "function definition" node includes a child node representing a compound statement; this child node and all its descendant nodes constitute the function body. In the AST, comments typically exist as "comment tokens" attached to specific grammatical nodes. Therefore, the starting position of the "function definition" node in the original source code is accessed, and the token flow before the function definition's starting position is traced back to identify the nearest unoccupied multi-line comment block, typically in the format / ... / or / ... The slash " / " serves as a descriptive comment for a function, i.e., a function-level code comment; within the function body boundaries, all single-line comments are scanned, typically in the format " / / ...", serving as line-level code comments.

[0029] Furthermore, keyword extraction is performed on the function-level code comments and the line-level code comments to obtain a keyword set for each function; the keyword set includes a comment keyword set and a comment category tag set; wherein, The set of annotation keywords is obtained by semantic parsing the code comments of the source code of the software to be reviewed, and is used to reflect the functional logic and business attributes of the code.

[0030] The annotation category tag set has the same dimension as the case category tag set of each knowledge block in the software testing typical case knowledge base, and is used to reflect the core features of the code.

[0031] Specifically, to avoid the fragmentation of code comments affecting subsequent analysis, the extracted function-level and line-level code comments are preprocessed for standardization, and then integrated according to their position in the code to obtain preprocessed code comments. The preprocessing includes: adding periods or other closing symbols to line-level comments that do not have a closing symbol to avoid semantic or structural ambiguity in subsequent keyword extraction and typical case matching; and performing whitespace removal, standardization of punctuation, lowercase conversion of English letters, and conversion of full-width Chinese characters to half-width characters on all code comments. If the standardized strings are the same, they are considered duplicates, and the comment that appears first or in the function-level comments is retained.

[0032] Furthermore, the set of comment keywords is obtained by semantically parsing the code comments of the source code of the software to be reviewed.

[0033] Specifically, the annotation keywords are used to represent the high-level semantic summary of the design intent and business logic described by the code comments in the source code of the software to be reviewed. Obtaining the set of annotation keywords includes steps S11-S13: Step S11: Based on a predefined phrase list of the domain to which the source code of the software to be reviewed belongs, identify and extract a first subset of annotation keywords from the code annotations.

[0034] Specifically, to reduce reliance on subjective human experience, a structured, multi-dimensional case classification tagging system is pre-constructed based on the domain of the software source code to be reviewed. This system provides a standard knowledge framework. In this embodiment, the case classification tagging system includes five categories of aerospace-related case classification tags, each tag used to accurately characterize the core features of the code. The case classification tags include: software operating environment category tags, where tag values ​​can be embedded software, non-embedded software, FPGA software, etc.; software application domain category tags, where tag values ​​can be general software, big data software, office software, attitude control system, data transmission, task scheduling, etc.; software functional module category tags, where tag values ​​can be initialization, data acquisition, interface communication, driver, algorithm, storage, etc.; software design attribute category tags, where tag values ​​can be software reliability design, software security design, interface reliability design, interrupt reliability design, data acquisition and processing, device usage, etc.; and error type category tags, where tag values ​​can be logical errors, data anomalies, interface incompatibility, etc.

[0035] More specifically, to accurately capture core aerospace-related terms in the comments of the software source code under review, a high-frequency phrase vocabulary for aerospace software is predefined. This vocabulary is derived from all tag values ​​in the five categories of aerospace case classification labels mentioned above. A matching algorithm is used to preferentially identify key aerospace-related phrases from the code comments, ensuring these phrases are retained in the keyword set, thus obtaining a first subset of comment keywords. The matching algorithm can use a multi-pattern string matching algorithm (such as one based on the Aho-Corasick automaton), supporting simultaneous matching of thousands of phrases in the vocabulary.

[0036] Step S12: Use a pre-trained large language model to perform semantic parsing on the code comments of the source code of the software to be reviewed, and obtain a second subset of comment keywords; wherein, the pre-trained large language model is obtained by fine-tuning training data based on the domain of the source code of the software to be reviewed.

[0037] Specifically, in order to gain a deeper understanding of the semantics of the annotations, richer keywords are generated through a specially fine-tuned large language model. The large language model selected is a general-purpose large language model with strong code understanding capabilities, such as the Qwen-Coder series and CodeLlama.

[0038] More specifically, the general-purpose large language model is fine-tuned based on aerospace software annotation corpus, including: A training dataset is constructed, including code comment text as sample data and corresponding keyword sets as labels. The sample data includes comments corresponding to knowledge blocks in the software testing typical case knowledge base and comments from real code repositories that have been manually selected and supplemented. The comment text is subjected to unification and noise reduction processing, including symbol standardization, cleaning up mixed Chinese and English text, and abbreviation expansion. At the same time, in order to improve the robustness of the large language model, this embodiment introduces lightweight data augmentation, such as synonym rewriting, structural rearrangement, and negative sample construction, while ensuring that the augmentation does not distort the core semantics of the original comments. For the comments corresponding to knowledge blocks in the software testing typical case knowledge base in the sample data, their labels are directly derived from the standardized keyword set in the knowledge base that has been reviewed and entered by domain experts. For the comments from real code repositories in the sample data that have been manually selected and supplemented, their labels are extracted manually by professionals with knowledge in the aerospace field, based on the comment content, from a set of keywords that best reflect the code's functional logic, business attributes, and task scenarios.

[0039] To ensure that the fine-tuned large language model can fully understand various concepts in the aerospace software field, the constructed training dataset must cover all the label content of the case classification label system, so as to ensure that the model can extract core terms that reflect functional logic and task characteristics from the annotations.

[0040] When training large language models, efficient fine-tuning techniques such as LoRA or InstructionTuning are used to make the model more compliant with formatted output and domain constraints. To improve format compliance and reduce illusion rate, the training loss function is the standard cross-entropy loss. Format constraint loss and semantic consistency loss The weighted sum loss function is expressed as: ; Among them, standard cross-entropy loss The keyword set generated by the model is literally consistent with the keyword set annotated by humans; format constraint loss. Used to penalize samples whose output does not conform to the JSON Schema, in order to enhance format controllability; The weight representing the format constraint loss can be set to 0.5 for example; semantic consistency loss. This is used to measure the distance between model-generated keywords and manually labeled keywords in the semantic embedding space, in order to encourage the model to align with the manual labels at the semantic level, reduce synonym expression bias and semantic drift, and thus improve the semantic accuracy and robustness of keyword extraction. The weight representing the semantic consistency loss can be set to 0.2 or 0.3, for example. More specifically, the semantic consistency loss... The following formula is used to calculate: ; in, and These represent the average semantic embedding vectors of the predicted keyword set and the labeled keyword set, respectively, which can be obtained by the model encoder or the domain text embedding model.

[0041] During the inference process after training, a keyword extraction prompt template is introduced to generate keyword extraction prompts. These prompts constrain the model's output range and guide semantic focus. The design principles of the keyword extraction prompt template include: clear extraction objectives, with keywords covering code functional logic, business attributes, data interaction relationships, and task scenarios; constraining the output to JSON format, using `response_format` to force a fixed and automatic output for easier subsequent automated processing; and prompting semantic focus, encouraging the model to pay attention to code comments and contextual logic, rather than additional speculation or irrelevant information. For example, the keyword extraction prompt template can be: “ @system: You are a code analysis expert. Based on the provided code comment {C} and the context, please extract the relevant... Keywords covering the code's functional logic, business attributes, data interaction relationships, and task scenarios. Requirements: 1. Extract 3-7 keywords; 2. Extract keywords only from the provided content; do not introduce any external background / assumptions / domain knowledge, and do not fabricate information. Construction or inference details 3. The output must strictly follow the following JSON structure: { "keywords": ["keyword1","keyword2",...], "extracted_examples": ["corresponding comment line text 1","comment line text 2",...] } Example: If the code segment implements the "spacecraft attitude control system data synchronization logic", then the core keywords extracted by LLM are... for: { Keyword keywords: ["spacecraft", "attitude control system", "data synchronization", "logic processing"] "extracted_examples": ["Functionality: Implements data synchronization logic for spacecraft attitude control system"] }".

[0042] Replace the "" in the keyword extraction prompt template with the code comment. {C} "Obtain keyword extraction prompts, and through the pre-trained large language model, obtain the second subset of annotation keywords."

[0043] Step S13: Take the union of the first subset of annotation keywords and the second subset of annotation keywords to obtain the set of annotation keywords.

[0044] Specifically, the keywords of the first subset of annotation keywords and the second subset of annotation keywords are merged, and duplicate keywords are removed to obtain the set of annotation keywords.

[0045] Furthermore, each annotation category tag in the annotation category tag set corresponds to a predefined case category tag; wherein, the software operating environment category tag and the software application domain category tag are manually specified category tags; The software function module classification labels, the software design attribute classification labels, and the error type classification labels are corresponding classification labels selected from the predefined candidate label sets corresponding to each label category, based on the code comments of the source code of the software to be reviewed and the set of comment keywords.

[0046] Specifically, when creating a test project or test task, the tester manually selects and fixes the software operating environment classification label and the software application domain classification label from the candidate list of the case classification label system based on the known attributes of the software under test and the engineering background. These two types of labels usually have global consistency at the project level and depend on clear engineering context information (such as target platform and task system type). Manual determination can effectively avoid misjudgment caused by insufficient annotation information in the model.

[0047] For annotation category tags that are closely related to the specific code implementation logic, design intent, and potential defects, this embodiment uses a large language model to automatically determine them based on the code context, so as to achieve refined and dynamic classification.

[0048] In one specific embodiment, a general large language model is used to classify the code comments and comment keyword set of the input software source code to be reviewed according to the category of the classification label and the corresponding candidate label set. Using a pre-built comment classification label extraction prompt word template, comment classification label extraction prompt words are generated, which can achieve efficient and standardized assembly of prompt words.

[0049] For example, the annotation category tag extraction prompt word template can be: “ @system: You are a code analysis expert. Targeting the specified tag category { }, according to the provided code comments { } and keyword set { }, from the candidate tag set corresponding to this category { Choose one and only one best match from} Tags. Please strictly adhere to the following rules: 1. Only make judgments within the currently given tag category range; 2. The output must contain one and only one label; 3. If no candidate label can be explicitly matched, NULL must be output; 4. No labels outside of external context, empirical inferences, or candidate sets are permitted. 5. The output should include the corresponding evidence field and confidence level, clearly indicating the selection criteria. The basis for the annotation of the tag.

[0050] 6. The output must strictly follow the JSON structure, as shown in the example below: { "label": "Data Acquisition", "evidence": "Reading sensor data", "confidence": 0.7 } If confidence < { }(For example If the value is less than or equal to NULL, then the label should be marked as NULL. Replace the code comment with the comment category tag in the prompt word template. {C} Replace the "" in the annotation category tag extraction prompt word template with the set of annotation keywords. { } Replace the annotation category tag extraction prompt word template with the category tag of the case to be generated this time. { }、 Replace the candidate tag set corresponding to the case category tags to be generated this time in the annotation category tag extraction prompt word template. { } And replace the confidence threshold in the annotation category label extraction prompt word template { } The keyword extraction prompts are obtained. It should be noted that during the generation of annotation classification labels for any category, the large language model can only select the most matching label from the candidate label set corresponding to that category as the output result; when no candidate label can be explicitly matched, the output is uniformly empty. When the output content is not any candidate label or is empty, the large language model classification is repeated until a most matching label is selected as the output result.

[0051] By concatenating the manually specified software operating environment classification labels and software application domain classification labels, as well as the software function module classification labels, software design attribute classification labels, and error type classification labels extracted using a large language model, a set of annotation classification labels corresponding to the function is obtained.

[0052] The software testing typical case knowledge base described in this embodiment is a domain knowledge database specifically designed, structured, stored, and organized for aerospace software code review. The knowledge blocks in the knowledge base serve as core data units, with each knowledge block corresponding to a typical error case in aerospace software. That is, each knowledge block uniquely represents a typical error case. Each typical error case is associated with a case classification tag set by default. The case classification tag set strictly follows the predefined case classification tag system described above. In each dimension, the most appropriate tag is selected from the predefined candidate tag values ​​to accurately represent the core features of the typical error case.

[0053] During the initialization phase of the software testing typical case knowledge base, an initial weight is assigned to each tag. For example, all weights can be set to 1.0, meaning that in the initial state, each tag has an equal influence on the case matching result. At the same time, each knowledge block must completely store all information of the typical cases, including but not limited to: the specific manifestation of the error (such as runtime error messages, functional failure phenomena), the corresponding aerospace software review guidelines, and error repair technical solutions (such as code modification paths, parameter adjustment suggestions), providing a complete basis for subsequent testers' decisions.

[0054] Furthermore, based on the keyword set of each function, matching knowledge blocks are retrieved from the software testing typical case knowledge base, and recommended typical cases are obtained by combining the current weight of each case classification label of each knowledge block, including: for each function in the software source code, the following steps S21-S24 are executed: Step S21: Based on the annotation classification label set of the current function and the case classification label set of each knowledge block, perform label consistency measurement to obtain an initial knowledge block candidate set.

[0055] Specifically, to improve retrieval accuracy and computational efficiency, structured classification tags are used to quickly filter out cases from a massive knowledge base that have a basic degree of matching with the current function to be reviewed in the core dimensions.

[0056] Furthermore, the label consistency measure includes the number of consistent label categories among all predefined label categories, including the set of annotation category labels and the set of case category labels for each knowledge block.

[0057] When the number of knowledge blocks that have the same classification labels as the code comments of the source code of the software to be reviewed is greater than or equal to a preset threshold, they are used as the initial knowledge block candidate set.

[0058] Specifically, since both the annotation category tag set and the case category tag set for each knowledge block are based on the case category tag system, their dimensions are consistent. The tag consistency number is calculated using the following formula: ; in, This represents the number of tags that match the j-th knowledge block; N represents the total number of tags. This represents the i-th annotation category label in the annotation category label set; This represents the category label of the i-th case in the j-th knowledge block; 1() represents the indicator function, which takes 1 when the labels are exactly the same, and 0 otherwise.

[0059] More specifically, in this embodiment, the total number of tags in the set is 5. Therefore, when the number of consistent tags is greater than or equal to 4, that is, there are 4 or more consistent tags, the knowledge block can be used for typical case retrieval. When the number of consistent tags is less than or equal to 3, the knowledge block is not considered directly. If no knowledge block meets the threshold, an empty string is output directly. It should be noted that by adjusting the preset threshold, it can adapt to the specific requirements of different testing stages or projects.

[0060] Step S22: Calculate the semantic similarity between the annotation keyword set of the current function and each knowledge block in the initial knowledge block candidate set.

[0061] Specifically, keywords in software code often have complex semantic relationships. To reduce the impact of keyword order differences on semantic vectors, a hybrid strategy combining concatenated vectorization and average vectorization is introduced in keyword semantic vectorization. Concatenated vectorization preserves the contextual dependencies and combinatorial semantics between keywords through overall embedding, accurately reflecting the inherent connections between complex technical concepts. To reduce the impact of keyword order on semantic representation, this embodiment introduces average vectorization to eliminate the perturbation of the embedding space by the input order, thereby improving the stability of semantic representation, including: The set of comment keywords for the current function The keywords in the text are concatenated according to their order in the set to obtain the complete text. : .

[0062] The overall text is obtained using a semantic embedding model. The overall semantic vector .

[0063] For each keyword in the annotation keyword set K, the semantic embedding model is used to obtain the corresponding keyword semantic vector, and then the arithmetic average is performed to obtain the average semantic vector. .

[0064] The overall semantic vector and the average semantic vector The semantic vector of the annotation keyword set is obtained by fusion using a weighted summation method. ; wherein, the overall semantic vector Provides contextual integrity; the average semantic vector The bias introduced by word order was suppressed; the weight was used to adjust the balance between the two, and the weight range could be set empirically to [0.7, 0.8].

[0065] Similarly, the semantic vector of each knowledge block in the initial knowledge block candidate set is obtained through the semantic embedding model.

[0066] Calculate the semantic vector of the set of annotation keywords for the current function. The cosine similarity between the semantic vectors of each knowledge block in the initial knowledge block candidate set and the semantic vectors of each knowledge block. To determine the matching degree between each typical case knowledge block and the source code of the software to be reviewed; where p represents the p-th knowledge block in the initial knowledge block candidate set.

[0067] It should be noted that, since the original input vectors of the semantic embedding model have varying magnitudes, directly performing dot product or distance calculations would affect the results due to the vector length, thus masking the true semantic relationships. Therefore, this embodiment performs [further processing] on all embedded vectors. Normalization is performed so that the magnitude is 1. After normalization, the geometric relationship between semantic vectors is determined only by the difference in direction, which can guarantee the numerical stability and comparability of similarity measurement.

[0068] The semantic embedding model described in this embodiment is a deep learning model pre-trained on a large-scale general text corpus. For example, OpenAI's embedding models such as text-embedding-3-large and Sentence-BERT are models that can map text of arbitrary length into numerical vectors of fixed dimensions that include semantic information. Using the same model to obtain semantic vectors can ensure consistency in the semantic space.

[0069] Step S23: For each knowledge block in the initial knowledge block candidate set, calculate the recommendation score for the current function based on the corresponding semantic relevance, label consistency metric, and the current weight of each case classification label. For each knowledge block, execute the following steps S231-S233: Step S231: Based on the number of consistent classification labels and the total number of classification labels in the annotation classification label set, obtain the label consistency ratio.

[0070] Specifically, the label consistency ratio is used to ensure the rationality of the recommended knowledge blocks within the domain rule framework, and its formula is as follows: ; in, N represents the number of identical labels for knowledge block p in the initial candidate set of knowledge blocks; N represents the total number of labels. This represents the label consistency ratio of knowledge block p in the initial knowledge block candidate set.

[0071] Step S232: Based on the current weights of each case classification label in the case classification label set, obtain the normalized label weight mean.

[0072] Specifically, to avoid recommendation bias caused by excessively low or high current weights of case category tags, the average tag weight of each knowledge block is calculated. ; Based on the average of the label weights Maximum weight value and minimum weight value The normalized mean label weight of knowledge block p in the initial knowledge block candidate set is obtained using the following formula. : .

[0073] Step S233: After performing monotonic transformations on the semantic similarity, the label consistency ratio, and the normalized label weight mean, perform a weighted summation to obtain the recommendation score of the current knowledge block for the current function.

[0074] Specifically, to address the differences in numerical scale and distribution among the components, parameterizable monotonic transformations are applied to the three original components before fusion to adjust their numerical sensitivity and dynamic range. The transformations maintain monotonicity, thus preserving the fundamental relative ordering while effectively regulating the influence of each component. The following formula is used to perform a power-law monotonic transformation on each component of each knowledge block: ; in, , , These represent the semantic similarity transformation index, the label consistency ratio transformation index, and the normalized weight mean transformation index, respectively. All three values ​​are configurable hyperparameters and remain within the range [0,1] after transformation. For example, they can be set to... For smaller This amplifies the signal, enhancing its ability to distinguish weakly correlated signals. Even with low similarity, it retains some difference information, preventing the scores of all low-similarity cases from being compressed to near zero. (Settings are possible.) For larger Compression is performed to suppress the linear amplification effect of the label consistency ratio, through The transformation can be smoothed out, preventing over-reliance on perfect label matching and encouraging it to consider semantic information at the same time. Typically, the value is set to 1 (unchanged), indicating that the influence of the historical weighted mean is linear and direct; the initial parameter can be set to... , , .

[0075] More specifically, the components of each knowledge block after monotonic transformation are weighted and fused to obtain the final recommendation score. The higher the score, the higher the recommendation priority of the knowledge block. The weight of each component is 1.

[0076] Step S24: Based on the recommendation score, obtain typical recommended cases.

[0077] Specifically, the recommendation scores of the current function and each knowledge block in the initial knowledge block candidate set are sorted from high to low. From the top of the sorted list, the top K (for example, K=3) knowledge blocks with the highest similarity are selected, which are the typical cases recommended by the system to the current function.

[0078] Furthermore, in step S3, for the recommended typical cases, a matching score is given to the "matching effectiveness between typical cases and actual code problems" in conjunction with the actual problems in the current software source code to be reviewed. Based on the matching score results, the weights of each case category label associated with the recommended typical cases are adjusted, including: The matching score result is mapped to a target weight value within a preset range.

[0079] Specifically, the matching score uses a preset 5-point scale; where 1 point indicates no match, meaning the case is irrelevant to the current code problem; 2 points indicate a slight match, meaning the case has only marginal relevance; 3 points indicate a basic match, meaning the case points to a related problem type, but the specific manifestation is different; 4 points indicate a high match, meaning the case accurately points to the essence of the problem, with highly similar details; and 5 points indicate a perfect match, meaning the case is completely consistent with the current code problem. When the score is ≥3 points (i.e., the matching validity is "basic match" or above), it indicates that the tags of this knowledge block have a high degree of fit with the keywords of the current code comment, and the weight of all tags of this knowledge block is adjusted by a preset increase. When the score is ≤2 points (i.e., the matching validity is "slight match" or below), it indicates that the tags of this knowledge block have a low degree of fit with the keywords of the current code comment, and the weight of all tags of this knowledge block is adjusted by a preset decrease.

[0080] More specifically, the discrete matching score results Use the following formula to linearly map to a continuous target weight interval. The corresponding target weight value is obtained:

[0081] in, This represents the matching score of knowledge block p in the initial set of candidate knowledge blocks; This represents the target weight value of knowledge block p in the initial set of candidate knowledge blocks; and These represent the minimum and maximum matching scores, respectively. In this embodiment, the minimum score is 1 and the maximum score is 5.

[0082] Furthermore, based on the target weight value, the current weight of the case classification label, and the smoothing factor, the adjusted weight of the case classification label is obtained using the following formula: ; in, This represents the adjusted weight of the category label for the i-th case in knowledge block p; This represents the current weight of the category label for the i-th case in knowledge block p; The smoothing factor represents the knowledge block p; This represents the target weight value of knowledge block p; and represents the lower and upper bounds of the weights, respectively. In this embodiment, the lower and upper bounds are 0.5 and 1.5, respectively; clip() represents the clipping function, used to limit the weights to a certain value. and between.

[0083] Furthermore, the smoothing factor of the knowledge block is calculated based on the number of matching feedbacks corresponding to the knowledge block, and its formula is as follows: ; in, Indicates the initial smoothing factor; Indicates the attenuation parameter; This represents the number of times the matching degree of knowledge block p has been reported.

[0084] Specifically, to reduce the sensitivity of mature knowledge blocks to a single new feedback, the influence intensity of a single feedback can be adjusted according to the cumulative number of feedbacks to the knowledge block, wherein the initial smoothing factor... It can be set to 0.1; the attenuation parameter can be set to 0.05.

[0085] The weight adjustment method in this embodiment can ensure that a single extreme feedback is smoothly absorbed, and multiple consistent feedbacks can gradually accumulate and change the weight. For newly added cases or cases that have been evaluated less frequently, the system reacts quickly to the feedback, which is convenient for quickly accumulating initial experience. For mature cases or cases that have been evaluated multiple times, the system reacts cautiously to the feedback, and the weight changes smoothly, avoiding drastic fluctuations in stable knowledge due to a single abnormal score, thereby balancing the sensitivity and robustness of the weight.

[0086] After the weighting adjustment, it is updated to the corresponding knowledge block in the software testing typical case knowledge base for subsequent score calculation of typical case recommendations. Through the above dynamic adjustment mechanism, the knowledge base can optimize the case recommendation priority based on actual review feedback, and gradually improve the matching accuracy between typical cases and the code to be reviewed.

[0087] In summary, the typical case recommendation method based on weight update according to the embodiments of the present invention has the following beneficial effects: 1. In this embodiment of the invention, a dynamic weight is associated with the classification label of each case in the knowledge base, and relevant cases are recommended in combination with the current weight when recommending cases. This makes the recommended cases obtained based on the keywords extracted from the code comments not only rely on fixed text similarity, but also reflect the effectiveness of different error features in actual review scenarios. Cases that have been verified to be effective will be recommended with higher priority, making the recommendation results more accurate and practical.

[0088] 2. The embodiments of the present invention use a large language model finely tuned based on the domain corpus of the software source code to extract deep semantic features, and combine it with classification tags for hybrid retrieval. This can accurately parse complex domain terms and designs in code comments, improve the accuracy of keyword extraction, and make the recommended cases more accurate.

[0089] 3. In this embodiment of the invention, the matching degree score of the recommended typical cases by the user is used to update the weight of the case category tag of the recommended typical cases. Through the dynamic adjustment of the weight, the matching accuracy between typical cases and the code to be reviewed can be improved when recommending cases, and typical cases can be recommended quickly and accurately.

[0090] Those skilled in the art will understand that all or part of the processes of the methods described in the above embodiments can be implemented by a computer program instructing related hardware, and the program can be stored in a computer-readable storage medium. The computer-readable storage medium may be a disk, optical disk, read-only memory, or random access memory, etc.

[0091] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the scope of protection of the present invention.

Claims

1. A typical case recommendation method based on weight update, characterized in that, Includes the following steps: Obtain the code comments for each function in the source code of the software to be reviewed and extract the set of keywords from them; Based on the keyword set of each function, matching knowledge blocks are retrieved from the software testing typical case knowledge base, and recommended typical cases are obtained by combining the current weights of each case classification label of each knowledge block; wherein, the software testing typical case knowledge base includes multiple knowledge blocks, each knowledge block corresponds to a typical error case and is associated with a case classification label set; the case classification label set includes multiple predefined case classification labels of different categories, and each case classification label has a dynamic weight; Obtain a matching score for the recommended typical cases, and adjust the weights of each case category label of the recommended typical cases based on the matching score results.

2. The method according to claim 1, characterized in that, The keyword set includes a set of annotation keywords and a set of annotation category tags; wherein... The set of annotation keywords is obtained by semantic parsing of the code comments in the source code of the software to be reviewed, and is used to reflect the functional logic and business attributes of the code. The annotation category tag set has the same dimension as the case category tag set of each knowledge block in the software testing typical case knowledge base, and is used to reflect the core features of the code.

3. The method according to claim 2, characterized in that, The set of comment keywords is obtained by semantically parsing the code comments of the source code of the software to be reviewed, including: Based on a predefined vocabulary of phrases belonging to the domain of the source code of the software to be reviewed, a first subset of annotation keywords is identified and extracted from the code annotations; The code comments of the source code of the software to be reviewed are semantically parsed using a pre-trained large language model to obtain a second subset of comment keywords; wherein, the pre-trained large language model is obtained by fine-tuning training data based on the domain of the source code of the software to be reviewed. The set of annotation keywords is obtained by taking the union of the first subset of annotation keywords and the second subset of annotation keywords.

4. The method according to claim 2, characterized in that, Each annotation category tag in the annotation category tag set corresponds to a predefined case category tag; wherein, the case category tags include software operating environment category tags, software application domain category tags, software functional module category tags, software design attribute category tags, and error type category tags.

5. The method according to claim 4, characterized in that, The software operating environment classification labels and the software application domain classification labels are manually specified classification labels. The software function module classification labels, the software design attribute classification labels, and the error type classification labels are corresponding classification labels selected from the predefined candidate label sets corresponding to each label category, based on the code comments of the source code of the software to be reviewed and the set of comment keywords.

6. The method according to claim 2, characterized in that, The keyword set based on each function retrieves matching knowledge blocks from the software testing typical case knowledge base, and combines the current weight of each case classification label of each knowledge block to obtain recommended typical cases, including: for each function in the software source code, performing the following steps: Based on the annotation classification label set of the current function and the case classification label set of each knowledge block, a label consistency measure is performed to obtain an initial knowledge block candidate set; Calculate the semantic similarity between the set of annotation keywords for the current function and each knowledge block in the initial knowledge block candidate set; For each knowledge block in the initial knowledge block candidate set, a recommendation score for the current function is calculated based on the corresponding semantic relevance, label consistency metric, and the current weight of each case classification label therein. Based on the recommendation scores, typical recommended cases are obtained.

7. The method according to claim 6, characterized in that, The label consistency measurement based on the annotation category label set and the case category label set of each knowledge block, based on the current function, includes: the number of consistent category labels in the annotation category label set and the case category label set of each knowledge block among all predefined label categories.

8. The method according to claim 7, characterized in that, The calculation of the recommended score for the current function includes: for each knowledge block, performing the following steps: The label consistency ratio is obtained based on the number of consistent classification labels and the total number of classification labels in the annotation classification label set; Based on the current weights of each case category label in the case category label set, the normalized label weight mean is obtained; The semantic similarity, the label consistency ratio, and the normalized label weight mean are monotonically transformed and then weighted and summed to obtain the recommendation score of the current knowledge block for the current function.

9. The method according to any one of claims 1-8, characterized in that, The weights of each case category label associated with the recommended typical cases adjusted based on the matching score include: The matching score result is mapped to a target weight value within a preset range; Based on the target weight value, the current weight of the case classification label, and the smoothing factor, the adjusted weight of the case classification label is obtained using the following formula: ; in, This represents the adjusted weight of the category label for the i-th case in knowledge block p; This represents the current weight of the category label for the i-th case in knowledge block p; The smoothing factor represents the knowledge block p; This represents the target weight value of knowledge block p; and These represent the lower and upper weight limits, respectively; clip() represents the clipping function.

10. The method according to claim 9, characterized in that, The smoothing factor for a knowledge block is calculated based on the number of matching feedbacks corresponding to that knowledge block, and its formula is as follows: ; in, Indicates the initial smoothing factor; Indicates the attenuation parameter; This represents the number of times the matching degree of knowledge block p has been reported.