Service code version difference identification method and system based on syntax tree structure features
By dividing the syntax tree into node clusters and combining functions, hierarchical relationships, and data input nodes, service code version differences can be identified, solving the problem of high computational cost caused by full comparison and achieving efficient and accurate difference identification.
Patent Information
- Application Number
- CN202511325871.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-17
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2045-09-17
AI Technical Summary
In existing technologies for service code version management, the full traversal comparison method results in a large comparison task, and incremental comparison requires additional calibration tools and involves a large amount of data processing, making it difficult to efficiently identify differences between syntax trees.
By dividing the syntax tree into multiple node clusters, combining the functions, hierarchical relationships, and data input nodes within the node clusters, the system identifies difference nodes, reduces the number of comparison nodes, and identifies differences through iteration and semantic features.
It improves the efficiency and accuracy of code version difference identification, reduces the consumption of computing resources, and can quickly identify substantial differences between code versions.
Smart Images

Figure CN120821497A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and more particularly to a method and system for identifying service code version differences based on syntax tree structural features. Background Art
[0002] In service code version management, traditional code comparison methods are mostly based on the code content itself. However, in the current syntax tree comparison method, the full traversal comparison method leads to a large comparison task. Even if incremental comparison is adopted, additional calibration tools (such as version upgrade tables and version upgrade instructions) are required, and each node within the scope still needs to be compared one by one. Moreover, if semantic analysis is used to assist the comparison, the data processing volume is also large. Therefore, the existing technology has shortcomings. Summary of the Invention
[0003] In view of the shortcomings of the existing technology, the purpose of the present invention is to provide a method and system for identifying service code version differences based on syntax tree structural characteristics, which can identify the differences between syntax trees with fewer nodes and thus obtain the differences between code versions.
[0004] To achieve the above object, the present invention provides the following technical solutions:
[0005] The present invention provides a method for identifying service code version differences based on syntax tree structural features, comprising:
[0006] Obtain a first syntax tree and a second syntax tree, where the first syntax tree and the second syntax tree are abstract syntax trees corresponding to two service codes that need to be compared;
[0007] Dividing the first syntax tree into a plurality of node clusters according to structural characteristics of the first syntax tree;
[0008] Different nodes are identified in the second syntax tree according to the functions, hierarchical relationships, and data input nodes corresponding to each parent node in the plurality of node clusters.
[0009] As a further improvement of the present invention, identifying difference nodes in the second syntax tree according to the functions, hierarchical relationships, and data input nodes corresponding to each parent node in the plurality of node clusters includes:
[0010] For each parent node in the plurality of node clusters, identifying a corresponding node in the second syntax tree according to its corresponding function and hierarchical relationship;
[0011] Eliminate the parent node of the corresponding node from each parent node to obtain a different parent node;
[0012] A difference node is identified in the second syntax tree based on the difference parent node and its corresponding data input node.
[0013] As a further improvement of the present invention, identifying a difference node in the second syntax tree according to the difference parent node and its corresponding data input node includes:
[0014] Acquire nodes within a preset distance from each of the difference parent nodes, and obtain a node group corresponding to each of the difference parent nodes;
[0015] For the node group, a first iterative operation is performed, which includes taking out the current first node group from all current node groups according to a first preset rule, obtaining the data input node corresponding to the current first node group, and identifying the difference node corresponding to the current first node group in the second syntax tree according to the data corresponding to the data input node, until the preset first number of iterations is reached, and outputting all difference nodes.
[0016] As a further improvement of the present invention, identifying, in the second syntax tree, the difference node corresponding to the current first node group according to the data corresponding to the data input node includes:
[0017] Identifying, in the second syntax tree, a second node corresponding to the current first node group according to the data corresponding to the data input node;
[0018] A difference node corresponding to the current first node group is obtained according to the semantic features of the current first node group and the second node.
[0019] As a further improvement of the present invention, identifying, in the second syntax tree, a second node corresponding to the current first node group according to the data corresponding to the data input node, includes:
[0020] sorting the data corresponding to the data input nodes according to a hierarchical relationship to obtain a first data group;
[0021] identifying, based on the first data group, in the second syntax tree, a second data group having the highest similarity to the first data group;
[0022] The node corresponding to the second data group is used as the second node corresponding to the current first node group.
[0023] As a further improvement of the present invention, identifying, based on the first data group, in the second syntax tree, a second data group having the highest similarity to the first data group includes:
[0024] Obtaining the number of data included in the first data group and the data corresponding to all data input nodes in the second syntax tree;
[0025] Arrange and combine the data corresponding to all the data input nodes according to the quantity to obtain a plurality of third data groups;
[0026] According to the similarity between the first data group and each third data group, the third data group with the highest similarity is selected as the second data group.
[0027] As a further improvement of the present invention, extracting the current first node group from all current node groups according to the first preset rule includes:
[0028] Get the first node group corresponding to all difference nodes at the current iteration number;
[0029] Determining a selection area according to positions of the first node groups corresponding to all the difference nodes;
[0030] Among all the current node groups, the node group closest to the selected area is selected as the current first node group.
[0031] As a further improvement of the present invention, for each parent node in the plurality of node clusters, identifying a corresponding node in the second syntax tree according to its corresponding function and hierarchical relationship includes:
[0032] For each parent node, a second iterative operation is performed, which includes taking out the current first node from each current parent node according to a second preset rule, obtaining the function and hierarchical relationship corresponding to the current first node, and using the nodes in the second syntax tree that have the same function and hierarchical relationship as the corresponding nodes of the current first node, until the preset second number of iterations is reached, and outputting all corresponding nodes.
[0033] As a further improvement of the present invention, extracting the current first node from each current parent node according to the second preset rule includes:
[0034] Randomly select a node from each of the current parent nodes as the current first node;
[0035] Alternatively, a node with the most child nodes is taken from each current parent node as the current first node.
[0036] The present invention provides a service code version difference identification system based on syntax tree structural features, comprising:
[0037] An acquisition module, configured to acquire a first syntax tree and a second syntax tree, where the first syntax tree and the second syntax tree are abstract syntax trees corresponding to two service codes that need to be compared;
[0038] a partitioning module, configured to partition the first syntax tree into a plurality of node clusters according to structural features of the first syntax tree;
[0039] An identification module is configured to identify difference nodes in the second syntax tree according to functions, hierarchical relationships, and data input nodes corresponding to each parent node in the plurality of node clusters.
[0040] The present invention divides the syntax tree into multiple node clusters, identifies differences based on each parent node in the node cluster, and increases the granularity of comparison from a single node to a node cluster, thereby reducing the number of nodes that need to be compared. At the same time, by combining functions, hierarchical relationships and data input nodes, the difference nodes can be identified more accurately, thereby obtaining the differences between code versions. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 is a flow chart of the steps of the present invention;
[0042] Figure 2 is a schematic diagram of the structure of the first syntax tree;
[0043] Figure 3 is a schematic diagram of the structure of the second syntax tree;
[0044] Figure 4 Schematic diagram of the difference parent node;
[0045] Figure 5 is a schematic diagram of the first node group;
[0046] Figure 6 is a schematic diagram of the selected area;
[0047] Figure 7 Schematic diagram of the implementation scenario. DETAILED DESCRIPTION
[0048] The technical solution of the present invention is described in detail below through the accompanying drawings and specific embodiments. It should be understood that the embodiments of the present invention and the specific features in the embodiments are detailed descriptions of the technical solution of the present invention, rather than limitations of the technical solution of the present invention.
[0049] Identical components are denoted by the same reference numerals. It should be noted that the terms "front," "rear," "left," "right," "upper," and "lower" used in the following description refer to directions in the accompanying drawings, and the terms "bottom," "top," "inner," and "outer" refer to directions toward or away from the geometric center of a particular component, respectively.
[0050] The term "and / or" in the following text simply describes an association between related objects, indicating that three possible relationships exist. For example, "A and / or B" can represent: A exists alone, A and B exist simultaneously, or B exists alone. Additionally, the character " / " generally indicates an "or" relationship between the related objects.
[0051] like Figure 1 As shown, the embodiment of the present application provides a method for identifying service code version differences based on syntax tree structure features, including:
[0052] Obtain a first syntax tree and a second syntax tree, where the first syntax tree and the second syntax tree are abstract syntax trees corresponding to two service codes that need to be compared;
[0053] Dividing the first syntax tree into a plurality of node clusters according to structural characteristics of the first syntax tree;
[0054] Different nodes are identified in the second syntax tree based on the functions, hierarchical relationships, and data input nodes corresponding to each parent node in the plurality of node clusters.
[0055] This embodiment does not limit the selection of the first syntax tree, that is, any one of the abstract syntax trees (ASTs) corresponding to the two service codes can be selected as the first syntax tree, and the other as the second syntax tree.
[0056] For example, Figure 2 As shown in the figure, the syntax tree corresponding to the operation "(3+5)×(8-4)÷2+7-1×(6+9-10)" is used as the first syntax tree, where each line of the syntax tree corresponds to a level, for example, the last line corresponds to level 1, and the first line corresponds to level 6. According to the structure of the first syntax tree, the first syntax tree can be divided into multiple node clusters (such as Figure 2 Each dotted box in represents a node cluster), where Figure 2 In the figure, not all node clusters are outlined with dotted lines. Each node cluster includes two generations of nodes, that is, nodes at two levels, and each node cluster includes a parent node and at least one child node, as shown in Figure 2 In the node cluster in the lower left corner, the parent node is "add(+)" and the child nodes are "3" and "5." For this parent node in this node cluster, the corresponding function is the addition function (add), the hierarchical relationship is level 2, and the data input nodes are the child nodes "3" and "5" of this node. While this embodiment uses the syntax tree corresponding to simple arithmetic operations as an example, this application is not limited to this. The abstract syntax tree corresponding to any service code can be applied to the methods provided in this embodiment.
[0057] This embodiment divides the syntax tree into multiple node clusters, identifies differences based on each parent node in the node cluster, and increases the granularity of comparison from a single node to a node cluster, thereby reducing the number of nodes that need to be compared. At the same time, by combining functions, hierarchical relationships, and data input nodes, it can more accurately identify difference nodes and thus obtain the differences between code versions.
[0058] Furthermore, the present application provides a step of identifying difference nodes in a second syntax tree based on functions, hierarchical relationships, and data input nodes corresponding to each parent node in a plurality of node clusters, including:
[0059] For each parent node in the plurality of node clusters, identifying a corresponding node in the second syntax tree according to its corresponding function and hierarchical relationship;
[0060] Eliminate the parent nodes that have corresponding nodes from each parent node to obtain the difference parent nodes;
[0061] A difference node is identified in the second syntax tree based on the difference parent node and its corresponding data input node.
[0062] Furthermore, this embodiment provides a step of identifying, for each parent node in the plurality of node clusters, a corresponding node in the second syntax tree according to its corresponding function and hierarchical relationship, including:
[0063] For each parent node, a second iterative operation is performed. The second iterative operation includes taking out the current first node from each current parent node according to the second preset rule, obtaining the function and hierarchical relationship corresponding to the current first node, and using the node in the second syntax tree that has the same function and hierarchical relationship as the corresponding node of the current first node, until the preset second iteration number is reached, and outputting all corresponding nodes.
[0064] Among them, the second preset rule can be randomly selected, or selected according to the number of child nodes, that is, a node can be randomly selected from each current parent node as the current first node; or the node with the most child nodes can be selected from each current parent node as the current first node; the preset second number of iterations can be set to the number of node clusters in the first syntax tree, that is, all parent nodes need to be traversed, and the corresponding second preset rule is random selection; the second number of iterations can also be less than the number of node clusters in the first syntax tree, and the corresponding second preset rule is selection based on the number of child nodes. This embodiment does not limit this number.
[0065] For example, for the first iteration, each parent node is composed of the parent nodes in each node cluster in the first syntax tree, and then a parent node is randomly taken from each parent node. Assume that the current first node taken is Figure 2The parent node "add(+)" in the lower left node cluster is obtained, and the function and hierarchical relationship corresponding to the parent node are obtained. The corresponding node of the parent node can be found in the second syntax tree. Figure 3 As shown, this is the syntax tree corresponding to the "(4+6)+(9-7)×3-2×(8-5+1)" operation, which is used as the second syntax tree. Figure 3 The corresponding node is in the dashed box to the left of . The function and hierarchical relationship corresponding to this node are the same as those of the current first node. Next, the second iteration is performed. Since one node has already been extracted in the first iteration, the number of nodes in each parent node is reduced by one compared to the previous iteration. Repeat the above steps until the preset second iteration number is reached, obtaining all corresponding nodes and, in turn, all parent nodes that have corresponding nodes.
[0066] Then, the parent nodes of the corresponding nodes are removed from each parent node to obtain the difference parent nodes. For example, for the first syntax tree, the parent nodes of the corresponding nodes are as follows: Figure 4 As shown in the dotted box in , the parent nodes corresponding to each node cluster in the first syntax tree are removed from the parent nodes where the corresponding nodes exist, and the difference parent nodes are obtained, as shown in Figure 4 Shown in the solid line box.
[0067] This embodiment uses the functions and hierarchical relationships corresponding to each parent node to identify corresponding nodes in the second syntax tree. It then further filters out different parent nodes from each parent node based on the corresponding nodes. Finally, it identifies different nodes in the second syntax tree based on the different parent nodes and the data input nodes, ultimately determining the differences between the code corresponding to the two syntax trees. In large code bases, there is relatively little code that undergoes substantial changes between versions. Therefore, this embodiment can quickly narrow the node range through functions and hierarchical relationships. Compared to the existing method that requires comparing all nodes, this method can avoid the subsequent meaningless identification of a large number of nodes, thereby reducing the amount of comparison and improving recognition efficiency.
[0068] In addition, this embodiment sets two methods for selecting the current first node according to the number of iterations, namely random selection and selection according to the number of child nodes. When the preset second number of iterations can be the number of node clusters in the first syntax tree, all parent nodes can be quickly traversed by random selection, thereby improving recognition efficiency. For scenarios with larger code scales, the structure of the corresponding syntax tree is also relatively complex, and traversing all parent nodes will consume a lot of time and computing resources. Therefore, this embodiment selects according to the number of child nodes, that is, giving priority to nodes with complex structures and containing more logical information, thereby saving time and computing resources while ensuring recognition accuracy.
[0069] Furthermore, this embodiment provides a step of identifying a difference node in the second syntax tree based on the difference parent node and its corresponding data input node, including:
[0070] Get the nodes within a preset distance from each difference parent node, and obtain the node group corresponding to each difference parent node;
[0071] For the node group, a first iterative operation is performed. The first iterative operation includes taking out the current first node group from all current node groups according to the first preset rule, obtaining the data input node corresponding to the current first node group, and identifying the difference node corresponding to the current first node group in the second syntax tree according to the data corresponding to the data input node, until the preset first number of iterations is reached, and outputting all difference nodes.
[0072] The preset distance is the number of levels of difference, and the nodes within the preset distance should also be parent nodes in the node cluster and have a connection relationship with the difference parent node. For example, Figure 5 The difference parent node "div(÷)" in the preset distance is one layer, and its corresponding nodes within the preset distance are "add(+)" and " ”, and its corresponding node group is , where the order of nodes in the node group is arranged from large to small according to the level, such as Figure 5 As shown in the dotted box in the figure; if the preset distance is two layers, the corresponding nodes within the preset distance are "sub(-)", "add(+)", " " and "add(+)", the corresponding node groups are ,like Figure 5 As shown in the solid box.
[0073] The data input node corresponding to the current first node group is the child node corresponding to each node in the current first node group. For example, if the current first node group is , the child nodes corresponding to “add(+)” are “div(÷)” and “7”, and the child nodes corresponding to “div(÷)” are “ ” and “2”, “ "The corresponding child nodes are "add(+)" and "sub(-)". Since "div(÷)" and " " already exists in the current first node group, so "7", "2", "add(+)" and "sub(-)" are used as data input nodes corresponding to the current first node group.
[0074] This embodiment comprehensively considers the contextual information around the difference parent node through the node group, and further determines the difference node by analyzing the data input node corresponding to the node group. The data input node is a key factor in the execution of code logic, and the change of its data often directly reflects the change of code logic. Therefore, this embodiment can further accurately identify the difference node through the data input node.
[0075] Furthermore, this embodiment provides a step of identifying, in the second syntax tree, a difference node corresponding to the current first node group based on data corresponding to the data input node, including:
[0076] According to the data corresponding to the data input node, a second node corresponding to the current first node group is identified in the second syntax tree;
[0077] According to the semantic features of the current first node group and the second node, a difference node corresponding to the current first node group is obtained.
[0078] The data corresponding to the data input node is the data input at the node, for example Figure 5 The data corresponding to the data input node "7" is the number 7. Since the example in this embodiment is a simple arithmetic operation, the name of the node is the same as the data. However, in most cases, the name of the node is different from the data. For example, if a node is the first data set, the data corresponding to the node is all the data in the set. If the data input node is a function or code, for example Figure 5 , the data corresponding to the data input node is the data obtained after the function operation. Specifically, there may be multiple second nodes, and the semantic characteristics include internal logic and implementation functions.
[0079] This embodiment focuses on the input data to avoid interference in difference identification caused by subtle changes in the code syntax (such as variable name modification, comment addition, etc.), thereby more accurately locating the second node associated with the current first node group, and then combining semantic features to further accurately identify the difference nodes. Even if the input data of the current first node group and the second node are the same, but their internal logic and implementation functions are different, they will still be treated as difference nodes.
[0080] Furthermore, this embodiment provides a step of identifying a second node corresponding to the current first node group in the second syntax tree according to data corresponding to the data input node, including:
[0081] Sort the data corresponding to the data input node according to the hierarchical relationship to obtain a first data group;
[0082] Based on the first data group, identifying in the second syntax tree a second data group having the highest similarity to the first data group;
[0083] The node corresponding to the second data group is used as the second node corresponding to the current first node group.
[0084] For example, if the current first node group is , the data input nodes corresponding to the current first node group are "7", "2", "add(+)" and "sub(-)". The data corresponding to the data input nodes are sorted from high to low according to the hierarchical relationship, and the first data group obtained is [7,2,add(+),sub(-)], where "add(+)" and "sub(-)" in the first data group represent the data obtained after function operation.
[0085] In this embodiment, the data corresponding to the data input node is sorted according to the hierarchical relationship to form a first data group. In the code, data at different levels often have different logical meanings and dependencies. The hierarchical relationship reflects the organizational structure and execution order of the code. By retaining the hierarchical information, the intrinsic connection between the data can be captured more accurately, and then the second data group can be identified based on this relationship.
[0086] Furthermore, this embodiment provides a step of identifying, in a second syntax tree, a second data group having the highest similarity to the first data group based on the first data group, including:
[0087] Obtaining the number of data included in the first data group and the data corresponding to all data input nodes in the second syntax tree;
[0088] Arrange and combine the data corresponding to all the data input nodes according to the quantity to obtain multiple third data groups;
[0089] According to the similarity between the first data group and each third data group, the third data group with the highest similarity is selected as the second data group.
[0090] The similarity calculation method can be adjusted according to specific application scenarios and requirements. For example, in some cases, more emphasis may be placed on the content similarity of the data, while in other cases, more emphasis may be placed on the order or structure similarity of the data.
[0091] For example, when the first data group is [7,2,add(+),sub(-)], the number of data contained in the first data group is 4. At this time, the data corresponding to all the data input nodes in the second syntax tree are obtained and these data are arranged and combined to obtain multiple third data groups. Each third data group includes 4 data. For example, the third data groups that can be combined are [3,2,8,5], [5,8,9,6] and [6,7,6,5]. Then, based on the similarity between the first data group and each third data group, the third data group with the highest similarity is selected as the second data group. According to the comparison result, the second data group is [2,add(+),sub(-),7]. Figure 3 As shown in the dotted box on the right, "add(+)" and "sub(-)" also represent the data obtained after function operation.
[0092] Then obtain the node corresponding to the second data group. Specifically, the node corresponding to the second data group is the parent node of the data input node corresponding to each data in the second data group. Figure 3 It can be seen that the node corresponding to the second data group [2, add (+), sub (-), 7] is " ”, “add(+)” and “sub(-)”, and use it as the second node corresponding to the current first node group. Finally, the semantic features of the first node group and the second node are compared. Through comparison, it is found that the internal logic and implementation functions of the first node group and the second node are different at this time. Therefore, the second node is used as the difference node corresponding to the current first node group. If the semantic comparison result is the same, there is no corresponding difference node in the current first node group.
[0093] This embodiment arranges and combines the data corresponding to all data input nodes in the second syntax tree according to the quantity, generates multiple third data groups, and obtains the second data group based on the similarity, fully considering the quantity information and possible combinations of the data. In addition, the screening method based on similarity comparison provided by this embodiment can comprehensively consider multiple factors such as the content and sequence of the data, rather than relying solely on a single feature. At the same time, the method provided by this embodiment can be applied to various types of abstract syntax trees, whether they are simple linear data structures or complex nested structures, as long as the data corresponding to the data input nodes can be obtained and arranged and combined and similarity calculated.
[0094] Furthermore, this embodiment provides a step of extracting a current first node group from all current node groups according to a first preset rule, including:
[0095] Get the first node group corresponding to all difference nodes at the current iteration number;
[0096] Determine the selection area according to the positions of the first node groups corresponding to all the difference nodes;
[0097] Among all current node groups, the node group closest to the selected area is selected as the current first node group.
[0098] Among them, the current first node group is taken out from all current node groups according to the first preset rule, that is, the current first node group is taken out from all current node groups according to the selected area. The node group closest to the selected area is the node group that overlaps with the selected area; if there is no node group that overlaps with the selected area, the node group closest to the selected area is the node group that passes through the least nodes to reach the selected area; if there are multiple node groups that overlap with the selected area, one is randomly selected from these node groups as the current first node group. In addition, since multiple iterations are required, new difference nodes will be obtained in each iteration, so the difference nodes under each iteration number may be different. In the first iteration, that is, when the current iteration number is 1, since there is no difference node at this time, one can be randomly selected from all current node groups as the current first node group. And the current first node group selected in each iteration should be different.
[0099] For example, assuming that the preset distance is one layer, and at the current number of iterations, the first node group of the difference nodes determined is and ,like Figure 6 As shown in the dotted box, the selected area is the area included in the two dotted boxes. Assume that the current node group includes [sub(-), add(+), div(÷)], and ,like Figure 6 The solid box in the middle shows this. Since [sub(-), add(+), div(÷)] overlaps with the selected area, this node group is the current first node group. If multiple selected areas exist, the area with the most nodes is selected for subsequent analysis.
[0100] This embodiment determines the selected area based on the positions of the first node groups corresponding to all difference nodes. When computing resources are limited and it is impossible to traverse all node groups, the method provided by this embodiment prioritizes areas with larger changes and selects the first node group near the area for identification to ensure the accuracy of difference identification. Therefore, since it is impossible to traverse all node groups, the first number of iterations can be set by those skilled in the art based on computing resources.
[0101] For further understanding, the following is a general usage scenario to illustrate the above steps as a whole, such as Figure 7 As shown, Figure 7 Case (a) is the first syntax tree, Figure 7 Case (b) is the second syntax tree obtained by modifying the code corresponding to the first syntax tree. Figure 7 The numbers on the left represent the corresponding hierarchical relationships. The purpose of this example is to find the difference nodes in the second syntax tree.
[0102] First, the first syntax tree is divided into multiple node clusters, and the parent nodes in each node cluster are parent node 2, parent node 3, and parent node 4 respectively. Then, according to the hierarchical relationship corresponding to each parent node and the function of the function or code, the corresponding node is determined in the second syntax tree. Assuming that there are corresponding nodes between parent node 2 and parent node 4, the difference parent node is parent node 3 at this time. Assuming that the preset distance is 1 layer, the node group corresponding to the difference parent node is [parent node 4, parent node 3, parent node 2], and the data input nodes corresponding to the node group are child node 1, child node 2, and child node 3. Then, the first data group is obtained according to the data corresponding to the data input node, and the second data group is obtained according to the similarity test. Assuming that the second data group is child node 11, child node 12, and child node 3 in the second syntax tree, the second node is parent node 2 and parent node 4 in the second syntax tree. Then, a semantic comparison is performed. If the semantics of this node group are the same as those of the second node, it means that the input data, internal logic, and implementation functions of this node group and the second node are the same. Although this part of the code has changed, its actual function has not changed. At this time, the second node is not a difference node, and it is considered that there is no substantial difference between the second syntax tree and the first syntax tree. Otherwise, the second node is regarded as a difference node, and the position of the difference node is the position where the code has substantially changed.
[0103] In summary, the solution provided by this embodiment includes first dividing the first syntax tree into multiple node clusters, and for each parent node in the node cluster, determining the corresponding node in the second syntax tree according to its corresponding hierarchical relationship and the function of the function or code, and further obtaining the difference parent node, and then generating a node group based on the difference parent node, for example, taking the parent node N, parent node N-1 and parent node N+1 as a node group, and then performing a similarity test on the data input node corresponding to the node group, finding the second node with the highest similarity for semantic test, and finally determining the difference node. Through the above overall solution, this embodiment can reduce the amount of comparison while ensuring recognition accuracy.
[0104] Furthermore, an embodiment of the present application provides a service code version difference identification system based on syntax tree structure features, including:
[0105] An acquisition module, configured to acquire a first syntax tree and a second syntax tree, where the first syntax tree and the second syntax tree are abstract syntax trees corresponding to two service codes that need to be compared;
[0106] a partitioning module, configured to partition the first syntax tree into a plurality of node clusters according to structural features of the first syntax tree;
[0107] The identification module is configured to identify difference nodes in the second syntax tree according to functions, hierarchical relationships, and data input nodes corresponding to each parent node in the plurality of node clusters.
[0108] An embodiment of the present application provides a method and system for identifying service code version differences based on syntax tree structural features. The method divides a first syntax tree into multiple node clusters, and filters difference parent nodes from the parent nodes in each node cluster. Finally, code differences are identified based on the difference parent nodes. Compared with the method in the prior art that requires node-by-node identification, the embodiment of the present application only uses fewer nodes for identification, reducing the amount of comparison. In addition, the embodiment takes into account the limitations of computing resources and sets different selection schemes when selecting the current first node and the current first node group to ensure the accuracy of identification while saving computing resources.
[0109] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0110] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0111] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0112] The above description is merely a preferred embodiment of the present invention. The scope of protection of the present invention is not limited to the above embodiment. All technical solutions based on the concept of the present invention are within the scope of protection of the present invention. It should be noted that for those skilled in the art, various improvements and modifications that do not depart from the principles of the present invention should also be considered within the scope of protection of the present invention.
Claims
1. A method for identifying service code version differences based on syntax tree structure features, characterized in that: include: Obtain a first syntax tree and a second syntax tree, where the first syntax tree and the second syntax tree are abstract syntax trees corresponding to two service codes that need to be compared; Dividing the first syntax tree into a plurality of node clusters according to structural characteristics of the first syntax tree; Different nodes are identified in the second syntax tree according to the functions, hierarchical relationships, and data input nodes corresponding to each parent node in the plurality of node clusters.
2. The method for identifying service code version differences based on syntax tree structure features according to claim 1, characterized in that: Identifying difference nodes in the second syntax tree according to the functions, hierarchical relationships, and data input nodes corresponding to each parent node in the plurality of node clusters includes: For each parent node in the plurality of node clusters, identifying a corresponding node in the second syntax tree according to its corresponding function and hierarchical relationship; Eliminate the parent node of the corresponding node from each parent node to obtain a different parent node; A difference node is identified in the second syntax tree based on the difference parent node and its corresponding data input node.
3. The method for identifying service code version differences based on syntax tree structure features according to claim 2, characterized in that: Identifying a difference node in the second syntax tree according to the difference parent node and its corresponding data input node includes: Acquire nodes within a preset distance from each of the difference parent nodes, and obtain a node group corresponding to each of the difference parent nodes; For the node group, a first iterative operation is performed, which includes taking out the current first node group from all current node groups according to a first preset rule, obtaining the data input node corresponding to the current first node group, and identifying the difference node corresponding to the current first node group in the second syntax tree according to the data corresponding to the data input node, until the preset first number of iterations is reached, and outputting all difference nodes.
4. The method for identifying service code version differences based on syntax tree structure features according to claim 3, characterized in that: Identifying, in the second syntax tree, a difference node corresponding to the current first node group according to the data corresponding to the data input node, includes: Identifying, in the second syntax tree, a second node corresponding to the current first node group according to the data corresponding to the data input node; A difference node corresponding to the current first node group is obtained according to the semantic features of the current first node group and the second node.
5. The method for identifying service code version differences based on syntax tree structure features according to claim 4, characterized in that: Identifying, in the second syntax tree according to the data corresponding to the data input node, a second node corresponding to the current first node group, including: sorting the data corresponding to the data input nodes according to a hierarchical relationship to obtain a first data group; identifying, based on the first data group, in the second syntax tree, a second data group having the highest similarity to the first data group; The node corresponding to the second data group is used as the second node corresponding to the current first node group.
6. The method for identifying service code version differences based on syntax tree structure features according to claim 5, characterized in that: Identifying, based on the first data group, in the second syntax tree, a second data group having the highest similarity to the first data group, comprising: Obtaining the number of data included in the first data group and the data corresponding to all data input nodes in the second syntax tree; Arrange and combine the data corresponding to all the data input nodes according to the quantity to obtain a plurality of third data groups; According to the similarity between the first data group and each third data group, the third data group with the highest similarity is selected as the second data group.
7. The method for identifying service code version differences based on syntax tree structure features according to claim 3, characterized in that: The extracting the current first node group from all current node groups according to the first preset rule includes: Get the first node group corresponding to all difference nodes at the current iteration number; Determining a selection area according to positions of the first node groups corresponding to all the difference nodes; Among all the current node groups, the node group closest to the selected area is selected as the current first node group.
8. The method for identifying service code version differences based on syntax tree structure features according to claim 2, characterized in that: For each parent node in the plurality of node clusters, identifying a corresponding node in the second syntax tree according to its corresponding function and hierarchical relationship includes: For each parent node, a second iterative operation is performed, which includes taking out the current first node from each current parent node according to a second preset rule, obtaining the function and hierarchical relationship corresponding to the current first node, and using the nodes in the second syntax tree that have the same function and hierarchical relationship as the corresponding nodes of the current first node, until the preset second number of iterations is reached, and outputting all corresponding nodes.
9. The method for identifying service code version differences based on syntax tree structure features according to claim 8, characterized in that: The extracting the current first node from each current parent node according to the second preset rule includes: Randomly select a node from each of the current parent nodes as the current first node; Alternatively, a node with the most child nodes is taken from each current parent node as the current first node.
10. A service code version difference identification system based on syntax tree structure features, characterized in that: include: An acquisition module, configured to acquire a first syntax tree and a second syntax tree, where the first syntax tree and the second syntax tree are abstract syntax trees corresponding to two service codes that need to be compared; a partitioning module, configured to partition the first syntax tree into a plurality of node clusters according to structural features of the first syntax tree; An identification module is configured to identify difference nodes in the second syntax tree according to functions, hierarchical relationships, and data input nodes corresponding to each parent node in the plurality of node clusters.
Citation Information
Patent Citations
Software defect prediction method for open source software defect feature deep learning
CN110597735A
Difference generation method and device, difference display method and device, equipment and storage medium
CN117539752A
Method for Analyzing Changes in a Software Code and Software Analysis System
US20130152046A1
