Code checking method and device
By converting the code into a code topology map and utilizing large model queries, the problem of low efficiency of static code analysis tools in complex logic inspection is solved, and efficient and accurate code inspection is achieved.
Patent Information
- Application Number
- CN202410903278.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-05
- Publication Date
- 2024-08-23
AI Technical Summary
Existing static code analysis tools are inefficient and poor in versatility when checking complex logic. They require a large amount of development resources for hard-coded personalized development, resulting in missed detections and low code inspection efficiency.
Convert the code to be checked into a code topology map and store it in a graph database, use a large model to convert natural language query questions into a graph database query format, call the code topology map for query to determine the code inspection results, and improve the efficiency and versatility of code inspection sex.
Complex logic checks can be performed without additional development resources, which improves the accuracy and efficiency of code checks and can accurately reflect the relationships and dependencies between codes.
Smart Images

Figure CN118535482A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a code checking method and device. Background Art
[0002] Static code quality checking is a process of analyzing the source code or compiled code of computer software to find errors, vulnerabilities, style issues, and code that does not meet predetermined coding standards without actually executing the program. This checking is usually done automatically by static code analysis tools.
[0003] However, using static code analysis tools to check the code can only perform relatively simple checks on the complexity of code snippets, input parameter formats, etc. For checking the complex logic of the program context, the existing technology is usually completed through personalized development through hard coding, which consumes a lot of development resources and has poor versatility, resulting in low efficiency of code checking. Summary of the invention
[0004] In view of this, the embodiments of the present disclosure provide a code checking method, device, electronic device and storage medium, which can realize personalized checking of codes while saving development resources, thereby improving the efficiency and versatility of code checking.
[0005] In a first aspect, an embodiment of the present disclosure provides a code checking method, comprising:
[0006] Converting the code to be checked into a code topology graph, and storing the code topology graph in a graph database;
[0007] In response to receiving a first query question for the code to be checked, converting the first query question into a second query question in a target format; wherein the first query question is in a natural language format and the target format is a query format corresponding to the graph database;
[0008] Based on the second query question, the code topology graph in the graph database is called to perform a query to determine a code inspection result.
[0009] Optionally, the code to be checked is converted into a code topology diagram, including:
[0010] Based on the code to be checked, using a static code analysis tool, generating a code property graph corresponding to the code to be checked;
[0011] Extracting nodes and edges in the code attribute graph, and determining a network structure of the code attribute graph based on the nodes and edges; wherein the network structure indicates a connection relationship between each of the nodes;
[0012] The network structure is exported as a graph database file to obtain the code topology graph.
[0013] Optionally, in response to receiving a first query question for the code to be checked, converting the first query question into a second query question in a target format includes:
[0014] A pre-trained large model is used to convert a first query question in a natural language format into a second query question in a target format.
[0015] Optionally, based on the second query question, calling the code topology graph in the graph database for query includes:
[0016] Associating the code topology graph in the graph database with the large model;
[0017] The second query question is used as input data of the large model, so that the large model outputs a query result corresponding to the second query question based on the code topology graph.
[0018] Optionally, based on the second query question, calling the code topology graph in the graph database to query to determine the code inspection result includes:
[0019] If a query result corresponding to the second query question is returned based on the code topology map, the code check passes; otherwise, the code check fails.
[0020] Optionally, the method further comprises:
[0021] In response to the code check failing, a prompt message is generated; the prompt message indicates that a code segment in the to-be-checked code corresponding to the second query question is abnormal.
[0022] Optionally, before converting the code to be checked into a code topology map, the method further includes:
[0023] The code to be checked is obtained from a code library; the code library includes multiple groups of codes to be checked; wherein the code language types of the multiple groups of codes to be checked are different.
[0024] In a second aspect, an embodiment of the present disclosure provides a code checking device, including:
[0025] A code conversion module, used for converting the code to be checked into a code topology map, and storing the code topology map in a map database;
[0026] A question conversion module, configured to, in response to receiving a first query question for the code to be checked, convert the first query question into a second query question in a target format; wherein the first query question is in a natural language format, and the target format is a query format corresponding to the graph database;
[0027] The inspection module is used to call the code topology map in the graph database to query based on the second query question to determine the code inspection result.
[0028] In a third aspect, an embodiment of the present disclosure further provides an electronic device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the computer device is running, the processor and the memory communicate through the bus, and when the machine-readable instructions are executed by the processor, the steps in the above-mentioned first aspect, or any optional implementation of the first aspect are performed.
[0029] In a fourth aspect, an embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned first aspect, or any optional implementation of the first aspect are executed.
[0030] Any of the above aspects or any implementation methods of any of the aspects, by converting the code to be checked into a code topology map, and storing the code topology map in a graph database; in response to receiving a first query question for the code to be checked, converting the first query question into a second query question in a target format; wherein the first query question is in a natural language format, and the target format is a query format corresponding to the graph database; based on the second query question, calling the code topology map in the graph database for query to determine the code inspection result. In this way, any question in a natural language format can be converted into a question that can be recognized by a computer. When checking the complex logic of the code, there is no need to waste additional development resources. It is only necessary to directly input the question you want to query, thereby improving the versatility and efficiency of code inspection. In addition, the present invention checks the code based on the code topology map, and the code topology map can accurately reflect the relationship and dependency between the codes, that is, the embodiment of the present disclosure can also improve the accuracy of code inspection.
[0031] The effects of the above-mentioned code checking device, electronic device and storage medium refer to the description of the above-mentioned code checking method, which will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following is a brief introduction to the drawings required for use in the embodiments. The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can also be obtained based on these drawings without creative work.
[0033] Figure 1 A flowchart of a code checking method provided by an embodiment of the present disclosure is shown; Figure 2 A schematic diagram of a code topology diagram in a code checking method provided by an embodiment of the present disclosure is shown; Figure 3 A schematic diagram of a code property graph in a code checking method provided by an embodiment of the present disclosure is shown; Figure 4 A schematic diagram of the structure of a code checking method provided by an embodiment of the present disclosure is shown; Figure 5 A schematic diagram of a code checking device provided by an embodiment of the present disclosure is shown; Figure 6 An exemplary system architecture is shown in which embodiments of the present disclosure may be applied; Figure 7 A schematic diagram of the structure of a computer system of a terminal device or a server used to implement an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0034] In order to make the purpose, technical scheme and advantages of the embodiments of the present disclosure clearer, the technical scheme in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.
[0035] It should be noted that in the technical solution of the present invention, the collection, use, storage, sharing and transfer of user personal information involved are in compliance with the provisions of relevant laws and regulations, and it is necessary to inform the user and obtain the user's consent or authorization. When applicable, the user's personal information is de-identified and / or anonymized and / or encrypted.
[0036] Research has found that static code quality checking plays a vital role in software development. By analyzing the source code or compiled code of computer software, errors, vulnerabilities, style issues, and code that does not meet predetermined coding standards can be discovered early. Compared with traditional dynamic testing, static code analysis does not require actual program execution, so problems can be discovered early in the development process, saving time and cost. Static code checking is usually done automatically by static code analysis tools, which can quickly scan the entire code base and provide detailed reports to help developers find and fix problems in a timely manner.
[0037] However, although static code analysis tools perform well in checking simple problems, they still have certain limitations in checking complex logic in programs. Existing technologies can often only perform relatively simple checks on code snippets, such as complexity and input parameter format, but are unable to cope with the complex logic of the entire program context. To address this issue, existing technologies usually perform personalized development through hard coding to achieve the inspection of complex logic. This method requires a lot of development resources, and because this personalized development is only applicable to specific projects or programming languages, its versatility is low. In addition, as the complexity of the program continues to increase, this hard coding method is difficult to keep up with the evolution and update of the code, which leads to low efficiency of code inspection and may even result in missed inspections.
[0038] Based on the above research, the embodiment of the present disclosure provides a code checking method, which converts the code to be checked into a code topology map, and stores the code topology map in a graph database; in response to receiving a first query question for the code to be checked, converts the first query question into a second query question in a target format; wherein the first query question is in a natural language format, and the target format is a query format corresponding to the graph database; based on the second query question, the code topology map in the graph database is called for query to determine the code checking result. In this way, any question in a natural language format can be converted into a question that can be recognized by a computer. When checking the complex logic of the code, there is no need to waste additional development resources for personalized development. It is only necessary to directly input the question you want to query, which improves the versatility and efficiency of code checking. In addition, the present invention checks the code based on the code topology map, and the code topology map can accurately reflect the relationship and dependency between the codes, that is, the embodiment of the present disclosure can also improve the accuracy of code checking.
[0039] The raising of the above problems and the solutions are the results obtained by the inventor after practice and careful research. The discovery process of the above problems and the solutions proposed for the above problems should be the contributions made by the inventor to the present disclosure during the disclosure process.
[0040] The technical solutions in the present disclosure will be clearly and completely described below in conjunction with the drawings in the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure claimed for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.
[0041] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0042] To facilitate understanding of this embodiment, a code checking method disclosed in the embodiment of the present disclosure is first introduced in detail. The execution subject of the code checking method provided in the embodiment of the present disclosure is generally a computer device with certain computing capabilities, and the computer device includes, for example: a terminal device or a server or other processing device, and the terminal device can be a user equipment (User Equipment, UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (Personal Digital Assistant, PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. In some possible implementations, the code checking method can be implemented by a processor calling a computer-readable instruction stored in a memory.
[0043] See also Figure 1 FIG. 1 is a flowchart of a code checking method provided by an embodiment of the present disclosure, wherein the method includes S101 to S103, wherein:
[0044] S101: Convert the code to be checked into a code topology map, and store the code topology map in a map database.
[0045] Figure 2 A schematic diagram of a code topology diagram in a code checking method provided by an embodiment of the present disclosure. Figure 2 As shown in the figure, the code topology diagram is a graphical representation method that uses nodes and edges to represent the various parts of the code and the connection relationship between the various parts, thus forming a complete graphical structure. In the code topology diagram, a node usually represents an entity in the code, such as a file, module, class, or function, and an edge represents the association or dependency between these entities. In specific implementations, developers can intuitively understand the structure and organization of the code through the code topology diagram, which helps relevant personnel better understand the overall architecture of the code, quickly locate and understand the various parts of the code, and thus ensure the readability and maintainability of the code.
[0046] In one possible implementation, the code to be checked is converted into a code topology graph, including: based on the code to be checked, using a static code analysis tool to generate a code property graph corresponding to the code to be checked; extracting nodes and edges in the code property graph, and based on the nodes and edges, determining the network structure of the code property graph; wherein the network structure indicates the connection relationship of each of the nodes; and exporting the network structure as a graph database file to obtain the code topology graph.
[0047] Figure 3 A schematic diagram of a code attribute graph in a code checking method provided by an embodiment of the present disclosure. Figure 3As shown in Figure 1, the code attribute graph is used to display the various code entities in the code and the attributes and relationships between them. In the code attribute graph, nodes represent various entities in the code, and edges represent the attribute relationships or dependency relationships between these entities. Each node usually contains some attribute information, such as name, type, access rights, etc., while edges represent the association relationships between entities, such as function calls, variable references, etc.
[0048] In the specific implementation, the static code analysis tool can be used to convert the code to be checked into a code property graph (CPG), which may include an abstract syntax tree (AST), a control flow graph (CFG), a program flow graph (PFG), etc. Then the code property graph is exported as a corresponding code topology graph.
[0049] For example, when the sample code is as shown below, the corresponding code attribute diagram is as follows: Figure 3 The code flow chart is shown in Figure 1. Figure 3 The code attribute diagram shown in the figure includes the attributes and relationships between the following code entities. Figure 3 The code topology diagram derived from the code property diagram shown in the figure is as follows Figure 2 As shown, the overall structure and organization of the following code are included.
[0050] void foo() { int x = source(); if (x < MAX) { int y = 2 * x; sink(y); } }
[0051] In the disclosed embodiment, a code attribute graph can be first obtained based on the code to be checked, and then a corresponding code topology graph can be obtained based on the code attribute graph. In this way, the code attribute graph can abstractly represent the attributes and relationships of the code entities, and the code attribute graph can help filter out some unnecessary or redundant information and retain only key attributes and relationships, which can reduce the noise and interference in the generated code topology graph, thereby making the generated code topology graph clearer and more concise. In addition, in this way, when generating a code topology graph, customized processing can be performed based on the attributes and relationships in the code attribute graph, so that the generated topology graph is more in line with actual needs, making it more suitable for specific analysis and application scenarios.
[0052] In another possible implementation, a corresponding code topology map may be directly generated based on the code to be checked.
[0053] In the embodiment of the present disclosure, before converting the code to be checked into a code topology graph, it also includes: acquiring the code to be checked from a code library; the code library includes multiple groups of codes to be checked; wherein the code language types of the multiple groups of codes to be checked are different.
[0054] Specifically, Figure 4 A schematic diagram of a code checking method provided by an embodiment of the present disclosure. Figure 4 As shown, you can get the currently required code to be checked from the code library and then use Figure 4 The conversion module in converts it into a corresponding code topology map. In the disclosed embodiment, a plurality of groups of codes to be checked may be stored in the code library. When checking the code, the code may be obtained according to the current checking requirements, or the plurality of groups of codes to be checked in the code library may be checked simultaneously in parallel.
[0055] In the embodiment of the present disclosure, the generated code topology graph can be stored in the form of a graph database file such as Figure 4 In the graph database shown in Figure 1. Storing the code topology in this way can make it have higher query efficiency, support complex queries, and improve flexibility and scalability compared to other storage methods. In addition, this storage method matches the code structure and has better data integration capabilities.
[0056] S102: In response to receiving a first query question for the code to be checked, converting the first query question into a second query question in a target format; wherein the first query question is in a natural language format, and the target format is a query format corresponding to the graph database.
[0057] In this step, the target format can be any format that can be queried in the graph database. For example, the second query question in the target format can be a structured Cypher query statement, or a Gremlin graph traversal language, a SQL extension language, etc.
[0058] In a possible implementation, a pre-trained large model may be used to convert a first query question in a natural language format into a second query question in a target format.
[0059] In a specific implementation, taking the query problem in the target format as a structured Cypher query statement as an example, the large model can be trained in the following manner so that it has the ability to convert the first query problem in the natural language format into the second query problem in the target format. It should be noted that the following model training method is only used as an example of a possible implementation method of the embodiment of the present disclosure. In actual applications, the training method can be adjusted according to needs, and the embodiment of the present disclosure does not specifically limit this.
[0060] Step 1: Collect a dataset containing natural language questions and corresponding Cypher query statements. Make sure the questions in the dataset cover a variety of query scenarios and semantic expressions. And preprocess the collected data, including word segmentation, stemming, and removing stop words. Make sure the format of the input natural language questions and Cypher query statements is standardized to facilitate model learning and processing.
[0061] Step 2: Use the above dataset to train the large model. During the training process, the large model learns to map natural language questions to corresponding Cypher query statements. Specifically, supervised, semi-supervised or unsupervised learning methods can be used for training.
[0062] Step 3: During the training process, you can use evaluation metrics to evaluate the similarity between the query sentences generated by the model and the standard answers. Based on the evaluation results, you can fine-tune the model to improve its performance and generalization ability.
[0063] In another possible implementation, a mapping table between the first query question and the second query question may be pre-created, and when the first query question in a natural language format is received, the second query question in a target format may be determined based on the mapping table. Specifically, the first query question and the second query question may be in a one-to-one relationship or a many-to-one relationship in the mapping table.
[0064] Exemplarily, still taking the second query question in the target format as a Cypher query statement as an example, the correspondence between the first query question in the natural language format and the second query question in the target format may be shown in the following table:
[0065]
[0066] S103: Based on the second query question, call the code topology graph in the graph database to query to determine the code inspection result.
[0067] In this step, after obtaining the second query question that can be used to query the code topology map, the code inspection result can be obtained based on the question.
[0068] In one possible implementation, this step can be completed using a pre-trained big model. Specifically, based on the second query question, the code topology map in the graph database is called for query, including: associating the code topology map in the graph database with the big model; using the second query question as input data for the big model, so that the big model outputs a query result corresponding to the second query question based on the code topology map.
[0069] In the specific implementation, Figure 4 As shown, the graph database can be associated with the big model through the language chain, and the node type, node attribute, relationship type and other information in the graph database can be uploaded to the big model. Once the big model can understand and process the structure, attributes and relationship represented by the code topology diagram in the graph database. In addition, the code topology diagram in the graph database and the node type and other information therein can be directly uploaded to the big model, which can also realize the process of completing the code inspection using the pre-trained big model.
[0070] Exemplarily, uploading information such as node types, node attributes, and relationship types in the graph database to the big model can be completed based on the method shown in the following table:
[0071]
[0072] Among them, node attributes are code attribute graphs generated through previous static code analysis. These elements are usually part of the code's abstract syntax tree (AST) or control flow graph (CFG). For example, CONTROL_STRUCTURE identifies the control structure in the code, such as loops (for, while), conditionals (if, switch), etc. FIELD_IDENTIFIER usually refers to the field identified in the code (such as a variable in a class or structure). The relationship type identifies the relationship between two nodes. For example, two methods have a calling relationship, and the identifier in the topology graph is a CALL type edge.
[0073] In another possible implementation, this step can also be achieved by directly establishing an association between the graph database and the query interface without relying on a large model.
[0074] In an embodiment of the present disclosure, based on the second query question, the code topology map in the graph database is called for query to determine the code inspection result, including: if the query result corresponding to the second query question is returned based on the code topology map, the code inspection passes; otherwise, the code inspection fails.
[0075] In the specific implementation, whether the code is checked using the big model or by directly calling the query interface, if the graph database returns the query result corresponding to the second query question based on the code topology graph, it can be confirmed that there is no problem with the code corresponding to the question; conversely, if no result is returned, it can be determined that the code corresponding to the question is abnormal. In addition, the big model can also be instructed to output a check success or check failure flag to determine whether the code corresponding to the query question is abnormal.
[0076] In an embodiment of the present disclosure, the method further includes: in response to the code check failing, generating prompt information; the prompt information indicates that a code segment in the to-be-checked code corresponding to the second query question is abnormal.
[0077] In a specific implementation, if the code check fails, a corresponding prompt message may be generated, which may include the query problem, the corresponding abnormal code snippet, the time when the abnormality was detected, etc. In a preferred implementation, the abnormal code snippet may also be parsed, and the cause of the abnormality may be added to the prompt message, which helps developers to intuitively understand the health of the code and modify it in time.
[0078] According to a second aspect of the embodiment of the present disclosure, Figure 5 As shown, a code checking device 500 is provided, comprising:
[0079] A code conversion module 501, used to convert the code to be checked into a code topology map, and store the code topology map in a map database;
[0080] A question conversion module 502 is used for, in response to receiving a first query question for the code to be checked, converting the first query question into a second query question in a target format; wherein the first query question is in a natural language format, and the target format is a query format corresponding to the graph database;
[0081] The checking module 503 is used to call the code topology graph in the graph database to perform a query based on the second query question to determine a code checking result.
[0082] Optionally, the code conversion module 501 is specifically used for:
[0083] Based on the code to be checked, using a static code analysis tool, generating a code property graph corresponding to the code to be checked;
[0084] Extracting nodes and edges in the code attribute graph, and determining a network structure of the code attribute graph based on the nodes and edges; wherein the network structure indicates a connection relationship between each of the nodes;
[0085] The network structure is exported as a graph database file to obtain the code topology graph.
[0086] Optionally, the question conversion module 502 is specifically used for:
[0087] A pre-trained large model is used to convert a first query question in a natural language format into a second query question in a target format.
[0088] Optionally, the query module 503 is specifically used for:
[0089] Associating the code topology graph in the graph database with the large model;
[0090] The second query question is used as input data of the large model, so that the large model outputs a query result corresponding to the second query question based on the code topology graph.
[0091] Optionally, the query module 503 is specifically used for:
[0092] If a query result corresponding to the second query question is returned based on the code topology map, the code check passes; otherwise, the code check fails.
[0093] Optionally, the query module 503 is specifically used for:
[0094] In response to the code check failing, a prompt message is generated; the prompt message indicates that a code segment in the to-be-checked code corresponding to the second query question is abnormal.
[0095] Optionally, the code conversion module 501 is further used for:
[0096] The code to be checked is obtained from a code library; the code library includes multiple groups of codes to be checked; wherein the code language types of the multiple groups of codes to be checked are different.
[0097] According to a third aspect of an embodiment of the present disclosure, a code checking electronic device is provided, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method provided by the first aspect of the embodiment of the present invention.
[0098] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method provided by the first aspect of the embodiment of the present disclosure is implemented.
[0099] Figure 6 An exemplary system architecture 600 to which the code checking method or code checking apparatus implemented by the present disclosure can be applied is shown.
[0100] like Figure 6 As shown, system architecture 600 may include terminal devices 601, 602, 603, network 604 and server 605. Network 604 is used to provide a medium for communication links between terminal devices 601, 602, 603 and server 605. Network 604 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0101] The user can use the terminal devices 601, 602, 603 to interact with the server 605 through the network 604 to receive or send messages, etc. Various communication client applications can be installed on the terminal devices 601, 602, 603, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only for example).
[0102] The terminal devices 601 , 602 , and 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.
[0103] The server 605 may be a server that provides various services, such as a background management server (only as an example) that provides support for shopping websites browsed by users using the terminal devices 601, 602, and 603. The background management server may process the received code check request and feed back the processing result (only as an example) to the terminal device.
[0104] It should be noted that the code checking method provided in the embodiment of the present invention is generally executed by the server 605, and accordingly, the code checking device is generally set in the server 605. The code checking method provided in the embodiment of the present invention can also be executed by the terminal devices 601, 602, and 603, and accordingly, the code checking device can be set in the terminal devices 601, 602, and 603.
[0105] It should be understood that Figure 6 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0106] Reference below Figure 7 , which shows a schematic diagram of the structure of a computer system 700 of a terminal device suitable for implementing an embodiment of the present invention. Figure 7 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0107] like Figure 7As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other through a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0108] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage section 708 as needed.
[0109] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 709, and / or installed from the removable medium 711. When the computer program is executed by the central processing unit (CPU) 701, the above-mentioned functions defined in the system of the present invention are executed.
[0110] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0111] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0112] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor. For example, a processor includes a code conversion module, a problem conversion module, and a check module, wherein the names of these modules do not constitute a limitation on the modules themselves in certain cases. For example, the code conversion module may also be described as a "module for converting the code to be checked into a code topology map and storing the code topology map in a graph database".
[0113] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device implements the following method: converting the code to be checked into a code topology map, and storing the code topology map in a map database;
[0114] In response to receiving a first query question for the code to be checked, converting the first query question into a second query question in a target format; wherein the first query question is in a natural language format and the target format is a query format corresponding to the graph database;
[0115] Based on the second query question, the code topology graph in the graph database is called to perform a query to determine a code inspection result.
[0116] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure shall be based on the protection scope of the claims.
Claims
1. A code checking method, characterized in that: include: Converting the code to be checked into a code topology graph, and storing the code topology graph in a graph database; In response to receiving a first query question for the code to be checked, converting the first query question into a second query question in a target format; wherein the first query question is in a natural language format and the target format is a query format corresponding to the graph database; Based on the second query question, the code topology graph in the graph database is called to perform a query to determine a code inspection result.
2. The method according to claim 1, characterized in that Convert the code to be checked into a code topology diagram, including: Based on the code to be checked, using a static code analysis tool, generating a code property graph corresponding to the code to be checked; Extracting nodes and edges in the code attribute graph, and determining a network structure of the code attribute graph based on the nodes and edges; wherein the network structure indicates a connection relationship between each of the nodes; The network structure is exported as a graph database file to obtain the code topology graph.
3. The method according to claim 1, characterized in that In response to receiving a first query question for the code to be checked, converting the first query question into a second query question in a target format includes: A pre-trained large model is used to convert a first query question in a natural language format into a second query question in a target format.
4. The method according to claim 3, characterized in that Based on the second query question, calling the code topology graph in the graph database to perform a query includes: Associating the code topology graph in the graph database with the large model; The second query question is used as input data of the large model, so that the large model outputs a query result corresponding to the second query question based on the code topology graph.
5. The method according to claim 1, characterized in that Based on the second query question, calling the code topology graph in the graph database to query to determine the code inspection result includes: If a query result corresponding to the second query question is returned based on the code topology map, the code check passes; otherwise, the code check fails.
6. The method according to claim 5, characterized in that The method further comprises: In response to the code check failing, a prompt message is generated; the prompt message indicates that a code segment in the to-be-checked code corresponding to the second query question is abnormal.
7. The method according to claim 1, characterized in that Before converting the code to be checked into a code topology diagram, it also includes: The code to be checked is obtained from a code library; the code library includes multiple groups of codes to be checked; wherein the code language types of the multiple groups of codes to be checked are different.
8. A code checking device, characterized in that: include: A code conversion module, used for converting the code to be checked into a code topology map, and storing the code topology map in a map database; A question conversion module, configured to, in response to receiving a first query question for the code to be checked, convert the first query question into a second query question in a target format; wherein the first query question is in a natural language format, and the target format is a query format corresponding to the graph database; The inspection module is used to call the code topology map in the graph database to query based on the second query question to determine the code inspection result.
9. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.
10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Method and apparatus for acquiring data by means of graph traversal query, and computer device
WO2026044509A1
