Code and document consistency reasoning verification system based on cross-modal logic graph

By mapping code and documentation to a unified structure through cross-modal logic graphs, logical reasoning verification is performed, solving the accuracy and efficiency problems of code and documentation consistency verification, and achieving efficient contradiction location and report generation.

CN121279433APending Publication Date: 2026-01-06ANHUI GAOSHAN TECH CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202511356970.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-22
Publication Date
2026-01-06

AI Technical Summary

Technical Problem

Existing technologies struggle to accurately verify consistency between code and documentation, and lack the ability to model and reason about complex logical relationships and behavioral constraints, resulting in inefficiency and a high risk of errors.

Method used

A code-document consistency reasoning verification system based on cross-modal logic graphs is adopted. Through feature extraction and formal representation, code logic and document semantics are mapped to a unified graph structure. Descriptive logic is used for formal representation and logical reasoning verification is performed.

Benefits of technology

It achieves deep matching and contradiction location of code and documentation consistency, improves verification accuracy to over 90%, reduces false positive and false negative rates, generates interpretable reports, and improves debugging efficiency by 60%.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121279433A_ABST
    Figure CN121279433A_ABST
Patent Text Reader

Abstract

The invention relates to code verification, in particular to a code and document consistency reasoning verification system based on a cross-modal logic atlas, which comprises an input layer for receiving source codes and software documents; the feature extraction layer is used for performing feature extraction on the source code and the software document; the abstraction layer is used for converting the extracted features into comparable intermediate representations; the unified modeling layer is used for mapping code logic and document semantics into a unified atlas structure and performing formalized representation by using description logic to obtain a cross-modal logic atlas; the reasoning verification layer is used for performing reasoning verification on the consistency of the code and the document according to the cross-modal logic graph; the result processing layer is used for judging a verification result according to the reasoning verification condition, starting a contradiction positioning mechanism when inconsistency is found, and carrying out contradiction positioning and report generation to obtain an interpretable report; according to the technical scheme provided by the invention, the defects that the consistency between the code and the document is difficult to accurately verify, and accurate contradiction positioning and an interpretable report are difficult to provide can be effectively overcome.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to code verification, and more specifically to a code and document consistency reasoning verification system based on cross-modal logic graphs. Background Technology

[0002] In the field of software engineering, code analysis techniques are relatively mature, including: Static analysis techniques: generating structured representations such as AST (Abstract Syntax Tree), CFG, and DFG by parsing source code; Natural Language Processing (NLP) techniques: using deep learning models for text understanding and semantic extraction; Knowledge graph technology: used for the representation and storage of structured knowledge; Logical reasoning technology: an automated reasoning mechanism based on descriptive logic.

[0003] Currently, the main solutions for code and documentation consistency verification include: 1) Manual review Implementation method: Developers manually compare the code implementation with the documentation description; Drawbacks: Extremely inefficient, prone to errors, and unable to adapt to the rapid iteration requirements of agile development; 2) Shallow matching based on information retrieval Implementation method: Use TF-IDF, cosine similarity, etc. to calculate the text similarity between code comments and code body; Specific steps: Extract comments and identifiers from the code; Extract relevant text fragments from the document; Calculate the text feature vector; Use similarity metrics to determine consistency; 1. Shortcomings: It only stays at the vocabulary level and cannot understand the execution logic of the code and the deep semantics of the documentation; 3) Structured analysis based on AST Implementation method: Parse the AST of the code and check whether the function names, parameter names, etc. in the comments match the actual code; Specific steps: Use the parser to generate the AST of the code; Extract structural information such as function signature and parameter list; Search for the corresponding entity reference in the document; Compare the consistency of structural information; 1. Defects: Unable to verify the consistency of behavioral logic, for example, unable to determine whether the business rules described in the document are correctly implemented in the code; 4) Preliminary graph association Implementation method: Use knowledge graphs to associate code entities with document fragments; Deficiencies: It remains at the level of entity links and lacks the ability to model and reason about complex logical relationships and behavioral constraints. Summary of the Invention

[0004] (a) Technical problems to be solved In view of the above-mentioned shortcomings of the existing technology, the present invention provides a code and document consistency reasoning verification system based on cross-modal logic graphs, which can effectively overcome the shortcomings of the existing technology in accurately verifying the consistency between code and documents and providing precise contradiction location and interpretability report.

[0005] (II) Technical Solution To achieve the above objectives, the present invention provides the following technical solution: A code and document consistency reasoning and verification system based on cross-modal logic graphs includes: The input layer receives source code and software documentation. The feature extraction layer extracts features from the source code and software documentation; The abstraction layer transforms extracted features into comparable intermediate representations; The unified modeling layer maps code logic and document semantics to a unified graph structure and uses description logic for formal representation, resulting in a cross-modal logic graph. The inference verification layer performs inference verification on the consistency between code and documentation based on the cross-modal logic graph; The results processing layer judges the verification results based on the reasoning verification situation, and activates the contradiction location mechanism when an inconsistency is found to locate the contradiction and generate a report, resulting in an interpretable report.

[0006] Preferably, the feature extraction layer includes: The code logic extraction module uses compiler technology to parse the code structure and extract the program execution logic constraints from the code to obtain the code logic. The document semantic extraction module uses NLP technology to understand document semantics and extract semantic constraints from the document to obtain the document semantics.

[0007] Preferably, the code logic extraction module's work includes: Lexical analysis breaks down the source code into a token sequence, identifies keywords, identifiers, operators and constants, filters comments and whitespace characters, and outputs a token stream. Syntax analysis checks the syntax correctness according to the grammar rules of the programming language, constructs a syntax tree, handles and corrects syntax errors, and outputs the syntax tree. AST generation simplifies the syntax tree into an abstract syntax tree, removes syntactic sugar and redundant nodes, retains the essential structural information of the program, and outputs the abstract syntax tree. CFG construction analyzes the control flow relationships of the program, identifies basic blocks, constructs a jump relationship graph between basic blocks, and handles the control structures of conditional branches, loops, and exception handling. Control flow logic extraction: Extract condition judgment logic based on CFG, identify loop invariants and termination conditions, extract exception handling logic, and generate control flow constraints; DFG construction analyzes the definition and usage relationships of variables, builds a data flow dependency graph, tracks the lifecycle of variables, and identifies the dependencies between variables; Data dependency analysis, based on DFG analysis of data flow constraints, identifies the range of variable values, analyzes the constraint relationship between function parameters and return values, and detects potential data races and dependency conflicts; Logical constraint generation: Integrates control flow constraints and data flow constraints to generate formal program execution logical constraint expressions and outputs a set of program execution logical constraints. For a given code snippet, a logical constraint extraction function is defined: LogicExtract(AST)={C1,C2,…,C n}; In the above formula, LogicExtract is the logical constraint extraction function, AST is the abstract syntax tree, and C... n Let n be the nth logical constraint, representing a logical rule in the code, where n is the total number of logical constraints; For each logical constraint, it is represented as a triple: C n =<condition,action,context> ; In the above formula, condition is the triggering condition, which represents the precondition for the logical constraint to take effect; action is the execution action, which represents the sequence of operations executed when the logical constraint takes effect; and context is the context environment, including environment information such as variable scope and function call stack. For conditional branch statements, logical constraint extraction is expressed as follows: ; In the above formula, C ifFor the logical constraints of conditional branch statements, This is a conditional formalization function that transforms conditional expressions in code into logical expressions. This is an action serialization function that transforms the code block in the then branch into an action sequence representation. This is a context extraction function that retrieves information about the execution environment of the current code snippet.

[0008] Preferably, the work of the document semantic extraction module includes: Text preprocessing, document format standardization, sentence segmentation and word segmentation, stop word filtering and stemming, text cleaning and noise removal, outputting a standardized text sequence; Named entity recognition identifies key entities in documents: function names, class names, variable names, parameter names; technical concepts: data types, algorithm names, design patterns; and business entities: user roles, business objects, and actions. It uses BiLSTM+CRF or BERT-based models for sequence labeling and outputs text sequences with entity labels, i.e., entity labeling results. Relation extraction identifies semantic relationships between entities: inheritance, implementation, calling, and inclusion; operational relationships: creation, modification, deletion, and query; and constraint relationships: preconditions, postconditions, and abnormal conditions. Using relation classification models or knowledge graph embedding techniques, the output is a set of entity relation triples, i.e., relation annotation results. Semantic role labeling identifies the semantic roles of each component in a sentence, labels actions and participants, and identifies roles including agent, patient, and instrument. It uses a deep semantic role labeling model to output semantic role labeling results, i.e., semantic role results. Semantic constraint construction integrates entity, relation, and semantic role information to build a structured semantic constraint representation, identify conditional logic: if-then rules and exception handling rules, and extract functional and non-functional constraints; Formal semantic constraints transform natural language constraints into logical expressions, formalize them using first-order logic or descriptive logic, generate an axiom set for subsequent reasoning, and output a set of formal constraints. For a given document, a semantic constraint extraction function is defined: SemanticExtract(Doc)={S1,S2,…,S m}; In the above formula, SemanticExtract is the semantic constraint extraction function, Doc is the input document, and S m Let m be the m-th semantic constraint, representing a semantic rule in the document, where m is the total number of semantic constraints; For each semantic constraint, the logical formula is: ; In the above formula, Let k be a set of variables, representing function parameters, global variables, or other related entities, where k is the total number of variables. This is a preconditional predicate, describing the conditions that must be met before a function call. This is a postconditional predicate that describes the state that should be reached after a function call. It is a logical implication symbol that represents the logical relationship of "if...then...".

[0009] Preferably, the abstraction layer includes: Program logic abstraction involves extracting function call relationships, control flow logic, and data dependencies from program execution logic constraints. Semantic constraint abstraction extracts functional descriptions, parameter constraints, and exception handling rules from semantic constraints.

[0010] Preferably, the unified modeling layer includes cross-modal logic graph construction, which includes a code logic layer, a semantic constraint layer, a logical axiom layer, mapping relationships, and reasoning relationships. The code logic layer is the bottom layer, including: The function node has attributes including function signature, parameter list, return type, and access modifier; The variable node has attributes including variable name, data type, scope, and lifecycle; Condition nodes have attributes including the condition expression, the number of branches, and the coverage path. Action nodes have attributes including operation type, operation object, and side effects; The semantic constraint layer is a middle layer, including: The functional description node extracts the functional specification description from the document, including the main functions, input and output descriptions, and business rules; The parameter constraint node extracts parameter constraints from the document, including value range, type constraints, and null value handling. The return value constraint node extracts the return value specification from the document, including the return value type, value range, and special cases; The exception constraint node extracts exception handling rules from the document, including exception type, triggering conditions, and handling method; The logical axiom layer is the top level and includes: Implication relationship, This means that if A is true, then B must be true. Equivalence relation This indicates that A and B are logically equivalent; Conflict relationship This means that A and B cannot both be true at the same time; The dependency relationship, depends(A,B), means that the existence of A depends on B; The mapping relationship is represented by dashed lines. Nodes in the code logic layer are mapped to corresponding nodes in the semantic constraint layer through a semantic matching algorithm. The mapping is based on multiple dimensions, including name similarity, type compatibility, and semantic relevance. The mapping strength is represented by a confidence score. The reasoning relationship is represented by solid lines. The nodes of the semantic constraint layer generate corresponding logical axioms based on their constraint content, which are used for subsequent consistency reasoning verification and contradiction location. Here, the mapping function is defined as follows: ; In the above formula, M is a mapping function that maps program execution logic constraints and semantic constraints to a unified graph structure, C is the set of program execution logic constraints, S is the set of semantic constraints, and g is a cross-modal logic graph that represents cross-modal logical relationships. The mapping process includes entity alignment and relation mapping. Entity alignment is represented by the following formula: align(entity c entity s =similarity(entity) c entity s )>τ; In the above formula, `align` is the entity alignment function, which returns a boolean value indicating whether the two entities match. c For code entities, including function names, variable names, and class names, entity s For semantic entities, including the function names and parameter descriptions mentioned in the document, similarity is the similarity calculation function, and τ is the similarity threshold, which ranges from [0,1]. If the value exceeds the threshold, the two entities are considered to be matched. Relational mapping is represented by the following formula: map_relation(rel c ,rel s )=R(rel c ,rel s ); In the above formula, map_relation represents the relation mapping operation, establishing cross-modal relational connections, and rel... c For relationships in the code, including function call relationships and variable dependencies, rel s R represents the semantic relationships in the document, including the functional dependencies and parameter constraints described therein. R is the relation mapping function that maps relations of different modalities to a unified representation. Logical axioms are generated using the following formula: axiom=logic_transform(constraint); In the above formula, axiom is the generated logical axiom, and logic_transform is the logical transformation function that transforms the input constraint into the standard logical axiom form. The input constraint includes program execution logic constraints and semantic constraints.

[0011] Preferably, the reasoning verification layer includes a logical reasoning engine, the working content of which includes: The inference engine is initialized, the rule base describing logical inference is loaded, the inferencer state and memory structure are initialized, inference parameters are set: maximum number of inference steps, timeout limit, and inference log recording mechanism is established. Axiom loading extracts all logical axioms from the cross-modal logic graph, performs syntax checking and standardization on the logical axioms, builds an axiom index to optimize reasoning efficiency, and detects potential conflicts between logical axioms. Consistency checks are performed using the tableaux algorithm for satisfiability testing, applying the following inference rules: Rule 1: ; Rule Two: ; Rule 3: ; Rule Four: ; Perform closure operations to detect contradictions, and record the reasoning process and intermediate states; The test results are evaluated as follows: if no contradiction is found, "Verification passed" is output; if a contradiction is found, the contradiction detection mechanism is activated; if the inference times out or memory overflows, "Verification incomplete" is output. Conflict detection identifies the axiom subset that leads to the conflict, uses the minimum unsatisfiable core MUC algorithm to find the minimum conflict set, and classifies the conflict types: type conflict, logical conflict, and constraint conflict. The reasoning chain is traced backward from the point of contradiction, the reasoning steps are traced in reverse, a reasoning tree is constructed to show the reasoning dependencies, key reasoning nodes and branch points are marked, and the contribution of each logical axiom to the contradiction is calculated. Contradiction localization maps logical axioms back to code and document locations, calculates the confidence and accuracy of the localization, and generates multi-level localization results: file-level, function-level, and statement-level. Report generation: Generates a structured consistency reasoning verification report, including contradiction descriptions, location information, and remediation suggestions, supporting multiple output formats: JSON, XML, and HTML; Wherein, for a given cross-modal logic graph g: g=<N,ε,A> ; In the above formula, N is the set of nodes, including all code entity nodes and document entity nodes; ε is the set of edges, representing various relationships between entities, including calls, dependencies and constraints; and A is the set of logical axioms, including all logical reasoning rules and constraints. Define a consistency check function: ; In the above formula, Consistency is a consistency check function that returns a Boolean value indicating whether the cross-modal logic graph g is consistent. For logical NOT operator, For logical formula variables, it represents a logical assertion in the cross-modal logic graph g. These are logical derivation symbols, indicating that something can be deduced. For logical AND operator, For logical formula variables The negative form; Define the contradiction tracing function: ; In the above formula, Contradiction_Trace is a contradiction tracing function that identifies the set of logical axioms that lead to contradictions. For a positive assertion of contradiction, As the opposite assertion of the contradiction, {axiom i} is a subset of logical axioms, including all logical axioms involved in contradictory reasoning. i Let i be the logical axiom that participates in the contradictory reasoning.

[0012] Preferably, the result processing layer includes conflict localization and report generation, the work content of which includes: Reasoning chain analysis involves parsing the proof tree generated during the reasoning process, identifying all logical axioms and reasoning steps involved in contradictory reasoning, constructing an axiom dependency graph, and calculating the weights of logical axioms. , For the i-th logical axiom i The weights are used to mark key reasoning paths and branch points; By associating code snippets, tracing the mapping relationship between logical axioms and source code, locating specific code line numbers and character positions, extracting relevant code context, identifying involved program entities: variables, functions, and classes, and calculating the relevance score of the code snippets; By associating document descriptions, tracing the mapping relationship between logical axioms and documents, locating specific chapters, paragraphs and sentences, extracting relevant document context, identifying the document entities involved: functional descriptions, parameter descriptions and constraints, and calculating the relevance score of document fragments; Problem localization involves fusing location information from code and documentation, using a weighted fusion algorithm to calculate the final problem location, and generating multi-granularity localization results: coarse-grained: module / chapter level; medium-granular: function / paragraph level; fine-grained: statement / sentence level. Localization reliability is then calculated. ; Generate explanations based on templates, including: contradiction type classification; causes of contradictions; relevant code and document content; simplified description of logical reasoning process; text generation method using a hybrid of rules and neural networks; and adjustment of the technical depth of the explanation according to the user role. Output reports, generating structured JSON reports for program processing and human-friendly HTML reports for reading. Supports integration into IDEs and code review tools, and provides API interfaces for third-party tools to call.

[0013] (III) Beneficial Effects Compared with existing technologies, the code and document consistency reasoning verification system based on cross-modal logic graphs provided by this invention has the following advantages: 1) A unified cross-modal logic representation framework: It is the first to map code logic and document semantics to a unified graph structure based on description logic, effectively solving the semantic gap problem of heterogeneous data; 2) Deep matching algorithm based on logical reasoning: Transforms consistency verification reasoning into logical consistency detection within the graph, and discovers deep-seated logical contradictions through formal reasoning; 3) Intelligent conflict location and tracing mechanism: Through reasoning chain tracing technology, it is possible to accurately locate the specific code fragments and related document descriptions that cause the conflict; 4) Explainability Report Generation: Automatically generates explainable reports that are close to natural language, clarifying the causes of contradictions and providing remedial suggestions; By adopting the technical solution of this invention, the accuracy of consistency inference verification is improved to over 90%, which is 30% higher than that of traditional methods. The false alarm rate is reduced to below 5%, the false negative rate is reduced to below 8%, and an interpretability report is automatically generated, improving debugging efficiency by over 60%. Attached Figure Description

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

[0015] Figure 1This is a schematic diagram illustrating the working principle of the system of the present invention; Figure 2 This is a schematic diagram illustrating the working principle of the code logic extraction module in this invention; Figure 3 This is a schematic diagram illustrating the working principle of the document semantic extraction module in this invention; Figure 4 This is a schematic diagram illustrating the working principle of cross-modal logic graph construction in this invention; Figure 5 This is a schematic diagram illustrating the working principle of the logic reasoning engine in this invention; Figure 6 This is a schematic diagram illustrating the working principle of contradiction location and report generation in this invention. Detailed Implementation

[0016] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, 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, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.

[0017] The following section describes the specific architecture of the code and document consistency reasoning verification system based on cross-modal logic graphs provided by this invention, using concrete examples: The input layer receives source code (including various source code files such as .java, .py, .cpp, etc.) and software documentation (including API documentation, requirements specifications, user manuals, etc.). The feature extraction layer extracts features from the source code and software documentation; The abstraction layer transforms extracted features into comparable intermediate representations; The unified modeling layer maps code logic and document semantics to a unified graph structure and uses description logic for formal representation, resulting in a cross-modal logic graph. The inference verification layer performs inference verification on the consistency between code and documentation based on the cross-modal logic graph; The results processing layer judges the verification results based on the reasoning verification situation, and activates the contradiction location mechanism when an inconsistency is found to locate the contradiction and generate a report, resulting in an interpretable report.

[0018] I. Feature Extraction Layer like Figure 1 As shown, the feature extraction layer includes: The code logic extraction module uses compiler technology to parse the code structure and extract the program execution logic constraints from the code to obtain the code logic. The document semantic extraction module uses NLP technology to understand document semantics and extract semantic constraints from the document to obtain the document semantics.

[0019] 1) Code logic extraction module like Figure 2 As shown, the code logic extraction module's tasks include: Lexical analysis breaks down the source code into a token sequence, identifies keywords, identifiers, operators and constants, filters comments and whitespace characters, and outputs a token stream. Syntax analysis checks the syntax correctness according to the grammar rules of the programming language, constructs a syntax tree, handles and corrects syntax errors, and outputs the syntax tree. AST generation simplifies the syntax tree into an abstract syntax tree, removes syntactic sugar and redundant nodes, retains the essential structural information of the program, and outputs the abstract syntax tree. CFG construction analyzes the control flow relationships of the program, identifies basic blocks, constructs a jump relationship graph between basic blocks, and handles the control structures of conditional branches, loops, and exception handling. Control flow logic extraction: Extract condition judgment logic based on CFG, identify loop invariants and termination conditions, extract exception handling logic, and generate control flow constraints; DFG construction analyzes the definition and usage relationships of variables, builds a data flow dependency graph, tracks the lifecycle of variables, and identifies the dependencies between variables; Data dependency analysis, based on DFG analysis of data flow constraints, identifies the range of variable values, analyzes the constraint relationship between function parameters and return values, and detects potential data races and dependency conflicts; Logical constraint generation: Integrates control flow constraints and data flow constraints to generate formal program execution logical constraint expressions and outputs a set of program execution logical constraints. For a given code snippet, a logical constraint extraction function is defined: LogicExtract(AST)={C1,C2,…,C n}; In the above formula, LogicExtract is the logical constraint extraction function, AST is the abstract syntax tree, and C... n Let n be the nth logical constraint, representing a logical rule in the code, where n is the total number of logical constraints; For each logical constraint, it is represented as a triple: C n =<condition,action,context> ; In the above formula, condition is the triggering condition, which represents the precondition for the logical constraint to take effect; action is the execution action, which represents the sequence of operations executed when the logical constraint takes effect; and context is the context environment, including environment information such as variable scope and function call stack. For conditional branch statements, logical constraint extraction is expressed as follows: ; In the above formula, C if For the logical constraints of conditional branch statements, This is a conditional formalization function that transforms conditional expressions in code into logical expressions. This is an action serialization function that transforms the code block in the then branch into an action sequence representation. This is a context extraction function that retrieves information about the execution environment of the current code snippet.

[0020] 2) Document semantic extraction module like Figure 3 As shown, the work of the document semantic extraction module includes: Text preprocessing, document format standardization, sentence segmentation and word segmentation, stop word filtering and stemming, text cleaning and noise removal, outputting a standardized text sequence; Named entity recognition identifies key entities in documents: function names, class names, variable names, parameter names; technical concepts: data types, algorithm names, design patterns; and business entities: user roles, business objects, and actions. It uses BiLSTM+CRF or BERT-based models for sequence labeling and outputs text sequences with entity labels, i.e., entity labeling results. Relation extraction identifies semantic relationships between entities: inheritance, implementation, calling, and inclusion; operational relationships: creation, modification, deletion, and query; and constraint relationships: preconditions, postconditions, and abnormal conditions. Using relation classification models or knowledge graph embedding techniques, the output is a set of entity relation triples, i.e., relation annotation results. Semantic role labeling identifies the semantic roles of each component in a sentence, labels actions and participants, and identifies roles including agent, patient, and instrument. It uses a deep semantic role labeling model to output semantic role labeling results, i.e., semantic role results. Semantic constraint construction integrates entity, relation, and semantic role information to build a structured semantic constraint representation, identify conditional logic: if-then rules and exception handling rules, and extract functional and non-functional constraints; Formal semantic constraints transform natural language constraints into logical expressions, formalize them using first-order logic or descriptive logic, generate an axiom set for subsequent reasoning, and output a set of formal constraints. For a given document, a semantic constraint extraction function is defined: SemanticExtract(Doc)={S1,S2,…,S m}; In the above formula, SemanticExtract is the semantic constraint extraction function, Doc is the input document, and S m Let m be the m-th semantic constraint, representing a semantic rule in the document, where m is the total number of semantic constraints; For each semantic constraint, the logical formula is: ; In the above formula, Let k be a set of variables, representing function parameters, global variables, or other related entities, where k is the total number of variables. This is a preconditional predicate, describing the conditions that must be met before a function call. This is a postconditional predicate that describes the state that should be reached after a function call. It is a logical implication symbol that represents the logical relationship of "if...then...".

[0021] II. Abstract Layer like Figure 1 As shown, the abstraction layer includes: Program logic abstraction involves extracting function call relationships, control flow logic, and data dependencies from program execution logic constraints. Semantic constraint abstraction extracts functional descriptions, parameter constraints, and exception handling rules from semantic constraints.

[0022] III. Unified Modeling Layer like Figure 1 As shown, the unified modeling layer includes cross-modal logic graph construction, such as... Figure 4 As shown, the construction of the cross-modal logic graph includes a code logic layer, a semantic constraint layer, a logical axiom layer, mapping relationships, and reasoning relationships; The code logic layer is the bottom layer, including: The function node has attributes including function signature, parameter list, return type, and access modifier; The variable node has attributes including variable name, data type, scope, and lifecycle; Condition nodes have attributes including the condition expression, the number of branches, and the coverage path. Action nodes have attributes including operation type, operation object, and side effects; The semantic constraint layer is a middle layer, including: The functional description node extracts the functional specification description from the document, including the main functions, input and output descriptions, and business rules; The parameter constraint node extracts parameter constraints from the document, including value range, type constraints, and null value handling. The return value constraint node extracts the return value specification from the document, including the return value type, value range, and special cases; The exception constraint node extracts exception handling rules from the document, including exception type, triggering conditions, and handling method; The logical axiomatic level is the top level, including: Implication relationship, This means that if A is true, then B must be true. Equivalence relation This indicates that A and B are logically equivalent; Conflict relationship This means that A and B cannot both be true at the same time; The dependency relationship, depends(A,B), means that the existence of A depends on B; The mapping relationship is represented by dashed lines. Nodes in the code logic layer are mapped to corresponding nodes in the semantic constraint layer through a semantic matching algorithm. The mapping is based on multiple dimensions, including name similarity, type compatibility, and semantic relevance. The mapping strength is represented by a confidence score. Reasoning relationships are represented by solid lines. Nodes in the semantic constraint layer generate corresponding logical axioms based on their constraint content, which are used for subsequent consistency reasoning verification and contradiction location. Here, the mapping function is defined as follows: ; In the above formula, M is a mapping function that maps program execution logic constraints and semantic constraints to a unified graph structure, C is the set of program execution logic constraints, S is the set of semantic constraints, and g is a cross-modal logic graph that represents cross-modal logical relationships. The mapping process includes entity alignment and relation mapping. Entity alignment is represented by the following formula: align(entity c entity s =similarity(entity) c entity s )>τ; In the above formula, `align` is the entity alignment function, which returns a boolean value indicating whether the two entities match. c For code entities, including function names, variable names, and class names, entity sFor semantic entities, including the function names and parameter descriptions mentioned in the document, similarity is the similarity calculation function, and τ is the similarity threshold, which ranges from [0,1]. If the value exceeds the threshold, the two entities are considered to be matched. Relational mapping is represented by the following formula: map_relation(rel c ,rel s )=R(rel c ,rel s ); In the above formula, map_relation represents the relation mapping operation, establishing cross-modal relational connections, and rel... c For relationships in the code, including function call relationships and variable dependencies, rel s R represents the semantic relationships in the document, including the functional dependencies and parameter constraints described therein. R is the relation mapping function that maps relations of different modalities to a unified representation. Logical axioms are generated using the following formula: axiom=logic_transform(constraint); In the above formula, axiom is the generated logical axiom, and logic_transform is the logical transformation function that transforms the input constraint into the standard logical axiom form. The input constraint includes program execution logic constraints and semantic constraints.

[0023] IV. Reasoning and Verification Layer like Figure 1 As shown, the reasoning verification layer includes a logical reasoning engine, such as... Figure 5 As shown, the tasks of a logic reasoning engine include: The inference engine is initialized, the rule base describing logical inference is loaded, the inferencer state and memory structure are initialized, inference parameters are set: maximum number of inference steps, timeout limit, and inference log recording mechanism is established. Axiom loading extracts all logical axioms from the cross-modal logic graph, performs syntax checking and standardization on the logical axioms, builds an axiom index to optimize reasoning efficiency, and detects potential conflicts between logical axioms. Consistency checks are performed using the tableaux algorithm for satisfiability testing, applying the following inference rules: Rule 1: ; Rule Two: ; Rule 3: ; Rule Four: ; Perform closure operations to detect contradictions, and record the reasoning process and intermediate states; The test results are evaluated as follows: if no contradiction is found, "Verification passed" is output; if a contradiction is found, the contradiction detection mechanism is activated; if the inference times out or memory overflows, "Verification incomplete" is output. Conflict detection identifies the axiom subset that leads to the conflict, uses the minimum unsatisfiable core MUC algorithm to find the minimum conflict set, and classifies the conflict types: type conflict, logical conflict, and constraint conflict. The reasoning chain is traced backward from the point of contradiction, the reasoning steps are traced in reverse, a reasoning tree is constructed to show the reasoning dependencies, key reasoning nodes and branch points are marked, and the contribution of each logical axiom to the contradiction is calculated. Contradiction localization maps logical axioms back to code and document locations, calculates the confidence and accuracy of the localization, and generates multi-level localization results: file-level, function-level, and statement-level. Report generation: Generates a structured consistency reasoning verification report, including contradiction descriptions, location information, and remediation suggestions, supporting multiple output formats: JSON, XML, and HTML; Wherein, for a given cross-modal logic graph g: g=<N,ε,A> ; In the above formula, N is the set of nodes, including all code entity nodes and document entity nodes; ε is the set of edges, representing various relationships between entities, including calls, dependencies and constraints; and A is the set of logical axioms, including all logical reasoning rules and constraints. Define a consistency check function: ; In the above formula, Consistency is a consistency check function that returns a Boolean value indicating whether the cross-modal logic graph g is consistent. For logical NOT operator, For logical formula variables, it represents a logical assertion in the cross-modal logic graph g. These are logical derivation symbols, indicating that something can be deduced. For logical AND operator, For logical formula variables The negative form; Define the contradiction tracing function: ; In the above formula, Contradiction_Trace is a contradiction tracing function that identifies the set of logical axioms that lead to contradictions. For a positive assertion of contradiction, As the opposite assertion of the contradiction, {axiom i} is a subset of logical axioms, including all logical axioms involved in contradictory reasoning. i Let i be the logical axiom that participates in the contradictory reasoning.

[0024] V. Result Processing Layer like Figure 1 As shown, the results processing layer includes conflict localization and report generation, such as... Figure 6 As shown, the work content of conflict identification and report generation includes: Reasoning chain analysis involves parsing the proof tree generated during the reasoning process, identifying all logical axioms and reasoning steps involved in contradictory reasoning, constructing an axiom dependency graph, and calculating the weights of logical axioms. , For the i-th logical axiom i The weights are used to mark key reasoning paths and branch points; By associating code snippets, tracing the mapping relationship between logical axioms and source code, locating specific code line numbers and character positions, extracting relevant code context, identifying involved program entities: variables, functions, and classes, and calculating the relevance score of the code snippets; By associating document descriptions, tracing the mapping relationship between logical axioms and documents, locating specific chapters, paragraphs and sentences, extracting relevant document context, identifying the document entities involved: functional descriptions, parameter descriptions and constraints, and calculating the relevance score of document fragments; Problem localization involves fusing location information from code and documentation, using a weighted fusion algorithm to calculate the final problem location, and generating multi-granularity localization results: coarse-grained: module / chapter level; medium-granular: function / paragraph level; fine-grained: statement / sentence level. Localization reliability is then calculated. ; Generate explanations based on templates, including: contradiction type classification; causes of contradictions; relevant code and document content; simplified description of logical reasoning process; text generation method using a hybrid of rules and neural networks; and adjustment of the technical depth of the explanation according to the user role. Output reports, generating structured JSON reports for program processing and human-friendly HTML reports for reading. Supports integration into IDEs and code review tools, and provides API interfaces for third-party tools to call.

[0025] Below is a sample report: Inconsistency Report: 1) Problem type: Contradictory behavior and logic; 2) Contradictory description: The documentation states: "The function returns -1 when the input parameter is less than 0". Code implementation: When the input parameter is less than 0, the function throws an IllegalArgumentException exception; 3) Location information: - Code location: lines 23-27 in src / main.java; - Documentation location: Section 2.3 of the API documentation; 4) Recommended repair: Modify the code logic to return -1 when the input is less than 0; Alternatively, modify the documentation to explain that an exception will be thrown instead of returning -1.

[0026] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions will not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A code and document conformance inference verification system based on cross-modal logical atlas, characterized in that: Comprise: An input layer that receives source code and software documentation; A feature extraction layer that extracts features from the source code and software documentation; An abstraction layer that converts the extracted features into a comparable intermediate representation; A unified modeling layer that maps code logic and document semantics into a unified graph structure and uses description logic for formal representation, resulting in a cross-modal logical graph; An inference verification layer that infers and verifies the consistency of the code and the documentation based on the cross-modal logical graph; A result processing layer that determines the verification result based on the inference and verification, and initiates a contradiction positioning mechanism when inconsistencies are found, performs contradiction positioning and report generation, and obtains an explainability report.

2. The cross-modal logical graph based code-to-document conformance inference verification system of claim 1, wherein: The feature extraction layer comprises: A code logic extraction module that uses compiler technology to parse code structure and extract program execution logic constraints from code to obtain code logic; A document semantic extraction module that uses NLP technology to understand document semantics and extract semantic constraints from documents to obtain document semantics.

3. The cross-modal logical graph based code-to-document conformance inference verification system of claim 2, wherein: The work content of the code logic extraction module includes: Lexical analysis, which decomposes source code into Token sequences, identifies keywords, identifiers, operators, and constants, filters comments and white spaces, and outputs Token streams; Syntax analysis, which checks syntax correctness according to programming language grammar rules, constructs syntax analysis trees, handles syntax errors and corrects them, and outputs syntax analysis trees; AST generation, which simplifies syntax analysis trees into abstract syntax trees, removes syntax sugar and redundant nodes, and retains essential structural information of programs, and outputs abstract syntax trees; CFG construction, which analyzes the control flow transition relationship of the program, identifies basic blocks, and constructs the jump relationship graph between basic blocks to handle conditional branches, loops, and exception handling control structures; Control flow logic extraction, which extracts conditional judgment logic based on CFG, identifies loop invariants and termination conditions, extracts exception handling logic, and generates control flow constraints; DFG construction, which analyzes the definition and use relationship of variables, constructs data flow dependency graph, traces the life cycle of variables, and identifies the dependency relationship between variables; Data dependency analysis, which analyzes data flow constraints based on DFG, identifies variable value range limits, analyzes function parameter and return value constraint relationships, and detects potential data races and dependency conflicts; Logical constraint generation, which combines control flow constraints and data flow constraints to generate formal program execution logic constraint expressions, and outputs program execution logic constraint sets; For a given code snippet, define a logical constraint extraction function: LogicExtract(AST) = {C1, C2,..., C n}; In the above formula, LogicExtract is a logic constraint extraction function, AST is an abstract syntax tree, C n is the nth logic constraint, representing a logic rule in the code, and n is the total number of logic constraints. For each logical constraint, represent it as a triple: C n = <condition, action, context>; In the above formula, condition is the trigger condition, which represents the prerequisite condition for the logical constraint to take effect, action is the execution action, which represents the operation sequence performed when the logical constraint takes effect, and context is the context environment, including variable scope, function call stack, and other environmental information; For conditional branch statements, the logical constraint extraction uses the following formula: ; In the above formula, C if Logical constraints for conditional branching statements, Conditional formalization function, which converts conditional expressions in the code into logical expressions, Action serialization function, which converts code blocks in the then branch into action sequence representations, Context extraction function, which obtains the execution environment information of the current code fragment.

4. The cross-modal logical graph based code-to-document conformance inference verification system of claim 2, wherein: The work content of the document semantic extraction module includes: Text preprocessing, document format standardization, sentence segmentation and word segmentation, stop word filtering and stem extraction, text cleaning and noise removal, and output of standardized text sequences; Named entity recognition, identify key entities in the document: function name, class name, variable name, parameter name, identify technical concepts: data type, algorithm name, design pattern, identify business entities: user role, business object, operation action, use BiLSTM+CRF or BERT-based model for sequence labeling, output text sequence with entity label, that is, entity annotation result; Relation extraction, identify semantic relationships between entities: inheritance, implementation, call, include, identify operation relationships: create, modify, delete, query, identify constraint relationships: preconditions, postconditions, exception conditions, use relationship classification model or knowledge graph embedding technology, output entity relationship triple set, that is, relationship annotation result; Semantic role labeling, identify the semantic roles of each component in the sentence, label actions and participants, identify roles such as agents, patients, and instruments, use deep semantic role labeling model, output semantic role labeling result, that is, semantic role result; Semantic constraint construction, integrate entity, relationship, and semantic role information to construct structured semantic constraint representation, identify conditional logic: if-then rules, exception handling rules, extract functional constraints and non-functional constraints; Formal semantic constraints, convert natural language constraints into logical expressions, formalize using first-order logic or description logic, generate a set of axioms for subsequent reasoning, output formal constraint set; Wherein, for a given document, define a semantic constraint extraction function: SemanticExtract(Doc) = {S1, S2,..., S m} ; In the above formula, SemanticExtract is a semantic constraint extraction function, Doc is an input document, S m is the mth semantic constraint, representing a semantic rule in the document, and m is the total number of semantic constraints. For each semantic constraint, its logical formula is: ; In the above formula, is a set of variables, representing function parameters, global variables or other related entities, and k is the total number of variables, is a precondition predicate, describing the conditions that must be met before the function is called, is a postcondition predicate, describing the state that should be reached after the function is called, is a logical implication symbol, representing the logical relationship of "if … then …".

5. The cross-modal logical graph based code-to-document conformance inference verification system of claim 2, wherein: The abstraction layer includes: Program logic abstraction, extract function call relationships, control flow logic, and data dependencies from program execution logic constraints; Semantic constraint abstraction, extract functional description, parameter constraints, and exception handling rules from semantic constraints. 6.The cross-modal logical graph based code-to-document conformance inference verification system of claim 5, wherein: The unified modeling layer includes cross-modal logic graph construction, which includes code logic layer, semantic constraint layer, logical axiom layer, mapping relationship, and reasoning relationship; The code logic layer is the bottom layer, including: Function node, attributes include function signature, parameter list, return type, and access modifier; Variable node, attributes include variable name, data type, scope, and lifetime; Conditional node, attributes include conditional expression, branch number, and coverage path; Action node, attributes include operation type, operation object, and side effect; The semantic constraint layer is the middle layer, including: Functional description node, extract functional specification description from the document, including main function, input and output description, and business rules; Parameter constraint node, extract parameter limit conditions from the document, including value range, type constraint, and null value processing; Return value constraint node, extract return value specification from the document, including return value type, value range, and special cases; Exception constraint node, extract exception handling rules from the document, including exception type, trigger condition, and processing method; The logical axiom layer is the top layer, including: implication, , means that if A is true, then B must be true; equivalence relation, denotes that A is logically equivalent to B; conflicting relations, denotes that A and B cannot be true at the same time; Dependency relationship, depends(A, B), indicates that the establishment of A depends on B; The mapping relationship is represented by a dashed line, and the nodes of the code logic layer are mapped to the corresponding nodes of the semantic constraint layer through a semantic matching algorithm. The mapping is based on multiple dimensions including name similarity, type compatibility, and semantic relevance, and the mapping strength is represented by a confidence score; The inference relationship is represented by a solid line, and the nodes of the semantic constraint layer generate corresponding logical axioms according to their constraint content, which are used for subsequent consistency inference verification and contradiction positioning; Where the mapping function is defined as: ; In the above formula, M is a mapping function that maps program execution logic constraints and semantic constraints into a unified graph structure, C is a set of program execution logic constraints, S is a set of semantic constraints, g is a cross-modal logical graph, and represents the logical relationship between cross-modal; The mapping process includes entity alignment and relationship mapping, which is represented by the following formula: align(entity c , entity s ) = similarity(entity c , entity s ) > tau; In the above formula, align is an entity alignment function returning a Boolean value indicating whether two entities match, entity c is a code entity, including function names, variable names, and class names, entity s is a semantic entity, including function names and parameter descriptions mentioned in the document, similarity is a similarity calculation function, and τ is a similarity threshold value, with a value range of [0, 1], and two entities are considered to match if the threshold value is exceeded. The relationship mapping is represented by the following formula: map_relation(rel c , rel s )=R(rel c , rel s ); In the above formula, map relation represents the relationship mapping operation, which establishes the cross-modal relationship connection, rel c For the relationship in the code, including function call relationship and variable dependency relationship, rel s For the semantic relationship in the document, including the described function dependency and parameter constraint relationship, R is a relationship mapping function that maps the relationships of different modalities to a unified representation; The logical axiom generation is represented by the following formula: axiom = logic_transform(constraint); In the above formula, axiom is the generated logical axiom, logic_transform is a logical transformation function that converts the input constraint constraint into a standard logical axiom form, and the input constraint constraint includes program execution logic constraints and semantic constraints.

7. The cross-modal logical graph based code-to-document conformance inference verification system of claim 6, wherein: The inference verification layer includes a logical inference engine, and the working content of the logical inference engine includes: Inference engine initialization, load the description of the logical inference rule library, initialize the inference state and memory structure, set the inference parameters: maximum inference step, timeout limit, and establish the inference log recording mechanism; Axiom loading, extracting all logical axioms from the cross-modal logical graph, performing syntax checking and standardization on the logical axioms, building an axiom index to optimize inference efficiency, and detecting potential conflicts between logical axioms; Consistency check, using the tableaux algorithm for satisfiability detection, applying the following inference rules: Rule one: ; Rule two: ; Rule three: ; Rule Four: ; Performing a closure operation to detect contradictions, recording the inference process and intermediate state; Detection result judgment, if no contradiction is found, output "verification passed"; if a contradiction is found, start the contradiction detection mechanism; if the inference times out or the memory overflows, output "verification not completed"; Contradiction detection, identifying the axiom subset that causes the contradiction, using the minimal unsatisfiable core (MUC) algorithm to find the minimal contradiction set, and classifying the contradiction type: type conflict, logical conflict, and constraint conflict; Inference chain tracing, starting from the contradiction point and tracing the inference steps in reverse, building an inference tree to display the inference dependency relationship, marking key inference nodes and branch points, and calculating the contribution of each logical axiom to the contradiction; Contradiction positioning, mapping the logical axioms back to the code and document locations, calculating the confidence and accuracy of the positioning, and generating multi-level positioning results: file level, function level, and statement level; Report generation, generating a structured consistency inference verification report including contradiction description, location information, and repair suggestions, supporting multiple output formats: JSON, XML, and HTML; Where, for a given cross-modal logical graph g: g = <N, ε, A>; In the above formula, N is the node set, including all code entity nodes and document entity nodes, ε is the edge set, representing various relationships between entities, including call, dependency and constraint, A is the logical axiom set, including all logical reasoning rules and constraint conditions; Define the consistency check function: ; In the above formula, Consistency is a consistency checking function that returns a Boolean value indicating whether the cross-modal logical graph atlas g is consistent, is a logical NOT operator, is a logical formula variable, indicating a certain logical assertion in the cross-modal logical graph atlas g, is a logical deduction symbol, indicating that can be deduced from is a logical AND operator, is a logical formula variable is the negation of Define the contradiction backtracking function: ; In the above formula, Contradiction_Trace is a contradiction trace function to find out the set of logical axioms that cause the contradiction, is a positive assertion of the contradiction, is a negative assertion of the contradiction,{axiom i} is a subset of logical axioms including all logical axioms involved in the contradiction reasoning, axiom i is the i-th logical axiom involved in the contradiction reasoning.

8. The cross-modal logical graph based code-to-document conformance inference verification system of claim 7, wherein: The result processing layer includes contradiction positioning and report generation, and the work content of contradiction positioning and report generation includes: Reasoning chain analysis, parsing the proof tree generated in the reasoning process, identifying all logical axioms and reasoning steps involved in the contradictory reasoning, constructing the axiom dependency graph, and calculating the weight of the logical axiom: , The weight of the i-th logical axiom axiom i , mark the key reasoning path and branch point; Correlate code snippets, trace logical axioms to source code mapping relationships, locate specific code line numbers and character positions, extract relevant code context, identify involved program entities: variables, functions and classes, and calculate the relevance score of the code snippet; Correlate document descriptions, trace logical axioms to document mapping relationships, locate specific chapter, paragraph and sentence positions, extract relevant document context, identify involved document entities: function descriptions, parameter descriptions and constraint conditions, and calculate the relevance score of the document snippet; Problem localization, fusing code and document location information, using weighted fusion algorithm to calculate the final problem location, generating multi-granularity localization results: coarse granularity: module / section level; medium granularity: function / paragraph level; fine granularity: sentence / sentence level, calculating the location confidence: ; Generate an explanation, generate a natural language explanation based on a template, and the explanation content includes: contradiction type classification; contradiction causes; involved code and document content; simplified description of logical reasoning process, using a hybrid text generation method of rules and neural networks, adjusting the technical depth of the explanation according to the user role; Output the report, generate a structured JSON format report for program processing, generate a human-friendly HTML format report for reading, support integration into IDE and code review tools, and provide API interfaces for third-party tools to call.

Citation Information

Cited By

  • API knowledge graph construction method, medium and equipment

    CN121501339A

  • An API knowledge graph construction method, medium and device

    CN121501339B

  • Query response and code generation method and system based on power field document analysis

    CN121958316A