A method and device for quantifying code availability

By building a resource library and using tree structure similarity to evaluate the differences between target code files and standard code files, the code availability is quantified, which solves the problem of lack of code availability evaluation in the existing technology and improves the accuracy of code evaluation and the iteration speed of the D2C algorithm.

CN114968815BActive Publication Date: 2025-09-16BEIJING JINWEI ZHIGUANG INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210720025.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-23
Publication Date
2025-09-16
Estimated Expiration
2042-06-23

AI Technical Summary

Technical Problem

The existing technology lacks an effective code usability evaluation scheme, resulting in a lack of reliable evaluation indicators when automatically generating code from design drafts during iteration. This makes it impossible to quantify the quality of the generated code, severely limiting the iteration speed of D2C algorithm research.

Method used

Build a resource library, including design drafts and corresponding standard code files, quantify the differences between target code files and standard code files through tree structure similarity evaluation, calculate code availability using layout tree structure and component label difference results, and use a preset difference value calculation formula to quantify code availability.

Benefits of technology

The quantification of code availability is achieved, the accuracy and reliability of code evaluation are improved, and the iteration speed of the D2C algorithm is promoted.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114968815B_ABST
    Figure CN114968815B_ABST
Patent Text Reader

Abstract

The present application provides a method and device for quantifying code availability. In the method, a resource library is constructed, the resource library including a design draft and a standard code file corresponding to the design draft; the design draft is run to automatically generate a target code file; the difference between the target code file and the standard code file is quantified based on a tree structure similarity evaluation method to determine a target difference result, and the target difference result is used to represent the availability of the target code file. In the solution of the present application, the evaluation of code availability is converted into a similarity calculation of two codes, the difference between the two is automatically evaluated and the difference result is quantified based on the tree structure similarity method, and the difference result is used as the evaluation result of the availability of the target code automatically generated from the design draft, thereby realizing the quantification of code availability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing, and in particular to a method and device for quantifying code availability. Background Art

[0002] With the rapid development of science and technology, codes are widely used in many fields, spanning at least two categories: machine language and human language, and even involving the best practices of coding schemes such as design patterns.

[0003] The industry currently lacks an effective code usability assessment solution for automated code generation from design drafts. Code usability is a highly abstract concept with no universal standard. This results in a lack of reliable evaluation metrics during iterations of automated code generation from design drafts, making it impossible to quantify the quality of generated code. Furthermore, there's no direct correlation between algorithmic solutions and code usability, severely limiting the speed of iteration in D2C algorithm research. Summary of the Invention

[0004] In view of this, embodiments of the present application provide a code availability quantification method and apparatus to measure the availability of code and achieve quantification of code availability.

[0005] In a first aspect, an embodiment of the present application provides a code availability quantification method, including:

[0006] Constructing a resource library, the resource library including a design draft and a standard code file corresponding to the design draft;

[0007] Run the design draft to automatically generate a target code file;

[0008] The difference between the target code file and the standard code file is quantified based on a tree structure similarity evaluation method to determine a target difference result, where the target difference result is used to indicate the usability of the target code file.

[0009] Preferably, the method of quantifying the difference between the target code file and the standard code file based on tree structure similarity evaluation to determine a target difference result includes:

[0010] Acquire a target layout tree structure of the target code file and a standard layout tree structure of the standard code file;

[0011] quantifying the difference between the target layout tree structure and the standard layout tree structure based on an unlabeled tree structure similarity evaluation method to obtain a layout tree structure difference result;

[0012] Obtaining a target component tag of the target code file and a standard component tag of the standard code file;

[0013] quantifying the difference between the target component label and the standard component label based on a labeled tree structure similarity evaluation method to obtain a component label difference result;

[0014] The target difference result is determined according to the layout tree structure difference result and the component label difference result.

[0015] Preferably, the method of quantifying the difference between the target layout tree structure and the standard layout tree structure based on the unlabeled tree structure similarity evaluation to obtain a layout tree structure difference result specifically includes:

[0016] Generate the total number of nodes of the target code file;

[0017] Calculating a tree edit distance between the target layout tree structure and the standard layout tree structure based on a minimum edit distance;

[0018] The layout tree structure difference result is determined based on the total number of nodes and the tree edit distance.

[0019] Preferably, the method based on labeled tree structure similarity evaluation quantifies the difference between the target component label and the standard component label to obtain a component label difference result, specifically including:

[0020] Matching the nodes of the target code file with the nodes of the standard code file to obtain a first matching result, where the first matching result includes the number of excess nodes, the number of missing nodes, and the number of successfully matched nodes;

[0021] Matching the target component label of the successfully matched node with the standard component label to obtain a second matching result, where the second matching result includes the number of successful label matches and the number of failed label matches;

[0022] A component label difference result is determined based on the total number of nodes, the first matching result, and the second matching result.

[0023] Preferably, determining the target difference result according to the layout tree structure difference result and the component label difference result specifically includes:

[0024] Calculate the target difference result using a preset difference value calculation formula;

[0025] The preset difference value calculation formula is: Z=(1-(D / (4×T)+(N1+N2+M2) / T))×100;

[0026] Among them, Z is the code difference rate between the target code file and the standard code file, which is used to represent the target difference result, D / (4×T) represents the layout tree structure difference result, (N1+N2+M2) / T represents the component label difference result, D is the tree edit distance, T is the total number of nodes, N1 is the number of extra nodes, N2 is the number of missing nodes, and M2 is the number of label matching failures.

[0027] On the other hand, an embodiment of the present application further provides a code availability quantification device, comprising:

[0028] A construction module is used to construct a resource library, wherein the resource library includes a design draft and a standard code file corresponding to the design draft;

[0029] A running module, used to run the design draft and automatically generate a target code file;

[0030] The quantification module is used to quantify the difference between the target code file and the standard code file based on a tree structure similarity evaluation method to determine a target difference result, wherein the target difference result is used to indicate the usability of the target code file.

[0031] Preferably, the quantization module includes:

[0032] A first acquisition submodule is configured to acquire a target layout tree structure of the target code file and a standard layout tree structure of the standard code file;

[0033] A first quantification submodule is configured to quantify the difference between the target layout tree structure and the standard layout tree structure based on an unlabeled tree structure similarity evaluation method to obtain a layout tree structure difference result;

[0034] A second acquisition submodule is used to acquire the target component tag of the target code file and the standard component tag of the standard code file;

[0035] A second quantification submodule is configured to quantify the difference between the target component label and the standard component label based on a labeled tree structure similarity evaluation method to obtain a component label difference result;

[0036] The result determination submodule is configured to determine the target difference result according to the layout tree structure difference result and the component label difference result.

[0037] Preferably, the first quantization submodule specifically includes:

[0038] A generating unit, configured to generate the total number of nodes of the target code file;

[0039] a first calculation unit, configured to calculate a tree edit distance between the target layout tree structure and the standard layout tree structure based on a minimum edit distance;

[0040] The first determining unit is configured to determine the layout tree structure difference result based on the total number of nodes and the tree edit distance.

[0041] Preferably, the second quantization submodule specifically includes:

[0042] a first matching unit, configured to match the nodes of the target code file with the nodes of the standard code file to obtain a first matching result, wherein the first matching result includes the number of excess nodes, the number of missing nodes, and the number of successfully matched nodes;

[0043] A second matching unit is configured to match the target component label of the successfully matched node with the standard component label to obtain a second matching result, where the second matching result includes the number of successful label matches and the number of failed label matches;

[0044] The second determining unit is configured to determine a component label difference result based on the total number of nodes, the first matching result, and the second matching result.

[0045] Preferably, the result determination submodule specifically includes:

[0046] A second calculation unit, configured to calculate the target difference result using a preset difference value calculation formula;

[0047] The preset difference value calculation formula is: Z=(1-(D / (4×T)+(N1+N2+M2) / T))×100;

[0048] Among them, Z is the code difference rate between the target code file and the standard code file, which is used to represent the target difference result, D / (4×T) represents the layout tree structure difference result, (N1+N2+M2) / T represents the component label difference result, D is the tree edit distance, T is the total number of nodes, N1 is the number of extra nodes, N2 is the number of missing nodes, and M2 is the number of label matching failures.

[0049] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, wherein instructions are stored in the computer-readable storage medium. When the computer-readable storage medium is run on a computer, the computer executes the method described in the first aspect above.

[0050] In a fourth aspect, an embodiment of the present application provides a code availability quantification system, the system comprising: a processor and a memory; the memory is used to store instructions; the processor is used to execute the instructions in the memory, so that the system performs the method as described in any one of the first aspects above.

[0051] In a fifth aspect, an embodiment of the present application provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the method described in the first aspect above.

[0052] In an embodiment of the present application, a resource library is first constructed, the resource library including a design draft and a standard code file corresponding to the design draft; secondly, the design draft is run to automatically generate a target code file; finally, the difference between the target code file and the standard code file is quantified based on a tree structure similarity evaluation method to determine a target difference result, and the target difference result is used to represent the availability of the target code file. The present application proposes a scheme for measuring code availability, which converts the evaluation of code availability into a similarity calculation of two codes, automatically evaluates the difference between the two based on a tree structure similarity method and quantifies the difference result, and uses the difference result as the evaluation result of the availability of the target code automatically generated from the design draft, thereby realizing the quantification of code availability. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] Figure 1 A schematic diagram of a process for quantifying code availability in an embodiment of the present application is shown;

[0054] Figure 2 A structural block diagram of a code availability quantification device in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0055] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0056] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present application. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application is not limited to the embodiments shown herein, but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.

[0057] Code usability is a highly abstract concept with no universal standard. It encompasses multiple fields, spanning at least two domains: machine language and human language, and even encompassing best practices for coding schemes like design patterns. To date, the industry for automated code generation from design drafts lacks an effective code usability assessment scheme. This results in a lack of reliable evaluation metrics during iteration, making it impossible to quantify the quality of generated code. Furthermore, there's no direct correlation between algorithmic solutions and code usability, severely limiting the speed of iteration in D2C algorithm research.

[0058] In order to measure the usability of the code, the embodiment of the present application converts the evaluation of the code usability into a similarity calculation of two codes, automatically evaluating the difference between the target code file B and the standard code file A, where the standard code file A is the template code and the target code file B is the code automatically generated from the design draft; the difference result is quantified to between 0 and 100, and the difference result is used as the evaluation result of the usability of the target code file B.

[0059] To facilitate understanding of the technical solution provided by the embodiment of the present application, a code availability quantification method provided by the embodiment of the present application is described below with reference to the accompanying drawings.

[0060] See also Figure 1 , which is a flow chart of a code availability quantification method provided in an embodiment of the present application, and includes the following steps S1 to S3:

[0061] S1: Construct a resource library, which includes a design draft and a standard code file corresponding to the design draft.

[0062] In the embodiment of the present application, a resource library is pre-established, and the resource library may include a design draft and a standard code file corresponding to the design draft, and the standard code file is used as a template code.

[0063] S2: Run the design draft to automatically generate a target code file.

[0064] In the embodiments of this application, the automatic generation of code from a design draft refers to the direct generation of executable code from a design drawing created by a user interface designer through automation technology. In the embodiments of this application, after running the design draft, a target code file corresponding to the design draft can be automatically generated. This target code file is the code file to be evaluated and performs a difference comparison operation with the above-mentioned standard code file.

[0065] S3: quantifying the difference between the target code file and the standard code file based on a tree structure similarity evaluation method to determine a target difference result, where the target difference result is used to indicate the usability of the target code file.

[0066] There are many factors that affect the results of code usability evaluation, among which the two most important factors are layout and component identification. In the embodiment of this application, the usability is evaluated based on these two dimensions, which can improve the accuracy of code usability evaluation. It should be noted that the factors used for code evaluation can be selected according to actual conditions, and this application does not limit them. Code usability can be described from two levels: content and content expression. Content refers to whether the layout and component identification are correct; expression refers to the adaptability, readability, modularity, reusability, etc. of the generated layout and component code.

[0067] In the embodiment of the present application, an algorithm based on tree structure similarity evaluation is used to compare layout tree structure differences and component label differences to obtain the results of code usability quantification. Among them, the evaluation of tree structure similarity can include unlabeled tree structure similarity evaluation and labeled tree structure similarity evaluation. Based on this, the aforementioned step S3 of the embodiment of the present application quantifies the differences between the target code file and the standard code file based on the tree structure similarity evaluation method to determine the specific implementation steps of the target difference result, including as shown in S31 to S35:

[0068] S31: Acquire the target layout tree structure of the target code file and the standard layout tree structure of the standard code file.

[0069] In the embodiment of the present application, the target layout tree structure of the target code file and the standard layout tree structure of the standard code file are obtained; the tree is composed of multiple nodes (components), and each node is defined as:

[0070]

[0071]

[0072] S32: quantifying the difference between the target layout tree structure and the standard layout tree structure based on an unlabeled tree structure similarity evaluation method to obtain a layout tree structure difference result.

[0073] In this embodiment, the results of the unlabeled tree structure similarity assessment are used as the layout tree structure difference results. The labels in the labeled and unlabeled tree structures refer to the node type, which is the result of component identification, such as buttons, input boxes, radio buttons, etc. The unlabeled tree structure similarity assessment method means that when comparing tree structures, only the IDs are compared, not the node types.

[0074] Preferably, the method of quantifying the difference between the target layout tree structure and the standard layout tree structure based on the unlabeled tree structure similarity evaluation to obtain a layout tree structure difference result specifically includes:

[0075] Generate the total number of nodes T of the target code file;

[0076] Calculating a tree edit distance D between the target layout tree structure and the standard layout tree structure based on the minimum edit distance;

[0077] Based on the total number of nodes T and the tree edit distance D, the layout tree structure difference result is determined.

[0078] The minimum edit distance refers to the tree edit distance. There are three types of tree edit operations: insertion, deletion, and transformation. Insertion refers to inserting a node into a tree. Deletion refers to removing a node from a tree. Transformation refers to transforming a node in a tree into another node. Calculating the tree edit distance specifically involves calculating the minimum number of tree edit operations required to transform from one tree to another.

[0079] In an implementable manner, the layout tree structure difference result is calculated using the total number of nodes T and the tree edit distance D, and the layout tree structure difference result is D / (4×T).

[0080] S33: Acquire the target component tag of the target code file and the standard component tag of the standard code file.

[0081] In this embodiment, a tree is composed of multiple nodes (or components), and a label is the type of the node (also called the component type), which is a node attribute. Before comparing component labels, it is necessary to first obtain the target component label of the target code file and the standard component label of the standard code file before comparing the component labels.

[0082] S34: quantifying the difference between the target component label and the standard component label based on a labeled tree structure similarity evaluation method to obtain a component label difference result.

[0083] In the embodiment of the present application, the result of the labeled tree structure similarity evaluation is used as the component label difference result. The labeled tree structure similarity evaluation method refers to comparing the ID and the node type at the same time when comparing the tree structure.

[0084] Preferably, the method based on labeled tree structure similarity evaluation quantifies the difference between the target component label and the standard component label to obtain a component label difference result, specifically including:

[0085] Matching the nodes of the target code file with the nodes of the standard code file to obtain a first matching result, where the first matching result includes a number N1 of extra nodes, a number N2 of missing nodes, and a number N3 of successfully matched nodes;

[0086] Matching the target component label of the successfully matched node with the standard component label to obtain a second matching result, where the second matching result includes a number M1 of successful label matches and a number M2 of failed label matches;

[0087] A component label difference result is determined based on the total number of nodes T, the first matching result, and the second matching result.

[0088] In the above embodiment of the present application, after obtaining the target code file and the standard code file, since the code file is organized in the form of a tree structure and the tree contains multiple nodes, the component label difference result can be obtained through node matching. Node matching can include: label-free matching and label matching. There are many ways to match without labels. Two methods are cited here. One is the node ID matching method, which determines the first matching result by comparing the node ID; the other is the node X coordinate, node Y coordinate, node width W, and node height H matching method, which compares whether the node X coordinate, node Y coordinate, node width W, and node height H are the same. If they are the same, the match is considered successful. In the embodiment of the present application, the node ID comparison method is selected for label-free matching.

[0089] The node ID matching method involves comparing the node IDs of the target code file with the node IDs of the standard code file to determine whether they are identical, thereby obtaining a first matching result. The first matching result may include the number of excess nodes N1, the number of missing nodes N2, and the number of successfully matched nodes N3. The number of excess nodes N1 refers to the number of nodes present in the standard code file but not in the target code file, the number of missing nodes N2 refers to the number of nodes present in the target code file but not in the standard code file, and the number of successfully matched nodes N3 refers to the number of nodes present in both the standard code file and the target code file.

[0090] In the embodiment of the present application, label-free matching is completed by node ID matching. Based on the first matching result obtained by label-free matching, label matching of the successfully matched nodes is performed. The label matching refers to comparing whether the types of the nodes are the same to obtain a second matching result. The second matching result may include the number of successful label matches M1 and the number of failed label matches M2. Among them, the number of successful label matches M1 refers to the number of nodes with the same ID, where the label of the target code file and the label of the standard code file are also the same; the number of failed label matches M2 refers to the number of nodes with the same ID, where the label of the target code file and the label of the standard code file are different.

[0091] In one achievable manner, based on the total number of nodes T, the number of extra nodes N1, the number of missing nodes N2, and the number of label matching failures M2, a component label difference result is calculated, and the label component difference result is (N1+N2+M2) / T.

[0092] S35: Determine the target difference result according to the layout tree structure difference result and the component label difference result.

[0093] Through the method described in the above embodiments of the present application, the layout tree structure difference results and the component label difference results are obtained, and the target difference result is calculated using a preset difference value calculation formula, wherein the preset difference value calculation formula is: Z = (1-(D / (4×T)+(N1+N2+M2) / T))×100. Z is the code difference rate between the target code file and the standard code file, which is used to represent the target difference result, D / (4×T) represents the layout tree structure difference result, (N1+N2+M2) / T represents the component label difference result, D is the tree editing distance, T is the total number of nodes, N1 is the number of extra nodes, N2 is the number of missing nodes, and M2 is the number of label matching failures. The difference result is quantified between 0-100, and the target difference result is used to represent the availability evaluation result of the target code file. The difference value represents the degree of availability of the code. The smaller the difference value, the higher the code availability.

[0094] In an embodiment of the present application, a method for quantifying code availability is provided, the method comprising constructing a resource library, the resource library comprising a design draft and a standard code file corresponding to the design draft; running the design draft to automatically generate a target code file; quantifying the difference between the target code file and the standard code file based on a tree structure similarity evaluation method to determine a target difference result, the target difference result being used to represent the availability of the target code file. The present application proposes a scheme for measuring code availability, converting the evaluation of code availability into a similarity calculation of two codes, automatically evaluating the difference between the two based on a tree structure similarity method and quantifying the difference result, and using the difference result as an evaluation result of the availability of the target code automatically generated from the design draft, thereby achieving the quantification of code availability.

[0095] The above embodiment of the present application provides a code availability quantification method based on the above. Next, a code availability quantification device also provided in the embodiment of the present application is described. The device performs the above Figure 1 Next, the function of the code availability quantification device is described. The structure block diagram of the code availability quantification device is shown in FIG. Figure 2 As shown, including:

[0096] A construction module 201 , an operation module 202 and a quantization module 203 .

[0097] in,

[0098] Construction module 201 is used to construct a resource library, which includes a design draft and a standard code file corresponding to the design draft;

[0099] The running module 202 is used to run the design draft and automatically generate a target code file;

[0100] The quantification module 203 is configured to quantify the difference between the target code file and the standard code file based on a tree structure similarity evaluation method to determine a target difference result, wherein the target difference result is used to indicate the usability of the target code file.

[0101] Preferably, the quantization module 203 includes:

[0102] A first acquisition submodule is configured to acquire a target layout tree structure of the target code file and a standard layout tree structure of the standard code file;

[0103] A first quantification submodule is configured to quantify the difference between the target layout tree structure and the standard layout tree structure based on an unlabeled tree structure similarity evaluation method to obtain a layout tree structure difference result;

[0104] A second acquisition submodule is used to acquire the target component tag of the target code file and the standard component tag of the standard code file;

[0105] A second quantification submodule is configured to quantify the difference between the target component label and the standard component label based on a labeled tree structure similarity evaluation method to obtain a component label difference result;

[0106] The result determination submodule is configured to determine the target difference result according to the layout tree structure difference result and the component label difference result.

[0107] Preferably, the first quantization submodule specifically includes:

[0108] A generating unit, configured to generate the total number of nodes of the target code file;

[0109] a first calculation unit, configured to calculate a tree edit distance between the target layout tree structure and the standard layout tree structure based on a minimum edit distance;

[0110] The first determining unit is configured to determine the layout tree structure difference result based on the total number of nodes and the tree edit distance.

[0111] Preferably, the second quantization submodule specifically includes:

[0112] a first matching unit, configured to match the nodes of the target code file with the nodes of the standard code file to obtain a first matching result, wherein the first matching result includes the number of excess nodes, the number of missing nodes, and the number of successfully matched nodes;

[0113] A second matching unit is configured to match the target component label of the successfully matched node with the standard component label to obtain a second matching result, where the second matching result includes the number of successful label matches and the number of failed label matches;

[0114] The second determining unit is configured to determine a component label difference result based on the total number of nodes, the first matching result, and the second matching result.

[0115] Preferably, the result determination submodule specifically includes:

[0116] A second calculation unit is used to calculate the target difference result using a preset difference rate calculation formula;

[0117] The preset difference rate calculation formula is: Z=(1-(D / (4×T)+(N1+N2+M2) / T))×100;

[0118] Among them, Z is the code difference rate between the target code file and the standard code file, which is used to represent the target difference result, D / (4×T) represents the layout tree structure difference result, (N1+N2+M2) / T) represents the component label difference result, D is the tree edit distance, T is the total number of nodes, N1 is the number of extra nodes, N2 is the number of missing nodes, and M2 is the number of label matching failures.

[0119] In an embodiment of the present application, a device for quantifying code availability is provided, the device comprising a construction module, an operation module and a quantification module; wherein the construction module is used to construct a resource library, the resource library comprising a design draft and a standard code file corresponding to the design draft; the operation module is used to run the design draft and automatically generate a target code file; the quantification module is used to quantify the difference between the target code file and the standard code file based on a tree structure similarity evaluation method to determine a target difference result, the target difference result being used to represent the availability of the target code file. The present application converts the evaluation of code availability into a similarity calculation of two codes, automatically evaluates the difference between the two based on a tree structure similarity method and quantifies the difference result, and uses the difference result as an evaluation result of the availability of the target code automatically generated from the design draft, thereby realizing the quantification of code availability.

[0120] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similarities between the various embodiments can be referred to in conjunction with each other. For device embodiments, since they are generally similar to method embodiments, their description is relatively simple, and for relevant details, reference can be made to the description of the method embodiments.

[0121] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.

[0122] For the convenience of description, the above device is described as being divided into various modules according to their functions. Of course, when implementing the present invention, the functions of each module can be implemented in the same or multiple software and / or hardware.

[0123] From the above description of the embodiments, it can be seen that those skilled in the art can clearly understand that the present invention can be implemented by means of software plus the necessary general-purpose hardware platform. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a storage medium such as ROM / RAM, a magnetic disk, or an optical disk, and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in various embodiments of the present invention or certain parts of the embodiments.

[0124] The above is a detailed introduction to a code availability quantification method and device provided by the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only intended to help understand the method and core concept of the present invention. At the same time, for those skilled in the art, according to the concept of the present invention, there may be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as limiting the present invention.

Claims

1. A code availability quantification method, characterized in that: include: Constructing a resource library, the resource library including a design draft and a standard code file corresponding to the design draft; Run the design draft to automatically generate a target code file; quantifying the difference between the target code file and the standard code file based on a tree structure similarity evaluation method to determine a target difference result, wherein the target difference result is used to indicate the usability of the target code file; The method of quantifying the difference between the target code file and the standard code file based on the tree structure similarity evaluation to determine a target difference result includes: Acquire a target layout tree structure of the target code file and a standard layout tree structure of the standard code file; quantifying the difference between the target layout tree structure and the standard layout tree structure based on an unlabeled tree structure similarity evaluation method to obtain a layout tree structure difference result; Obtaining a target component tag of the target code file and a standard component tag of the standard code file; quantifying the difference between the target component label and the standard component label based on a labeled tree structure similarity evaluation method to obtain a component label difference result; Determining the target difference result according to the layout tree structure difference result, the component label difference result and a preset difference value calculation formula; The method based on labeled tree structure similarity evaluation quantifies the difference between the target component label and the standard component label to obtain a component label difference result, specifically including: Matching the nodes of the target code file with the nodes of the standard code file to obtain a first matching result, where the first matching result includes the number of excess nodes, the number of missing nodes, and the number of successfully matched nodes; Matching the target component label of the successfully matched node with the standard component label to obtain a second matching result, where the second matching result includes the number of successful label matches and the number of failed label matches; Determining a component label difference result based on the total number of nodes in the target code file, the first matching result, and the second matching result; The determining the target difference result according to the layout tree structure difference result, the component label difference result and a preset difference value calculation formula includes: Calculating the target difference result using the preset difference value calculation formula; The preset difference value calculation formula is: Z=(1-(D / (4×T)+(N1+N2+M2) / T))×100; Among them, Z is the code difference rate between the target code file and the standard code file, which is used to represent the target difference result, D / (4×T) represents the layout tree structure difference result, (N1+N2+M2) / T represents the component label difference result, D is the tree edit distance, T is the total number of nodes, N1 is the number of extra nodes, N2 is the number of missing nodes, and M2 is the number of label matching failures.

2. The method according to claim 1, characterized in that The method based on unlabeled tree structure similarity evaluation quantifies the difference between the target layout tree structure and the standard layout tree structure to obtain a layout tree structure difference result, specifically including: Generate the total number of nodes of the target code file; Calculating a tree edit distance between the target layout tree structure and the standard layout tree structure based on a minimum edit distance; The layout tree structure difference result is determined based on the total number of nodes and the tree edit distance.

3. A code availability quantification device, characterized in that: include: A construction module is used to construct a resource library, wherein the resource library includes a design draft and a standard code file corresponding to the design draft; A running module, used to run the design draft and automatically generate a target code file; a quantification module, configured to quantify the difference between the target code file and the standard code file based on a tree structure similarity evaluation method to determine a target difference result, wherein the target difference result is used to indicate the usability of the target code file; The quantization module includes: A first acquisition submodule is configured to acquire a target layout tree structure of the target code file and a standard layout tree structure of the standard code file; A first quantification submodule is configured to quantify the difference between the target layout tree structure and the standard layout tree structure based on an unlabeled tree structure similarity evaluation method to obtain a layout tree structure difference result; A second acquisition submodule is used to acquire the target component tag of the target code file and the standard component tag of the standard code file; A second quantification submodule is configured to quantify the difference between the target component label and the standard component label based on a labeled tree structure similarity evaluation method to obtain a component label difference result; A result determination submodule, configured to determine the target difference result based on the layout tree structure difference result, the component label difference result, and a preset difference value calculation formula; The second quantization submodule specifically includes: a first matching unit, configured to match the nodes of the target code file with the nodes of the standard code file to obtain a first matching result, wherein the first matching result includes the number of excess nodes, the number of missing nodes, and the number of successfully matched nodes; A second matching unit is configured to match the target component label of the successfully matched node with the standard component label to obtain a second matching result, where the second matching result includes the number of successful label matches and the number of failed label matches; a second determining unit, configured to determine a component label difference result based on the total number of nodes in the target code file, the first matching result, and the second matching result; The result determination submodule specifically includes: A second calculation unit, configured to calculate the target difference result using a preset difference value calculation formula; The preset difference value calculation formula is: Z=(1-(D / (4×T)+(N1+N2+M2) / T))×100; Among them, Z is the code difference rate between the target code file and the standard code file, which is used to represent the target difference result, D / (4×T) represents the layout tree structure difference result, (N1+N2+M2) / T represents the component label difference result, D is the tree edit distance, T is the total number of nodes, N1 is the number of extra nodes, N2 is the number of missing nodes, and M2 is the number of label matching failures.

4. The device according to claim 3, characterized in that The first quantization submodule specifically includes: A generating unit, configured to generate the total number of nodes of the target code file; a first calculation unit, configured to calculate a tree edit distance between the target layout tree structure and the standard layout tree structure based on a minimum edit distance; The first determining unit is configured to determine the layout tree structure difference result based on the total number of nodes and the tree edit distance.

Citation Information

Patent Citations

  • Syntax tree similarity calculation method based on fuzzy tree kernel

    CN104679732A

  • Code generation method and device for front-end page, equipment and storage medium

    CN114237600A