Code equivalent comparison method and device, computer equipment and storage medium

By constructing an abstract syntax tree and combining it with a large language model, the problem of the existing technology's inability to deeply understand code semantics and evaluate code equivalence in real time is solved, and efficient and accurate code equivalence calculation is achieved.

CN120763025APending Publication Date: 2025-10-10SHANGHAI JIEYIN E-COMMERCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510726509.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-30
Publication Date
2025-10-10

AI Technical Summary

Technical Problem

Existing technologies are unable to deeply understand code semantics, cannot evaluate code equivalence in real time, and have difficulty adapting to the automation needs of multiple scenarios, resulting in low calculation accuracy and efficiency.

Method used

By constructing an abstract syntax tree and combining it with a large language model, code features are obtained, code similarity is calculated, and automatic evaluation of code equivalence is achieved.

Benefits of technology

It improves the accuracy and efficiency of code equivalent calculation, reduces the workload and errors of manual statistics, and can adapt to real-time evaluation of multiple scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120763025A_ABST
    Figure CN120763025A_ABST
Patent Text Reader

Abstract

The invention is applicable to the technical field of artificial intelligence, and particularly relates to a code equivalent comparison method and device, computer equipment and a storage medium, the method comprises the following steps: constructing a first abstract syntax tree based on first code information belonging to the same code control group in an obtained code submission record, and constructing a second abstract syntax tree based on second code information; obtaining a first code feature corresponding to the first abstract syntax tree and a second code feature corresponding to the second abstract syntax tree through a preset large language model; determining the code similarity between the first code feature and the second code feature in the same code control group; and determining a code equivalent comparison result of the target system based on the code similarity of each code control group. According to the method, code equivalent calculation is performed on code records submitted by research and development personnel each time through a method of combining the abstract syntax tree and the large model, and the accuracy and efficiency of code equivalent calculation performed on systems researched and developed in the fields of smart finance, smart medical treatment and the like are remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of development assistance technology, and in particular to a code equivalence comparison method, device, computer equipment and storage medium. Background Art

[0002] In software development management, code equivalent is a core metric for measuring development workload. Traditional methods for calculating code equivalent rely primarily on lines of code (LOC) statistics, function point analysis (FPA), or static code analysis tools. However, these methods have significant limitations. Line of code statistics focus solely on physical lines of code, ignoring the semantic complexity of the code (such as the logical complexity caused by algorithm optimization). Function point analysis relies on manually defined functional modules, which is highly subjective and difficult to adapt to dynamic development needs. Static tools focus on code quality testing and cannot quantify development workload.

[0003] Furthermore, existing methods often suffer from lags, requiring manual intervention or post-development statistics, and failing to provide real-time feedback on the value of each submission. Furthermore, rules must be customized for different programming languages ​​or frameworks, resulting in high maintenance costs. These issues hinder the accuracy, real-time nature, and versatility of traditional methods, making them incapable of meeting the demands of modern agile development. An automated solution is urgently needed that can deeply understand code semantics, conduct real-time evaluation, and adapt to multiple scenarios. Summary of the Invention

[0004] Embodiments of the present invention provide a code equivalence comparison method, apparatus, computer device, and storage medium to address the limitations of existing code equivalence calculation methods, such as the inability to understand code semantics, real-time evaluation, and automation requirements for multiple scenarios, resulting in low accuracy and efficiency in code equivalence calculation.

[0005] A code equivalence comparison method, comprising: Obtain code submission records for the target system; the code submission records include at least one code control group; each code control group includes a first code information and a second code information; the second code information refers to a code record whose code submission time is before and adjacent to the first code information; Constructing a first abstract syntax tree based on the first code information, and constructing a second abstract syntax tree based on the second code information; Obtaining a first code feature corresponding to the first abstract syntax tree and a second code feature corresponding to the second abstract syntax tree through a preset large language model; determining a code similarity between the first code feature and the second code feature in the same code control group; A code equivalence comparison result of the target system is determined based on the code similarity of each of the code control groups.

[0006] A code equivalence comparison device, comprising: A record acquisition module is configured to acquire code submission records of a target system; the code submission records include at least one code control group; each code control group includes a first code information and a second code information; the second code information refers to a code record whose code submission time is before and adjacent to the first code information; a syntax tree construction module, configured to construct a first abstract syntax tree based on the first code information, and to construct a second abstract syntax tree based on the second code information; a feature extraction module, configured to obtain a first code feature corresponding to the first abstract syntax tree and a second code feature corresponding to the second abstract syntax tree through a preset large language model; a similarity calculation module, configured to determine the code similarity between the first code feature and the second code feature in the same code control group; A code equivalent determination module is configured to determine a code equivalent comparison result of the target system based on the code similarity of each of the code control groups.

[0007] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the above-mentioned code equivalence comparison method is implemented.

[0008] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the code equivalence comparison method is implemented.

[0009] The aforementioned code equivalence comparison method, apparatus, computer device, and storage medium utilize a combination of an abstract syntax tree (AST) and a large model. The AST simplifies the amount of code submitted for each version, eliminating the need for the large model to analyze all code in the entire code file, reducing analysis time and improving the efficiency of code equivalence calculations. Furthermore, the large model provides a deep understanding of the code's structure and semantics, enabling more accurate assessments of code complexity and functional modules, effectively reducing the workload and errors associated with manual statistical analysis. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0011] Figure 1 1 is a schematic diagram of an application environment of a code equivalence comparison method according to an embodiment of the present invention; Figure 2 is a flow chart of a code equivalence comparison method according to an embodiment of the present invention; Figure 3 is a principle block diagram of a code equivalent comparison device in one embodiment of the present invention; Figure 4 FIG. 1 is a schematic diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0012] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.

[0013] The code equivalent comparison method provided by the embodiment of the present invention can be applied as follows: Figure 1 Specifically, the code equivalent comparison method is applied in a code equivalent comparison system, which includes the following: Figure 1 The client and server shown communicate over a network, and a service connection is established between the server and the smart cabinet. This addresses the limitations of existing code equivalent calculation methods, such as their inability to understand code semantics, meet real-time evaluation requirements, and meet multi-scenario automation requirements, resulting in low accuracy and efficiency in code equivalent calculations. The client, also known as the user end, refers to the program that corresponds to the server and provides local services to clients. The client can be installed on, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. The server can be implemented as a standalone server or a server cluster consisting of multiple servers. The server can be a standalone server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.

[0014] In one embodiment, if Figure 2 As shown, a code equivalent comparison method is provided, which is applied in Figure 1 The server in the example is used as an example, and the steps are as follows: S10: Obtain the code submission record of the target system; It is understood that the target system can be any developed software, system, or platform. For example, in the field of smart healthcare, the target system can be a smart medical guidance system, an intelligent medical Q&A system, or an intelligent registration and queuing system developed by R&D personnel. In the field of smart finance, the target system can be an insurance recommendation system, an insurance participation testing system, a card system, etc. developed by R&D personnel.

[0015] Furthermore, in the process of developing the target system, R&D personnel will develop multiple different versions, or iterative updates between versions. In each running version, developers will save the code of the current running version. The code files submitted by R&D personnel at different times under different running versions are code submission records. Code equivalence is used to measure the workload of R&D personnel in the new version of the code compared to the old version of the code. Therefore, two code records submitted at adjacent time points are often used as a group of code control groups to measure the software development workload of R&D personnel by comparing code files submitted at different time points. A code control group includes a first code information and a second code information; the second code information refers to a code record whose code submission time is before the first code information and is adjacent to the first code information. Among them, the code record contains relevant information such as the code file submitted by the R&D personnel this time, submission time, submitter, number of code lines, etc.

[0016] For example, the R&D personnel submitted a total of four code files for the target system. These four code files are regarded as four code records, and they are recorded as the first record, the second record, the third record and the fourth record in sequence. Among them, the time of the first record is 2024.07.01, the time of the second record is 2024.12.25, the time of the third record is 2025.2.26, and the time of the fourth record is 2025.5.21. In this way, three code control groups can be constructed based on the above four code records. In the first code control group, the second record is the first code information. The code submission time of the first record is before the second record and is adjacent to the second record. Therefore, the first record is the second code information corresponding to the second record in the first code control group. Similarly, the first code information in the second code control group is the third record, and the second code information is the second record; the first code information in the third code control group is the fourth record, and the second code information is the third record.

[0017] S20: Construct a first abstract syntax tree based on the first code information, and construct a second abstract syntax tree based on the second code information.

[0018] It can be understood that the first and second abstract syntax trees are tree representations of the abstract syntax structure of the code files submitted by the developers. In the first and second abstract syntax trees, there is a root node, several intermediate nodes, and one or more leaf nodes (there are no other nodes after the leaf nodes). That is, starting from the root node, one or more link paths can be obtained by spreading all nodes in the hierarchy of link relationships. These link paths are composed of: (1) root node-intermediate node-leaf node; (2) root node-leaf node.

[0019] Specifically, after obtaining the first code information and the second code information, the code files in the first code information are traversed, with the main function in the main function file of the code file in the first code information as the root node, the subsequent functions are traversed in sequence, and after generating a number of links, a first abstract syntax tree corresponding to the first code information is constructed. Similarly, the code files in the second code information are traversed, with the main function in the main function file of the code file in the second code information as the root node, the subsequent functions are traversed in sequence, and after generating a number of links, a second abstract syntax tree corresponding to the second code information is constructed.

[0020] S30: Obtaining a first code feature corresponding to the first abstract syntax tree and a second code feature corresponding to the second abstract syntax tree through a preset large language model.

[0021] It is understandable that the first code feature and the second code feature are features related to code equivalence calculation, such as: code complexity, code functional modules, etc. The preset large language model can be a pre-trained large model CodeBERT. After pre-training, the preset large language model has the ability to extract features related to code equivalence in the abstract syntax tree. In this way, after giving the preset large language model a certain prompt text, the preset large language model can parse according to the input abstract syntax tree and extract code features related to code equivalence calculation that meet the requirements.

[0022] S40: Determine the code similarity between the first code feature and the second code feature in the same code control group.

[0023] It can be understood that code similarity is used to measure the repetition rate between the first code information and the second code information. For example, if the existing code line number statistical method, static code analysis tool, etc. are used to evaluate the workload of R&D personnel, what they often care about is the comparison of the number of code lines, or the comparison of code changes. However, if a R&D personnel deletes 3862 lines of code in the new version and then re-adds 3862 lines of code, but the operation does not change or affect the code itself (such as only changing the order of the nodes corresponding to a certain function under its parent node, and the node itself has not been modified), then according to the method of the prior art, it will calculate this part of the workload. Therefore, by comparing the similarity between the first code feature and the second code feature, the difference between the first code information and the second code information can be better calculated, and whether the difference between each functional module has an impact on the code itself can be measured, thereby improving the accuracy of the code equivalent calculation.

[0024] S50: Determine a code equivalent comparison result of the target system based on the code similarity of each of the code control groups.

[0025] Specifically, after calculating the code similarity of all currently submitted code control groups, the workload of the R&D personnel between each new and old version can be determined. In this way, the code equivalence comparison results of the R&D personnel between each version can be determined based on the code similarity of each code control group. Finally, the R&D workload and work quality of the R&D personnel during the R&D cycle of the target system can be determined through the code equivalence comparison results between all versions. Furthermore, after determining the code equivalence comparison results between different versions each time, the code equivalence comparison results can be displayed and stored in a visual manner.

[0026] Furthermore, a code equivalence threshold can be pre-set based on specific application scenarios, and the code similarity and the code equivalence threshold can be compared. If the code similarity is greater than the code equivalence threshold, it is determined that the first code information and the second code information have a high degree of overlap and a low degree of distinction, which indicates that the workload of the R&D personnel between the two versions is small, and the substantive changes or updates to the code are small. If the code similarity is less than the code equivalence threshold, it is determined that the overlap between the first code information and the second code information is small, and the degree of distinction is large, which indicates that the workload of the R&D personnel between the two versions is large, and the substantive changes or updates to the code are large.

[0027] Furthermore, this embodiment incorporates a logging module that records exceptions that occur at each step. Preconfigured exception handling logic enhances system stability and reliability, preventing the entire system from crashing due to a single step failure. Detailed error logs facilitate rapid problem location and repair, enhancing the user experience. By skipping failed steps, the system optimizes resource utilization and improves operational efficiency.

[0028] In this embodiment, by combining an abstract syntax tree with a large model, the abstract syntax tree simplifies the amount of code submitted for each version, eliminating the need for the large model to analyze all code in the entire code file. This reduces analysis time and improves the efficiency of code equivalent calculations. Furthermore, the large model can deeply understand the structure and semantics of the code, allowing for more accurate assessment of code complexity and functional modules, effectively reducing the workload and errors of manual statistics.

[0029] In a specific application scenario, such as in smart finance, researchers develop an insurance recommendation system that recommends suitable insurance types or products based on recorded user basic information and demand information. The code equivalence comparison method proposed in this paper can be used to evaluate different versions of the insurance recommendation system submitted by researchers during the development cycle. This method assesses the newly added or modified functional modules between each version, thereby evaluating the workload and code quality of the researchers in each version.

[0030] In another specific application scenario, for example, in the field of smart healthcare, researchers develop a smart medical guidance system that recommends appropriate departments based on recorded user basic information and needs. The code equivalence comparison method proposed in this invention can be used to evaluate different versions of the smart medical guidance system submitted by researchers during the development cycle. This method assesses the newly added or modified functional modules between each version, thereby evaluating the workload and code quality of the researchers in each different version.

[0031] In one embodiment, step S20, i.e., constructing a first abstract syntax tree based on the first code information and constructing a second abstract syntax tree based on the second code information, includes: Code preprocessing is performed on the first code information and the second code information to obtain first preprocessing information corresponding to the first code information and second preprocessing information corresponding to the second code information.

[0032] It is understood that code preprocessing includes removing non-code content such as code comments, code spaces, and code blank lines, and converting the code into a unified format to facilitate the subsequent construction of a syntax tree. Furthermore, after code preprocessing the first code information and the second code information, the first preprocessed information and the second preprocessed information obtained only contain code content, and the code content is sorted in the order of main function and functional function module.

[0033] A first basic syntax tree is constructed based on the first preprocessing information, and a second basic syntax tree is constructed based on the second preprocessing information.

[0034] It can be understood that after obtaining the first preprocessing information, the main function corresponding to the first preprocessing information can be used as the root node of the preset syntax tree, and then each limited functional function can be traversed and queried based on the main function, and the functional function can be inserted into other nodes of the preset syntax tree except the root node to complete the construction of the first basic syntax tree. Similarly, after obtaining the second preprocessing information, the main function corresponding to the second preprocessing information can be used as the root node of the preset syntax tree, and then each limited functional function can be traversed and queried based on the main function, and the functional function can be inserted into other nodes of the preset syntax tree except the root node to complete the construction of the second basic syntax tree.

[0035] The first basic syntax tree is converted into an embedded graph representation to obtain a first embedded syntax tree, and the second basic syntax tree is converted into an embedded graph representation to obtain a second embedded syntax tree.

[0036] It can be understood that the embedded graph representation conversion step in this embodiment includes two steps: embedding node-level representation conversion of the first basic syntax tree / the second basic syntax tree and graph neural network modeling. Among them, the node-level representation conversion is used to convert the code on each node in the first basic syntax tree / the second basic syntax tree into a dense vector. Graph neural network modeling is used to capture the hierarchical relationship and cross-layer interaction between syntax trees to detect whether the hierarchical relationship between nodes in the constructed syntax tree is correct. When there are nodes with incorrect hierarchical relationships, these nodes are adjusted to construct a correct syntax tree.

[0037] The first embedded syntax tree is lightweight processed to obtain the first abstract syntax tree, and the second embedded syntax tree is lightweight processed to obtain the second abstract syntax tree.

[0038] Specifically, the lightweight processing is a method for reducing redundant information of the first embedded syntax tree and reducing resource occupancy when subsequently input to the preset large language model. The lightweight processing includes but is not limited to pruning, asynchronous pipeline processing, and lightweight compression protocol, etc. Among them, the pruning method of the embodiment is to set a filtering rule for automatically removing redundant tree nodes, for example, if the tree node is a constant number, then truncate the child nodes under the expression chain with no side effect in the tree node. The asynchronous pipeline processing method of the embodiment is to concurrently execute the parsing of the first embedded syntax tree or the second embedded syntax tree (corresponding to the code preprocessing step described above), feature extraction (feature extraction step throughout the entire process), and model inference disassembly (corresponding to the step of extracting the first code feature and the second code feature by the preset large language model) as three independent processes. The lightweight compression protocol of the embodiment is to change the storage part of the first embedded syntax tree or the second embedded syntax tree through differential encoding, so that it is serialized into a more compact format, reducing redundancy.

[0039] In an embodiment, the embedding graph representation conversion of the first base syntax tree obtains a first embedded syntax tree, including: A preset encoder is obtained, and each tree node in the first base syntax tree is converted into a vector by the preset encoder, and the first base syntax tree after vector conversion is recorded as a first encoded syntax tree.

[0040] Understandably, the preset encoder is used to convert each tree node (such as function call, variable declaration, control flow structure, etc.) in the first base syntax tree into a vector, so as to convert each tree node into a dense vector. The preset encoder can fuse multi-modal information, including but not limited to node type, name, attribute value, context dependency relationship (parent / child node path, sibling node order); dynamic execution characteristics (if combined with runtime analysis, it contains variable scope, parameter passing mode). The preset encoder can be pre-constructed, and then each tree node in the first base syntax tree is converted into a vector by the preset encoder, and the first base syntax tree after vector conversion is recorded as a first encoded syntax tree. Similarly, each tree node in the second base syntax tree is converted into a vector by the preset encoder, and the second base syntax tree after vector conversion is recorded as a second encoded syntax tree.

[0041] The first encoded syntax tree is input into a preset neural network model, so as to detect the hierarchical relationship of the first encoded syntax tree by the preset neural network model, and output the first embedded syntax tree.

[0042] It can be understood that the preset neural network is a graph neural network, which is used to capture the hierarchical relationship between each tree node in the first coding syntax tree, and determine whether the hierarchical order between the root node and each tree node in the first coding syntax tree is correct based on the captured hierarchical relationship and the relationship between the function modules in the code file in the originally obtained first code information. If not, the hierarchical relationship of the tree nodes in the first coding syntax tree is readjusted based on the relationship between the function modules in the code file in the first code information, and the first embedded syntax tree is output after the adjustment is completed. If correct, the first coding syntax tree is directly determined as the first embedded syntax tree.

[0043] Similarly, the hierarchical relationship between each tree node in the second encoding syntax tree is captured through a preset neural network. Based on the captured hierarchical relationship and the relationship between the functional modules in the code file in the originally obtained second code information, it is determined whether the hierarchical ordering between the root node and each tree node in the second encoding syntax tree is correct. If not, the hierarchical relationship of the tree nodes in the second encoding syntax tree is readjusted based on the relationship between the functional modules in the code file in the second code information, and after the adjustment is completed, the second embedded syntax tree is output. If correct, the second encoding syntax tree is directly determined as the second embedded syntax tree.

[0044] In one embodiment, obtaining the first code feature corresponding to the first abstract syntax tree and the second code feature corresponding to the second abstract syntax tree by using a preset large language model includes: A preset prompt text is obtained, and the preset prompt text, the first abstract syntax tree, and the second abstract syntax tree are input into the preset large language model.

[0045] It can be understood that the preset prompt text is used to prompt the preset large language model to extract features from the first abstract syntax tree and the second abstract syntax tree to output the first code feature and the second code feature.

[0046] The preset prompt text is converted into a prompt text vector through the preset large language model, and all first key-value pairs corresponding to the first abstract syntax tree and all second key-value pairs corresponding to the second abstract syntax tree are determined.

[0047] Specifically, after the preset prompt text, the first abstract syntax tree, and the second abstract syntax tree are input into the preset large language model, the preset prompt text is converted into a prompt text vector by the preset large language model. At the same time, all first key-value pairs corresponding to the first abstract syntax tree and all second key-value pairs corresponding to the second abstract syntax tree are determined by the preset large language model. The essence of the first key-value pairs and the second key-value pairs refers to the code function module represented by the root node and the tree node in the first abstract syntax tree or the second abstract syntax tree. The root node or the tree node serves as the key of the index, and the code function module serves as the value of the index.

[0048] outputting, by the preset large language model, the first code feature based on the prompt text vector and the first key-value pair, and outputting the second code feature based on the prompt text vector and the second key-value pair.

[0049] Specifically, the preset large language model has a hybrid attention mechanism to input the prompt text vector as one of the sequences, input the first abstract syntax tree / second abstract syntax tree as the other sequence, and use the prompt text vector to distinguish different structural positions in the first abstract syntax tree / second abstract syntax tree (such as conditional branches in the loop body, function headers, etc.).

[0050] As can be known from the above description, the preset large language model prompts the mutual guidance between the prompt text vector and the first key-value pair or the second key-value pair. Thus, the preset large language model can accurately locate the root node or tree node of each different function module in the first abstract syntax tree according to the prompt text vector, thereby identifying the specific code instance in the root node or tree node of the first abstract syntax tree and outputting the first code feature. Or, the preset large language model can accurately locate the root node or tree node of each different function module in the first abstract syntax tree according to the prompt text vector, thereby identifying the specific code instance in the root node or tree node of the second abstract syntax tree and outputting the second code feature.

[0051] In an embodiment, in step S40, determining the code similarity between the first code feature and the second code feature in the same code control group comprises: determining a basic similarity according to the first code feature and the second code feature.

[0052] Specifically, after outputting the first code feature and the second code feature by the preset large language model, the basic similarity between the first code feature and the second code feature can be calculated by the cosine similarity function. Understandably, the basic similarity is used to measure the similarity between all features related to the code equivalent calculation between the first code information and the second code information.

[0053] performing key node feature extraction on the first code feature and the second code feature to obtain all first key features in the first code feature and all second key features in the second code feature.

[0054] It can be understood that key nodes refer to related nodes such as loop logic and exception handling modules in the first code feature and the second code feature. The difference in key nodes can better measure the workload of R&D personnel on these important modules. Therefore, it is necessary to calculate the local similarity separately for the features corresponding to the key nodes. Furthermore, since the first code feature and the second code feature reflect the features related to the code equivalent calculation, and these features can be obtained by querying the tree nodes on the corresponding first abstract syntax tree and the second abstract syntax tree. In this way, the key nodes can be quickly located, and the first key feature can be extracted from the first code feature and the second key feature can be extracted from the second code feature based on the information of the key node. Furthermore, the extracted first key feature and the second key feature can each contain multiple, and the first key feature and the second key feature may be in a one-to-one correspondence. For example, if the R&D personnel add a new functional module to the new version, the first key feature in the first code information of the new version does not have a corresponding second key feature. At this time, the new functional module will not be included in the calculation of the subsequent feature correction coefficient.

[0055] A feature correction factor is determined based on the first key feature and the second key feature.

[0056] It can be understood that the feature correction coefficient is a coefficient that gives higher weight to the first key feature and the second key feature mentioned above.

[0057] The code similarity is determined according to the basic similarity and the feature correction coefficient.

[0058] Specifically, after determining the feature correction coefficient based on the first key feature and the second key feature, the sum of the basic similarity and the feature correction coefficient is determined as the code similarity.

[0059] In one embodiment, determining a feature correction coefficient based on the first key feature and the second key feature includes: All of the first key features and all of the second key features are grouped to determine a key feature group; one of the key feature groups includes one first key feature and one second key feature.

[0060] It is understandable that there are multiple first key features and second key features obtained by extracting key node features from the first code features and the second code features, and the first key features and the second key features may be in a one-to-one correspondence. For example, if the R&D personnel add a new functional module to the new version, the first key feature in the first code information of the new version does not have a corresponding second key feature. In this case, the new functional module is not included in the calculation of the subsequent feature correction coefficient. Therefore, the one-to-one corresponding first key features and second key features are grouped to form a key feature group.

[0061] Each of the key feature groups is classified, and a classification weight coefficient corresponding to each of the key feature groups is determined according to the classification result.

[0062] Specifically, it is pointed out in the above description that the key nodes refer to the relevant nodes such as the loop logic and the exception handling module in the first code feature and the second code feature. Therefore, each key feature group can be classified according to different functional modules to determine the classification results corresponding to each key feature group. Before implementing this method, a classification weight coefficient can be pre-assigned to each category of classification results, and the value range of the classification weight coefficient is between 0-1. For example, the classification weight coefficient assigned to the loop logic category is 0.8, and the classification weight coefficient assigned to the exception handling category is 0.1.

[0063] Determine the node path length corresponding to each of the key feature groups; the node path length refers to the path length from the feature node corresponding to the first key feature in the first abstract syntax tree to the root node, or the path length from the feature node corresponding to the second key feature in the second abstract syntax tree to the root node.

[0064] It can be understood that the first abstract syntax tree and the second abstract syntax tree are composed of a root node, several intermediate nodes, and one or more leaf nodes (there are no other nodes after the leaf nodes). The above description also points out that since the first code feature and the second code feature reflect features related to code equivalent calculation, and these features can be queried from the tree nodes on the corresponding first and second abstract syntax trees, the path length from the feature node corresponding to the first key feature in each key feature group in the first abstract syntax tree to the root node can be determined. This path length is the number of node edges in the link with the least node edges when the feature node is connected to the root node.

[0065] For example, assume that in the first abstract syntax tree, the feature node corresponding to the first key feature has two connected links with the root node. In one of these links, the feature node and the root node have three other nodes connected to it, resulting in four node edges (each node edge connecting two nodes). In the other link, the feature node and the root node have one other node connected to it, resulting in two node edges. Thus, we know that the node path length is 2.

[0066] Based on the classification weight coefficient and the node path length corresponding to the same key feature group, a weight correction coefficient corresponding to the key feature group is determined.

[0067] Specifically, after determining the classification weight coefficient and node path length corresponding to each key feature group, the weight correction coefficient corresponding to the key feature group can be determined based on the classification weight coefficient and node path length corresponding to the same key feature group. The weight correction coefficient can be determined according to the following expression : in, Refers to the i The classification weight coefficient corresponding to each key feature group; It refers to the i The node path length corresponding to each key feature group.

[0068] Determine the feature similarity between the first key feature and the second key feature in the same key feature group, and determine the feature correction coefficient according to the weight correction coefficients corresponding to all the key feature groups and the feature similarity.

[0069] Specifically, after determining the weight correction coefficient corresponding to each key feature group, the feature similarity between the first and second key features in the same key feature group can be determined using cosine similarity. The product of the feature similarity of the same key feature group and the weight correction coefficient is used as the correction coefficient corresponding to the key feature group. The total correction coefficient is determined based on the sum of the correction coefficients of all key feature groups. The total number of key feature groups included is counted, and the feature correction coefficient is finally determined by the ratio between the total correction coefficient and the total number of key feature groups.

[0070] In this embodiment, weight correction coefficients are assigned to the node features of key nodes in the abstract syntax tree, such as loop logic and exception handling, to improve the impact of these key nodes on code equivalent calculation. Compared to the existing technology that relies solely on global cosine similarity (the basic similarity mentioned above), this embodiment can improve the accuracy of code equivalent calculation. Furthermore, by assigning different classification weight coefficients to different types of key nodes, it can adapt to the specific needs of different programming paradigms and further improve the accuracy of code equivalent calculation.

[0071] In one embodiment, determining the code equivalence comparison result of the target system based on the code similarity of each code control group includes: A preset code equivalent threshold is obtained, and the code similarity corresponding to each of the code control groups is compared with the preset code equivalent threshold to obtain a similarity comparison result.

[0072] It can be understood that the preset code equivalence threshold can be pre-set by the administrator according to the application scenario of the target system. The preset code equivalence threshold is used to measure whether the workload between different versions of the code uploaded by the R&D personnel meets the expected requirements. Specifically, after determining the code similarity corresponding to each code control group, the code similarity and the code equivalence threshold are compared. If the code similarity is greater than the code equivalence threshold, it is determined that the overlap between the first code information and the second code information is high and the difference is small, which indicates that the workload of the R&D personnel between the two versions is small, and the substantial changes or updates to the code are small. If the code similarity is less than the code equivalence threshold, it is determined that the overlap between the first code information and the second code information is small and the difference is large, which indicates that the workload of the R&D personnel between the two versions is large, and the substantial changes or updates to the code are large.

[0073] Based on the similarity comparison results corresponding to each of the code control groups, a code equivalent comparison result of the target system is determined.

[0074] Specifically, after determining the similarity comparison results corresponding to each code control group, the specific development situation of the R&D personnel in modifying or updating the target system between each adjacent version can be viewed based on the similarity comparison results corresponding to each code control group, thereby determining the code equivalent comparison results when the R&D personnel developed the target system based on all similarity comparison results, and finally evaluating the workload and work quality of the R&D personnel during the entire R&D cycle of the target system based on the code equivalent comparison results. Compared with the existing method of measuring the workload of R&D personnel using methods such as the number of lines of code, this embodiment can better understand the structure and semantics of the code under different versions, thereby more accurately evaluating the code complexity and functional modules, effectively reducing the workload and errors of manual statistics.

[0075] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0076] In one embodiment, a code equivalent comparison device is provided, which corresponds one-to-one to the code equivalent comparison method in the above embodiment. Figure 3 As shown, the code equivalent comparison device includes a record acquisition module 10, a syntax tree construction module 20, a feature extraction module 30, a similarity calculation module 40 and a code equivalent determination module 50. The functional modules are described in detail as follows: The record acquisition module 10 is configured to acquire code submission records of the target system; the code submission records include at least one code control group; each code control group includes a first code information and a second code information; the second code information refers to a code record whose code submission time is before and adjacent to the first code information; A syntax tree construction module 20, configured to construct a first abstract syntax tree based on the first code information, and to construct a second abstract syntax tree based on the second code information; A feature extraction module 30 is configured to obtain a first code feature corresponding to the first abstract syntax tree and a second code feature corresponding to the second abstract syntax tree by using a preset large language model; a similarity calculation module 40, configured to determine the code similarity between the first code feature and the second code feature in the same code control group; The code equivalent determination module 50 is configured to determine a code equivalent comparison result of the target system based on the code similarity of each of the code control groups.

[0077] Furthermore, the syntax tree construction module 20 includes: a code preprocessing unit, configured to perform code preprocessing on the first code information and the second code information to obtain first preprocessing information corresponding to the first code information and second preprocessing information corresponding to the second code information; a basic syntax tree construction unit, configured to construct a first basic syntax tree based on the first preprocessing information, and to construct a second basic syntax tree based on the second preprocessing information; a graph representation conversion unit, configured to perform an embedded graph representation conversion on the first basic syntax tree to obtain a first embedded syntax tree, and to perform an embedded graph representation conversion on the second basic syntax tree to obtain a second embedded syntax tree; A lightweight processing unit is configured to perform lightweight processing on the first embedded syntax tree to obtain the first abstract syntax tree, and to perform lightweight processing on the second embedded syntax tree to obtain the second abstract syntax tree.

[0078] Furthermore, the diagram representation conversion unit includes: a vector conversion subunit, configured to obtain a preset encoder, perform vector conversion on each tree node in the first basic syntax tree using the preset encoder, and record the first basic syntax tree after vector conversion as a first coded syntax tree; A hierarchical detection subunit is used to input the first encoding syntax tree into a preset neural network model, perform hierarchical relationship detection on the first encoding syntax tree through the preset neural network model, and output the first embedded syntax tree.

[0079] Furthermore, the feature extraction module 30 includes: a data input unit, configured to obtain a preset prompt text, and input the preset prompt text, the first abstract syntax tree, and the second abstract syntax tree into the preset large language model; a first model processing unit, configured to convert the preset prompt text into a prompt text vector by using the preset large language model, and determine all first key-value pairs corresponding to the first abstract syntax tree and all second key-value pairs corresponding to the second abstract syntax tree; The second model processing unit is used to output the first code feature based on the prompt text vector and the first key-value pair through the preset large language model, and output the second code feature based on the prompt text vector and the second key-value pair.

[0080] Furthermore, the similarity calculation module 40 includes: a similarity calculation unit, configured to determine a basic similarity based on the first code feature and the second code feature; a feature extraction unit, configured to perform key node feature extraction on the first code feature and the second code feature to obtain all first key features in the first code feature and all second key features in the second code feature; a correction coefficient determining unit, configured to determine a feature correction coefficient based on all of the first key features and the second key features; The similarity correction unit is used to determine the code similarity according to the basic similarity and the feature correction coefficient.

[0081] Furthermore, the correction coefficient determination unit includes: a feature grouping subunit, configured to group all of the first key features and all of the second key features to determine a key feature group; one of the key feature groups includes one first key feature and one second key feature; a coefficient allocation subunit, configured to classify each of the key feature groups and determine a classification weight coefficient corresponding to each of the key feature groups according to the classification result; a path length determination subunit, configured to determine a node path length corresponding to each of the key feature groups; the node path length refers to a path length from a feature node corresponding to the first key feature in the first abstract syntax tree to a root node, or a path length from a feature node corresponding to the second key feature in the second abstract syntax tree to a root node; a weight correction subunit, configured to determine a weight correction coefficient corresponding to the key feature group based on the classification weight coefficient and the node path length corresponding to the same key feature group; The correction coefficient determination subunit determines the feature similarity between the first key feature and the second key feature in the same key feature group, and determines the feature correction coefficient according to the weight correction coefficients corresponding to all the key feature groups and the feature similarity.

[0082] Furthermore, the code equivalent determination module includes: a threshold comparison unit, configured to obtain a preset code equivalent threshold, and compare the code similarity corresponding to each code control group with the preset code equivalent threshold to obtain a similarity comparison result; The code equivalent determination unit is configured to determine a code equivalent comparison result of the target system based on a similarity comparison result corresponding to each of the code control groups.

[0083] For the specific definition of the code equivalence comparison device, please refer to the definition of the code equivalence comparison method above, which will not be repeated here. The various modules in the above-mentioned code equivalence comparison device can be implemented in whole or in part by software, hardware, or a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0084] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 4 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store the data used by the code equivalence comparison method in the above embodiment. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a code equivalence comparison method is implemented.

[0085] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the code equivalence comparison method in the above embodiment is implemented.

[0086] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the code equivalence comparison method in the above embodiment is implemented.

[0087] Those skilled in the art will understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0088] Those skilled in the art will clearly understand that for the sake of convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0089] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention, and should all be included in the scope of protection of the present invention.

Claims

1. A code equivalence comparison method, characterized in that: include: Obtain code submission records of the target system; The code submission record includes at least one code control group; One of the code control groups includes a first code information and a second code information; The second code information refers to a code record whose code submission time is before the first code information and adjacent to the first code information; Constructing a first abstract syntax tree based on the first code information, and constructing a second abstract syntax tree based on the second code information; Obtaining a first code feature corresponding to the first abstract syntax tree and a second code feature corresponding to the second abstract syntax tree through a preset large language model; determining a code similarity between the first code feature and the second code feature in the same code control group; A code equivalence comparison result of the target system is determined based on the code similarity of each of the code control groups.

2. The code equivalence comparison method according to claim 1, wherein: The constructing a first abstract syntax tree based on the first code information and constructing a second abstract syntax tree based on the second code information includes: performing code preprocessing on the first code information and the second code information to obtain first preprocessing information corresponding to the first code information and second preprocessing information corresponding to the second code information; constructing a first basic syntax tree based on the first preprocessing information, and constructing a second basic syntax tree based on the second preprocessing information; Performing an embedded graph representation conversion on the first basic syntax tree to obtain a first embedded syntax tree, and performing an embedded graph representation conversion on the second basic syntax tree to obtain a second embedded syntax tree; The first embedded syntax tree is lightweight processed to obtain the first abstract syntax tree, and the second embedded syntax tree is lightweight processed to obtain the second abstract syntax tree.

3. The code equivalent comparison method according to claim 2, wherein: The converting the first basic syntax tree into an embedded graph representation to obtain a first embedded syntax tree includes: Obtain a preset encoder, perform vector conversion on each tree node in the first basic syntax tree using the preset encoder, and record the first basic syntax tree after the vector conversion as a first coded syntax tree; The first encoding syntax tree is input into a preset neural network model to perform hierarchical relationship detection on the first encoding syntax tree through the preset neural network model, and the first embedded syntax tree is output.

4. The code equivalence comparison method according to claim 1, wherein: The obtaining, by using a preset large language model, a first code feature corresponding to the first abstract syntax tree and a second code feature corresponding to the second abstract syntax tree includes: Obtaining a preset prompt text, and inputting the preset prompt text, the first abstract syntax tree, and the second abstract syntax tree into the preset large language model; Converting the preset prompt text into a prompt text vector using the preset large language model, and determining all first key-value pairs corresponding to the first abstract syntax tree and all second key-value pairs corresponding to the second abstract syntax tree; The first code feature is output based on the prompt text vector and the first key-value pair through the preset large language model, and the second code feature is output based on the prompt text vector and the second key-value pair.

5. The code equivalent comparison method according to claim 1, wherein: The determining of the code similarity between the first code feature and the second code feature in the same code control group includes: determining a basic similarity based on the first code feature and the second code feature; Performing key node feature extraction on the first code feature and the second code feature to obtain all first key features in the first code feature and all second key features in the second code feature; determining a feature correction factor based on all of the first key features and the second key features; The code similarity is determined according to the basic similarity and the feature correction coefficient.

6. The code equivalent comparison method according to claim 5, wherein: The determining of a feature correction coefficient based on the first key feature and the second key feature includes: Grouping all of the first key features and all of the second key features to determine a key feature group; each of the key feature groups includes one first key feature and one second key feature; Classifying each of the key feature groups, and determining a classification weight coefficient corresponding to each of the key feature groups according to the classification results; Determining a node path length corresponding to each key feature group; the node path length refers to a path length from a feature node corresponding to the first key feature in the first abstract syntax tree to a root node, or a path length from a feature node corresponding to the second key feature in the second abstract syntax tree to a root node; Determining a weight correction coefficient corresponding to the key feature group based on the classification weight coefficient corresponding to the same key feature group and the node path length; Determine the feature similarity between the first key feature and the second key feature in the same key feature group, and determine the feature correction coefficient according to the weight correction coefficients corresponding to all the key feature groups and the feature similarity.

7. The code equivalence comparison method according to claim 1, wherein: The determining of the code equivalent comparison result of the target system based on the code similarity of each code control group includes: Obtaining a preset code equivalent threshold, and comparing the code similarity corresponding to each of the code control groups with the preset code equivalent threshold to obtain a similarity comparison result; Based on the similarity comparison results corresponding to each of the code control groups, a code equivalent comparison result of the target system is determined.

8. A code equivalent comparison device, characterized in that: include: Record acquisition module, used to obtain the code submission records of the target system; The code submission record includes at least one code control group; One of the code control groups includes a first code information and a second code information; The second code information refers to a code record whose code submission time is before the first code information and adjacent to the first code information; a syntax tree construction module, configured to construct a first abstract syntax tree based on the first code information, and to construct a second abstract syntax tree based on the second code information; a feature extraction module, configured to obtain a first code feature corresponding to the first abstract syntax tree and a second code feature corresponding to the second abstract syntax tree through a preset large language model; a similarity calculation module, configured to determine the code similarity between the first code feature and the second code feature in the same code control group; A code equivalent determination module is configured to determine a code equivalent comparison result of the target system based on the code similarity of each code control group.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the code equivalence comparison method according to any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the code equivalence comparison method according to any one of claims 1 to 7 is implemented.