System and method for checking source code based on artificial intelligence

By constructing a knowledge graph-based multimodal code inspection system, the syntax, logic, and dependencies of AI-generated code are analyzed. Combined with artificial intelligence models, a comprehensive quality inspection is carried out, which solves the problems of detecting hidden defects and false alarms in AI-generated code, and achieves efficient code quality assessment and intelligent repair.

CN120893036APending Publication Date: 2025-11-04SHANGHAI RUICHENG SOFTWARE CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202511419009.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-30
Publication Date
2025-11-04

AI Technical Summary

Technical Problem

Existing technologies struggle to effectively detect and verify hidden logical defects in AI-generated code. Traditional static analysis tools have a high false positive rate for AI-generated code and cannot achieve comprehensive and integrated verification of code standardization, security, and business compliance. They also cannot dynamically adapt to the differences in code style among different AI-generated models.

Method used

We will build a multimodal code inspection system based on knowledge graphs. By analyzing the syntax structure, logical behavior and dependency characteristics of the code, and combining it with artificial intelligence models, we will conduct multi-dimensional quality inspections, including quality inspections of standardization, security and business logic, and provide intelligent remediation solutions.

Benefits of technology

It improves the accuracy of detecting AI-generated code, reduces the false positive rate, enhances the ability to check code standardization and security, supports compatibility with multiple programming languages, and can quickly adapt to changes in the code generation environment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120893036A_ABST
    Figure CN120893036A_ABST
Patent Text Reader

Abstract

The invention provides a system and method for checking source codes based on artificial intelligence, and the method comprises the steps: constructing a quality basis knowledge graph by a knowledge graph module based on the existing code writing quality basis in the aspects of a specification layer, a security layer and a business logic layer; the code analysis module analyzes grammar structure features, logic behavior features and dependency relationship features of target codes; the feature fusion module fuses the grammar structure features, the logic behavior features and the dependency relationship features to obtain multi-modal fusion features; and the code inspection module performs quality inspection of normalization, security and business logic dimensions on the multi-modal fusion features in combination with artificial intelligence and a quality basis knowledge graph to obtain a code quality inspection result. Logic defects are checked out, generation of misinformation and missed protection of the defects is reduced, and code development efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of code quality inspection, and in particular to a system and method for inspecting source code based on artificial intelligence. BACKGROUND

[0002] With the rapid development and popularization of artificial intelligence (AI) code generation technology, tools such as GitHub Copilot and OpenAI Codex are increasingly widely used in software development. These AI code generation tools can significantly improve development efficiency, but at the same time, they also bring new challenges and risks, especially in terms of code quality control. Enterprises are facing unprecedented risks of losing control of code quality, which mainly manifests in the following aspects: 1. Difficulty in detecting implicit logic defects in AI-generated code Although AI-generated code may be syntactically correct, it may have implicit defects at the logic level. These defects are often difficult to be detected by traditional static inspection tools, because they are usually hidden in complex business logic and need to be analyzed in combination with specific application scenarios and business requirements.

[0003] 2. False positive / negative problems of traditional static inspection tools for AI-generated code AI-generated code contains many security vulnerabilities, and traditional static analysis tools have a high false positive rate for these codes. This means that existing static inspection tools are prone to produce a large number of false positives when dealing with AI-generated code, causing developers to waste time troubleshooting false issues, and are also prone to miss real security risks, posing potential risks to the system.

[0004] 3. Integrated verification requirements for code standardization, security, and business compliance Modern software development not only requires code to have good readability and maintainability, but also must meet strict security standards and business compliance requirements. However, traditional code review methods are difficult to achieve comprehensive integrated verification of code standardization, security, and business compliance, especially when facing complex and variable business scenarios, this limitation is particularly evident.

[0005] 4. Dynamically adapting to differences in code style of different AI generation models Different AI code generation models have their own code style and characteristics, which pose higher requirements on code review tools. Existing tools often have difficulty dynamically adapting to these differences, resulting in compatibility problems in actual application, affecting code quality and development efficiency.

[0006] To address the above challenges, there are some related technical solutions in the market, but they each have certain limitations: SonarQube: As a rule-based static inspection tool, SonarQube is complex in rule configuration and adjustment, and the rule library is outdated, which cannot effectively identify AI-specific patterns and adapt to the rapidly changing code generation environment.

[0007] DeepCode: This system uses AI-driven code pattern matching technology, but performs poorly in handling new structures and large-scale projects, and the analysis process is time-consuming, affecting development efficiency.

[0008] Meta's CodeT5: As a code quality evaluation pre-training model, CodeT5 only supports single-dimensional quality evaluation, lacking comprehensive consideration of code specification, security, and business compliance. SUMMARY

[0009] Based on the above problems, the present application provides a system and method for checking source code based on artificial intelligence, aiming to solve the technical problems of single-dimensional code inspection and long time consumption in the prior art.

[0010] The present application provides a system for checking source code based on artificial intelligence, comprising: a knowledge graph module for constructing a quality basis knowledge graph based on existing code writing quality basis in the specification layer, security layer and business logic layer; a code analysis module for analyzing the syntax structure features, logical behavior features and dependency relationship features of the target code to be inspected; a feature fusion module connected to the code analysis module for fusing the syntax structure features, logical behavior features and dependency relationship features of the target code to obtain multi-modal fusion features of the target code; a code inspection module connected to the knowledge graph module and the feature fusion module for combining the code inspection model based on artificial intelligence and the quality basis knowledge graph to perform quality inspection in the specification, security and business logic dimensions of the multi-modal fusion features, and obtain the code quality inspection result.

[0011] Further, the system further comprises: an intelligent scheduling module for analyzing the basic features of the target code and dynamically scheduling code analysis resources according to the basic features of the target code; a code analysis module connected to the intelligent scheduling module for analyzing the syntax structure features, logical behavior features and dependency relationship features of the target code using the scheduled code analysis resources; the code inspection module is also connected to the intelligent scheduling module for filtering the corresponding quality basis knowledge graph based on the basic features of the target code, combining the code inspection model and the filtered quality basis knowledge graph to perform quality inspection in the specification, security and business logic dimensions of the multi-modal fusion features, and obtain the code quality inspection result.

[0012] Further, the base features of the target code include a programming language type and a code size; the intelligent scheduling module includes: a parser matching unit, configured to match a corresponding code parser based on the programming language type of the target code; a resource allocation unit, configured to enable a corresponding resource occupation mode based on the code size of the target code for use by the code parsing module, the resource occupation mode including a single-thread mode and a distributed parsing pool mode; and a code parsing module, configured to parse out syntax structure features, logic behavior features, and dependency relationship features of the target code to be checked using the matched code parser.

[0013] Further, the code parser includes a syntax parser, a dependency parser, and a logic parser; the code parsing module includes: a syntax parsing unit, configured to parse the syntax structure of the target code using the syntax parser to parse out syntax structure features of the target code; a dependency parsing unit, configured to parse the dependency relationship of the target code based on the syntax structure features using the dependency parser to parse out dependency relationship features of the target code; and a logic parsing unit, configured to parse the logic behavior of the target code based on the syntax structure features and the dependency relationship features using the logic parser to parse out logic behavior features of the target code; and the intelligent scheduling module further includes: a parsing coordination unit, configured to: construct a parsing task priority according to a parsing order of the syntax structure, the dependency relationship, and the logic behavior, sequentially invoke the syntax parsing unit, the dependency parsing unit, and the logic parsing unit according to the parsing task priority, and share the parsed syntax structure features, the dependency relationship features, and the logic behavior features in real time among the syntax parsing unit, the dependency parsing unit, and the logic parsing unit.

[0014] Further, the feature fusion module includes: a structuring unit, configured to structure the syntax structure features, the dependency relationship features, and the logic behavior features respectively; a feature encoding unit, connected to the structuring unit, configured to perform feature encoding processing on the syntax structure features, the dependency relationship features, and the logic behavior features after the structuring processing; and a cross-modal association unit, connected to the feature encoding unit, configured to construct a feature association matrix for the syntax structure features, the dependency relationship features, and the logic behavior features after the feature encoding processing, and perform weight adjustment based on an attention mechanism, and then form multi-modal fusion features and output the multi-modal fusion features.

[0015] Further, the code checking module comprises: a specification checking unit configured to process the multi-modal fusion features to perform specification checking on the target code and obtain a specification checking result; a security checking unit configured to process the multi-modal fusion features to perform security checking on the target code and obtain a security checking result; and a business logic checking unit configured to process the multi-modal fusion features to perform business logic checking on the target code and obtain a business logic checking result; and the code quality checking result comprises the specification checking result, the security checking result and the business logic checking result.

[0016] Further, the system further comprises: a quality evaluation module connected to the code checking module and configured to perform quality evaluation on the target code based on the code quality checking result and generate a quality evaluation result, wherein the quality evaluation result comprises a quality defect distribution and a risk level of the target code.

[0017] Further, the system further comprises: an intelligent repair recommendation module connected to the code checking module and configured to use an intelligent recommendation model formed based on artificial intelligence to generate a code repair scheme and a refactoring path plan according to the code quality checking result.

[0018] Further, the system further comprises: a repair scheme verification module connected to the intelligent repair recommendation module and configured to verify the code repair scheme and output a repair scheme verification result.

[0019] The application further provides a method for checking source code based on artificial intelligence, which uses the aforementioned system for checking source code based on artificial intelligence, and comprises the following steps: A1, parsing syntax structure features, logic behavior features and dependency relationship features of target code to be checked; A2, fusing the parsed syntax structure features, logic behavior features and dependency relationship features of the target code to obtain multi-modal fusion features of the target code; and A3, performing quality checking on the multi-modal fusion features in the specification, security and business logic dimensions by combining a quality basis knowledge graph and a code checking model based on artificial intelligence to obtain a code quality checking result; and the quality basis knowledge graph is constructed according to existing code writing quality basis in the specification, security and business logic layers.

[0020] The application has the beneficial technical effects that: the application performs knowledge graph construction on the existing code writing quality basis in the specification, security and business logic layers, analyzes the syntax, logic and dependency of the code, performs multi-dimensional code quality evaluation by combining the knowledge graph and artificial intelligence, can check the defects in the logic layer, reduces the generation of defect false positives and missed alarms, improves the code development efficiency, realizes compatible checking of multiple types of codes, and can quickly adapt to the code generation environment. BRIEF DESCRIPTION OF DRAWINGS

[0021] Figure 1A module schematic diagram of an intelligent scheduling module of the system for checking source code based on artificial intelligence according to the present application; Figure 2 A module schematic diagram of an intelligent scheduling module of the system for checking source code based on artificial intelligence according to the present application; Figure 3 A module schematic diagram of a code parsing module of the system for checking source code based on artificial intelligence according to the present application; Figure 4 A module schematic diagram of a code checking module of the system for checking source code based on artificial intelligence according to the present application; Figure 5 A step flow chart of the method for checking source code based on artificial intelligence according to the present application. DETAILED DESCRIPTION

[0022] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the protection scope of the present application.

[0023] It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.

[0024] The present application will be further described below with reference to the drawings and specific embodiments, but is not limited by the present application.

[0025] Referring to Figure 1 The present application provides a system for checking source code based on artificial intelligence, comprising: a knowledge graph module 1, configured to construct a quality basis knowledge graph based on existing code writing quality basis in the specification layer, the security layer and the business logic layer; a code parsing module 2, configured to parse the syntax structure features, the logic behavior features and the dependency relationship features of the target code to be checked; a feature fusion module 3 connected to the code parsing module 2, configured to fuse the syntax structure features, the logic behavior features and the dependency relationship features of the target code to obtain the multi-modal fusion features of the target code; and a code checking module 4 connected to the knowledge graph module 1 and the feature fusion module 3, respectively, configured to perform quality checking in the specification, security and business logic dimensions on the multi-modal fusion features by combining the code checking model based on artificial intelligence and the quality basis knowledge graph, and obtain the code quality checking result.

[0026] Specifically, the target code is a code generated based on an artificial intelligence model, i.e. AI.

[0027] Regarding the construction of quality basis knowledge graph, at the specification layer, quality basis related to code checking includes industry standards, project specifications (coding style, naming conventions). Industry standards such as ISO / IEC (International Organization for Standardization / International Electrotechnical Commission), coding style refers to the uniform conventions in format, structure and syntax usage when writing code, different programming languages have their own preferred styles. Naming conventions refer to the rules followed when naming variables, functions, classes, files, etc.

[0028] At the security layer, quality basis related to code checking includes vulnerability libraries (OWASP Top 10), security rules (permission control, data encryption), etc. OWASP Top 10 refers to the "Top 10 Most Serious Web Application Security Risks" published by the OWASP organization, which is one of the globally recognized standards for web application security.

[0029] At the business level, quality basis related to code checking includes process specifications, compliance requirements (such as payment processes, user data processing). In software system architecture, the business layer is the core part connecting the underlying technical implementation and the upper layer user requirements. It not only handles core logic, but also must ensure that all operations comply with process specifications and compliance requirements, especially in sensitive areas such as payment processes, user data processing, etc.

[0030] By constructing knowledge graph module 1 through code basis materials at various levels, context awareness for subsequent code quality checking is achieved, improving the accuracy of code quality checking and avoiding false positives and false negatives, which is conducive to quickly capturing code quality defects.

[0031] Further, the system further comprises: an intelligent scheduling module 5 for analyzing the basic features of the target code and dynamically scheduling code parsing resources according to the basic features of the target code; a code parsing module 2 connected to the intelligent scheduling module 5, for parsing the syntax structure features, logic behavior features and dependency relationship features of the target code using the scheduled code parsing resources; a code checking module 4 also connected to the intelligent scheduling module 5, for filtering the corresponding quality basis knowledge graph based on the basic features of the target code, and performing quality checking in the specification, security and business logic dimensions on the multi-modal fusion features based on the code checking model and the filtered quality basis knowledge graph, to obtain the code quality checking result.

[0032] The detection and recognition of the basic features of the target code includes: detection of the programming language type (Python / Java / JavaScript, etc.) of the target code, analysis of the code size (number of lines, number of functions, complexity score), and recognition of special syntax structures (generics, decorators, macro definitions, etc.).

[0033] Referring toFigure 2 Further, the basic characteristics of the target code include the programming language type and the code size; the intelligent scheduling module 5 comprises: a parser matching unit 51, configured to match a corresponding code parser based on the programming language type of the target code; a resource allocation unit 52, configured to enable a corresponding resource occupation mode for the code parsing module based on the code size of the target code, the resource occupation mode including a single-thread mode and a distributed parsing pool mode; and a code parsing module 2, configured to parse the syntax structure characteristics, the logic behavior characteristics, and the dependency relationship characteristics of the target code to be checked by using the matched code parser; and a code checking module 4, configured to screen a quality basis knowledge graph matched with the programming language type of the target code.

[0034] The detection of the programming language type mainly matches a dedicated code parser. The dedicated code parser is, for example, an ast library of Python, an ANTLR of Java, and an Esprima of JavaScript, which are all key tools for parsing source code and generating an Abstract Syntax Tree (AST). Thus, the present application can be compatible with code checking of various types.

[0035] The recognition of the code size mainly determines the calculation resource occupation mode. For example, if the target code is small-scale code (for example, <500 lines), a single-thread occupation mode is selected for code parsing. If the target code is medium-large-scale code (for example, ≥500 lines), a distributed parsing pool is automatically enabled for code parsing.

[0036] In addition, the intelligent scheduling module 5 is further configured with an exception handling mechanism, which is used to automatically reduce the basic parsing mode when detecting that the parsing task is timed out (for example, the timeout is greater than 10s). Different programming language types involve differences in coding style, naming convention, safety rules, and the like. Therefore, the quality basis knowledge graph is adaptively screened according to the programming language type of the target code. For example, the knowledge graph is matched with a Python specification set constructed for Python code, so as to avoid errors, confusion, and the like caused by differences in other programming language types, thereby causing false detection and missed detection.

[0037] In addition, in the quality checking process of the target code performed by the code checking module 4, some keywords trigger knowledge in the quality basis knowledge graph in real time, for example, the keyword eval() function is detected to automatically associate code injection knowledge.

[0038] In addition, the quality has priority order according to the knowledge in the knowledge graph, the priority of the project specification is higher than the priority of the industry standard, and the priority of the industry standard is higher than the priority of the general rule. In the code quality inspection process, the code inspection module 4, when there is a conflict between the project specification, the industry standard, and the general rule for the same code, takes the highest priority as the criterion to make a quality conclusion.

[0039] Referring to Figure 3 Further, the code parser includes a syntax parser, a dependency parser, and a logic parser; the code parsing module 2 includes: a syntax parsing unit 21 configured to parse the syntax structure of the target code using the syntax parser to parse the syntax structure features of the target code; a dependency parsing unit 22 configured to parse the dependency relationship of the target code based on the syntax structure features using the dependency parser to parse the dependency relationship features of the target code; a logic parsing unit 23 configured to parse the logic behavior of the target code based on the syntax structure features and the dependency relationship features using the logic parser to parse the logic behavior features of the target code; the intelligent scheduling module 5 further includes: a parsing cooperation unit 53 configured to: construct a parsing task priority according to the parsing order of the syntax structure, the dependency relationship, and the logic behavior, sequentially call the syntax parsing unit, the dependency parsing unit, and the logic parsing unit according to the parsing task priority, and share the parsed syntax structure features, dependency relationship features, and logic behavior features in real time with the syntax parsing unit, the dependency parsing unit, and the logic parsing unit.

[0040] In addition to the basic feature analysis of the target code, the parser matching, the computing resource occupation mode matching, and the exception handling mechanism, the intelligent scheduling module 5 also performs multi-dimensional parsing cooperation, sets a parsing task priority, and the priority from high to low is: syntax structure parsing, dependency relationship parsing, and logic behavior parsing, establishes a three-level parsing task queue, realizes real-time sharing of the parsing results, and the output of the previous parsing task is taken as the input of the subsequent parsing task.

[0041] In addition, the intelligent scheduling module 5 further includes: a parsing progress monitoring unit 54 configured to monitor the parsing progress of each parsing unit in the code parsing module 2, such as the syntax parsing unit 21, the dependency parsing unit 22, and the logic parsing unit 23, and output the parsing progress for visual display; a parsing exception marking unit 55 configured to automatically mark the code nodes that have parsing exceptions and trigger the code parsing module 2 to retry. The corresponding parsing unit of the code parsing module 2 is parsed again to improve the success opportunity of the parsing task.

[0042] The code analysis module 2 of the present application includes a syntax analysis unit 21, a dependency analysis unit 22, and a logic analysis unit 23, which perform deep analysis on the target code. The code analysis module 2 of the present application separately sets an analysis unit module for different analysis tasks, which is uniformly scheduled by an intelligent scheduling module. When a new analysis task needs to be performed, an additional analysis unit can be added to perform the new analysis task on the basis of the original analysis unit or after slight modification, which is also scheduled by the intelligent scheduling module, facilitating the expansion of the module and improving the scalability and compatibility of the present application.

[0043] The syntax analysis unit 21 analyzes the syntax structure of the target code, including lexical analysis, such as disassembling the code into token units such as keywords, identifiers, and operators, and recording the position information (line number, column number) of each token unit for subsequent error positioning; AST construction, i.e., generating an abstract syntax tree containing complete syntax node levels (function definition, variable declaration, control structure, etc.), reflecting the syntax level relationship of the code.

[0044] Syntax unit stream extraction, code splitting to form the smallest execution unit (code is divided into small blocks that can be independently executed, such as function bodies, loop blocks, and conditional branches), i.e., syntax units, establishing a syntax unit call relationship chain (caller→callee mapping), and assigning a unique identifier to each syntax unit and associating the source code location.

[0045] The syntax analysis unit 21 is also used for syntax checking during syntax structure analysis to detect syntax errors (such as missing symbols, keyword errors, etc.), generate code positions of syntax errors, and provide correction suggestions.

[0046] The dependency analysis unit 22 analyzes the dependency relationship of the target code, analyzes the relationship between the inside and outside of the code, including data flow analysis, external dependency identification, dependency topology graph construction, etc.

[0047] Data flow analysis includes: tracking the full life cycle of variables: definition→assignment→reference→destruction; constructing variable dependency chains (such as the transitive dependency relationship x→y→z); detecting data anomalies (such as undefined references, type mismatches, etc.).

[0048] External dependency identification includes: parsing import statements to identify dependency libraries / modules and version requirements; extracting interface call relationships.

[0049] Dependency topology graph construction includes: generating a multi-level dependency relationship graph (current code→direct dependency→indirect dependency); labeling dependency types (mandatory dependency / optional dependency) and version compatibility.

[0050] The logical analysis unit 23 is configured to analyze the business logic of the target code, including control flow graph (CFG) construction, branch decision chain extraction, logical anomaly detection, and the like.

[0051] The control flow graph (CFG) construction includes: taking the syntax unit as the node and the execution order as the edge to construct a graphical model; adding a conditional judgment edge to the branch structure (if-else / switch-case); and marking the entering / exit condition node for the loop structure (for / while).

[0052] The branch decision chain extraction includes: tracing all possible execution paths and recording the judgment condition of each branch; loop structure analysis: iteration number constraint, termination condition verification; generating a decision path tree and marking the key judgment node.

[0053] The logical anomaly detection includes: identifying unreachable code, dead loops, and conditionally constant / always false problems.

[0054] Further, the feature fusion module 3 includes: a structured unit 31 configured to structure the syntax structure feature, the dependency relationship feature, and the logical behavior feature respectively; a feature coding unit 32 connected to the structured unit 31 and configured to perform feature coding processing on the syntax structure feature, the dependency relationship feature, and the logical behavior feature after the structured processing; and a cross-modal association unit 33 connected to the feature coding unit 32 and configured to construct a feature association matrix for the syntax structure feature, the dependency relationship feature, and the logical behavior feature after the feature coding processing, and perform weight adjustment based on an attention mechanism, and then form a multi-modal fusion feature and output.

[0055] The parsed syntax structure feature, dependency relationship feature, and logical behavior feature are partially unstructured features, which are not conducive to subsequent inspection and analysis processing, and therefore, advanced structured processing is performed to structure the features.

[0056] The structured processing of the syntax structure feature involves analysis of AST node distribution, nesting depth, and unit quantity, and the like. The AST node distribution, for example, counts the number of different types of nodes in the AST and their proportion, and the nesting depth, for example, counts the maximum level of code block nesting. The unit quantity, for example, counts the number of syntax units.

[0057] The structured processing of the logical behavior feature involves analysis of control flow complexity, branch quantity, and decision condition complexity, and the like.

[0058] The structured processing of the dependency relationship feature involves analysis of variable dependency chain length, external dependency quantity, and topological depth, and the like.

[0059] After the structured features are processed, feature encoding is performed, including: for discrete features such as node types, one-hot encoding is used; for continuous features, standard normalization processing is performed to map to the 0-1 interval; for text features such as variable names and function names, Word2Vec technology is used to convert them into word embedding vectors.

[0060] For the encoded features, a feature correlation matrix is established, such as associating syntax units with logical paths and associating variable dependencies with syntax definitions. This allows subsequent code checks to determine whether associated features have problems when a feature check detects a quality problem. Based on the attention mechanism, the weight is adjusted, and after the correlation matrix association and attention weight adjustment, the multi-modal fusion features are combined into the code checking module for checking.

[0061] Referring to Figure 4 , further, the code checking module 4 includes: a specification checking unit 41 for processing multi-modal fusion features to perform specification checking on the target code and obtaining a specification checking result; a security checking unit 42 for processing multi-modal fusion features to perform security checking on the target code and obtaining a security checking result; a business logic checking unit 43 for processing multi-modal fusion features to perform business logic checking on the target code and obtaining a business logic checking result; and the code quality checking result includes the specification checking result, the security checking result, and the business logic checking result.

[0062] The code checking module 4 is divided into the specification checking unit 41, the security checking unit 42, and the business logic checking unit 43. When new dimensions of code checking tasks are added, new checking units are constructed, which is beneficial to the expansion of the system's checking tasks, the expansion of the application, and the improvement of the compatibility. The specification checking unit, the security checking unit, and the business logic checking unit appear in the form of plug-ins.

[0063] The specification checking content items include: code style, indentation type (space / tab), blank line distribution, comment format, etc.; naming specification, variable / function / class naming format verification (camel case / snake case, etc.); code format, line length limit, bracket usage specification, statement terminator, etc.

[0064] The security checking content items include: vulnerability pattern matching: SQL injection, XSS attack, command injection, etc.; permission risk analysis: integrity check of permission verification before sensitive operations; data security: verification of encrypted storage of sensitive data (passwords, ID cards).

[0065] Business logic check content items include: process compliance: business process node integrity verification (such as login -> verification -> operation -> log); rule conflict detection: identification of logical contradictions between business rules; business coverage: check if all necessary business rules are implemented.

[0066] Further, the system further comprises a quality evaluation module 6 connected to the code checking module 4, for evaluating the quality of the target code based on the code quality checking result, and generating a quality evaluation result, the quality evaluation result including the quality defect distribution and risk level of the target code.

[0067] The quality evaluation module 6 sets weights for the severity of various defects in the target code, and then calculates a comprehensive score according to the number of defects, defect weights, and influence coefficients, and divides the risk level of the target code according to the comprehensive score. For example: fatal defects (remote code execution, etc.), set the weight to 10; serious defects (missing permission verification, etc.), set the weight to 7; general defects (non-standard naming, etc.), set the weight to 3; slight defects (formatting issues, etc.), set the weight to 1.

[0068] The calculation formula of the risk level of the target code is as follows: Comprehensive score = Σ (defect quantity x weight) x influence coefficient.

[0069] The risk level division rule is: the comprehensive score is 0-10, which is a low risk level; the comprehensive score is 11-30, which is a medium risk level; the comprehensive score is more than 30, which is a high risk level. Further, the system further comprises an intelligent repair recommendation module 7 connected to the code checking module 4, for using an intelligent recommendation model based on artificial intelligence to generate a code repair scheme and a refactoring path plan according to the code quality checking result.

[0070] The repair scheme for the syntax error problem directly generates a corrected code segment (such as completing the missing symbol); the repair scheme for the security vulnerability problem provides an alternative implementation scheme (such as parameterized query instead of string concatenation); the repair scheme for the specification problem generates standardized correction suggestions according to the rules (such as naming format conversion).

[0071] The refactoring path plan is, for example: a step-by-step repair guide for complex problems, code structure optimization suggestions (such as function splitting, module reorganization), dependency adjustment schemes (version upgrade, alternative library recommendation), etc. Further, the system further comprises a repair scheme verification module 8 connected to the intelligent repair recommendation module 7, for verifying the code repair scheme to obtain a repair scheme verification result and output.

[0072] The verification of the code repair solution includes verifying the syntax correctness of the code repair solution, evaluating the influence range of the code repair solution on other modules, and providing code quality comparison data before and after the code repair solution.

[0073] Referring to Figure 5 The application further provides a method for checking source code based on artificial intelligence, using the aforementioned system for checking source code based on artificial intelligence, comprising: step A1, parsing the syntax structure features, logical behavior features and dependency relationship features of the target code to be checked; step A2, fusing the parsed syntax structure features, logical behavior features and dependency relationship features of the target code to obtain multi-modal fusion features of the target code; step A3, performing quality inspection of the multi-modal fusion features in the dimensions of standardization, security and business logic by combining a quality basis knowledge graph and an artificial intelligence-based code inspection model, to obtain a code quality inspection result; the quality basis knowledge graph is constructed according to existing code writing quality basis in the aspects of standardization, security and business logic.

[0074] The system and method for checking source code based on artificial intelligence improve the detection rate of security defects, greatly reduce the false positive rate, add the business standardization inspection capability, and the quality basis knowledge graph can be dynamically updated, thereby reducing the artificial maintenance cost of the traditional rule base and supporting code inspection of multiple types of programming languages (Java\HTML\JS\CSS). Splitting the parsing unit according to the parsing task and splitting the inspection unit according to the inspection task are conducive to the compatibility and expansion of the application, and improve the application range.

[0075] The above is only the preferred embodiment of the application, and does not limit the implementation and protection scope of the application. It should be realized by those skilled in the art that any equivalent replacement and obvious change made according to the content of the specification and drawings should be included in the protection scope of the application.

Claims

1. A system for inspecting source code based on artificial intelligence, characterized in that, include: The knowledge graph module is used to build a quality basis knowledge graph based on existing code writing quality criteria in the specification layer, security layer, and business logic layer. The code parsing module is used to parse out the syntactic structure features, logical behavior features, and dependency relationship features of the target code to be inspected; The feature fusion module, connected to the code parsing module, is used to fuse the syntactic structure features, logical behavior features, and dependency relationship features of the parsed target code to obtain the multimodal fusion features of the target code. The code inspection module, connected to the knowledge graph module and the feature fusion module respectively, is used to combine the AI-based code inspection model and the quality basis knowledge graph to perform quality checks on the multimodal fusion features in terms of standardization, security, and business logic dimensions to obtain code quality inspection results.

2. The system for inspecting source code based on artificial intelligence as described in claim 1, characterized in that, The system further includes: an intelligent scheduling module, used to analyze the basic characteristics of the target code and dynamically schedule code parsing resources based on the basic characteristics of the target code; a code parsing module, connected to the intelligent scheduling module, used to use the scheduled code parsing resources to parse the syntactic structure features, logical behavior features, and dependency relationship features of the target code; and a code inspection module, also connected to the intelligent scheduling module, used to filter the corresponding quality basis knowledge graph based on the basic characteristics of the target code, and combine the code inspection model and the filtered quality basis knowledge graph to perform quality checks on the multimodal fusion features in terms of standardization, security, and business logic dimensions to obtain the code quality inspection results.

3. The system for inspecting source code based on artificial intelligence as described in claim 2, characterized in that, The fundamental characteristics of the target code include the programming language type and code size; The intelligent scheduling module includes: a parser matching unit, used to match a corresponding code parser based on the programming language type of the target code; a resource allocation unit, used to enable a corresponding resource allocation mode for the code parsing module to use based on the code size of the target code, wherein the resource allocation mode is divided into single-threaded mode and distributed parsing pool mode; a code parsing module, used to use the matched code parser to parse the syntactic structure features, logical behavior features, and dependency relationship features of the target code to be inspected; and a code inspection module, used to filter out the quality basis knowledge graph that matches the programming language type of the target code.

4. The system for inspecting source code based on artificial intelligence as described in claim 3, characterized in that, The code parser includes a syntax parser, a dependency parser, and a logic parser; The code parsing module includes: a syntax parsing unit, used to use the syntax parser to parse the target code into syntax structure features; a dependency parsing unit, used to use the dependency parser to parse the dependency relationships of the target code based on the syntax structure features, and to parse the dependency relationship features of the target code; and a logic parsing unit, used to use the logic parser to perform logical behavior on the target code based on the syntax structure features and the dependency relationship features, and to parse the logical behavior features of the target code. The intelligent scheduling module further includes: a parsing coordination unit, used to: construct parsing task priorities according to the parsing order of syntax structure parsing, dependency relationship parsing, and logical behavior parsing; sequentially call the syntax parsing unit, the dependency parsing unit, and the logic parsing unit according to the parsing task priorities; and share the parsed syntax structure features, dependency relationship features, and logical behavior features with the syntax parsing unit, the dependency parsing unit, and the logic parsing unit in real time.

5. A system for inspecting source code based on artificial intelligence as described in claim 1, characterized in that, The feature fusion module includes: a structuring unit, used to perform structuring processing on the syntactic structure features, the dependency features, and the logical behavior features respectively; a feature encoding unit, connected to the structuring unit, used to perform feature encoding processing on the structuring syntactic structure features, the dependency features, and the logical behavior features; and a cross-modal association unit, connected to the feature encoding unit, used to construct a feature association matrix on the feature-encoded syntactic structure features, the dependency features, and the logical behavior features, and perform weight adjustment based on an attention mechanism, and then form and output the multimodal fusion feature.

6. The system for inspecting source code based on artificial intelligence as described in claim 1, characterized in that, The code inspection module includes: a standardization inspection unit, used to process the multimodal fusion features to perform standardization checks on the target code and obtain standardization inspection results; a security inspection unit, used to process the multimodal fusion features to perform security checks on the target code and obtain security inspection results; and a business logic inspection unit, used to process the multimodal fusion features to perform business logic checks on the target code and obtain business logic inspection results. The code quality inspection results include the standardization inspection results, the security inspection results, and the business logic inspection results.

7. The system for inspecting source code based on artificial intelligence as described in claim 1, characterized in that, The system further includes a quality assessment module, connected to the code inspection module, used to perform a quality assessment on the target code based on the code quality inspection results, and generate a quality assessment result, the quality assessment result including the distribution of quality defects and risk level of the target code.

8. A system for inspecting source code based on artificial intelligence as described in claim 1, characterized in that, The system also includes an intelligent repair recommendation module, which is connected to the code inspection module and is used to generate code repair schemes and refactoring path plans based on the code quality inspection results using an intelligent recommendation model formed by artificial intelligence.

9. A system for inspecting source code based on artificial intelligence as described in claim 8, characterized in that, The system also includes a repair scheme verification module, which is connected to the intelligent repair recommendation module and is used to verify the code repair scheme, obtain the repair scheme verification result, and output it.

10. A method for inspecting source code based on artificial intelligence, characterized in that, Using a system for inspecting source code based on artificial intelligence as described in any one of claims 1-8, the system includes: step A1, parsing the syntactic structure features, logical behavior features, and dependency relationship features of the target code to be inspected; step A2, fusing the parsed syntactic structure features, logical behavior features, and dependency relationship features of the target code to obtain a multimodal fusion feature of the target code; step A3, combining a quality basis knowledge graph and an artificial intelligence-based code inspection model to perform quality checks on the multimodal fusion feature in terms of standardization, security, and business logic dimensions to obtain a code quality inspection result; wherein the quality basis knowledge graph is constructed based on existing code writing quality standards at the standardization layer, security layer, and business logic layer.

Citation Information

Patent Citations

  • C program code standard checking device based on PRDL rule description language

    CN106970819A

  • Source code detection method

    CN119442240A

  • Log quality detection method and system, electronic equipment and storage medium

    CN120371823A

  • Large model enhanced code security detection method

    CN120372627A