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.

CN120821497BActive Publication Date: 2025-12-05JIANGSU GUOXIN DIGITAL INTELLIGENCE SERVICE CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202511325871.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-17
Publication Date
2025-12-05
Estimated Expiration
2045-09-17

AI Technical Summary

Technical Problem

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.

Method used

By dividing the syntax tree into multiple node clusters, and combining the functions, hierarchical relationships, and data input nodes within the node clusters, the system identifies difference nodes, reduces the number of nodes to be compared, and accurately locates difference nodes through iteration and similarity calculation.

Benefits of technology

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.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120821497B_ABST
    Figure CN120821497B_ABST
Patent Text Reader

Abstract

The application discloses a service code version difference identification method and system based on syntax tree structure features, and belongs to the technical field of computers, and the technical solution points are as follows: a first syntax tree and a second syntax tree are acquired, the first syntax tree and the second syntax tree are abstract syntax trees corresponding to two service codes needing difference comparison respectively; the first syntax tree is divided into multiple node clusters according to the structure features of the first syntax tree; and difference nodes are identified in the second syntax tree according to functions, hierarchical relationships and data input nodes corresponding to each parent node in the multiple node clusters.The application divides the syntax tree into multiple node clusters, identifies differences according to each parent node in the node clusters, further selects comparison nodes according to the parent nodes, that is, the comparison range is further reduced, and finally, the difference nodes are identified according to the comparison nodes, so that the limitation of global comparison is avoided, the comparison amount is reduced, and the difference nodes are accurately determined.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, more particularly, to a service code version difference identification method and system based on syntax tree structure features. BACKGROUND

[0002] In service code version management, the traditional code comparison method is mainly based on code content itself, however, in the current syntax tree comparison method, the full traversal comparison method leads to the problem of large comparison task amount, even if incremental comparison is used, additional calibration tools (such as version upgrade table, version upgrade description) are needed, and each node still needs to be compared one by one within the scope, and if semantic analysis is used to assist comparison at the same time, the data processing amount is also large, therefore, the prior art has defects. SUMMARY

[0003] In view of the defects of the prior art, the purpose of the present application is to provide a service code version difference identification method and system based on syntax tree structure features, which can identify the differences between syntax trees through fewer nodes, and then obtain the differences between code versions.

[0004] To achieve the above purpose, the present application provides the following technical scheme:

[0005] The present application provides a service code version difference identification method based on syntax tree structure features, comprising:

[0006] Obtaining a first syntax tree and a second syntax tree, the first syntax tree and the second syntax tree are respectively the abstract syntax trees corresponding to two service codes which need to be compared for differences;

[0007] According to the structure features of the first syntax tree, the first syntax tree is divided into a plurality of node clusters;

[0008] According to the function, hierarchical relationship and data input node corresponding to each parent node in the plurality of node clusters, a difference node is identified in the second syntax tree.

[0009] As a further improvement of the present application, according to the function, hierarchical relationship and data input node corresponding to each parent node in the plurality of node clusters, a difference node is identified in the second syntax tree, comprising:

[0010] For each parent node in the plurality of node clusters, according to the function and hierarchical relationship corresponding thereto, a corresponding node is identified in the second syntax tree;

[0011] The parent node with the corresponding node is eliminated from each parent node to obtain a difference parent node;

[0012] According to the difference parent node and the corresponding data input node, a difference node is identified in the second syntax tree.

[0013] According to the difference parent node and the corresponding data input node, a difference node is identified in the second syntax tree.

[0014] A node group corresponding to each difference parent node is obtained by acquiring nodes within a preset distance from each difference parent node.

[0015] A first iteration operation is performed on the node group, and the first iteration operation includes: taking a current first node group from all current node groups according to a first preset rule, acquiring a data input node corresponding to the current first node group, identifying a difference node corresponding to the current first node group in the second syntax tree according to data corresponding to the data input node, and outputting all difference nodes until a preset first iteration number is reached.

[0016] According to the data corresponding to the data input node, a difference node corresponding to the current first node group is identified in the second syntax tree.

[0017] 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.

[0018] According to semantic features of the current first node group and the second node, a difference node corresponding to the current first node group is obtained.

[0019] 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.

[0020] The data corresponding to the data input node is sorted according to a hierarchical relationship to obtain a first data group.

[0021] According to the first data group, a second data group with the highest similarity to the first data group is identified in the second syntax tree.

[0022] The node corresponding to the second data group is taken as the second node corresponding to the current first node group.

[0023] According to the first data group, a second data group with the highest similarity to the first data group is identified in the second syntax tree.

[0024] The number of data contained in the first data group and data corresponding to all data input nodes in the second syntax tree are obtained.

[0025] According to the quantity, the data corresponding to all data input nodes are arranged and combined to obtain a plurality of third data groups;

[0026] According to the similarity between the first data group and each third data group, a third data group with the highest similarity is selected as the second data group.

[0027] As a further improvement of the application, the current first node group is taken out from the current all node groups according to a first preset rule, comprising:

[0028] The first node groups corresponding to all difference nodes at the current iteration number are obtained;

[0029] According to the positions of the first node groups corresponding to all difference nodes, a selection area is determined;

[0030] In the current all node groups, the node group closest to the selection area is selected as the current first node group.

[0031] As a further improvement of the application, for each parent node in the plurality of node clusters, a corresponding node in the second syntax tree is identified according to the function and hierarchical relationship corresponding thereto, comprising:

[0032] For each parent node, a second iteration operation is performed, the second iteration operation comprising: taking out a current first node from the current each parent node according to a second preset rule, obtaining the function and hierarchical relationship corresponding to the current first node, taking the node in the second syntax tree which is identical to the function and hierarchical relationship as the corresponding node of the current first node, until a preset second iteration number is reached, and outputting all corresponding nodes.

[0033] As a further improvement of the application, the current first node is taken out from the current each parent node according to a second preset rule, comprising:

[0034] A node is randomly taken out from the current each parent node as the current first node;

[0035] Or the node with the most child nodes is taken out from the current each parent node as the current first node.

[0036] The application provides a service code version difference identification system based on syntax tree structure characteristics, comprising:

[0037] An acquisition module is configured to acquire a first syntax tree and a second syntax tree, the first syntax tree and the second syntax tree being abstract syntax trees corresponding to two service codes to be compared for differences;

[0038] The dividing module is configured to divide the first syntax tree into a plurality of node clusters according to structural features of the first syntax tree.

[0039] The identifying module is configured to identify a difference node in the second syntax tree according to a function, a hierarchical relationship and a data input node corresponding to each parent node in the plurality of node clusters.

[0040] The present application divides a syntax tree into a plurality of node clusters, identifies differences according to each parent node in the node clusters, improves the granularity of comparison from a single node to a node cluster, reduces the number of nodes that need to be compared, and, in combination with a function, a hierarchical relationship and a data input node, more accurately identifies a difference node and further obtains differences between code versions. BRIEF DESCRIPTION OF DRAWINGS

[0041] Figure 1 A step flowchart of the present application is shown in FIG. 1.

[0042] Figure 2 A structural schematic diagram of a first syntax tree is shown in FIG. 2.

[0043] Figure 3 A structural schematic diagram of a second syntax tree is shown in FIG. 3.

[0044] Figure 4 A schematic diagram of a difference parent node is shown in FIG. 4.

[0045] Figure 5 A schematic diagram of a first node group is shown in FIG. 5.

[0046] Figure 6 A schematic diagram of a selected area is shown in FIG. 6.

[0047] Figure 7 An implementation scenario is shown in FIG. 7. DETAILED DESCRIPTION

[0048] The technical solutions of the present application are described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the embodiments and specific features in the embodiments are detailed descriptions of the technical solutions of the present application, rather than limitations of the technical solutions of the present application.

[0049] The same components are denoted by the same reference numerals. It should be noted that the words “front”, “back”, “left”, “right”, “up” and “down” used in the following description refer to the directions in the drawings, and the words “bottom” and “top”, “inner” and “outer” refer to the directions towards or away from the geometric center of a specific component.

[0050] The term "and / or" in the following description is only a description of the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B can represent the three cases of A alone, A and B together, and B alone. In addition, the character " / " generally represents that the associated objects before and after it are in an "or" relationship.

[0051] As Figure 1 indicated, the embodiment of the present application provides a service code version difference identification method based on syntax tree structure characteristics, comprising:

[0052] obtaining a first syntax tree and a second syntax tree, the first syntax tree and the second syntax tree being abstract syntax trees corresponding to two service codes needing to be compared for differences;

[0053] According to the structure characteristics of the first syntax tree, the first syntax tree is divided into a plurality of node clusters;

[0054] According to the function, hierarchical relationship and data input node corresponding to each parent node in the plurality of node clusters, a difference node is identified in the second syntax tree.

[0055] Wherein, the selection of the first syntax tree in the embodiment is not limited, that is, any one of the abstract syntax trees (AST) corresponding to the two service codes can be selected as the first syntax tree, and the other as the second syntax tree.

[0056] As Figure 2 indicated, it is the syntax tree corresponding to the operation of "(3+5)×(8-4)÷2+7-1×(6+9-10)", which is taken as the first syntax tree, wherein each row of the syntax tree corresponds to a level, for example, the last row corresponds to level 1, and the first row corresponds to level 6. According to the structure of the first syntax tree, the first syntax tree can be divided into a plurality of node clusters (each dotted box in Figure 2 indicates a node cluster), wherein Figure 2 all node clusters in Figure 2 are not boxed with dotted lines, each node cluster includes two generations of nodes, that is, includes nodes at two levels, and each node cluster includes a parent node and at least one child node, such as Figure 2 the node cluster in the lower left corner of Figure 2 , the parent node is "add (+)", and the child nodes are "3" and "5". For the parent node in the node cluster, the corresponding function is the addition function (add), the hierarchical relationship is level 2, and the data input node is the child nodes "3" and "5" of the node. And although the embodiment uses a simple syntax tree corresponding to the four arithmetic operations as an example, the present application is not limited thereto, and any abstract syntax tree corresponding to a service code can be applied to the method provided by the embodiment of the present application.

[0057] The embodiment divides the syntax tree into multiple node clusters, identifies differences according to each parent node in the node cluster, and improves the granularity of comparison from a single node to a node cluster, thereby reducing the number of nodes that need to be compared, and combining functions, hierarchical relationships and data input nodes to more accurately identify difference nodes and obtain differences between code versions.

[0058] Further, the application provides a step of identifying difference nodes in the second syntax tree according to functions, hierarchical relationships and data input nodes corresponding to each parent node in the multiple node clusters, comprising:

[0059] For each parent node in the multiple node clusters, identifying a corresponding node in the second syntax tree according to the function and the hierarchical relationship corresponding to the parent node;

[0060] Eliminating the parent node of the corresponding node from each parent node to obtain a difference parent node;

[0061] Identifying a difference node in the second syntax tree according to the difference parent node and the data input node corresponding to the difference parent node.

[0062] Further, the embodiment provides a step of identifying a corresponding node in the second syntax tree according to functions and hierarchical relationships corresponding to each parent node in the multiple node clusters, comprising:

[0063] For each parent node, performing a second iteration operation, the second iteration operation comprising: taking a current first node from each current parent node according to a second preset rule, obtaining the function and the hierarchical relationship corresponding to the current first node, taking a node in the second syntax tree that is the same in the function and the hierarchical relationship as the corresponding node of the current first node, and outputting all corresponding nodes until a preset second iteration number is reached.

[0064] The second preset rule can be random selection or selection according to the number of child nodes, that is, a node can be randomly taken from each current parent node as the current first node, or a node with the most child nodes can be taken from each current parent node as the current first node; the preset second iteration number can be set as 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 iteration number can also be less than the number of node clusters in the first syntax tree, and the corresponding second preset rule is selection according to the number of child nodes, which is not limited in the embodiment.

[0065] For example, for the first iteration, each current parent node is composed of parent nodes in each node cluster in the first syntax tree, then a parent node is randomly taken from each current parent node, and it is assumed that the taken current first node is Figure 2The parent node "add (+)" in the lower left node cluster, obtains the function and hierarchical relationship corresponding to the parent node, and can find the corresponding node of the parent node in the second syntax tree. As shown in Figure 3 The left dashed box of the second syntax tree corresponding to the operation of "(4+6)+(9-7) * 3-2*(8-5+1)", that is, Figure 3 The corresponding node in the left dashed box, the function and hierarchical relationship corresponding to the node are the same as the current first node. Then, the second iteration is performed. Since one node has been taken out in the first iteration, the number of nodes in each parent node of the current first node is reduced by one compared with the last iteration. Repeat the above steps until the preset second iteration number is reached, and all corresponding nodes are obtained. Then, all parent nodes with corresponding nodes are obtained.

[0066] Then, the parent nodes with corresponding nodes are removed from each parent node to obtain the difference parent nodes. For example, for the first syntax tree, the parent nodes with corresponding nodes are shown in the dashed box in Figure 4 The parent nodes with corresponding nodes are removed from each node cluster in the first syntax tree to obtain the difference parent nodes, as shown in the solid box in Figure 4 .

[0067] In this embodiment, the corresponding nodes are identified in the second syntax tree according to the function and hierarchical relationship corresponding to each parent node, and the difference parent nodes are further screened from each parent node according to the corresponding nodes. Finally, the difference nodes are identified in the second syntax tree according to the difference parent nodes and the data input nodes, and the difference between the codes corresponding to the two syntax trees is finally determined. In a large code library, there are fewer codes that change substantially between different versions. Therefore, this embodiment can quickly narrow the node range through the function and hierarchical relationship, and can avoid meaningless identification of a large number of nodes in subsequent steps compared with the prior art, thereby reducing the comparison amount and improving the identification efficiency.

[0068] And this embodiment sets two ways to select the current first node according to the iteration number, that is, random selection and selection according to the number of child nodes. When the preset second iteration number can be the number of node clusters in the first syntax tree, the random selection method can quickly traverse all parent nodes and improve the identification efficiency. For a large code size, the structure of the corresponding syntax tree is also complex, and a large amount of time resources and computing resources will be consumed when traversing all parent nodes. Therefore, this embodiment selects according to the number of child nodes, that is, it preferentially selects nodes with complex structure and more logical information, which saves time resources and computing resources while ensuring identification accuracy.

[0069] Furthermore, this embodiment provides a step for identifying difference nodes in a second syntax tree based on the difference parent node and its corresponding data input node, including:

[0070] Obtain nodes that are within a preset distance from each differing parent node, and obtain the node group corresponding to each differing parent node;

[0071] For a node group, perform the first iteration operation, which includes: extracting 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, 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 iteration number is reached, and outputting all difference nodes.

[0072] The preset distance represents the number of levels difference, and nodes within the preset distance should also be parent nodes in the node cluster and connected to the different parent node. For example, for Figure 5 The parent node with the difference "div(÷)" in the text, if the preset distance is one level, then its corresponding nodes within the preset distance are "add(+)" and "". The corresponding node group is In the node group, the nodes are arranged in descending order of hierarchy, such as... Figure 5 The dashed box in the image shows the node within the preset distance. If the preset distance is two layers, the corresponding nodes within the preset distance are "sub(-)", "add(+)", and "...". The corresponding node groups for "" and "add(+)" are... ,like Figure 5 The solid-line box in the image is shown.

[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 node corresponding to "div(÷)" is " "and "2", The corresponding child nodes are "add(+)" and "sub(-)", because "div(÷)" and " "7" already exists in the current first node group, so "7", "2", "add(+)" and "sub(-)" will be used as the data input nodes corresponding to the current first node group.

[0074] The embodiment comprehensively considers the context 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, wherein the data input node is a key factor of code logic execution, and the change of data thereof directly reflects the change of code logic, so that the difference node can be further accurately identified through the data input node.

[0075] Further, the embodiment provides a step of 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, comprising:

[0076] identifying a second node corresponding to the current first node group in the second syntax tree according to the data corresponding to the data input node;

[0077] obtaining the difference node corresponding to the current first node group according to the semantic features of the current first node group and the second node.

[0078] The data corresponding to the data input node is the data input in the node, for example Figure 5 The data corresponding to the data input node "7" in the example is the number 7. Since the example of the embodiment is a simple four arithmetic operation, the name of the node is the same as the data, but for most cases, the name of the node is different from the data, for example, a node is a first data set, and the data corresponding to the node is all data in the set. If the data input node is a function or code, for example Figure 5 The node "div (÷)" in the example, the data corresponding to the data input node is the data obtained after the function operation. Specifically, the second node can be multiple, and the semantic features include internal logic and implementation function.

[0079] The embodiment focuses on the input data to avoid the interference of the subtle changes in the code syntax level (such as variable name modification, comment addition, etc.) on the difference identification, so as to more accurately locate the second node associated with the current first node group, and then further accurately identify the difference node combined with the semantic features. Even if the input data of the current first node group and the second node is the same, but their internal logic and implementation function are different, they will still be regarded as difference nodes.

[0080] Further, the embodiment provides a step of 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, comprising:

[0081] sorting the data corresponding to the data input node according to the hierarchical relationship to obtain a first data group;

[0082] identifying a second data group with the highest similarity to the first data group in the second syntax tree according to the first data group;

[0083] The node corresponding to the second data set is taken as the second node corresponding to the current first node set.

[0084] For example, if the current first node set is , the data input nodes corresponding to the current first node set are "7", "2", "add(+)", and "sub(-)", and the data corresponding to the data input nodes are sorted according to the hierarchical relationship from high to low, obtaining the first data set [7, 2, add(+), sub(-)].

[0085] In this embodiment, the data corresponding to the data input nodes are sorted according to the hierarchical relationship to form the first data set. In the code, different levels of data often have different logical meanings and dependency relationships. The hierarchical relationship reflects the organization structure and execution order of the code. By preserving the hierarchical information, the internal relationship between the data can be more accurately captured, and then the second data set can be identified according to this relationship.

[0086] Further, the embodiment provides a step of identifying a second data set with the highest similarity to the first data set in a second syntax tree according to the first data set, comprising:

[0087] Obtaining the number of data contained in the first data set, and the data corresponding to all data input nodes in the second syntax tree;

[0088] According to the number, all data input nodes corresponding to the data are arranged and combined to obtain a plurality of third data sets;

[0089] According to the similarity between the first data set and each third data set, the third data set with the highest similarity is selected as the second data set.

[0090] The similarity calculation method can be adjusted according to specific application scenarios and requirements. For example, in some cases, more attention may be paid to the content similarity of data, while in other cases, more attention may be paid to the order or structural similarity of data.

[0091] For example, when the first data group is [7,2,add(+),sub(-)], the number of data points in the first data group is 4. At this time, the data corresponding to all data input nodes in the second syntax tree is obtained and these data are arranged and combined to obtain multiple third data groups, each containing 4 data points. 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 dashed box on the right, “add(+)” and “sub(-)” also represent the data obtained after function operations.

[0092] Next, 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 point 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 " The functions "add(+)" and "sub(-)" are used as the second nodes corresponding to the current first node group. Finally, the semantic features of the first node group and the second node are compared. The comparison reveals that the internal logic and implementation functions of the first node group and the second node are different. Therefore, the second node is considered the difference node corresponding to the current first node group. If the semantic comparison results are the same, then 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 to generate multiple third data groups, and obtains the second data group based on similarity. It fully considers the quantity information of the data and the possible combination methods. Furthermore, the similarity comparison-based filtering method provided in this embodiment can comprehensively consider multiple factors such as the content and order of the data, rather than relying solely on a single feature. At the same time, the method provided in this embodiment can be applied to various types of abstract syntax trees, whether it is a simple linear data structure or a complex nested structure, 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 retrieving the 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 differing nodes at the current iteration number;

[0096] The selection area is determined based on the location of the first node group corresponding to all the difference nodes;

[0097] Among all current node groups, select the node group that is closest to the selected area and use it as the current first node group.

[0098] Specifically, the process involves selecting the current first node group from all current node groups according to a first preset rule, which means selecting the current first node group based on the selected region. The node group closest to the selected region is the node group that overlaps with the selected region. If no node group overlaps with the selected region, the node group closest to the selected region is the one that takes the fewest nodes to reach the selected region. If multiple node groups overlap with the selected region, one of these node groups is randomly selected as the current first node group. Furthermore, since multiple iterations are required, each iteration yields new difference nodes, so the difference nodes may differ for each iteration. In the first iteration, i.e., when the current iteration number is 1, since no difference nodes exist, a random node group can be selected from all current node groups as the current first node group. The selected current first node group should be different for each iteration.

[0099] For example, assuming the preset distance is one layer, and in the current iteration, the first node group of the identified difference nodes is... and ,like Figure 6 As shown in the dashed box, the selected area is the region enclosed by the two dashed boxes. Assuming the current node group includes [sub(-), add(+), div(÷)], and ,like Figure 6 As shown in the solid line box. Because [sub(-), add(+), div(÷)] overlaps with the selected area, this node group is the current first node group. If multiple selected areas exist simultaneously, the area containing the most nodes is selected for subsequent analysis.

[0100] In this embodiment, the selection area is determined based on the location of the first node group corresponding to all the difference nodes. When computing resources are limited and it is not possible to traverse all node groups, the method provided in this embodiment prioritizes the area 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 not possible to traverse all node groups, the number of the first iteration can be set by those skilled in the art based on computing resources.

[0101] To further understand, the following is a common use case to illustrate the above steps as a whole, such as... Figure 7 As shown, Figure 7 Case (a) in the text refers to the first syntax tree.Figure 7 Case (b) refers to the second syntax tree obtained by modifying the code based on 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 identify the difference nodes in the second syntax tree.

[0102] First, the first syntax tree is divided into multiple node clusters, with parent nodes 2, 3, and 4 in each cluster. Then, based on the hierarchical relationship and function or code of each parent node, the corresponding node is determined in the second syntax tree. Assuming that parent nodes 2 and 4 have corresponding nodes, the difference parent node is parent node 3. Assuming the preset distance is 1 level, the node group corresponding to this difference parent node is [parent node 4, parent node 3, parent node 2]. The data input nodes corresponding to this node group are child nodes 1, 2, and 3. Then, the first data group is obtained based on the data corresponding to the data input nodes, and the second data group is obtained based on the similarity test. Assuming that the second data group is child nodes 11, 12, and 3 in the second syntax tree, the second node is parent nodes 2 and 4 in the second syntax tree. Then, semantic comparison is performed. If the semantics of the node group are the same as those of the second node, it means that the input data, internal logic and implementation functions of the node group are the same as those of the second node. In this case, although this part of the code has changed, its essential 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 undergone substantial changes.

[0103] In summary, the solution provided in this embodiment includes: firstly, dividing the first syntax tree into multiple node clusters; for each parent node in the node cluster, determining the corresponding node in the second syntax tree based on its corresponding hierarchical relationship and the function or code functionality, and further obtaining the differing parent nodes; then generating node groups based on the differing parent nodes, for example, taking parent node N, parent node N-1, and parent node N+1 as a node group; then performing similarity checks on the data input nodes corresponding to the node group, finding the second node with the highest similarity, performing semantic checks, and finally determining the differing nodes. Through the above overall solution, this embodiment can ensure recognition accuracy while reducing the amount of comparison.

[0104] Furthermore, embodiments of this application provide a service code version difference identification system based on syntax tree structure features, including:

[0105] The acquisition module is used to acquire the first syntax tree and the second syntax tree. The first syntax tree and the second syntax tree are the abstract syntax trees corresponding to the two service codes that need to be compared.

[0106] The dividing module is configured to divide the first syntax tree into a plurality of node clusters according to a structural feature of the first syntax tree.

[0107] The identifying module is configured to identify a difference node in the second syntax tree according to a function, a hierarchical relationship and a data input node corresponding to each parent node in the plurality of node clusters.

[0108] The service code version difference identification method and system based on a syntax tree structural feature provided by the embodiments of the present application divide the first syntax tree into a plurality of node clusters, filter difference parent nodes from the parent nodes in each node cluster, and finally identify the code difference based on the difference parent nodes. Compared with the method of identifying node by node in the prior art, the embodiments of the present application only use a small number of nodes for identification, thereby reducing the comparison amount. Moreover, the embodiments take into account the limitation of computing resources, and set different selection schemes when selecting the current first node and the current first node group, so as to guarantee the accuracy of identification on the premise of saving computing resources.

[0109] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system or a computer program product. Therefore, the present application can adopt a completely hardware embodiment, a completely software embodiment or an embodiment combining software and hardware aspects. Moreover, the present application can adopt a computer program product implemented on one or more computer usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer usable program codes.

[0110] The present application is described with reference to flowcharts and / or block diagrams of the method, device (system) and computer program product according to the embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of the flows 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 produce a device implemented in the flowcharts and / or block diagrams. Figure 1 The device for implementing the functions specified in one or more flows and / or blocks. Figure 1 The device for implementing the functions specified in one or more flows and / or blocks.

[0111] These computer program instructions can also be stored in a computer readable storage medium capable of guiding the computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable storage medium produce a manufactured product including instruction devices, which implement the functions specified in the flowcharts and / or block diagrams. Figure 1 The device for implementing the functions specified in one or more flows and / or blocks. Figure 1 The device for implementing the functions specified in one or more flows and / or blocks.

[0112] The above merely describes the preferred embodiments of the present application, and the protection scope of the present application is not limited to the above-described embodiments. Any technical solution falling within the concept of the present application shall fall within the protection scope of the present application. It should be noted that, for ordinary skilled persons in the art, some improvements and refinements without departing from the principles of the present application shall also be considered as falling within the protection scope of the present application.

Claims

1. A method for identifying service code version difference based on syntax tree structure features, characterized in that, The method comprises the following steps: obtaining a first syntax tree and a second syntax tree, wherein the first syntax tree and the second syntax tree are abstract syntax trees corresponding to two service code pairs that need to be compared; dividing the first syntax tree into a plurality of node clusters according to the structural characteristics of the first syntax tree, wherein each node cluster comprises nodes belonging to two levels, and each node cluster comprises a parent node and at least one child node; identifying a difference node in the second syntax tree according to the function, hierarchical relationship and data input node corresponding to each parent node in the plurality of node clusters; wherein identifying a difference node in the second syntax tree according to the function, hierarchical relationship and data input node corresponding to each parent node in the plurality of node clusters comprises: for each parent node in the plurality of node clusters, identifying a corresponding node in the second syntax tree according to the function and hierarchical relationship corresponding to the parent node; eliminating the parent node having the corresponding node from each parent node to obtain a difference parent node; identifying a difference node in the second syntax tree according to the difference parent node and the data input node corresponding to the difference parent node; wherein identifying a difference node in the second syntax tree according to the difference parent node and the data input node corresponding to the difference parent node comprises: obtaining nodes within a preset distance from each difference parent node to obtain a node group corresponding to each difference parent node; for the node group, performing a first iteration operation, wherein the first iteration operation comprises: taking out a current first node group from all current node groups according to a first preset rule, obtaining a data input node corresponding to the current first node group, identifying a difference node corresponding to the current first node group in the second syntax tree according to data corresponding to the data input node, until a preset first iteration number is reached, and outputting all difference nodes; the data input node corresponding to the current first node group is a child node corresponding to each node in the current first node group. 2.The method of claim 1, wherein, identifying a difference node corresponding to the current first node group in the second syntax tree according to data corresponding to the data input node comprises: 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; obtaining a difference node corresponding to the current first node group according to the semantic characteristics of the current first node group and the second node. 3.The method of claim 2, wherein, 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 comprises: sorting data corresponding to the data input node according to the hierarchical relationship to obtain a first data group; identifying a second data group having the highest similarity with the first data group in the second syntax tree according to the first data group; taking a node corresponding to the second data group as a second node corresponding to the current first node group. 4.The method of claim 3, wherein, identifying a second data group having the highest similarity with the first data group in the second syntax tree according to the first data group comprises: obtaining the number of data contained in the first data group and data corresponding to all data input nodes in the second syntax tree; According to the quantity, the data corresponding to all the data input nodes are arranged and combined to obtain a plurality of third data groups; According to the similarity between the first data group and each third data group, a third data group with the highest similarity is selected as the second data group. 5.The method of claim 1, wherein, The current first node group is taken out from the current all node groups according to the first preset rule, including: Obtaining the first node groups corresponding to all the difference nodes at the current iteration number; According to the positions of the first node groups corresponding to all the difference nodes, a selection area is determined; In the current all node groups, the node group closest to the selection area is selected as the current first node group. 6.The method of claim 1, wherein, For each parent node in the plurality of node clusters, corresponding nodes in the second syntax tree are identified according to the function and hierarchical relationship corresponding thereto, including: For each parent node, a second iteration operation is performed, and the second iteration operation includes: taking out a current first node from each parent node according to a second preset rule, obtaining the function and hierarchical relationship corresponding to the current first node, taking the nodes in the second syntax tree which are the same in the function and hierarchical relationship as the corresponding nodes of the current first node, until a preset second iteration number is reached, and outputting all the corresponding nodes.

7. The method of claim 6, wherein the method further comprises: The current first node is taken out from each parent node according to the second preset rule, including: A node is randomly taken out from the current each parent node as the current first node; Or the node with the most child nodes is taken out from the current each parent node as the current first node. 8.A service code version difference identification system based on syntax tree structure features, characterized in that, Including: The acquisition module is configured to acquire a first syntax tree and a second syntax tree, the first syntax tree and the second syntax tree being abstract syntax trees corresponding to two service codes to be compared for differences; The division module is configured to divide the first syntax tree into a plurality of node clusters according to the structural features of the first syntax tree; each node cluster includes nodes belonging to two levels, and each node cluster includes a parent node and at least one child node; The identification module is configured to identify difference nodes in the second syntax tree according to the function, hierarchical relationship and data input node corresponding to each parent node in the plurality of node clusters. According to the function, hierarchical relationship and data input node corresponding to each parent node in the plurality of node clusters, difference nodes in the second syntax tree are identified, including: For each parent node in the plurality of node clusters, corresponding nodes in the second syntax tree are identified according to the function and hierarchical relationship corresponding thereto; The parent nodes with corresponding nodes are eliminated from each parent node to obtain difference parent nodes; Difference nodes in the second syntax tree are identified according to the difference parent nodes and the data input nodes corresponding thereto; According to the function, hierarchical relationship and data input node corresponding to each parent node in the plurality of node clusters, difference nodes in the second syntax tree are identified, including: For each parent node in the plurality of node clusters, corresponding nodes in the second syntax tree are identified according to the function and hierarchical relationship corresponding thereto; Obtaining nodes within a preset distance from each of the difference parent nodes, to obtain a node group corresponding to each of the difference parent nodes; performing a first iteration operation on the node group, the first iteration operation comprising: taking out a current first node group from all current node groups according to a first preset rule, obtaining data input nodes corresponding to the current first node group, and identifying difference nodes corresponding to the current first node group in the second syntax tree according to data corresponding to the data input nodes, until a preset first iteration number is reached, and outputting all difference nodes; the data input nodes corresponding to the current first node group are child nodes corresponding to each node in the current first node group.

Citation Information

Patent Citations

  • Software defect prediction method for open source software defect feature deep learning

    CN110597735A