AI auxiliary method for demand and code static consistency analysis
By combining AI large language models and dictionary matching tables, the system automates the analysis of requirements and code consistency, solving the problems of time consumption and insufficient consistency in manual review, and achieving efficient and accurate verification of requirements and code consistency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-23
- Publication Date
- 2026-04-21
AI Technical Summary
In existing technologies, manual code review is time-consuming, requires a high level of professional background and experience from reviewers, and is subject to subjectivity and limitations in understanding, resulting in insufficient accuracy and consistency in verifying the consistency between requirements and code.
By employing an AI-powered large language model combined with preset prompts and dictionary matching tables, the system automates the execution of requirements analysis, code retrieval, and logic comparison. Through multi-step analysis, it replaces manual review and ensures variable matching and logical equivalence checks.
It achieves efficient and objective requirements and code consistency analysis, with 100% code version coverage, solving the problems of low efficiency and insufficient consistency in manual review, and providing verifiable and repeatable analysis results.
Smart Images

Figure CN121901084A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software automated testing technology, specifically to an AI-assisted method for static consistency analysis of requirements and code. Background Technology
[0002] In software development, ensuring that the final implemented code is highly consistent with the initial requirements document is a core aspect of guaranteeing software quality and avoiding subsequent defects and rework. Verification of this "requirements-code" consistency primarily relies on manual code review. Specifically, reviewers first need to deeply understand the requirements described in natural language, and then, by reading the source code line by line, judge based on their personal experience whether the code's logic, inputs, outputs, and behaviors fully comply with the requirements. This manual assessment determines the consistency between the code implementation and the requirements. This traditional manual review model has revealed significant limitations in practice.
[0003] Its shortcomings and deficiencies are reflected in the fact that manual code review is time-consuming and requires a high level of professional background and experience from the reviewers; at the same time, due to the subjectivity and limitations in the understanding of requirements, it is easy to cause conceptual confusion, and there are also omissions in the understanding of code logic, resulting in problems with the completeness, accuracy and consistency of the review results. Summary of the Invention
[0004] To address the shortcomings of existing technologies, this invention provides an AI-assisted method for static consistency analysis of requirements and code, thus solving the problems mentioned in the background above.
[0005] This invention provides the following technical solution: an AI-assisted method for static consistency analysis of requirements and code, comprising the following steps: Step S1: Input the natural language requirement to be analyzed into the AI large language model, and guide the AI large language model to perform requirement analysis based on the preset first prompt, and identify and decompose the requirement action variables, the set of requirement condition variables and the logical expression of requirement condition variables from the natural language requirement. Step S2: Based on the required action variable, call the dictionary matching tool to retrieve the preset dictionary matching table, find and obtain one or more code output variables corresponding to the required action variable, wherein the dictionary matching table stores the predefined mapping relationship between required variables and code variables; Step S3: Based on the obtained code output variables, call the code search tool to search in the code library and find all code snippets in the code library that affect the code output variables; Step S4: Input the found code snippet into the AI large language model, and guide the AI large language model to perform code analysis based on the preset second prompt, and identify the set of all code input variables that affect the code output variables and their corresponding logical expressions from the code snippet; Step S5: Perform a matching check between the set of requirement condition variables and the set of code input variables. The matching check includes: based on the dictionary matching table, comparing the variables in the set of requirement condition variables with the variables in the set of code input variables one by one to see if there is a mapping relationship, and outputting the inconsistent variables and the reasons. Step S6: Perform an equivalence check on the logical expression of the requirement condition variable and the logical expression of the code input variable, determine whether the two sets of logical expressions are logically equivalent, and output the reason for the inequivalence; Step S7: Based on the results of the matching check and the equivalence check, generate and output the consistency analysis conclusion between the natural language requirements and the corresponding code implementation.
[0006] Preferably, in step S1, guiding the AI language model to perform requirement analysis based on a preset first prompt specifically involves sending a prompt containing the natural language requirement and the first task instruction to the AI language model, enabling the AI language model to understand and execute the task of identifying the behavioral subject, conditional variables, and their logical relationships from the natural language requirement.
[0007] Preferably, in step S2, calling the dictionary matching tool to retrieve the preset dictionary matching table specifically involves the AI large language model triggering and calling the external dictionary matching tool query interface based on the semantics of the required action variable, and performing a matching query in the dictionary matching table.
[0008] Preferably, in step S3, calling the code retrieval tool to search the code library specifically involves the AI large language model triggering and calling the external code retrieval tool query interface based on the information of the code output variables, and searching the code library with functions as the smallest unit.
[0009] Preferably, in step S4, guiding the AI language model to perform code analysis based on a preset second prompt specifically involves sending a prompt containing the code snippet and a second task instruction to the AI language model, enabling the AI language model to understand and execute the task of extracting input variables, global variables, interface functions, and their logical expressions from the code snippet.
[0010] Preferably, in step S5, the matching check between the set of demand condition variables and the set of code input variables specifically involves: the AI large language model extracting variables from the set of demand condition variables one by one, and using the dictionary matching tool to search the dictionary matching table to determine whether a corresponding code input variable exists.
[0011] Preferably, in step S6, the equivalence check between the logical expression of the requirement condition variable and the logical expression of the code input variable specifically involves: the AI large language model analyzing and comparing the logical structures of the two sets of logical expressions to determine whether they describe the same logical constraint relationship.
[0012] Preferably, the dictionary matching table is a static mapping table between requirement terms and code implementation terms that is predefined and maintained manually, independent of the AI large language model.
[0013] Compared with the prior art, the present invention has the following beneficial effects: 1. This invention guides a large language model by combining task decomposition with specific prompts, breaking down the complex analysis process into multiple sequentially executed atomic tasks. This defines the reasoning path of the large model, suppresses its free play, and generates traceable intermediate analysis results as the basis for final judgment. This solves the problems of insufficient accuracy and consistency caused by subjective understanding and logical oversights in manual review.
[0014] 2. This invention introduces and relies on a pre-defined, static dictionary table mapping requirement variables to code variables, providing a unique and objective comparison standard for variable matching checks. This makes the judgment of large models have a verifiable and repeatable benchmark, solving the problems of insufficient consistency and low credibility in judgments caused by differences in personal experience and conceptual understanding in manual review.
[0015] 3. This invention, by calling a code retrieval tool to perform an automated full scan of the code repository, can retrieve all related code fragments without being affected by human factors, achieving 100% coverage review of a specified code version. This solves the problem of insufficient completeness and incomplete impact analysis caused by manual review, which usually only reviews changed code due to efficiency limitations.
[0016] 4. This invention, by comprehensively utilizing the natural language understanding, code semantic parsing, and logical relationship processing capabilities of a large language model, automates the entire chain of analysis from requirements analysis and code location to logical comparison. It replaces the previously time-consuming manual line-by-line reading process that heavily relied on experienced personnel, thus solving the problems of low efficiency and excessively high requirements for the professional background and experience of reviewers in traditional methods. Attached Figure Description
[0017] Figure 1 This is a flowchart of the present invention. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] Please see Figure 1 An AI-assisted method for static consistency analysis of requirements and code includes the following steps: Step S1: Input the natural language requirement to be analyzed into the AI large language model, and guide the AI large language model to perform requirement analysis based on the preset first prompt, and identify and decompose the requirement action variables, the set of requirement condition variables and the logical expression of requirement condition variables from the natural language requirement. Step S2: Based on the required action variable, call the dictionary matching tool to retrieve the preset dictionary matching table, find and obtain one or more code output variables corresponding to the required action variable, wherein the dictionary matching table stores the predefined mapping relationship between required variables and code variables; Step S3: Based on the obtained code output variables, call the code search tool to search in the code library and find all code snippets in the code library that affect the code output variables; Step S4: Input the found code snippet into the AI large language model, and guide the AI large language model to perform code analysis based on the preset second prompt, and identify the set of all code input variables that affect the code output variables and their corresponding logical expressions from the code snippet; Step S5: Perform a matching check between the set of requirement condition variables and the set of code input variables. The matching check includes: based on the dictionary matching table, comparing the variables in the set of requirement condition variables with the variables in the set of code input variables one by one to see if there is a mapping relationship, and outputting the inconsistent variables and the reasons. Step S6: Perform an equivalence check on the logical expression of the requirement condition variable and the logical expression of the code input variable, determine whether the two sets of logical expressions are logically equivalent, and output the reason for the inequivalence; Step S7: Based on the results of the matching check and the equivalence check, generate and output the consistency analysis conclusion between the natural language requirements and the corresponding code implementation.
[0020] In step S1, guiding the AI language model to perform requirement analysis based on a preset first prompt is specifically as follows: by sending a prompt containing the natural language requirement and the first task instruction to the AI language model, the AI language model can understand and execute the task of identifying the behavioral subject, condition variables and their logical relationships from the natural language requirement.
[0021] In step S2, calling the dictionary matching tool to retrieve the preset dictionary matching table specifically involves the AI large language model triggering and calling the external dictionary matching tool query interface based on the semantics of the required action variable, and performing a matching query in the dictionary matching table.
[0022] In step S3, calling the code retrieval tool to search the code library specifically involves the AI large language model triggering and calling the external code retrieval tool query interface based on the information of the code output variables, and searching the code library with functions as the smallest unit.
[0023] In step S4, guiding the AI language model to perform code analysis based on a preset second prompt specifically involves sending a prompt containing the code snippet and a second task instruction to the AI language model, enabling the AI language model to understand and execute the task of extracting input variables, global variables, interface functions, and their logical expressions from the code snippet.
[0024] In step S5, the matching check between the set of requirement condition variables and the set of code input variables specifically involves: the AI large language model extracting variables from the set of requirement condition variables one by one, and using the dictionary matching tool to search the dictionary matching table to determine whether there are corresponding code input variables.
[0025] In step S6, the equivalence check between the logical expression of the requirement condition variable and the logical expression of the code input variable is specifically performed by the AI large language model to parse and compare the logical structures of the two sets of logical expressions to determine whether they describe the same logical constraint relationship.
[0026] The dictionary matching table is a static mapping table between requirement terms and code implementation terms that is predefined and maintained manually, independent of the AI large language model.
[0027] In a specific implementation: I. Complete the following basic configurations Access AI Large Language Model: Integrate a large language model service with natural language understanding, code analysis, and logical reasoning capabilities.
[0028] Build and analyze tools: Constructing a dictionary matching table: Based on the business domain and technology stack of the target software system, a structured mapping table is pre-defined and maintained manually. This table explicitly records the correspondence between key requirement terms in natural language descriptions and terms such as code variables and function names actually implemented in the system.
[0029] Encapsulated tool interfaces: The query function of the dictionary matching table and the retrieval function for the target code library are encapsulated into standardized tool interfaces that can be called by large language models.
[0030] II. Detailed Implementation Steps Taking an abstract requirement item "If condition set C is true, then execute action A" as an example, the implementation steps of the method of the present invention are explained in detail: Step S1: Structured Analysis of Requirements The user inputs the natural language description of their needs into the AI large language model and sends an initial prompt, instructing it to perform a needs decomposition task. After analysis, the large language model outputs structured results. Identified demand action variables: corresponding to "Action A" in the demand.
[0031] The identified set of requirement condition variables: corresponding to the various sub-conditions contained in the "condition set C" in the requirement.
[0032] The derived logical expression for the requirement condition variables describes the logical relationship between the various sub-conditions contained in the "condition set C" in the requirement.
[0033] Step S2: Determine the code output variables The system prompts the large language model to invoke the dictionary matching tool for the "Action A" obtained in the previous step. This tool queries a preset dictionary matching table and returns the code output variable that maps to "Action A", such as a specific function name func_A().
[0034] Step S3: Retrieve related code snippets The system prompts that the large language model, based on the code output variable `func_A()`, invokes a code retrieval tool. This tool scans the entire codebase, locates and returns a set of all code snippets that directly call `func_A()` or are critically affected in its call chain by influencing the execution of `func_A()`.
[0035] Step S4: Extract code logic The retrieved set of code snippets is input into the large language model, and a second prompt is sent to instruct it to perform the code logic extraction task. After analysis, the large language model outputs: The set of all code input variables that affect the execution of func_A(), identified from the set of code snippets.
[0036] The logical expressions between these input variables are derived from the code logic.
[0037] Step S5: Variable matching check The system guides the large language model to perform a matching check: for each variable in the set of requirement condition variables, it sequentially calls the dictionary matching tool to query whether there is a corresponding code variable in the dictionary matching table. This check will compare the requirement condition variables and code input variables one by one to see if they form a valid mapping pair, and record the matching result of each pair, whether it passes or fails, and the reason.
[0038] Step S6: Logical expression equivalence check The system guides the large language model to perform an equivalence check: the requirement logic expression is compared with the code logic expression. The large language model analyzes the logical structure of the two expressions, determines whether they are logically equivalent, that is, whether they describe the same combination of conditions and triggering relationships, and outputs the equivalence judgment result and reason.
[0039] Step S7: Generate a consistent conclusion Based on the variable matching results of step S5 and the logical equivalence results of step S6, the system prompts the large language model to make a final decision, generating a conclusive report on whether the current requirements and code implementation are consistent, along with key analytical evidence.
[0040] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. An AI-assisted method for static consistency analysis of requirements and code, characterized in that, Includes the following steps: Step S1: Input the natural language requirement to be analyzed into the AI large language model. Based on the preset first prompt, guide the AI large language model to perform requirement analysis, and identify and decompose the requirement action variables, the set of requirement condition variables, and the logical expression of requirement condition variables from the natural language requirement. Step S2: Based on the required action variable, call the dictionary matching tool to retrieve the preset dictionary matching table, find and obtain one or more code output variables corresponding to the required action variable, wherein the dictionary matching table stores the predefined mapping relationship between required variables and code variables; Step S3: Based on the obtained code output variables, call the code search tool to search the code library and find all code segments in the code library that affect the code output variables; Step S4: Input the found code fragment into the AI large language model, and guide the AI large language model to perform code analysis based on the preset second prompt, and identify the set of all code input variables that affect the code output variables and their corresponding logical expressions from the code fragment; Step S5: Perform a matching check between the set of requirement condition variables and the set of code input variables. The matching check includes: based on the dictionary matching table, comparing the variables in the set of requirement condition variables with the variables in the set of code input variables one by one to see if there is a mapping relationship, and outputting the inconsistent variables and the reasons. Step S6: Perform an equivalence check on the logical expression of the requirement condition variable and the logical expression of the code input variable, determine whether the two sets of logical expressions are logically equivalent, and output the reason for the inequivalence; Step S7: Based on the results of the matching check and the equivalence check, generate and output the consistency analysis conclusion between the natural language requirements and the corresponding code implementation.
2. The AI-assisted method for static consistency analysis of requirements and code according to claim 1, characterized in that, In step S1, guiding the AI language model to perform requirement analysis based on a preset first prompt is specifically as follows: by sending a prompt containing the natural language requirement and the first task instruction to the AI language model, the AI language model can understand and execute the task of identifying the behavioral subject, condition variables and their logical relationships from the natural language requirement.
3. The AI-assisted method for static consistency analysis of requirements and code according to claim 1, characterized in that, In step S2, calling the dictionary matching tool to retrieve the preset dictionary matching table specifically involves the AI large language model triggering and calling the external dictionary matching tool query interface based on the semantics of the required action variable, and performing a matching query in the dictionary matching table.
4. The AI-assisted method for static consistency analysis of requirements and code according to claim 1, characterized in that, In step S3, calling the code retrieval tool to search the code library specifically involves the AI large language model triggering and calling the external code retrieval tool query interface based on the information of the code output variables, and searching the code library with functions as the smallest unit.
5. The AI-assisted method for static consistency analysis of requirements and code according to claim 1, characterized in that, In step S4, guiding the AI language model to perform code analysis based on a preset second prompt is specifically as follows: by sending a prompt containing the code fragment and the second task instruction to the AI language model, the AI language model understands and executes the task of extracting input variables, global variables, interface functions and their logical expressions from the code fragment.
6. The AI-assisted method for static consistency analysis of requirements and code according to claim 1, characterized in that, In step S5, the matching check between the set of requirement condition variables and the set of code input variables specifically involves: the AI large language model extracting variables from the set of requirement condition variables one by one, and using the dictionary matching tool to search the dictionary matching table to determine whether there are corresponding code input variables.
7. The AI-assisted method for static consistency analysis of requirements and code according to claim 1, characterized in that, In step S6, the equivalence check between the logical expression of the requirement condition variable and the logical expression of the code input variable specifically involves the AI large language model parsing and comparing the logical structures of the two sets of logical expressions to determine whether they describe the same logical constraint relationship.
8. The AI-assisted method for static consistency analysis of requirements and code according to any one of claims 1-7, characterized in that, The dictionary matching table is a static mapping table between requirement terms and code implementation terms that is predefined and maintained manually, independent of the AI large language model.