Code file difference analysis method and device
By generating an initial node mapping set and using code representation learning technology to perform weighted similarity calculation, the shortcomings of existing technologies in code difference analysis in cross-file reconstruction scenarios are solved, and more accurate analysis of complex code changes and defect localization are achieved.
Patent Information
- Application Number
- CN202511068606.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-31
- Publication Date
- 2025-11-07
AI Technical Summary
Existing code file difference analysis methods are not suitable for complex code change analysis, defect location and repair, especially neglecting one-to-many mapping in cross-file code refactoring scenarios, resulting in inaccurate analysis results.
By acquiring code file groups, an initial set of one-to-one node mappings and a set of one-to-many node mappings are generated. Weighted similarity calculation is performed using code representation learning techniques to identify cross-file node mapping pairs. Based on similarity thresholds, the pairs are filtered and analyzed, and the difference analysis results are output.
It can better capture code migration and refactoring across files, improving the accuracy of complex code change analysis, defect location and repair.
Smart Images

Figure CN120911432A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, and in particular, to a code file difference analysis method and device. BACKGROUND
[0002] File Difference Analysis aims to analyze the differences between the contents of two files, and is a technical method specially used for comparing the similarities and differences between the contents of two or more files. The core goal is to accurately identify and quantify the modified, added or deleted contents between files through systematic comparison means.
[0003] File Difference Analysis can be widely applied to code version control, document revision tracking, data consistency verification and other scenarios. The typical analysis process includes three levels: text-level differences (such as in-line character changes), structure-level differences, and semantic-level differences (such as code logic equivalence but syntax restructuring).
[0004] Existing code file difference analysis methods usually compare and analyze version changes of isolated code files, but in actual development, there are often cross-file code restructuring scenarios (such as splitting class methods into new files, merging multiple utility classes, etc.). Only considering the difference analysis of single file revisions and being limited to one-to-one mapping between original files and target files, the one-to-many mapping caused by code splitting and restructuring in reality is ignored, resulting in the existing method being unable to be applied to complex code change analysis, defect positioning and repair tasks. SUMMARY
[0005] The present application provides a code file difference analysis method and device, which solves the technical problem that the existing code file difference analysis method cannot be applied to complex code change analysis, defect positioning and repair tasks.
[0006] The first aspect of the present application provides a code file difference analysis method, comprising:
[0007] Obtaining a code file group, and preprocessing an original code file in the code file group and a plurality of target code files corresponding to the original code file to generate an initial one-to-one node mapping set and an initial one-to-many node mapping set;
[0008] Judging whether the original file statement node and the target file statement node in the plurality of statement node mapping pairs in the initial one-to-one node mapping set belong to different code files;
[0009] Taking any original file statement node and target file statement node pair corresponding to the statement node mapping pair belonging to different code files as an initial cross-file node mapping pair;
[0010] The code representation learning technology is used to perform weighted similarity calculation on each initial cross-file node mapping pair to determine a cross-file weighted similarity corresponding to each initial cross-file node mapping pair.
[0011] Based on the code representation learning technology, a plurality of sentence node mapping pairs in the initial one-to-many node mapping set are screened and weighted similarity calculation is performed to determine a one-to-many weighted similarity corresponding to each initial one-to-many node mapping pair.
[0012] Based on the cross-file weighted similarity corresponding to each initial cross-file node mapping pair and the one-to-many weighted similarity corresponding to each initial one-to-many node mapping pair, screening and analysis are respectively performed, and code file difference analysis results corresponding to a plurality of target cross-file node mapping pairs and code file difference analysis results corresponding to a plurality of target one-to-many node mapping pairs are respectively output.
[0013] Optionally, the preprocessing of the original code file in the code file group and the plurality of target code files corresponding to the original code file to generate the initial one-to-one node mapping set and the initial one-to-many node mapping set comprises:
[0014] The original code file and the plurality of target code files corresponding to the original code file are parsed to generate an original file abstract syntax tree of the original code file and a target file abstract syntax tree of each target code file.
[0015] The original file abstract syntax tree and each target file abstract syntax tree are respectively subjected to node extraction to generate a plurality of original file abstract syntax tree nodes corresponding to the original file abstract syntax tree and a plurality of target file abstract syntax tree nodes corresponding to each target file abstract syntax tree.
[0016] It is judged whether the label data and value data of each original file abstract syntax tree node corresponding to the original code file are the same as the label data and value data of each target file abstract syntax tree node corresponding to each target code file.
[0017] Any original file abstract syntax tree node and target file abstract syntax tree node with the same label data and value data are subjected to equal node mapping to generate a plurality of equal node mapping pairs.
[0018] Any original file abstract syntax tree node and target file abstract syntax tree node with different label data or value data are subjected to similarity-based iterative node mapping to generate a plurality of candidate one-to-one node mapping pairs.
[0019] The initial one-to-one node mapping set is constructed according to the plurality of candidate one-to-one node mapping pairs and the plurality of equal node mapping pairs.
[0020] perform similarity calculation on the original file abstract syntax tree nodes and the target file abstract syntax tree nodes that are not identical in any label data or value data, and output a plurality of similarity values;
[0021] compare the similarity values with a preset similarity threshold value;
[0022] perform node mapping on the original file abstract syntax tree nodes and the target file abstract syntax tree nodes corresponding to the similarity values greater than or equal to the preset similarity threshold value, and output a plurality of candidate one-to-many node mapping pairs;
[0023] construct an initial one-to-many node mapping set according to the plurality of candidate one-to-many node mapping pairs and the plurality of equal node mapping pairs;
[0024] The original file abstract syntax tree nodes include original file statement nodes, original file internal statement nodes, and original file word nodes. The target file abstract syntax tree nodes include target file statement nodes, target file internal statement nodes, and target file word nodes. The equal node mapping pairs include statement node mapping pairs, internal statement node mapping pairs, and word node mapping pairs that are identical in label data and value data. The candidate one-to-one node mapping pairs and the candidate one-to-many node mapping pairs each include statement node mapping pairs, internal statement node mapping pairs, and word node mapping pairs that are not identical in label data or value data.
[0025] Optionally, the code representation learning technology includes a code-oriented multi-modal pre-training model, a graph neural network algorithm, and an attention network. The code representation learning technology is used to perform weighted similarity calculation according to the initial cross-file node mapping pairs, to determine cross-file weighted similarities corresponding to the initial cross-file node mapping pairs, including:
[0026] Based on the code-oriented multi-modal pre-training model, language vectorization is respectively performed on the original file statement nodes and the target file statement nodes in the initial cross-file node mapping pairs, to generate original file statement node semantic vectors corresponding to the original file statement nodes in the initial cross-file node mapping pairs and target file statement node semantic vectors corresponding to the target file statement nodes in the initial cross-file node mapping pairs;
[0027] The graph neural network algorithm is used to output original file statement node graph embedding vectors corresponding to the original file statement nodes in the initial cross-file node mapping pairs and target file statement node graph embedding vectors corresponding to the target file statement nodes in the initial cross-file node mapping pairs according to the plurality of initial cross-file node mapping pairs;
[0028] performing word segmentation and deduplication on the original file statement corresponding to the original file statement node and the target file statement corresponding to the target file statement node in each of the initial cross-file node mapping pairs, to generate a bag-of-words table corresponding to each of the initial cross-file node mapping pairs;
[0029] based on the bag-of-words table corresponding to each of the initial cross-file node mapping pairs, generating an original file statement node bag-of-words vector corresponding to the original file statement node in each of the initial cross-file node mapping pairs, and a target file statement node bag-of-words vector corresponding to the target file statement node in each of the initial cross-file node mapping pairs;
[0030] normalizing the original file statement node semantic vector, the target file statement node semantic vector, the original file statement node graph embedding vector, the target file statement node graph embedding vector, the original file statement node bag-of-words vector, and the target file statement node bag-of-words vector corresponding to each of the initial cross-file node mapping pairs, respectively, to output a normalized original file statement node semantic vector, a normalized target file statement node semantic vector, a normalized original file statement node graph embedding vector, a normalized target file statement node graph embedding vector, a normalized original file statement node bag-of-words vector, and a normalized target file statement node bag-of-words vector corresponding to each of the initial cross-file node mapping pairs;
[0031] based on the normalized original file statement node semantic vector, the normalized target file statement node semantic vector, the normalized original file statement node graph embedding vector, the normalized target file statement node graph embedding vector, the normalized original file statement node bag-of-words vector, and the normalized target file statement node bag-of-words vector corresponding to each of the initial cross-file node mapping pairs, calculating a semantic vector cosine similarity, a graph embedding vector cosine similarity, and a bag-of-words vector cosine similarity corresponding to each of the initial cross-file node mapping pairs;
[0032] concatenating the semantic vector cosine similarity, the graph embedding vector cosine similarity, and the bag-of-words vector cosine similarity corresponding to each of the initial cross-file node mapping pairs, respectively, to output a similarity feature vector corresponding to each of the initial cross-file node mapping pairs;
[0033] using the attention network to output a semantic vector weight, a graph feature vector weight, and a bag-of-words vector weight corresponding to each of the initial cross-file node mapping pairs according to the similarity feature vector corresponding to each of the initial cross-file node mapping pairs;
[0034] using the semantic vector cosine similarity, the graph embedding vector cosine similarity, the bag-of-words vector cosine similarity, the semantic vector weight, the graph feature vector weight, and the bag-of-words vector weight corresponding to each of the initial cross-file node mapping pairs, to calculate a cross-file weighted similarity corresponding to each of the initial cross-file node mapping pairs.
[0035] Optionally, the employing the graph neural network algorithm to output a graph embedding vector corresponding to an original file statement node in each of the plurality of initial cross-file node mapping pairs and a graph embedding vector corresponding to a target file statement node in each of the plurality of initial cross-file node mapping pairs based on the original file statement node and the target file statement node in each of the plurality of initial cross-file node mapping pairs comprises:
[0036] employing the graph neural network algorithm to generate an abstract syntax graph based on the original file statement node and the target file statement node in each of the plurality of initial cross-file node mapping pairs;
[0037] generating the graph embedding vector corresponding to the original file statement node in each of the plurality of initial cross-file node mapping pairs and the graph embedding vector corresponding to the target file statement node in each of the plurality of initial cross-file node mapping pairs based on a node feature and an edge feature in the abstract syntax graph.
[0038] Optionally, the filtering and weighted similarity calculation on the plurality of statement node mapping pairs in the initial one-to-many node mapping set based on the code representation learning technology comprises:
[0039] performing language vectorization on the original file statement node and the target file statement node in each of the plurality of statement node mapping pairs in the initial one-to-many node mapping set based on the code-oriented multi-modal pre-training model to generate an original file statement node semantic vector corresponding to the original file statement node in each of the plurality of statement node mapping pairs in the initial one-to-many node mapping set and a target file statement node semantic vector corresponding to the target file statement node in each of the plurality of statement node mapping pairs in the initial one-to-many node mapping set;
[0040] performing cosine similarity calculation on the original file statement node semantic vector and the target file statement node semantic vector corresponding to each of the plurality of statement node mapping pairs in the initial one-to-many node mapping set to output a semantic vector cosine similarity corresponding to each of the plurality of statement node mapping pairs in the initial one-to-many node mapping set;
[0041] comparing the semantic vector cosine similarity corresponding to each of the plurality of statement node mapping pairs in the initial one-to-many node mapping set with a preset cosine similarity threshold;
[0042] taking any statement node mapping pair corresponding to a semantic vector cosine similarity greater than the preset cosine similarity threshold as an initial one-to-many node mapping pair;
[0043] The graph neural network algorithm is used to output a source file statement node graph embedding vector corresponding to a source file statement node in each of the initial one-to-many node mapping pairs, and a target file statement node graph embedding vector corresponding to a target file statement node in each of the initial cross-file node mapping pairs.
[0044] Cosine similarity calculation is performed based on the source file statement node graph embedding vector corresponding to the source file statement node in each of the initial one-to-many node mapping pairs and the target file statement node graph embedding vector corresponding to the target file statement node in each of the initial cross-file node mapping pairs, and a graph embedding vector cosine similarity corresponding to each of the initial one-to-many node mapping pairs is output.
[0045] The attention network is used to output a semantic vector weight and a graph feature vector weight corresponding to each of the initial one-to-many node mapping pairs based on the graph embedding vector cosine similarity and the semantic vector cosine similarity corresponding to each of the initial one-to-many node mapping pairs.
[0046] A one-to-many weighted similarity corresponding to each of the initial one-to-many node mapping pairs is calculated based on the semantic vector weight, the graph feature vector weight, the graph embedding vector cosine similarity, and the semantic vector cosine similarity corresponding to each of the initial one-to-many node mapping pairs.
[0047] Optionally, the cross-file weighted similarities corresponding to each of the initial cross-file node mapping pairs and the one-to-many weighted similarities corresponding to each of the initial one-to-many node mapping pairs are respectively screened and analyzed, and code file difference analysis results corresponding to a plurality of target cross-file node mapping pairs and code file difference analysis results corresponding to a plurality of target one-to-many node mapping pairs are respectively output, including:
[0048] The cross-file weighted similarities corresponding to each of the initial cross-file node mapping pairs are compared with a preset first similarity threshold, respectively.
[0049] An initial cross-file node mapping pair corresponding to any cross-file weighted similarity greater than or equal to the preset first similarity threshold is taken as a target cross-file node mapping pair, and a code file difference analysis result associated with the target cross-file node mapping pair is determined as existing cross-file mapping.
[0050] The one-to-many weighted similarities corresponding to each of the initial one-to-many node mapping pairs are compared with a preset second similarity threshold, respectively.
[0051] An initial one-to-many node mapping pair corresponding to any one-to-many weighted similarity greater than or equal to the preset second similarity threshold is taken as a target one-to-many node mapping pair, and a code file difference analysis result associated with the target one-to-many node mapping pair is determined as existing one-to-many mapping.
[0052] The second aspect of the present application provides a code file difference analysis device, comprising:
[0053] An acquisition module is configured to acquire a code file group, and pre-process an original code file and a plurality of target code files corresponding to the original code file in the code file group to generate an initial one-to-one node mapping set and an initial one-to-many node mapping set;
[0054] A judgment module is configured to judge whether the original file statement node and the target file statement node in the plurality of statement node mapping pairs in the initial one-to-one node mapping set belong to different code files;
[0055] An output module is configured to take the statement node mapping pair corresponding to the original file statement node and the target file statement node belonging to different code files as an initial cross-file node mapping pair;
[0056] A first calculation module is configured to perform weighted similarity calculation according to each initial cross-file node mapping pair by using a code representation learning technology, and determine a cross-file weighted similarity corresponding to each initial cross-file node mapping pair;
[0057] A second calculation module is configured to perform screening and weighted similarity calculation on the plurality of statement node mapping pairs in the initial one-to-many node mapping set based on the code representation learning technology, and determine a one-to-many weighted similarity corresponding to the plurality of initial one-to-many node mapping pairs;
[0058] A generation module is configured to perform screening and analysis based on the cross-file weighted similarity corresponding to each initial cross-file node mapping pair and the one-to-many weighted similarity corresponding to each initial one-to-many node mapping pair, respectively, and output a code file difference analysis result corresponding to a plurality of target cross-file node mapping pairs and a code file difference analysis result corresponding to a plurality of target one-to-many node mapping pairs, respectively.
[0059] The third aspect of the present application provides a computer device, comprising a memory and a processor, the memory stores a computer program, and the computer program is executed by the processor to make the processor execute the steps of the code file difference analysis method according to any one of the above aspects.
[0060] The fourth aspect of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed to implement the steps of the code file difference analysis method according to any one of the above aspects.
[0061] The fifth aspect of the present application provides a computer program product, the computer program product comprises a computer program stored on a non-transitory computer-readable storage medium, the computer program comprises program instructions, wherein when the program instructions are executed by a computer, the computer executes the steps of the code file difference analysis method according to any one of the above.
[0062] From the above technical solutions, the present application has the following advantages:
[0063] The above-mentioned scheme of the present application provides a code file difference analysis method, acquires a code file group, and pre-processes original code files in the code file group and a plurality of target code files corresponding to the original code files to generate an initial one-to-one node mapping set and an initial one-to-many node mapping set; determines whether the original file statement nodes and the target file statement nodes in a plurality of statement node mapping pairs in the initial one-to-one node mapping set belong to different code files; takes any original file statement node and target file statement node pair corresponding to the statement node mapping pair belonging to different code files as an initial cross-file node mapping pair; performs weighted similarity calculation according to each initial cross-file node mapping pair by using a code representation learning technology to determine a cross-file weighted similarity corresponding to each initial cross-file node mapping pair; based on the code representation learning technology, screens and performs weighted similarity calculation on a plurality of statement node mapping pairs in the initial one-to-many node mapping set to determine a one-to-many weighted similarity corresponding to a plurality of initial one-to-many node mapping pairs; respectively screens and analyzes the cross-file weighted similarity corresponding to each initial cross-file node mapping pair and the one-to-many weighted similarity corresponding to each initial one-to-many node mapping pair, and respectively outputs a code file difference analysis result corresponding to a plurality of target cross-file node mapping pairs and a code file difference analysis result corresponding to a plurality of target one-to-many node mapping pairs; based on the above-mentioned scheme, the single / multiple mapping set is generated by pre-processing, the cross-file node pairs are identified, the weighted similarity (cross-file weighted similarity, one-to-many weighted similarity) is calculated by using the code representation learning, and finally the difference analysis result is output. The present application can capture the code migration and reconstruction between different files, and can be better applied to complex code change analysis, defect positioning and repair and the like. BRIEF DESCRIPTION OF DRAWINGS
[0064] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor.
[0065] Figure 1A code file difference analysis method provided for the embodiment one of the present application has a step flow chart;
[0066] Figure 2 The cross-file mapping output schematic diagram provided for the embodiment one of the present application (one original statement is mapped into one or more target statements) is shown in the following figure:
[0067] Figure 3 The one-to-many mapping output schematic diagram provided for the embodiment one of the present application (one original method is split into two methods and mapped into two target files) is shown in the following figure:
[0068] Figure 4 The cross-file mapping example schematic diagram provided for the embodiment one of the present application (a method in one original file is mapped into multiple target files) is shown in the following figure:
[0069] Figure 5 The one-to-many mapping example schematic diagram provided for the embodiment one of the present application (a method body in one original file is split and mapped into two different target files) is shown in the following figure:
[0070] Figure 6 The overall framework diagram of the code file difference analysis method provided for the embodiment one of the present application is shown in the following figure:
[0071] Figure 7 The structural block diagram of the code file difference analysis device provided for the embodiment two of the present application is shown in the following figure. DETAILED DESCRIPTION
[0072] The embodiment of the present application provides a code file difference analysis method and device, which is used to solve the technical problem that the existing code file difference analysis method cannot be applied to complex code change analysis, defect positioning and repair and the like.
[0073] In order to make the technical scheme of the present application more clear and easy to understand, the technical scheme in the embodiment of the present application will be described clearly and completely in conjunction with the drawings in the embodiment of the present application. Obviously, the following described embodiments are only a part of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.
[0074] Term explanation:
[0075] Abstract Syntax Tree (AST): a tree representation of source code, each node in the tree represents a syntax structure in the source code, such as a statement, an expression or a declaration, etc.
[0076] File Group Revision: a joint revision of a group of files, or a revision involving multiple files. A file group revision can be considered as a collection of multiple file revisions, each of which has a corresponding original file and target file. Note that there will be cross-file and one-to-many mappings of content in a file group revision, such as a statement in an original file can be moved or split into multiple target files.
[0077] Cross-file AST Mapping: in the AST difference analysis of a code file group revision, the mapping relationship between the AST of an original file (original AST) and the ASTs of multiple target files (target ASTs).
[0078] One-to-Many AST Mapping: in the AST difference analysis of a code file (group) revision, the node structure corresponding to a code fragment in the original AST is reorganized into multiple different nodes or node combinations in the target ASTs in the revision process.
[0079] Please refer to Figure 1 , Figure 1 A step flowchart of a code file difference analysis method provided for an embodiment of the present application.
[0080] The present application provides a code file difference analysis method, comprising:
[0081] Step 101, obtain a code file group, and pre-process the original code file in the code file group and the multiple target code files corresponding to the original code file to generate an initial one-to-one node mapping set and an initial one-to-many node mapping set.
[0082] The code file group includes multiple original code files and multiple target code files corresponding to each original code file, and the multiple target code files corresponding to the original code file include multiple code files with the same file name as the original code file and multiple code files with different file names from the original code file; the present application can perform code file difference analysis based on one or more original code files and one or more target code files corresponding to the original code files.
[0083] It should be noted that this step pre-processes the input file (group) revision, i.e. the code file group, to generate an initial one-to-one node mapping set and an initial one-to-many node mapping set, and uses them as the input of the subsequent steps to further improve the mapping accuracy through cross-file mapping algorithm and one-to-many mapping algorithm. At the same time, the mapping efficiency is improved.
[0084] Specifically, step 101 can include the following sub-steps S11-S111:
[0085] Step S11, parsing the original code file and the plurality of target code files corresponding to the original code file to generate an original file abstract syntax tree of the original code file and a plurality of target file abstract syntax trees of the plurality of target code files;
[0086] Step S12, respectively extracting nodes from the original file abstract syntax tree and the plurality of target file abstract syntax trees to generate a plurality of original file abstract syntax tree nodes corresponding to the original file abstract syntax tree and a plurality of target file abstract syntax tree nodes corresponding to the plurality of target file abstract syntax trees;
[0087] Step S13, judging whether the label data and the value data of each original file abstract syntax tree node corresponding to the original code file are same as the label data and the value data of each target file abstract syntax tree node corresponding to the plurality of target code files;
[0088] Step S14, performing equal node mapping on the original file abstract syntax tree nodes and the target file abstract syntax tree nodes which are same in any label data and value data to generate a plurality of equal node mapping pairs;
[0089] Step S15, performing similarity-based iterative node mapping on the original file abstract syntax tree nodes and the target file abstract syntax tree nodes which are different in any label data or value data to generate a plurality of candidate one-to-one node mapping pairs;
[0090] Step S16, constructing an initial one-to-one node mapping set according to the plurality of candidate one-to-one node mapping pairs and the plurality of equal node mapping pairs;
[0091] Step S17, performing similarity calculation on the original file abstract syntax tree nodes and the target file abstract syntax tree nodes which are different in any label data or value data to output a plurality of similarity values;
[0092] Step S18, comparing each similarity value with a preset similarity threshold value;
[0093] Step S19, performing node mapping on the original file abstract syntax tree nodes and the target file abstract syntax tree nodes corresponding to any similarity value greater than or equal to the preset similarity threshold value to output a plurality of candidate one-to-many node mapping pairs;
[0094] Step S110, constructing an initial one-to-many node mapping set according to the plurality of candidate one-to-many node mapping pairs and the plurality of equal node mapping pairs;
[0095] The step S111, wherein the original file abstract syntax tree node includes an original file statement node, an original file internal statement node, and an original file word node; the target file abstract syntax tree node includes a target file statement node, a target file internal statement node, and a target file word node; the equal node mapping pair includes a statement node mapping pair, an internal statement node mapping pair, and a word node mapping pair with the same label data and value data; the candidate one-to-one node mapping pair and the candidate one-to-many node mapping pair each include a statement node mapping pair, an internal statement node mapping pair, and a word node mapping pair with different label data or value data.
[0096] It should be noted that, first, the original code file and the target code file are parsed using the Eclipse JDT Parser to obtain their respective ASTs (abstract syntax trees) and the corresponding relationship. Then, the label data (node type) and the value data (node content) of each node in each AST are extracted, and the nodes are divided into three types according to the label and the value: statement nodes, internal statement nodes, and word nodes. Meanwhile, the association between nodes at different levels is established, such as the internal statement nodes and the word nodes contained in a statement node. Among them, the internal statement refers to the non-leaf nodes in the descendant nodes of the statement node (except the statement node); the leaf node is the word node.
[0097] Further, the equal nodes (i.e., the nodes with the same label and value) in each original AST and the corresponding target AST are mapped, that is, the label data and the value data of the original file abstract syntax tree node of the original code file and the label data and the value data of the target file abstract syntax tree node associated with the corresponding target original code file of the original code file are all the same. The equal node refers to the node that has not been modified, and these nodes do not need to be involved in the subsequent iterative mapping process.
[0098] Further, the present application further establishes the mapping between the unmapped original AST(s) node and the target AST(s) node in the equal node mapping process through multiple rounds of heuristic similarity measurement rules, that is, the iteration node mapping based on similarity between the original file abstract syntax tree nodes and the target file abstract syntax tree nodes which are not the same in label data or value data. In the iteration mapping process, according to the order of statement nodes, internal statement nodes and word nodes, each unmapped original AST(s) node will be calculated with all target AST(s) nodes of the same type and not yet mapped in all target files under the file (group) revision. Specifically, the similarity of the original and candidate target AST(s) nodes is calculated according to the heuristic rules of the three levels in the order of "statement-internal statement-word". The heuristic rules of each level are mainly based on the number of mapped nodes in the descendant word nodes of the node, the number of mapped nodes in the upper and lower sibling nodes, and other structural information. However, since the node mapping of different levels will affect each other, after completing a round of node mapping of different levels (i.e. "statement element mapping -> internal statement mapping -> word element mapping"), if new word node mapping appears, a new round of node mapping is started to establish more accurate node mapping, if there is no new word node generated, the iteration loop is terminated. Finally, after multiple iterations, each original AST(s) node will be matched with the target AST(s) node with the highest similarity, thereby outputting multiple candidate one-to-one node mapping pairs, indicating that the original file abstract syntax tree node is mapped with only one target file abstract syntax tree node. The candidate one-to-one node mapping pairs established in this step will be saved in a node mapping set, and combined with multiple equal node mapping pairs to construct an initial one-to-one node mapping set.
[0099] Further, in order to effectively identify the one-to-many mapping caused by code splitting, refactoring and other operations, in the node mapping process at the statement level, it is necessary to pre-store the most possible target AST(s) statement node set corresponding to each original AST(s) statement node. The specific method is to filter out the target AST(s) nodes with a similarity value less than 0.5 (preset similarity threshold) with the original AST(s) node, and only keep the similarity values between the candidate nodes and the statement pairs of all potential matches, that is, calculate the similarity values between each original file abstract syntax tree node and each target file abstract syntax tree node, and keep the original file abstract syntax tree nodes and the target file abstract syntax tree nodes with a similarity value greater than or equal to 0.5, and then map each retained original file abstract syntax tree node with each target file abstract syntax tree node to obtain multiple candidate one-to-many node mapping pairs, so as to identify one-to-many mapping in subsequent steps. Since developers usually pay more attention to statement-level code revisions and less attention to internal statement and word-level code revisions, the present application only considers the cross-file and one-to-many mapping of statement nodes.
[0100] Step 102, judging whether the original file statement node and the target file statement node in the plurality of statement node mapping pairs in the initial one-to-one node mapping set belong to different code files.
[0101] It should be noted that this step will filter the cross-file mappings from the initial one-to-one node mapping set established in the above steps. For each statement node in the original AST(s), find the target statements mapped thereto from the initial one-to-one node mapping set, and judge whether they belong to different files (if the file name of the original code file is different from the file name of the target code file, it means that they belong to different files, otherwise they belong to the same code file). If so, determine whether it can constitute a cross-file mapping according to the following semantic similarity measurement step.
[0102] Step 103, taking any original file statement node and target file statement node pair corresponding to the statement node mapping pair belonging to different code files as an initial cross-file node mapping pair.
[0103] Step 104, using a code representation learning technique to perform weighted similarity calculation according to each initial cross-file node mapping pair to determine the cross-file weighted similarity corresponding to each initial cross-file node mapping pair.
[0104] The code representation learning technique includes a code-oriented multi-modal pre-training model, a graph neural network algorithm, and an attention network.
[0105] Specifically, step 104 can include the following sub-steps S41-S49:
[0106] Step S41, based on a code-oriented multi-modal pre-training model, respectively language vectorizing the original file statement node and the target file statement node in each initial cross-file node mapping pair to generate an original file statement node semantic vector corresponding to the original file statement node in each initial cross-file node mapping pair and a target file statement node semantic vector corresponding to the target file statement node in each initial cross-file node mapping pair.
[0107] The code-oriented multi-modal pre-training model is a pre-training model UniXcoder (Unified Cross-modal Pre-trained Model for Programming and Natural Language).
[0108] It should be noted that the semantic vector focuses on the meaning of the code literal. The original sentence node (original file sentence node) and the target sentence node (target file sentence node) are subjected to semantic vectorization by using a pre-trained model UniXcoder to generate feature vectors that fuse syntax structure and semantic information (i.e., original file sentence node semantic vector, target file sentence node semantic vector). UniXcoder has fusion training on code and annotation semantics, and is suitable for processing the "semantic migration" problem in cross-file mapping. The generated semantic vector of the original sentence node is denoted as , and the semantic vector of the target sentence node is denoted as .
[0109] Step S42, using a graph neural network algorithm, outputs the original file sentence node graph embedding vector corresponding to the original file sentence node in each initial cross-file node mapping pair and the target file sentence node graph embedding vector corresponding to the target file sentence node in each initial cross-file node mapping pair according to the plurality of initial cross-file node mapping pairs.
[0110] Further, step S42 can include the following sub-steps S421-S422:
[0111] Step S421, using a graph neural network algorithm, generating an abstract syntax graph according to the original file sentence node and the target file sentence node in the plurality of initial cross-file node mapping pairs.
[0112] Step S422, based on the node features and edge features in the abstract syntax graph, generating the original file sentence node graph embedding vector corresponding to the original file sentence node in each initial cross-file node mapping pair and the target file sentence node graph embedding vector corresponding to the target file sentence node in each initial cross-file node mapping pair.
[0113] The graph neural network algorithm is a GraphSAGE (Graph Sample and AggregatE) algorithm.
[0114] It should be noted that the graph feature vector (graph embedding vector) generated in this step focuses on the logical connection of code runtime. By introducing an abstract syntax graph (ASG) that can more comprehensively capture code dependencies compared to an abstract syntax tree to represent the code snippet, the data flow and control flow features between nodes are extracted by GraphSAGE (an algorithm), and a graph feature vector is constructed. GraphSAGE is a graph neural network (GNN) algorithm that runs quickly and can automatically adapt to changes in mapping structure. The specific process is as follows: first, the AST nodes of the original statement and the target statement are extracted, i.e., the original file statement node and the target file statement node, and an abstract syntax graph is generated. Among them, the nodes of the graph are composed of code elements such as variables, functions, and classes; the edges of the graph are composed of data flow (variable transmission) and control flow (conditional / loop dependency). Then the node features and edge features of the ASG are input into GraphSAGE to obtain the graph embedding vector of the original statement and the graph embedding vector of the target statement .
[0115] Step S43, respectively, the original file statement corresponding to the original file statement node in each initial cross-file node mapping pair and the target file statement corresponding to the target file statement node are segmented and de-duplicated to generate a bag-of-words table corresponding to each initial cross-file node mapping pair;
[0116] Step S44, based on the bag-of-words table corresponding to each initial cross-file node mapping pair, generate the original file statement node bag-of-words vector corresponding to the original file statement node in each initial cross-file node mapping pair, and the target file statement node bag-of-words vector corresponding to the target file statement node in each initial cross-file node mapping pair;
[0117] It should be noted that this vector focuses on statement similarity. The word elements in the code snippet are treated as unordered "bags of words", the frequency of these word elements is counted, and a fixed-dimensional vector is generated. Let the bag-of-words vector of the original statement be , and the bag-of-words vector of the target statement be For example, given a source language sentence "public int calculateSum(int a, int b)" and a target language sentence "public int sum(int x, int y)", after tokenization and deduplication, the bag-of-words table is obtained: ["public", "int", "calculateSum", "sum", "a", "b", "x", "y"]. Based on the bag-of-words table, the corresponding feature vectors of the two sentences can be generated, where each dimension represents the number of times a word in the bag-of-words table appears in the sentence, that is, bag = [1, 3, 1, 0, 1, 1, 0, 0] and bag = [1, 3, 0, 1, 0, 0, 1, 1] respectively.
[0118] In step S45, the original file sentence node semantic vector, the target file sentence node semantic vector, the original file sentence node graph embedding vector, the target file sentence node graph embedding vector, the original file sentence node bag-of-words vector, and the target file sentence node bag-of-words vector corresponding to each initial cross-file node mapping pair are normalized respectively, and the normalized original file sentence node semantic vector, the normalized target file sentence node semantic vector, the normalized original file sentence node graph embedding vector, the normalized target file sentence node graph embedding vector, the normalized original file sentence node bag-of-words vector, and the normalized target file sentence node bag-of-words vector corresponding to each initial cross-file node mapping pair are output.
[0119] It should be noted that, in order to eliminate the dominant effect of high-value features of the bag-of-words vector on other feature vectors, each type of feature vector described above is subjected to L2 normalization, that is, each element of the data vector is divided by the L2 norm (square root of the sum of the elements of the vector) of the vector to obtain the normalized vector representation, as follows:
[0120] , ;
[0121] , ;
[0122] , ;
[0123] wherein, is the normalized original file sentence node semantic vector; is the normalized target file sentence node semantic vector; is the normalized original file sentence node graph embedding vector; is the normalized target file sentence node graph embedding vector; is the normalized original file sentence node bag-of-words vector; to normalize the target file sentence node bag-of-words vector.
[0124] Step S46, based on the normalized original file sentence node semantic vector, the normalized target file sentence node semantic vector, the normalized original file sentence node graph embedding vector, the normalized target file sentence node graph embedding vector, the normalized original file sentence node bag-of-words vector, and the normalized target file sentence node bag-of-words vector corresponding to each initial cross-file node mapping pair, the semantic vector cosine similarity, the graph embedding vector cosine similarity, and the bag-of-words vector cosine similarity corresponding to each initial cross-file node mapping pair are calculated.
[0125] Step S47, the semantic vector cosine similarity, the graph embedding vector cosine similarity, and the bag-of-words vector cosine similarity corresponding to each initial cross-file node mapping pair are respectively spliced to output the similarity feature vector corresponding to each initial cross-file node mapping pair.
[0126] Step S48, the attention network is used to output the semantic vector weight, the graph feature vector weight, and the bag-of-words vector weight corresponding to each initial cross-file node mapping pair according to the similarity feature vector corresponding to each initial cross-file node mapping pair.
[0127] Step S49, the semantic vector cosine similarity, the graph embedding vector cosine similarity, the bag-of-words vector cosine similarity, the semantic vector weight, the graph feature vector weight, and the bag-of-words vector weight corresponding to each initial cross-file node mapping pair are used to calculate the cross-file weighted similarity corresponding to each initial cross-file node mapping pair.
[0128] It should be noted that, since the influence weights of the above three types of feature vectors in cross-file mapping are different, a dynamic weighting strategy (using a neural network to automatically learn weight distribution) is used to fuse them, and the specific process is as follows:
[0129] 1) Similarity calculation: the cosine similarity of the original node and the target node in the three types of feature vectors is calculated respectively. The semantic vector cosine similarity sim_semantic, the graph embedding vector cosine similarity sim_graph, and the bag-of-words vector cosine similarity sim_bag are obtained.
[0130] 2) Feature splicing: the above three similarity values are spliced into a unified feature vector, i.e., the similarity feature vector =[sim_semantic; sim_graph; sim_bag].
[0131] 3) Automatic generation of weights: the similarity feature vector is input into the trained attention network, first through a hidden layer for non-linear mapping. The hidden layer includes 32 neuron nodes and uses the ReLU (Rectified Linear Unit) function most suitable for the code feature space as the activation function. Subsequently, the hidden layer output is subjected to a linear transformation, mapped to a 3-dimensional space, and normalized by Softmax, ensuring that the results are between (0, 1) and add up to 1. Finally, the importance weights of the three types of features (semantic vector weight , graph feature vector weight , bag of words vector weight ) are output.
[0132] Further, the calculation formula of the cross-file weighted similarity Similarity1 is:
[0133] Similarity1= sim_semantic+ sim_graph+ sim_bag.
[0134] Step 105, based on the code representation learning technology, screening and weighted similarity calculation are performed on the plurality of statement node mapping pairs in the initial one-to-many node mapping set to determine the one-to-many weighted similarity corresponding to the plurality of initial one-to-many node mapping pairs.
[0135] It should be noted that this step screens the one-to-many node mapping from the candidate set with a similarity greater than 0.5 to the original statement established in step 101, that is, the initial one-to-many node mapping set is processed. The overall process follows the idea in the cross-file mapping, but because the one-to-many mapping focuses on code splitting, refactoring, and other scenarios, although some original statements have low similarity with the target statements at the text level, there is a clear one-to-many logical relationship at the semantic or structural level. Therefore, the semantic and logical features of the mapping are focused on in this step.
[0136] Specifically, step 105 can include the following sub-steps S51-S58:
[0137] Step S51, based on the code-oriented multi-modal pre-training model, respectively vectorizes the original file statement nodes and target file statement nodes in the plurality of statement node mapping pairs in the initial one-to-many node mapping set to generate the original file statement node semantic vector corresponding to the original file statement node in each statement node mapping pair in the initial one-to-many node mapping set, and the target file statement node semantic vector corresponding to the target file statement node in each statement node mapping pair in the initial one-to-many node mapping set.
[0138] Step S52, respectively, the original pair of multiple node mapping set in each statement node mapping pair corresponding to the original file statement node semantic vector, target file statement node semantic vector cosine similarity calculation, output the original pair of multiple node mapping set in each statement node mapping pair corresponding semantic vector cosine similarity;
[0139] Step S53, comparing the original pair of multiple node mapping set in each statement node mapping pair corresponding semantic vector cosine similarity and the preset cosine similarity threshold;
[0140] Step S54, any greater than the preset cosine similarity threshold of semantic vector cosine similarity corresponding statement node mapping pair as the original pair of multiple node mapping pair;
[0141] Step S55, using the graph neural network algorithm according to multiple original pair of multiple node mapping pairs, output each original pair of multiple node mapping pair in the original file statement node corresponding original file statement node graph embedding vector, each initial cross file node mapping pair in the target file statement node corresponding target file statement node graph embedding vector;
[0142] Step S56, based on each original pair of multiple node mapping pair in the original file statement node corresponding original file statement node graph embedding vector, each initial cross file node mapping pair in the target file statement node corresponding target file statement node graph embedding vector cosine similarity calculation, output each original pair of multiple node mapping pair corresponding graph embedding vector cosine similarity;
[0143] Step S57, using attention network according to each original pair of multiple node mapping pair corresponding graph embedding vector cosine similarity, semantic vector cosine similarity, output each original pair of multiple node mapping pair corresponding semantic vector weight, graph feature vector weight;
[0144] Step S58, according to each original pair of multiple node mapping pair corresponding semantic vector weight, graph feature vector weight, graph embedding vector cosine similarity, semantic vector cosine similarity, calculate each original pair of multiple node mapping pair corresponding one-to-many weighted similarity.
[0145] It should be noted that the pre-trained model UniXcoder is used to generate the original file statement node semantic vector and target file statement node semantic vector for each original node and all its target nodes, and the cosine similarity between the original node and each candidate target node is calculated: . Wherein, is the semantic vector cosine similarity; is the cosine similarity calculation.
[0146] Further, filter out the sentence pairs with a threshold less than 0.8 (preset cosine similarity threshold) to exclude surface similar but semantically irrelevant sentence pairs, thereby obtaining a plurality of initial one-to-many node mapping pairs.
[0147] Further, abstract syntax graphs are generated for all remaining sentence pairs, and the node features and edge features of the abstract syntax graphs are input into GraphSAGE to obtain graph embedding vectors of the original sentences and graph embedding vectors of the target sentence nodes , and calculate the cosine similarity graph_sim between them.
[0148] Further, the weight distribution of semantic_sim and graph_sim is automatically measured using a neural network based on an attention mechanism, and a one-to-many weighted similarity Similarity2 is obtained.
[0149] Similarity2= semantic_sim+ graph_sim.
[0150] Step 106, based on the respective cross-file weighted similarities of the initial cross-file node mapping pairs and the respective one-to-many weighted similarities of the initial one-to-many node mapping pairs, respectively, screen and analyze, and output code file difference analysis results corresponding to the target cross-file node mapping pairs and the target one-to-many node mapping pairs.
[0151] Specifically, step 106 can include the following sub-steps S61-S64:
[0152] Step S61, respectively compare the cross-file weighted similarities corresponding to the initial cross-file node mapping pairs with the preset first similarity threshold;
[0153] Step S62, any initial cross-file node mapping pair corresponding to a cross-file weighted similarity greater than or equal to the preset first similarity threshold is taken as a target cross-file node mapping pair, and the code file difference analysis result associated with the target cross-file node mapping pair is determined to exist cross-file mapping.
[0154] Step S63, respectively compare the one-to-many weighted similarities corresponding to the initial one-to-many node mapping pairs with the preset second similarity threshold;
[0155] Step S64, taking the initial one-to-many node mapping pair corresponding to any one pair of multi-weighted similarities greater than or equal to the preset second similarity threshold as a target one-to-many node mapping pair, and determining the code file difference analysis result associated with the target one-to-many node mapping pair as existing one-to-many mapping.
[0156] It should be noted that if the weighted similarity between the original sentence and the target sentence is greater than or equal to the set threshold 0.75 (preset first similarity threshold), it can be marked as cross-file mapping. In addition, there is a special case of cross-file mapping. In actual scenarios, the migration of sentences can not only be from one original file to another target file, but also can be migrated to multiple different target files at the same time. That is, the same original sentence can also exist in multiple target files with the same cross-file mapping.
[0157] Further, if Similarity2 is greater than or equal to the threshold 0.8 (preset second similarity threshold), it is considered that the original code block (sentence) and the plurality of target code blocks (sentences) determined currently exist one-to-many mapping.
[0158] It is worth mentioning that the present application designs a simple and intuitive output format that is easy for users to understand, which helps users understand the concept of cross-file and one-to-many mapping. According to the cross-file and one-to-many node mapping results output by the above steps, a structured text file is systematically generated to record the node mapping information between the original file and the target file. As shown in Figure 2 Cross-file mapping output and Figure 3 one-to-many mapping output,
[0159] As a comparison of technical effects, reference can be made to the prior art. The existing file difference analysis algorithms can be roughly divided into three categories: line (Line) difference analysis algorithm, graph (Graph) difference analysis algorithm and tree (Tree) difference analysis algorithm.
[0160] Line difference analysis algorithm: the file is divided into lines, and the longest common subsequence (LCS) algorithm is used to identify the difference. This algorithm is simple to implement and efficient, but it can only compare the content of the whole line. For example, changes in indentation, different line breaks, and other format changes will also be considered as differences, which makes it difficult to capture structural differences.
[0161] Graph difference analysis algorithm: the file is modeled as a graph structure, such as a control flow graph or a dependency graph. This algorithm is suitable for analyzing complex dependency relationships and high-level structural changes in programs, but it is complex to implement and has high computational overhead.
[0162] Tree difference analysis algorithm: Its main type is AST difference analysis, which is used to describe how to transform the tree structure of the source file into the tree structure of the target file. The basic method is to compare the AST nodes of the source file and the target file and generate an editing script. Generally, it includes three steps: AST construction, AST node mapping and AST editing script generation. The difference between different algorithms is mainly in the first two steps, and the third step is generally implemented by a general algorithm. Based on the AST difference analysis method, a new algorithm is proposed to optimize and improve the existing AST difference analysis process. The existing mainstream AST difference analysis algorithm includes: GumTree (GT), MTDiff (MTD), IJM, iASTMapper.
[0163] GT is an AST node mapping algorithm based on a two-stage strategy. The first stage uses a top-down greedy algorithm to map equal sub-trees to ensure that matching sub-trees are quickly found in higher level nodes. The second stage uses a bottom-up algorithm to map nodes that share a large number of mapped descendants. GT algorithm has limited mapping accuracy when dealing with complex scenarios such as refactoring or cross-file migration, especially in variable renaming scenarios, which is prone to mismatch.
[0164] MTD is a fine-grained node mapping algorithm based on sub-tree pruning and multi-granularity classification. First, an equal sub-tree optimization algorithm is used to remove unchanged sub-trees from the AST to reduce the amount of data processed. Then, the ChangeDistiller algorithm [6] is used to divide nodes into different types, and combined with editing distance calculation and other methods to perform more detailed node mapping. MTD algorithm has insufficient flexibility in cross-file scenarios due to its reliance on complex node information, and ChangeDistiller algorithm may have unstable matching problems in cases where the syntax tree changes significantly.
[0165] IJM is a hierarchical mapping algorithm based on name node merging and declaration splitting. First, the values of name nodes (such as nodes representing variable names and function names) are merged into their parent nodes to simplify the AST, and then the AST is split along the declaration statement nodes and the GT algorithm is used to map the nodes in each split part. IJM algorithm easily splits the context semantic environment, resulting in mapping omissions and mismatches in cross-file or refactoring scenarios.
[0166] iASTMapper is an iterative mapping algorithm based on similarity measurement rules. AST nodes are divided into three levels: statements, internal statements, and words. Heuristic rules are applied to iteratively map nodes at these three levels. The heuristic rules designed by iASTMapper are difficult to cover variable code refactoring patterns, and do not consider mapping in cross-file scenarios.
[0167] Based on the above foundation, the existing code file difference analysis method has a common technical problem: only considering single file revision difference analysis, and being limited to one-to-one mapping between the original file and the target file, ignoring the one-to-many mapping caused by code splitting and refactoring in reality, and the cross-file mapping situation brought by a single revision involving multiple files (i.e. file group revision), such as the code statements in an original file being moved to multiple target files. Figure 4 A specific example of cross-file mapping is shown. The start() method declaration statement and method body in the original file "Original File 1" do not have a node mapping that meets the conditions in its corresponding target file "Target File 1", but there are node mappings that meet the similarity threshold in the other two target files "Target File 3" and "Target File 4".
[0168] Further, as shown in Figure 5 , Figure 5 A specific example of one-to-many mapping is shown. The processData() method in the original file "OriginalFile1" is split into two methods, validateData() and transformData(), which are mapped to the target files "Target File2" and "Target File3", respectively.
[0169] Therefore, the existing code file difference analysis algorithm has two main shortcomings: first, it only focuses on single code file revision difference analysis and cannot detect cross-file code migration and update in the code file group revision scenario; second, it only considers one-to-one mapping of AST nodes, ignoring the possible one-to-many mapping situation.
[0170] To solve the above technical problems, the present application proposes a code file difference analysis method, denoted as XFDiff, by deeply analyzing the characteristics of file group revision and cross-file and one-to-many mapping. Specifically, please refer to Figure 6 The present application takes Java code file (group) revision as input and outputs the structured representation of cross-file and one-to-many mapping. The XFDiff algorithm includes four steps: 1) iterative mapping based on AST nodes; 2) cross-file mapping; 3) one-to-many mapping; 4) cross-file and one-to-many mapping output. Among them, step 1) preprocesses the input file group revision, and after sub-steps: AST parsing and node extraction, equal node mapping and similarity-based iterative node mapping, a set of node mapping sets is constructed. The mapping pairs in this set may not be accurate in the cross-file mapping scenario. Therefore, the present application proposes a more accurate cross-file mapping algorithm, which can obtain an accurate cross-file mapping output for any given cross-file input.
[0171] Further, the method proposed by the present application can capture code migration and refactoring between different files, and can be better applied to complex code change analysis, defect positioning and repair, etc. To enhance the interpretability of the method results and the user understanding efficiency, the present application further designs a hierarchical output structure for displaying the cross-file and one-to-many statement mapping results. As shown below Figure 3 The output file of cross-file mapping adopts a hierarchical organization structure, which is divided into three levels. The first level is named by the unique identifier commitId as a unit of each independent file group revision. Each commitId corresponds to a set of cross-file mapping results. The second level is the file pair (File Pair) name, which represents the original file (srcFile) and the target file (dstFile) that exist cross-file mapping. This level is recorded in the form of srcFile: <original file path> and dstFile: <target file path>. The third level is the cross-file statement mapping pair, which lists each pair of cross-file mapping statements in the format of original statement → target statement. Note that if there are multiple target file paths and only one set of statement pairs, it means that the original code is migrated to multiple target files, as shown in the lower part of Figure 2 The output file of one-to-many mapping adopts a double-column form as a unit of each independent file group revision. As shown in Figure 3 Each one-to-many mapping is composed of left and right columns. The left column shows the original file path and the original code block; the right column shows the reconstructed or split multiple target code block set, including the target file path and the split target code block. In addition, the present application extends the difference analysis from the mapping between the original AST and the corresponding target AST in the single file revision scenario to the mapping between each original AST and multiple target ASTs in the file group revision scenario. A method for evaluating the accuracy of cross-file and one-to-many mapping is designed. XFDiff can filter out the most accurate cross-file and one-to-many mapping output for any given set of inaccurate cross-file AST inputs.
[0172] Compared with existing mainstream file mapping / code change tracking algorithms (such as GT, MTD, IJM, iASTDAnalyzer), the present application realizes a cross-file and one-to-many mapping mechanism, can perform code correlation analysis among multiple files, and thus captures complex code migration, splitting, cloning and functional expansion and other diversified change modes. Specifically, the present application constructs three types of feature vectors, namely semantic vectors, graph embedding vectors and bag-of-words vectors, fuses multi-dimensional features such as semantics, logical structure and statement similarity, uses a trained neural network to dynamically evaluate weighted similarity, and identifies cross-file code statement mapping, and supports one-to-many migration scenarios. At the same time, the present application generates two types of feature vectors based on semantics and logical structure, namely semantic vectors and graph embedding vectors, and dynamically allocates weights to the two types of feature vectors according to a trained neural network, comprehensively evaluates the weighted similarity value, and identifies one-to-many logical mapping in code splitting. In addition, the present application provides a simple and intuitive structured output form to assist users in understanding the concept of cross-file and one-to-many mapping.
[0173] In the embodiment of the present application, the present application provides a code file difference analysis method, acquires a code file group, and pre-processes an original code file and a plurality of target code files corresponding to the original code file in the code file group to generate an initial one-to-one node mapping set and an initial one-to-many node mapping set; judges whether the original file statement node and the target file statement node in each statement node mapping pair in the initial one-to-one node mapping set belong to different code files; takes any original file statement node and target file statement node pair corresponding to a statement node mapping pair belonging to different code files as an initial cross-file node mapping pair; uses a code representation learning technology to calculate the weighted similarity of each initial cross-file node mapping pair according to the initial cross-file node mapping pairs; based on the code representation learning technology, screens and calculates the weighted similarity of a plurality of statement node mapping pairs in the initial one-to-many node mapping set to determine the one-to-many weighted similarity corresponding to the plurality of initial one-to-many node mapping pairs; respectively screens and analyzes the cross-file weighted similarity corresponding to each initial cross-file node mapping pair and the one-to-many weighted similarity corresponding to each initial one-to-many node mapping pair, and respectively outputs the code file difference analysis result corresponding to a plurality of target cross-file node mapping pairs and the code file difference analysis result corresponding to a plurality of target one-to-many node mapping pairs; based on the above scheme, the single / multiple mapping set is generated by pre-processing, the cross-file node pair is identified, the weighted similarity (cross-file weighted similarity, one-to-many weighted similarity) is calculated by using the code representation learning, and finally the difference analysis result is output. The present application can capture code migration and reconstruction between different files, and can be better applied to complex code change analysis, defect positioning and repair and other tasks.
[0174] Please refer to Figure 7 , Figure 7A structural block diagram of a code file difference analysis device provided for embodiment two of the present application.
[0175] The present application provides a code file difference analysis device, comprising:
[0176] The acquisition module 701 is configured to acquire a code file group, and pre-process an original code file and a plurality of target code files corresponding to the original code file in the code file group to generate an initial one-to-one node mapping set and an initial one-to-many node mapping set.
[0177] The judgment module 702 is configured to judge whether the original file statement node and the target file statement node in the plurality of statement node mapping pairs in the initial one-to-one node mapping set belong to different code files.
[0178] The output module 703 is configured to take the statement node mapping pair corresponding to any original file statement node and target file statement node belonging to different code files as an initial cross-file node mapping pair.
[0179] The first calculation module 704 is configured to perform weighted similarity calculation according to each initial cross-file node mapping pair by using a code representation learning technology to determine the cross-file weighted similarity corresponding to each initial cross-file node mapping pair.
[0180] The second calculation module 705 is configured to perform screening and weighted similarity calculation on the plurality of statement node mapping pairs in the initial one-to-many node mapping set based on the code representation learning technology to determine the one-to-many weighted similarity corresponding to the plurality of initial one-to-many node mapping pairs.
[0181] The generation module 706 is configured to perform screening and analysis based on the cross-file weighted similarity corresponding to each initial cross-file node mapping pair and the one-to-many weighted similarity corresponding to each initial one-to-many node mapping pair, respectively, and output the code file difference analysis result corresponding to the plurality of target cross-file node mapping pairs and the code file difference analysis result corresponding to the plurality of target one-to-many node mapping pairs, respectively.
[0182] Further, the acquisition module 701 is specifically configured to:
[0183] The original code file and the plurality of target code files corresponding to the original code file are parsed to generate an original file abstract syntax tree of the original code file and a target file abstract syntax tree of each target code file.
[0184] The original file abstract syntax tree and each target file abstract syntax tree are extracted to generate a plurality of original file abstract syntax tree nodes corresponding to the original file abstract syntax tree and a plurality of target file abstract syntax tree nodes corresponding to each target file abstract syntax tree.
[0185] determine whether the label data and value data of each original file abstract syntax tree node corresponding to the original code file are same as the label data and value data of each target file abstract syntax tree node corresponding to the target code file;
[0186] perform equal node mapping on the original file abstract syntax tree node and the target file abstract syntax tree node which are same in any label data and value data, to generate a plurality of equal node mapping pairs;
[0187] perform similarity-based iterative node mapping on the original file abstract syntax tree node and the target file abstract syntax tree node which are not same in any label data or value data, to generate a plurality of candidate one-to-one node mapping pairs;
[0188] construct an initial one-to-one node mapping set according to the plurality of candidate one-to-one node mapping pairs and the plurality of equal node mapping pairs;
[0189] perform similarity calculation on the original file abstract syntax tree node and the target file abstract syntax tree node which are not same in any label data or value data, to output a plurality of similarity values;
[0190] compare each similarity value with a preset similarity threshold value;
[0191] perform node mapping on the original file abstract syntax tree node and the target file abstract syntax tree node corresponding to any similarity value greater than or equal to the preset similarity threshold value, to output a plurality of candidate one-to-many node mapping pairs;
[0192] construct an initial one-to-many node mapping set according to the plurality of candidate one-to-many node mapping pairs and the plurality of equal node mapping pairs;
[0193] The original file abstract syntax tree node includes an original file statement node, an original file internal statement node, and an original file word node. The target file abstract syntax tree node includes a target file statement node, a target file internal statement node, and a target file word node. The equal node mapping pair includes a statement node mapping pair, an internal statement node mapping pair, and a word node mapping pair which are same in label data and value data. The candidate one-to-one node mapping pair and the candidate one-to-many node mapping pair each include a statement node mapping pair, an internal statement node mapping pair, and a word node mapping pair which are not same in label data or value data.
[0194] Further, the code representation learning technology includes a code-oriented multi-modal pre-training model, a graph neural network algorithm, and an attention network. The first computing module 704 includes:
[0195] The first sub-module is configured to perform language vectorization on the original file statement nodes and the target file statement nodes in each initial cross-file node mapping pair based on the code-oriented multi-modal pre-training model, to generate an original file statement node semantic vector corresponding to each original file statement node in each initial cross-file node mapping pair, and a target file statement node semantic vector corresponding to each target file statement node in each initial cross-file node mapping pair.
[0196] The second sub-module is configured to output an original file statement node graph embedding vector corresponding to each original file statement node in each initial cross-file node mapping pair and a target file statement node graph embedding vector corresponding to each target file statement node in each initial cross-file node mapping pair by using a graph neural network algorithm based on the plurality of initial cross-file node mapping pairs.
[0197] The third sub-module is configured to perform word segmentation and deduplication on the original file statements corresponding to the original file statement nodes and the target file statements corresponding to the target file statement nodes in each initial cross-file node mapping pair, to generate a bag-of-words table corresponding to each initial cross-file node mapping pair.
[0198] The fourth sub-module is configured to generate an original file statement node bag-of-words vector corresponding to each original file statement node in each initial cross-file node mapping pair and a target file statement node bag-of-words vector corresponding to each target file statement node in each initial cross-file node mapping pair based on the bag-of-words table corresponding to each initial cross-file node mapping pair.
[0199] The fifth sub-module is configured to normalize the original file statement node semantic vector, the target file statement node semantic vector, the original file statement node graph embedding vector, the target file statement node graph embedding vector, the original file statement node bag-of-words vector, and the target file statement node bag-of-words vector corresponding to each initial cross-file node mapping pair, to output a normalized original file statement node semantic vector, a normalized target file statement node semantic vector, a normalized original file statement node graph embedding vector, a normalized target file statement node graph embedding vector, a normalized original file statement node bag-of-words vector, and a normalized target file statement node bag-of-words vector corresponding to each initial cross-file node mapping pair.
[0200] The sixth sub-module is configured to calculate a semantic vector cosine similarity, a graph embedding vector cosine similarity, and a bag-of-words vector cosine similarity corresponding to each initial cross-file node mapping pair based on the normalized original file statement node semantic vector, the normalized target file statement node semantic vector, the normalized original file statement node graph embedding vector, the normalized target file statement node graph embedding vector, the normalized original file statement node bag-of-words vector, and the normalized target file statement node bag-of-words vector corresponding to each initial cross-file node mapping pair.
[0201] the seventh submodule is configured to respectively splice the semantic vector cosine similarity, the graph embedding vector cosine similarity, and the bag-of-words vector cosine similarity of each initial cross-file node mapping pair, and output a similarity feature vector corresponding to each initial cross-file node mapping pair;
[0202] the eighth submodule is configured to output a semantic vector weight, a graph feature vector weight, and a bag-of-words vector weight corresponding to each initial cross-file node mapping pair according to the similarity feature vector corresponding to each initial cross-file node mapping pair by using an attention network;
[0203] the ninth submodule is configured to calculate a cross-file weighted similarity corresponding to each initial cross-file node mapping pair by using the semantic vector cosine similarity, the graph embedding vector cosine similarity, the bag-of-words vector cosine similarity, the semantic vector weight, the graph feature vector weight, and the bag-of-words vector weight corresponding to each initial cross-file node mapping pair.
[0204] Further, the second submodule is specifically configured to:
[0205] generate an abstract syntax graph according to the original file statement node and the target file statement node in the plurality of initial cross-file node mapping pairs by using a graph neural network algorithm;
[0206] generate an original file statement node graph embedding vector corresponding to the original file statement node in each initial cross-file node mapping pair and a target file statement node graph embedding vector corresponding to the target file statement node in each initial cross-file node mapping pair based on the node features and the edge features in the abstract syntax graph.
[0207] Further, the second calculation module 705 is specifically configured to:
[0208] perform language vectorization on the original file statement node and the target file statement node in each statement node mapping pair in the initial one-to-many node mapping set based on the code-oriented multi-modal pre-training model, and generate an original file statement node semantic vector corresponding to the original file statement node in each statement node mapping pair in the initial one-to-many node mapping set and a target file statement node semantic vector corresponding to the target file statement node in each statement node mapping pair in the initial one-to-many node mapping set;
[0209] perform cosine similarity calculation on the original file statement node semantic vector and the target file statement node semantic vector corresponding to each statement node mapping pair in the initial one-to-many node mapping set, and output a semantic vector cosine similarity corresponding to each statement node mapping pair in the initial one-to-many node mapping set;
[0210] compare the semantic vector cosine similarity corresponding to each statement node mapping pair in the initial one-to-many node mapping set with a preset cosine similarity threshold;
[0211] mapping pair corresponding to any semantic vector cosine similarity greater than the preset cosine similarity threshold as an initial one-to-many node mapping pair;
[0212] adopting a graph neural network algorithm to output a source file sentence node graph embedding vector corresponding to a source file sentence node in each initial one-to-many node mapping pair and a target file sentence node graph embedding vector corresponding to a target file sentence node in each initial cross-file node mapping pair according to the plurality of initial one-to-many node mapping pairs and the plurality of initial cross-file node mapping pairs;
[0213] performing cosine similarity calculation based on the source file sentence node graph embedding vector corresponding to the source file sentence node in each initial one-to-many node mapping pair and the target file sentence node graph embedding vector corresponding to the target file sentence node in each initial cross-file node mapping pair to output a graph embedding vector cosine similarity corresponding to each initial one-to-many node mapping pair;
[0214] adopting an attention network to output a semantic vector weight and a graph feature vector weight corresponding to each initial one-to-many node mapping pair according to the graph embedding vector cosine similarity and the semantic vector cosine similarity corresponding to each initial one-to-many node mapping pair;
[0215] calculating a one-to-many weighted similarity corresponding to each initial one-to-many node mapping pair according to the semantic vector weight, the graph feature vector weight, the graph embedding vector cosine similarity, and the semantic vector cosine similarity corresponding to each initial one-to-many node mapping pair.
[0216] Further, the generating module 706 is specifically configured to:
[0217] respectively compare the cross-file weighted similarities corresponding to the plurality of initial cross-file node mapping pairs with a preset first similarity threshold;
[0218] mapping pair corresponding to any cross-file weighted similarity greater than or equal to the preset first similarity threshold as a target cross-file node mapping pair, and determining the code file difference analysis result associated with the target cross-file node mapping pair as existing cross-file mapping;
[0219] respectively compare the one-to-many weighted similarities corresponding to the plurality of initial one-to-many node mapping pairs with a preset second similarity threshold;
[0220] mapping pair corresponding to any one-to-many weighted similarity greater than or equal to the preset second similarity threshold as a target one-to-many node mapping pair, and determining the code file difference analysis result associated with the target one-to-many node mapping pair as existing one-to-many mapping.
[0221] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices, modules and sub-modules can refer to the corresponding processes in the foregoing method embodiments, which will not be described here.
[0222] The embodiment of the present application further provides a computer device, comprising a memory and a processor, the memory stores a computer program; the computer program is executed by the processor, so that the processor executes the steps of the code file difference analysis method according to any one of the foregoing embodiments.
[0223] The embodiment of the present application further provides a computer readable storage medium, which stores a computer program / instruction, and the computer program / instruction is executed by a processor to realize the steps of the code file difference analysis method according to any one of the foregoing embodiments.
[0224] The embodiment of the present application further provides a computer program product, which comprises a computer program / instruction, and the computer program / instruction is executed by a processor to realize the steps of the code file difference analysis method according to any one of the foregoing embodiments.
[0225] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented by other manners. For example, the apparatus embodiments described above are only schematic, for example, the division of units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interfaces, apparatuses or units, and can be electrical, mechanical or other forms.
[0226] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, that is, they can be located in one place, or can be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.
[0227] The above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced by equivalents; and these modifications 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 application.
Claims
1. A method of code file difference analysis, characterized by, The method comprises the following steps: acquire a code file group, and preprocess original code files in the code file group and a plurality of target code files corresponding to the original code files, to generate an initial one-to-one node mapping set and an initial one-to-many node mapping set; determine whether the original file statement nodes and the target file statement nodes in the plurality of statement node mapping pairs in the initial one-to-one node mapping set belong to different code files; take any original file statement node and target file statement node pair corresponding to the statement node mapping pair belonging to different code files as an initial cross-file node mapping pair; perform weighted similarity calculation on each initial cross-file node mapping pair according to a code representation learning technology to determine a cross-file weighted similarity corresponding to each initial cross-file node mapping pair; based on the code representation learning technology, perform screening and weighted similarity calculation on a plurality of statement node mapping pairs in the initial one-to-many node mapping set to determine a one-to-many weighted similarity corresponding to a plurality of initial one-to-many node mapping pairs; based on the cross-file weighted similarity corresponding to each initial cross-file node mapping pair and the one-to-many weighted similarity corresponding to each initial one-to-many node mapping pair, respectively perform screening and analysis, and output a code file difference analysis result corresponding to a plurality of target cross-file node mapping pairs and a code file difference analysis result corresponding to a plurality of target one-to-many node mapping pairs.
2. The code file difference analysis method according to claim 1, characterized by, The preprocessing of the original code files in the code file group and the plurality of target code files corresponding to the original code files to generate the initial one-to-one node mapping set and the initial one-to-many node mapping set comprises the following steps: parse the original code files and the plurality of target code files corresponding to the original code files to generate an original file abstract syntax tree of the original code files and a target file abstract syntax tree of each target code file; extract nodes from the original file abstract syntax tree and each target file abstract syntax tree respectively to generate a plurality of original file abstract syntax tree nodes corresponding to the original file abstract syntax tree and a plurality of target file abstract syntax tree nodes corresponding to each target file abstract syntax tree; determine whether the label data and value data of each original file abstract syntax tree node corresponding to the original code files are the same as the label data and value data of each target file abstract syntax tree node corresponding to each target code file; perform equal node mapping on any original file abstract syntax tree node and target file abstract syntax tree node with the same label data and value data to generate a plurality of equal node mapping pairs; perform similarity-based iterative node mapping on any original file abstract syntax tree node and target file abstract syntax tree node with different label data or value data to generate a plurality of candidate one-to-one node mapping pairs; construct an initial one-to-one node mapping set according to the plurality of candidate one-to-one node mapping pairs and the plurality of equal node mapping pairs; perform similarity calculation on any original file abstract syntax tree node and target file abstract syntax tree node with different label data or value data to output a plurality of similarity values; compare each similarity value with a preset similarity threshold value; mapping the original file abstract syntax tree node and the target file abstract syntax tree node corresponding to any similarity value greater than or equal to the preset similarity threshold, outputting a plurality of candidate one-to-many node mapping pairs; constructing an initial one-to-many node mapping set according to the plurality of candidate one-to-many node mapping pairs and the plurality of equal node mapping pairs; The original file abstract syntax tree node includes an original file statement node, an original file internal statement node, and an original file word node. The target file abstract syntax tree node includes a target file statement node, a target file internal statement node, and a target file word node. The equal node mapping pair includes a statement node mapping pair, an internal statement node mapping pair, and a word node mapping pair with the same label data and value data. The candidate one-to-one node mapping pair and the candidate one-to-many node mapping pair each include a statement node mapping pair, an internal statement node mapping pair, and a word node mapping pair with different label data or value data.
3. The code file difference analysis method of claim 1, wherein, The code representation learning technology includes a code-oriented multi-modal pre-training model, a graph neural network algorithm, and an attention network. The code representation learning technology is used to perform weighted similarity calculation according to the initial cross-file node mapping pairs to determine cross-file weighted similarities corresponding to the initial cross-file node mapping pairs, including: Based on the code-oriented multi-modal pre-training model, language vectorization is performed on the original file statement node and the target file statement node in each initial cross-file node mapping pair to generate an original file statement node semantic vector corresponding to the original file statement node in each initial cross-file node mapping pair and a target file statement node semantic vector corresponding to the target file statement node in each initial cross-file node mapping pair. The graph neural network algorithm is used to output an original file statement node graph embedding vector corresponding to the original file statement node in each initial cross-file node mapping pair and a target file statement node graph embedding vector corresponding to the target file statement node in each initial cross-file node mapping pair according to the plurality of initial cross-file node mapping pairs. Tokenization and deduplication are performed on the original file statement corresponding to the original file statement node and the target file statement corresponding to the target file statement node in each initial cross-file node mapping pair to generate a bag-of-words table corresponding to each initial cross-file node mapping pair. Based on the bag-of-words table corresponding to each initial cross-file node mapping pair, an original file statement node bag-of-words vector corresponding to the original file statement node in each initial cross-file node mapping pair and a target file statement node bag-of-words vector corresponding to the target file statement node in each initial cross-file node mapping pair are generated. normalize the corresponding original file statement node semantic vector, the target file statement node semantic vector, the original file statement node graph embedding vector, the target file statement node graph embedding vector, the original file statement node bag of words vector, and the target file statement node bag of words vector of each of the initial cross-file node mapping pairs, and output the normalized original file statement node semantic vector, the normalized target file statement node semantic vector, the normalized original file statement node graph embedding vector, the normalized target file statement node graph embedding vector, the normalized original file statement node bag of words vector, and the normalized target file statement node bag of words vector corresponding to each of the initial cross-file node mapping pairs; calculate the semantic vector cosine similarity, the graph embedding vector cosine similarity, and the bag of words vector cosine similarity corresponding to each of the initial cross-file node mapping pairs based on the normalized original file statement node semantic vector, the normalized target file statement node semantic vector, the normalized original file statement node graph embedding vector, the normalized target file statement node graph embedding vector, the normalized original file statement node bag of words vector, and the normalized target file statement node bag of words vector corresponding to each of the initial cross-file node mapping pairs; concatenate the semantic vector cosine similarity, the graph embedding vector cosine similarity, and the bag of words vector cosine similarity corresponding to each of the initial cross-file node mapping pairs, and output the similarity feature vector corresponding to each of the initial cross-file node mapping pairs; output the semantic vector weight, the graph feature vector weight, and the bag of words vector weight corresponding to each of the initial cross-file node mapping pairs using the attention network based on the similarity feature vector corresponding to each of the initial cross-file node mapping pairs; calculate the cross-file weighted similarity corresponding to each of the initial cross-file node mapping pairs using the semantic vector cosine similarity, the graph embedding vector cosine similarity, the bag of words vector cosine similarity, the semantic vector weight, the graph feature vector weight, and the bag of words vector weight corresponding to each of the initial cross-file node mapping pairs.
4. The code file difference analysis method according to claim 3, characterized by, The method for outputting the original file statement node graph embedding vector corresponding to the original file statement node in each of the initial cross-file node mapping pairs and the target file statement node graph embedding vector corresponding to the target file statement node in each of the initial cross-file node mapping pairs based on the plurality of initial cross-file node mapping pairs using the graph neural network algorithm comprises: generating an abstract syntax graph based on the original file statement node and the target file statement node in each of the plurality of initial cross-file node mapping pairs using the graph neural network algorithm; generating the original file statement node graph embedding vector corresponding to the original file statement node in each of the initial cross-file node mapping pairs and the target file statement node graph embedding vector corresponding to the target file statement node in each of the initial cross-file node mapping pairs based on the node features and edge features in the abstract syntax graph.
5. The code file difference analysis method according to claim 3, characterized by, The method for screening and calculating the weighted similarity of a plurality of statement node mapping pairs in the initial one-to-many node mapping set based on the code representation learning technology and determining a one-to-many weighted similarity corresponding to a plurality of initial one-to-many node mapping pairs comprises: Based on the code-oriented multi-modal pre-training model, the original file sentence nodes and the target file sentence nodes in a plurality of sentence node mapping pairs in the initial one-to-many node mapping set are respectively language vectorized to generate an original file sentence node semantic vector corresponding to an original file sentence node in each sentence node mapping pair in the initial one-to-many node mapping set and a target file sentence node semantic vector corresponding to a target file sentence node in each sentence node mapping pair in the initial one-to-many node mapping set; The original file sentence node semantic vectors and the target file sentence node semantic vectors corresponding to each sentence node mapping pair in the initial one-to-many node mapping set are respectively subjected to cosine similarity calculation to output semantic vector cosine similarities corresponding to each sentence node mapping pair in the initial one-to-many node mapping set; The semantic vector cosine similarities corresponding to each sentence node mapping pair in the initial one-to-many node mapping set are compared with a preset cosine similarity threshold; Any sentence node mapping pair corresponding to a semantic vector cosine similarity greater than the preset cosine similarity threshold is taken as an initial one-to-many node mapping pair; The graph neural network algorithm is used to output an original file sentence node graph embedding vector corresponding to an original file sentence node in each initial one-to-many node mapping pair and a target file sentence node graph embedding vector corresponding to a target file sentence node in each initial cross-file node mapping pair based on a plurality of initial one-to-many node mapping pairs; Cosine similarity calculation is performed on the original file sentence node graph embedding vectors corresponding to each initial one-to-many node mapping pair and the target file sentence node graph embedding vectors corresponding to each initial cross-file node mapping pair to output graph embedding vector cosine similarities corresponding to each initial one-to-many node mapping pair; The attention network is used to output a semantic vector weight and a graph feature vector weight corresponding to each initial one-to-many node mapping pair based on the graph embedding vector cosine similarities and the semantic vector cosine similarities corresponding to each initial one-to-many node mapping pair; A one-to-many weighted similarity corresponding to each initial one-to-many node mapping pair is calculated based on the semantic vector weight, the graph feature vector weight, the graph embedding vector cosine similarity, and the semantic vector cosine similarity corresponding to each initial one-to-many node mapping pair.
6. The code file difference analysis method of claim 1, wherein, The initial cross-file node mapping pairs and the initial one-to-many node mapping pairs are respectively screened and analyzed based on the cross-file weighted similarities corresponding to the initial cross-file node mapping pairs and the one-to-many weighted similarities corresponding to the initial one-to-many node mapping pairs to respectively output code file difference analysis results corresponding to a plurality of target cross-file node mapping pairs and code file difference analysis results corresponding to a plurality of target one-to-many node mapping pairs, including: The cross-file weighted similarities corresponding to each initial cross-file node mapping pair are compared with a preset first similarity threshold; corresponding to any of the initial cross-file node mapping pairs with a cross-file weighted similarity greater than or equal to the preset first similarity threshold is taken as a target cross-file node mapping pair, and a code file difference analysis result associated with the target cross-file node mapping pair is determined as existing cross-file mapping; a one-to-many weighted similarity corresponding to any of the initial one-to-many node mapping pairs greater than or equal to the preset second similarity threshold is compared with a preset second similarity threshold; corresponding to any of the initial one-to-many node mapping pairs with a one-to-many weighted similarity greater than or equal to the preset second similarity threshold is taken as a target one-to-many node mapping pair, and a code file difference analysis result associated with the target one-to-many node mapping pair is determined as existing one-to-many mapping.
7. A code file difference analysis apparatus characterized by comprising: The method comprises: an acquisition module configured to acquire a code file group, and pre-process an original code file and a plurality of target code files corresponding to the original code file in the code file group to generate an initial one-to-one node mapping set and an initial one-to-many node mapping set; a judgment module configured to judge whether original file statement nodes and target file statement nodes in a plurality of statement node mapping pairs in the initial one-to-one node mapping set belong to different code files; an output module configured to take any statement node mapping pair corresponding to original file statement nodes and target file statement nodes belonging to different code files as an initial cross-file node mapping pair; a first calculation module configured to perform weighted similarity calculation on each of the initial cross-file node mapping pairs according to a code representation learning technique to determine a cross-file weighted similarity corresponding to each of the initial cross-file node mapping pairs; a second calculation module configured to perform screening and weighted similarity calculation on a plurality of statement node mapping pairs in the initial one-to-many node mapping set based on the code representation learning technique to determine a one-to-many weighted similarity corresponding to a plurality of initial one-to-many node mapping pairs; a generation module configured to perform screening and analysis based on the cross-file weighted similarity corresponding to each of the initial cross-file node mapping pairs and the one-to-many weighted similarity corresponding to each of the initial one-to-many node mapping pairs, respectively, and output a code file difference analysis result corresponding to a plurality of target cross-file node mapping pairs and a code file difference analysis result corresponding to a plurality of target one-to-many node mapping pairs, respectively.
8. A computer device, comprising: The computer program is executed to implement the code file difference analysis method according to any one of claims 1-6.
9. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed to implement the code file difference analysis method according to any one of claims 1-6.
10. A computer program product, characterised in that, The computer program product comprises a computer program stored on a non-transitory computer-readable storage medium, and the computer program comprises program instructions, wherein when the program instructions are executed by a computer, the computer executes the code file difference analysis method according to any one of claims 1-6.