Code generation method, electronic equipment, readable storage medium and program product
By obtaining component repository documents, business templates, and structured description information, page implementation code is automatically generated, solving the low efficiency problem of manual code writing by developers in the existing technology and achieving efficient and accurate code generation.
Patent Information
- Application Number
- CN202510740652.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-04
- Publication Date
- 2025-09-09
AI Technical Summary
In the prior art, developers need to manually write page implementation codes, which results in a large investment of time and energy and is prone to errors, and the efficiency of page implementation code generation is low.
By obtaining component repository documents, business templates, and structured description information, page implementation code is automatically generated. Code is generated using abstract syntax tree analysis and preset models. Combined with user interface design drafts and business requirement information, the generated code is ensured to meet specifications and actual needs.
It improves the efficiency and accuracy of page implementation code generation, reduces the workload of manual coding, is suitable for the automation needs of complex page development, and improves the standardization and accuracy of code generation.
Smart Images

Figure CN120610703A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical fields of computers and the like, and in particular to a code generation method, an electronic device, a readable storage medium, and a program product. Background Art
[0002] With the development of Internet technology, front-end page development has occupied an important position in software development.
[0003] In order to achieve the visual effects and functional requirements presented in the user interface design draft, developers usually need to manually write page implementation code based on the user interface design draft.
[0004] However, user interface design drafts contain numerous details, requiring developers to invest a lot of time and energy, and are prone to errors, resulting in low efficiency in generating page implementation codes. Summary of the Invention
[0005] The present disclosure provides a code generation method, an electronic device, a readable storage medium, and a program product.
[0006] According to one aspect of the present disclosure, a code generation method is provided, comprising: Obtain component repository documents, business templates, structured description information, and user interface design drafts. The component repository documents are used to illustrate component implementation codes, the business templates are used to illustrate the combination of component implementation codes, and the structured description information is business requirement information and page information described in the form of structured data. Extracting component implementation code writing rules from the component repository document; Determine the type, quantity, and calling interface information of components on the page based on the user interface design draft and the page information in the structured description information; Generate a plurality of target component implementation codes that meet the types and quantities according to the writing rules, the calling interface information and the business requirement information in the structured description information; and Based on the business template, the multiple target component implementation codes are combined together to obtain page implementation code.
[0007] According to at least one embodiment of the present disclosure, a code generation method for obtaining structured description information includes: Based on the name of the preset field, prompt the user to enter the field content of the preset field; receiving the field content of the preset field input by the user; and A mapping relationship between the name of the preset field and the field content of the preset field is generated to obtain the structured description information.
[0008] According to at least one embodiment of the present disclosure, a code generation method for obtaining structured description information includes: Receive business requirement information and page information input by users; Based on the name of the preset field, extracting the field content of the preset field from the business requirement information and page information input by the user; and A mapping relationship between the name of the preset field and the field content of the preset field is generated to obtain the structured description information.
[0009] According to at least one embodiment of the present disclosure, a code generation method generates a mapping relationship between the name of the preset field and the field content of the preset field to obtain the structured description information, including: A key-value pair is generated with the name of the preset field as the key and the field content of the preset field as the value, and the key-value pair is used as the structured description information.
[0010] According to at least one embodiment of the present disclosure, a code generation method extracting component implementation code writing rules from the component repository document includes: Parsing the component implementation code in the component repository document to obtain an abstract syntax tree corresponding to the component implementation code; Extracting grammatical features and semantic features in the component implementation code based on the abstract syntax tree; Clustering different component implementation codes in the component repository document based on the grammatical features and the semantic features; Analyze the implementation codes of the same type of components to obtain the grammatical patterns and semantic patterns of the implementation codes of the same type of components; and According to the coverage of the grammatical pattern and the semantic pattern in the component repository document, a writing rule for the component implementation code is generated.
[0011] According to at least one embodiment of the present disclosure, the code generation method, after obtaining the component repository document, the business template, the structured description information, and the user interface design draft, further includes: The component warehouse document, the business template, the structured description information and the user interface design draft are input into a preset model, and page implementation code is generated through the preset model to obtain the page implementation code.
[0012] According to at least one embodiment of the present disclosure, the code generation method, after combining the multiple target component implementation codes based on the business template to obtain the page implementation code, further includes: receiving evaluation information for the page implementation code; Adjusting the writing rules based on the evaluation information; and Based on the adjusted writing rules, the page implementation code is modified.
[0013] According to another aspect of the present disclosure, an electronic device is provided, comprising: a memory storing execution instructions; and a processor executing the execution instructions stored in the memory, so that the processor executes the code generation method of any embodiment of the present disclosure.
[0014] According to another aspect of the present disclosure, a readable storage medium is provided, wherein the readable storage medium stores execution instructions, and when the execution instructions are executed by a processor, the code generation method of any embodiment of the present disclosure is implemented.
[0015] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the code generation method according to any one of the embodiments of the present disclosure is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings illustrate exemplary embodiments of the present disclosure and together with the description serve to explain the principles of the present disclosure. These drawings are included to provide a further understanding of the present disclosure and are incorporated in and constitute a part of this specification.
[0017] Figure 1 It is a flowchart of a code generation method according to an embodiment of the present disclosure.
[0018] Figure 2 It is a schematic diagram of a process of obtaining structured description information according to an embodiment of the present disclosure.
[0019] Figure 3 It is a schematic diagram of a process of obtaining structured description information according to another embodiment of the present disclosure.
[0020] Figure 4 It is a schematic diagram of the process of generating writing rules according to an embodiment of the present disclosure.
[0021] Figure 5 It is a schematic diagram of the process of modifying page implementation code according to an embodiment of the present disclosure.
[0022] Figure 6 It is a flowchart of a code generation method according to another embodiment of the present invention.
[0023] Figure 7 It is a schematic block diagram of the structure of a code generation device according to an embodiment of the present disclosure.
[0024] Figure 8It is a schematic block diagram of the structure of an electronic device according to one embodiment of the present disclosure. DETAILED DESCRIPTION
[0025] The present disclosure is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific examples described herein are intended only to illustrate the relevant content and are not intended to limit the present disclosure. It should also be noted that, for ease of description, only the portions relevant to the present disclosure are shown in the accompanying drawings.
[0026] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in the present disclosure can be combined with each other. The technical solution of the present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0027] In related technologies, developers manually write page implementation code based on user interface design drafts. Since user interface design drafts are usually provided in the form of images or static files, containing detailed information such as page layout, component styles, and interaction requirements, developers need to manually analyze and convert them into page implementation code. This process requires developers to invest a lot of time and effort and is prone to errors, resulting in low efficiency in page implementation code generation.
[0028] To this end, the present disclosure proposes a code generation method.
[0029] The code generation method disclosed herein can be used by an electronic device to automatically generate page implementation code corresponding to a user interface design draft after receiving a component repository document, a business template, structured description information, and a user interface design draft. In this disclosure, electronic devices include, but are not limited to, servers, mobile phones, tablets, laptops, personal computers, wearable devices, and ATMs.
[0030] Figure 1 FIG. 1 shows a schematic diagram of the overall flow of a code generation method M100 according to an embodiment of the present disclosure. Figure 1 The method shown includes steps S110 to S150, wherein the method can be executed by electronic devices such as a server, a mobile phone, and a computer.
[0031] Specifically, Figure 1 The methods shown include: S110. Obtain component repository documents, business templates, structured description information, and user interface design drafts, wherein the component repository documents are used to illustrate component implementation codes, the business templates at least illustrate the combination of component implementation codes, and the structured description information is business requirement information and page information described in the form of structured data.
[0032] The component repository document may be a document that stores multiple examples of component implementation code. By analyzing the example component implementation code in the component repository document, it is possible to understand the writing rules of the component implementation code.
[0033] A business template can be an example template for page implementation code that includes multiple component implementation codes. By analyzing the page implementation code in a business template, you can understand how the multiple component implementation codes are combined within the page implementation code, thereby facilitating the understanding of the component implementation code combination rules within the page implementation code.
[0034] Business requirement information may include one or more of the requirement name, requirement background, and business direction. Business requirement information can constrain the direction of component implementation code generation, avoiding the generation of component implementation code that does not meet business requirements.
[0035] The page information may include one or more of the page name, page function description, page interaction description, and call interface information. The page information can guide which component implementation codes are generated.
[0036] Structured data refers to data with a clear structure and format that can be easily stored, queried and processed by computers. It can be in tabular form, XML form, JSON form or key-value pair form.
[0037] Exemplarily, the component warehouse documents, business templates, and structured description information corresponding to different businesses may be different, and the component warehouse documents, business templates, and structured description information in step S110 can be understood as the component warehouse documents, business templates, and structured description information corresponding to the business to which the user interface design draft belongs.
[0038] S120. Extracting component implementation code writing rules from the component repository document.
[0039] Writing rules dictate how component implementation code should be written.
[0040] For example, different developers have different understanding abilities, programming habits, and programming styles. When manually writing page implementation codes based on user interface design drafts, it is possible that the page implementation codes written by developers are difficult for other developers to understand. If the page implementation codes are explained to others every time work is handed over or collaborated, it will lead to redundant work, consume a lot of time and energy, and affect work efficiency. However, since the writing rules and combination rules in the present disclosure can be extracted from known component warehouse documents and business templates respectively, when the component warehouse documents and business templates do not change, the page implementation codes automatically generated based on different user interface design drafts can have the same programming style, which makes it easier for different developers to quickly understand the page implementation codes. There is no need to repeatedly explain the page implementation codes to developers, thereby improving work efficiency.
[0041] S130: Determine the type, quantity, and calling interface information of components in the page according to the user interface design draft and the page information in the structured description information.
[0042] For example, the user interface design draft and page information may include the types, quantities and calling interface information of the components in the page. Therefore, after obtaining the user interface design draft and page information, the types, quantities and calling interface information of the components in the page can be accurately determined.
[0043] The call interface information may include one or more of an interface description, interface output parameters, interface input parameters, and a link to the interface documentation. The interface description can be used to explain the purpose of the interface, for example, explaining that a certain interface is used to click a certain button. The interface documentation link is a reference or address pointing to the interface documentation. The interface documentation link allows for quick locating and access to the interface documentation. The interface documentation may record the interface input parameters and interface output parameters.
[0044] S140: Generate multiple target component implementation codes that meet the types and quantities based on the writing rules, the calling interface information, and the business requirement information in the structured description information.
[0045] Combining the calling interface information and business requirements can ensure that the generated target component implementation code meets actual requirements in terms of functional implementation, thereby improving the integrity and usability of the final generated page implementation code, and is suitable for a variety of page development scenarios.
[0046] S150. Based on the business template, multiple target component implementation codes are combined to obtain page implementation code.
[0047] For example, after determining which components (i.e., types), how many components (i.e., quantity), how to write them (i.e., calling interface information and writing rules), how to combine them (i.e., business templates) and business constraints (i.e., business requirement information) are needed in the page, the page implementation code can be accurately and automatically generated to ensure the correctness of the generated single target component implementation code and the rationality of the overall layout of multiple target component implementation codes.
[0048] The business template can be pre-set according to the business specifications, for example, the business template can be set based on business specifications such as compact layout, normal layout, top-bottom layout, grid layout, etc. In one example, the compact layout business template includes<Input.Group compact> Features and<Form.Item> Sub-features,<Input.Group compact> The probability of the feature appearing in the compact layout business template is 100%, multiple<Form.Item> Sub-features are arranged in parallel and use noStyle respectively. Electronic devices can determine the following information through the compact layout business template: Compact layout requires<Input.Group compact> ,and<Form.Item> Use noStyle in<Form.Item noStyle> Arranged side by side. An example of a compact layout business template is as follows: / ** Compact layout example, xxx is replaced with a business string based on actual situation* / <Form.Item label="xxx" name="xxx"> / ** Compact layout template * / <Input.Group compact> <Form.Item name="xxx" noStyle> { / ** Replace the input component with the corresponding one based on the image recognition result. Pay attention to the input width* / } < / Form.Item> <Form.Item name="xxx" noStyle> / ** Replace the image with the corresponding input component based on the image recognition result. Pay attention to the input width* / < / Form.Item> < / Input.Group> < / Form.Item> The code generation method of the embodiment of the present disclosure, after obtaining the component warehouse document, business template, structured description information and user interface design draft, extracts the writing rules of the component implementation code from the component warehouse document, and determines the type, quantity and calling interface information of the components in the page according to the page information in the user interface design draft and the structured description information, and then generates multiple target component implementation codes that meet the types and quantities according to the writing rules, calling interface information and business requirement information in the structured description information, and combines multiple target component implementation codes together based on the business template to obtain page implementation code. Thus, a systematic process from multi-source input to automatic generation of page implementation code is realized, and the generation efficiency of page implementation code is improved. In addition, through the example role of the combination warehouse document and business template, the electronic device can accurately extract the writing rules and combination rules of the component implementation code, thereby helping the electronic device understand how to write and combine component implementation code, thereby improving the standardization and accuracy of the generated page implementation code. In addition, the page implementation code generation process combines the user interface design draft with the business requirements and page information in the structured description information, so that the generated page implementation code is highly matched with the actual needs, thereby improving the generation efficiency of the page implementation code, reducing the workload of manual coding, and being suitable for the automation needs of complex page development.
[0049] Regarding step S110, as a possible implementation, it may include the following: Figure 2 Steps S111 to S113 are shown.
[0050] S111. Based on the name of the preset field, prompt the user to enter the field content of the preset field.
[0051] Preset fields are fields in business requirement information and page information.
[0052] For example, the name of the preset field and text for prompting the user to input the field content of the preset field may be displayed, thereby prompting the user to input the field content of the preset field.
[0053] S112: Receive the field content of the preset field input by the user.
[0054] As a possible implementation, upon receiving the field content of a currently prompted preset field input by the user, the user may be prompted to enter the field content of another preset field, and so on, the user may be prompted to enter the content of the preset fields field by field, thereby obtaining the field content of all preset fields required to generate structured description information and avoiding omissions.
[0055] As another possible implementation, the user may be prompted to input the field contents of multiple preset fields required to generate structured description information at the same time, thereby simplifying the processing logic and improving prompt efficiency.
[0056] S113: Generate a mapping relationship between the name of the preset field and the field content of the preset field to obtain structured description information.
[0057] The mapping relationship between the generated name and the field content can be used as structured description information.
[0058] The code generation method of the above embodiment prompts the user to input the field content of the preset field based on the name of the preset field, and upon receiving the field content of the preset field input by the user, obtains structured description information by generating a mapping relationship between the name of the preset field and the field content of the preset field. Thus, a user-friendly interaction method is provided, which guides the user to input the field content of the preset field through the preset field, can standardize the expression of business demand information and page information, avoid information omission or ambiguity, and improve the accuracy of the generated structured description information. At the same time, the name of the preset field and the field content of the preset field are converted into a structured mapping relationship, which is convenient for subsequent processing and analysis, improves the generation efficiency and consistency of the structured description information, and provides a high-quality input basis for the generation of subsequent page implementation code.
[0059] Regarding step S110, as another possible implementation, it may include the following: Figure 3 Steps S111 ′ to S113 ′ are shown.
[0060] S111 ′: receiving business requirement information and page information input by the user.
[0061] S112 ′: Based on the name of the preset field, extract the field content of the preset field from the business requirement information and page information input by the user.
[0062] The business requirement information and page information input by the user may not be structured data, but text or documents. The electronic device can automatically extract the field content of the preset fields from the business requirement information and page information input by the user based on the name of the preset field, thereby providing data support for the subsequent generation of structured description information.
[0063] For example, the business demand information and page information input by the user can be split into multiple phrases, sentences or paragraphs by performing text segmentation and classification on the business demand information and page information input by the user, and the categories to which the multiple phrases, sentences or paragraphs belong are obtained, and then the phrases, sentences or paragraphs whose categories are the same as the names of the preset fields are used as the field contents of the corresponding preset fields.
[0064] S113': Generate a mapping relationship between the name of the preset field and the field content of the preset field to obtain structured description information.
[0065] The mapping relationship between the generated name and the field content can be used as structured description information.
[0066] In some embodiments, after step S113', the process further includes: displaying the generated structured description information; upon receiving a confirmation operation on the structured description information, executing steps S140 and S150 based on the structured description information; and upon receiving a modification operation on the structured description information, executing steps S140 and S150 based on the modified structured description information. In this way, the accuracy of the structured description information is ensured through manual verification, thereby providing high-quality data for code generation for page generation.
[0067] The code generation method of the above embodiment, when receiving the business requirement information and page information input by the user, extracts the field content of the preset field from the business requirement information and page information input by the user based on the name of the preset field, and then obtains structured description information by generating a mapping relationship between the name of the preset field and the field content of the preset field. In this way, the conversion from unstructured input to structured data is achieved. Compared with directly requiring users to input in a structured format, the code generation method of this embodiment allows users to provide business requirement information and page information in natural language or free form, which lowers the usage threshold and improves the user's operational convenience. At the same time, by generating structured description information through field content extraction and mapping, it is possible to effectively mine the key information in the business requirement information and page information input by the user, improve the flexibility and adaptability of information processing, and provide diversified input support for the generation of page implementation code.
[0068] Regarding step S113 or step S113', in some embodiments of the present disclosure, specifically: using the name of the preset field as the key and the field content of the preset field as the value, a key-value pair is generated, and the key-value pair is used as structured description information.
[0069] In an example, in the structured description information, the key of the requirement name field is prd_name, and the value of the requirement name field is a character string representing the requirement name; the key of the requirement background field is prd_background, and the value of the requirement background field is a character string representing the requirement background; the key of the business direction field is prd_business_direction, and the value of the business direction field is a character string representing the business direction; the key of the page name field is page_name, and the value of the page name field is a character string representing the page name; the key of the page function description field is page_desc, and the value of the page function description field is a character string representing the page function description; the key of the page interaction description field is page_Interaction, and the value of the page interaction description field is a character string representing the page interaction description; the key of the interface description field is api_desc, and the value of the interface description field is a character string representing the interface description; the key of the interface document link field is api_doc, and the value of the interface document link field is a character string representing the interface document link.
[0070] Furthermore, in the structured description information, the number of interface description fields and interface document link fields can be multiple, and the key-value pairs corresponding to the multiple interface description fields and the key-value pairs corresponding to the interface document link field can be recorded in an array named page_api, the page_api array, the key-value pairs corresponding to the page interaction description, the key-value pairs corresponding to the page function description, and the key-value pairs corresponding to the page name can be recorded in an array named pages, and the pages array, the key-value pairs corresponding to the requirement name field, the key-value pairs corresponding to the requirement background field, and the key-value pairs corresponding to the business direction field are recorded in the structured description information. In this way, compared to splitting the business requirement information and the page information into two documents, and / or forming the interface call information in the page information into a separate document, in this example, the business requirement information, page information, and interface call information are all aggregated in the same document (i.e., structured description information) in the form of structured data, thereby reducing the computer's understanding cost and facilitating the direct and rapid understanding and acquisition of business requirement information and page information through the structured description information.
[0071] The code generation method of the above embodiment uses the name of the preset field as the key and the field content of the preset field as the value to generate a key-value pair, and uses the key-value pair as structured description information. In this way, structured description information can be generated concisely and universally. It can be understood that the key-value pair format has good readability and scalability, and is convenient for storage, transmission and parsing; at the same time, compared to a whole paragraph of text in which business requirement information and page information are mixed together, the key-value pair format can intuitively reflect business requirement information and page information, and provide a standardized and consistent data foundation for the generation of subsequent page implementation code, thereby improving the stability and accuracy of the page implementation code generation process.
[0072] Regarding step S113 or step S113 ′, in other implementations, the mapping relationship between the name of the preset field and the field content of the preset field may also be represented in the form of an array, a table, or a graph structure, which is not limited here.
[0073] Regarding step S120, in some embodiments of the present disclosure, it may include the following: Figure 4 Steps S121 to S125 are shown.
[0074] S121. Parse the component implementation code in the component repository document to obtain an abstract syntax tree corresponding to the component implementation code.
[0075] For example, the component implementation code in the component repository document may be parsed by a syntax parser to obtain an abstract syntax tree corresponding to the component implementation code.
[0076] S122. Extract grammatical features and semantic features from the component implementation code based on the abstract syntax tree.
[0077] Syntactic features may include one or more of variable declaration features (such as the total number of variable declarations), function definition features (such as the average number of parameters in a function definition), control flow statement features (such as the nesting depth of control flow statements), and operator usage pattern features (such as the frequency and combination of arithmetic, logical, and comparison operators).
[0078] Exemplarily, each abstract syntax tree records multiple syntax units of each component implementation code. The abstract syntax tree can automatically identify and record the basic syntax units in each component implementation code, namely, one or more of variable declarations (such as type, name and initialization method), function definitions (such as function name, parameter list and return type), control flow statements (such as the structure and nesting level of if, for, while) and operator usage patterns (such as the frequency and combination of arithmetic, logical and comparison operators), and quantify the above syntax units into statistically significant features, such as the total number of variable declarations, the average number of parameters in function definitions, the nesting depth of control flow statements, etc., so as to obtain the syntax features corresponding to each component implementation code.
[0079] Semantic features may include one or more of function call relationship features (such as the depth and breadth of function call relationships), data flow dependency features (such as the length and complexity of data flow dependency chains), and logical execution path features (such as the number of branches and loop times of the logical execution path).
[0080] For example, each abstract syntax tree records the execution logic of each component implementation code. By performing semantic analysis on the abstract syntax tree, the execution logic of each component implementation code can be automatically identified. For example, by tracing function call relationships and recording the dependency graph between callers and callees; by analyzing variable usage and assignments, data flow dependency chains are generated to identify how data is passed within the code; and by simulating the execution order of control flow statements, logical execution paths are extracted and the triggering patterns of conditional branches and loops are recorded. This semantic information (i.e., execution logic) is then quantified into features, such as the depth and breadth of function call relationships, the length and complexity of data flow dependency chains, the number of branches in the logical execution path, and the number of loops, thereby obtaining the semantic features corresponding to each component implementation code.
[0081] S123. Clustering different component implementation codes in the component repository document based on grammatical features and semantic features.
[0082] Exemplarily, the grammatical features and semantic features corresponding to the component implementation code can be taken as an overall feature, and then the overall features corresponding to multiple component implementation codes in the component repository document can be clustered to obtain multiple groups of related component implementation codes.
[0083] S124. Analyze the implementation codes of the components of the same type to obtain the grammatical pattern and semantic pattern of the implementation codes of the components of the same type.
[0084] Syntax patterns refer to the structural commonalities of component implementation codes, such as specific control flow structures (such as the usage habits of if-else) or function definition methods. For example, first, determine the key grammatical features in the same type of component implementation code. The key grammatical features are grammatical features whose average value in the current type of component implementation code is greater than the average value in other types of component implementation code, and / or grammatical features whose average value in the current type of component implementation code is greater than the average value in other types of component implementation code. For example, if the average value of "control flow statement nesting depth" in a cluster is significantly higher than that in other clusters, it means that these codes tend to use deeply nested control structures; if the average value of "average number of parameters in function definition" is lower than that in other clusters, it means that these codes tend to define functions with fewer parameters. Next, trace back the component implementation code, that is, extract several representative samples from the component implementation code corresponding to the cluster, and analyze how these grammatical features are reflected in the component implementation code. For example, a high nesting depth may be manifested as multiple layers of if-else or for loops. Furthermore, based on the analysis results, specific grammatical patterns are summarized, for example, “multi-layer nested if-else structures tend to be used to handle conditional logic” and “function definitions usually contain no more than 2 parameters”.
[0085] Semantic patterns refer to the logical or functional commonalities within component implementation code, such as how data flows or how functions collaborate. For example, key semantic features are first identified within the implementation code of components of the same class. These are semantic features whose mean value in the implementation code of the current class is greater than the mean value in the implementation code of components of other classes, and / or semantic features whose mean value in the implementation code of the current class is greater than the mean value in the implementation code of components of other classes. For example, if the mean value of "data flow dependency chain length" is long, it indicates that these codes tend to pass data through multiple variables; if the "breadth of function call relationships" is high, it indicates that these codes have a high degree of collaboration between functions. Next, the component implementation code is retrospectively analyzed, that is, several representative samples are extracted from the component implementation code corresponding to the cluster, and how semantic features such as data flow or function calls are reflected in the component implementation code. For example, a long dependency chain may be manifested as a variable passing from function A to B and then to C. Furthermore, based on the analysis results, specific semantic patterns are summarized, such as "data flow tends to pass continuously through more than three variables" and "function call patterns are multiple small functions collaborating to complete a single function."
[0086] S125. Generate writing rules for component implementation code based on the coverage of grammatical patterns and semantic patterns in component repository documents.
[0087] For example, if the coverage rate of a certain grammatical pattern or a certain semantic pattern in a group of associated component implementation codes in multiple component implementation codes in the component repository document is greater than the coverage threshold (for example, 80%), then the grammatical pattern or semantic pattern can be used as a writing rule, for example, "the number of parameters in the function definition shall not exceed 3", "avoid more than 5 continuous variable passes in the data flow dependency chain", and so on. In this way, multiple groups of associated component implementation codes are automatically analyzed to obtain multiple writing rules for the component implementation codes.
[0088] It should be noted that the specific numerical values mentioned above are only used as examples to illustrate the implementation of the present disclosure in detail and should not be understood as limiting the present disclosure. In other examples, implementation methods, or embodiments, other numerical values can be selected according to the present disclosure and are not specifically limited here.
[0089] The code generation method of the above embodiment parses the component implementation code in the component warehouse document to obtain the abstract syntax tree corresponding to the component implementation code, and extracts the grammatical features and semantic features in the component implementation code based on the abstract syntax tree, and then clusters the different component implementation codes in the component warehouse document based on the grammatical features and semantic features; and analyzes the same type of component implementation code to obtain the grammatical pattern and semantic pattern of the same type of component implementation code; and generates the writing rules of the component implementation code based on the coverage of the grammatical pattern and semantic pattern in the component warehouse document. Thus, a systematic refinement from the example component implementation code to the writing rules is achieved. Among them, through the analysis of the abstract syntax tree, the structure and logical characteristics of the component implementation code can be fully captured; combined with the statistics of the frequency of occurrence and correlation of the features, it is ensured that the extracted component implementation code writing rules are representative and universal, so that the component implementation code automatically generated based on the writing rules conforms to the specifications of the component warehouse, improves the quality and maintainability of the automatically generated component implementation code, and reduces the generation errors caused by the lack of writing rules.
[0090] In some embodiments of the present disclosure, after step S110, the following may also be included: inputting component warehouse documents, business templates, structured description information and user interface design drafts into a preset model, generating page implementation code through the preset model, and obtaining page implementation code.
[0091] The preset model can be a deep learning model, such as one based on the Transformer architecture or other deep learning models. Component repository documents, business templates, and structured description information can be input into the preset model as one or more documents or as a single, long text file, without limitation.
[0092] For example, the preset model can implement steps S120 to S150 to generate page implementation code. Different businesses can use different preset models, so that each preset model can focus on processing its own business, thereby isolating the businesses from each other and improving the accuracy of the generated page implementation code.
[0093] The code generation method of the above embodiment inputs component repository documents, business templates, structured description information, and user interface design drafts into a preset model, and generates page implementation code using the preset model. Thus, by integrating multiple inputs using the preset model and automatically generating page implementation code, a model-based code generation path is provided, improving the efficiency and intelligence of page implementation code generation. Furthermore, the introduction of the preset model provides flexibility for page implementation code generation in complex scenarios, enabling it to adapt to page requirements of different types and sizes, thereby enhancing the scope of application and generation quality of the method.
[0094] In some embodiments of the present disclosure, after step S150, the following steps may also be included: Figure 5 Steps S160 to S180 are shown.
[0095] S160: Receive evaluation information for the page implementation code.
[0096] Evaluation information may include one or more of likes, dislikes, ratings, and evaluation text. Evaluation information may be entered by a person who views the page implementation code.
[0097] S170. Adjust the writing rules based on the evaluation information.
[0098] For example, if the review information indicates dissatisfaction with the generated page implementation code, such as a number of downvotes, a score below a threshold, or negative descriptions in the review text, the writing rules can be adjusted. If the review information contains adjustment instructions, the writing rules can be adjusted based on the adjustment instructions; if the review information does not contain adjustment instructions, the writing rules can be adjusted based on pre-set adjustment instructions.
[0099] S180. Based on the adjusted writing rules, modify the page implementation code.
[0100] It is understandable that before the next adjustment of the writing rules, the page implementation code will be generated based on the writing rules after this adjustment, so as to meet the user's needs and generate the page implementation code that meets the user's requirements.
[0101] The code generation method of the above-described embodiment receives evaluation information regarding page implementation code, adjusts the writing rules based on the evaluation information, and modifies the page implementation code based on the adjusted writing rules. This allows for timely correction of deficiencies in the generated page implementation code based on the evaluation information, implementing a feedback optimization mechanism for page implementation code generation and improving the accuracy and adaptability of the adjusted writing rules. By adjusting the writing rules to drive subsequent page implementation code modifications, the modified page implementation code is ensured to better meet user needs, thereby improving the practicality and user satisfaction of the code generation method and supporting long-term use and continuous improvement.
[0102] Please combine Figure 6 In one example, the code generation method may include the following steps S201 to S205. The contents related to steps S201 to S205 can refer to the description of the above embodiment. For the sake of brevity, they will not be repeated here.
[0103] In step S201, component repository documents, business templates, structured description information and user interface design drafts are obtained.
[0104] In step S202, the component warehouse document, business template, structured description information and user interface design draft are input into the preset model, and the page implementation code is generated through the preset model to obtain the page implementation code.
[0105] In step S203, evaluation information on the page implementation code is received.
[0106] In step S204 , the writing rules are adjusted based on the evaluation information.
[0107] In step S205 , the page implementation code is modified based on the adjusted writing rules.
[0108] Based on any of the above embodiments, the present disclosure also provides a code generation device.
[0109] Figure 7 It is a schematic block diagram of the structure of a code generation device according to an embodiment of the present disclosure.
[0110] like Figure 7 As shown, the code generating device includes: Acquisition module 110 is used to obtain component warehouse documents, business templates, structured description information and user interface design drafts, wherein the component warehouse documents are used to illustrate the component implementation code, the business templates are used to illustrate the combination method of the component implementation code, and the structured description information is business requirement information and page information described in the form of structured data.
[0111] The extraction module 120 is used to extract the writing rules of the component implementation code from the component repository document.
[0112] The determination module 130 is used to determine the type, quantity and calling interface information of the components in the page according to the user interface design draft and the page information in the structured description information.
[0113] The generation module 140 is used to generate a plurality of target component implementation codes of the required types and quantities according to the writing rules, the calling interface information and the business requirement information in the structured description information.
[0114] The combining module 150 is used to combine multiple target component implementation codes based on the business template to obtain page implementation code.
[0115] The above-mentioned code generating device may be in the form of computer software, and each module of the above-mentioned code generating device may be implemented by a computer software module.
[0116] In some embodiments of the present disclosure, the acquisition module 110 is used to: prompt the user to enter the field content of the preset field based on the name of the preset field; receive the field content of the preset field entered by the user; and generate a mapping relationship between the name of the preset field and the field content of the preset field to obtain structured description information.
[0117] In other embodiments of the present disclosure, the acquisition module 110 is used to: receive business requirement information and page information input by the user; extract the field content of the preset field from the business requirement information and page information input by the user based on the name of the preset field; and generate a mapping relationship between the name of the preset field and the field content of the preset field to obtain structured description information.
[0118] In some embodiments of the present disclosure, the acquisition module 110 is used to generate a key-value pair using the name of the preset field as the key and the field content of the preset field as the value, and use the key-value pair as structured description information.
[0119] In some embodiments of the present disclosure, the extraction module 120 is used to: parse the component implementation code in the component repository document to obtain an abstract syntax tree corresponding to the component implementation code; extract the grammatical features and semantic features in the component implementation code based on the abstract syntax tree; cluster different component implementation codes in the component repository document based on the grammatical features and semantic features; analyze the same type of component implementation code to obtain the grammatical pattern and semantic pattern of the same type of component implementation code; and generate writing rules for the component implementation code based on the coverage of the grammatical pattern and semantic pattern in the component repository document.
[0120] In some embodiments of the present disclosure, the code generation device also includes a second generation module, which is used to input component warehouse documents, business templates, structured description information and user interface design drafts into a preset model, generate page implementation code through the preset model, and obtain page implementation code.
[0121] In some embodiments of the present disclosure, the code generation device further includes a receiving module, an adjustment module, and a modification module. The receiving module is configured to receive evaluation information for the page implementation code; the adjustment module is configured to adjust the writing rules based on the evaluation information; and the modification module is configured to modify the page implementation code based on the adjusted writing rules.
[0122] The implementation process of the functions and effects of each module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0123] The execution subject of the code generation method in the specific embodiment of the present disclosure can be an electronic device such as a server, a mobile phone, or a computer.
[0124] Therefore, based on any of the above embodiments, the present disclosure further provides an electronic device, which can execute the code generation method of any of the above embodiments described in the present disclosure.
[0125] Figure 8 1 is a schematic block diagram of the structure of an electronic device 1000 according to an embodiment of the present disclosure.
[0126] The hardware structure of the electronic device 1000 can be implemented using a bus architecture. The bus architecture can include any number of interconnecting buses and bridges, depending on the specific application and overall design constraints of the hardware. The bus 1100 connects various circuits including one or more processors 1200, memory 1300, and / or hardware modules. The bus 1100 can also connect various other circuits 1400 such as peripheral devices, voltage regulators, power management circuits, external antennas, etc.
[0127] Bus 1100 may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Component Architecture (EISA) bus. Buses can be classified as address buses, data buses, control buses, and the like. For ease of illustration, this figure shows only one connecting line, but this does not imply that there is only one bus or only one type of bus.
[0128] The present disclosure also provides a readable storage medium having a computer program stored therein, which is used to implement the above-mentioned method when the computer program is executed by a processor. "Readable storage medium" can be any device that can contain, store, communicate, propagate or transmit a program for use in an instruction execution system, device or equipment or in combination with these instruction execution systems, devices or equipment. More specific examples of readable storage media include the following: an electrical connection portion with one or more wirings (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and editable read-only memory (EPROM or flash memory), an optical fiber device, and a portable read-only memory (CDROM), etc.
[0129] The present disclosure also provides a computer program product. The method of the present disclosure can be implemented in whole or in part using software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instructions are loaded and executed, the process or function of the present disclosure is performed in whole or in part.
[0130] A computer program or instruction can be stored in a readable storage medium or transferred from one readable storage medium to another. For example, the computer program or instruction can be transferred from one website, computer, server, or data center to another website, computer, server, or data center via wired or wireless means. The readable storage medium can be any accessible medium or a data storage device such as a server or data center that integrates one or more accessible media. The accessible medium can be a magnetic medium such as a floppy disk, hard disk, or magnetic tape; an optical medium such as a digital video disk; or a semiconductor medium such as a solid-state drive. The computer-readable storage medium can be a volatile or non-volatile storage medium, or can include both volatile and non-volatile types of storage media.
[0131] Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as methods, systems, or computer program products. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present disclosure may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0132] The present disclosure is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present disclosure. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0133] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0134] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0135] In the description of this specification, the description with reference to the terms "one embodiment / method", "some embodiments / methods", "example", "specific example", or "some examples" means that the specific features, structures, or characteristics described in conjunction with the embodiment / method or example are included in at least one embodiment / method or example of the present disclosure. In this specification, the schematic expressions of the above terms do not necessarily refer to the same embodiment / method or example. Moreover, the specific features, structures, or characteristics described may be combined in a suitable manner in any one or more embodiments / methods or examples. In addition, those skilled in the art may combine and combine different embodiments / methods or examples described in this specification and the features of different embodiments / methods or examples, unless they are contradictory.
[0136] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features being referred to. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. Throughout the present disclosure, "plurality" means at least two, such as two, three, etc., unless otherwise specifically defined.
[0137] Those skilled in the art will appreciate that the above embodiments are merely intended to clearly illustrate the present disclosure and are not intended to limit the scope of the present disclosure. Other changes or modifications may be made based on the above disclosure, and such changes or modifications are still within the scope of the present disclosure.
Claims
1. A code generation method, characterized in that: include: Obtain component repository documents, business templates, structured description information, and user interface design drafts. The component repository documents are used to illustrate component implementation codes, the business templates are used to illustrate the combination of component implementation codes, and the structured description information is business requirement information and page information described in the form of structured data. Extracting component implementation code writing rules from the component repository document; Determine the type, quantity, and calling interface information of components on the page based on the user interface design draft and the page information in the structured description information; Generate a plurality of target component implementation codes that meet the types and quantities according to the writing rules, the calling interface information and the business requirement information in the structured description information; and Based on the business template, the multiple target component implementation codes are combined together to obtain page implementation code.
2. The code generation method according to claim 1, characterized in that Get structured description information, including: Based on the name of the preset field, prompt the user to enter the field content of the preset field; receiving the field content of the preset field input by the user; and A mapping relationship between the name of the preset field and the field content of the preset field is generated to obtain the structured description information.
3. The code generation method according to claim 1, characterized in that Get structured description information, including: Receive business requirement information and page information input by users; Based on the name of the preset field, extracting the field content of the preset field from the business requirement information and page information input by the user; and A mapping relationship between the name of the preset field and the field content of the preset field is generated to obtain the structured description information.
4. The code generation method according to claim 2 or 3, characterized in that: Generating a mapping relationship between the name of the preset field and the field content of the preset field to obtain the structured description information includes: A key-value pair is generated with the name of the preset field as the key and the field content of the preset field as the value, and the key-value pair is used as the structured description information.
5. The code generation method according to claim 1, characterized in that: Extract the component implementation code writing rules from the component repository document, including: Parsing the component implementation code in the component repository document to obtain an abstract syntax tree corresponding to the component implementation code; Extracting grammatical features and semantic features in the component implementation code based on the abstract syntax tree; Clustering different component implementation codes in the component repository document based on the grammatical features and the semantic features; Analyze the implementation codes of the same type of components to obtain the grammatical patterns and semantic patterns of the implementation codes of the same type of components; and According to the coverage of the grammatical pattern and the semantic pattern in the component repository document, a writing rule for the component implementation code is generated.
6. The code generation method according to claim 1, characterized in that After obtaining component repository documents, business templates, structured description information, and user interface design drafts, it also includes: The component warehouse document, the business template, the structured description information and the user interface design draft are input into a preset model, and page implementation code is generated through the preset model to obtain the page implementation code.
7. The code generation method according to claim 1, characterized in that After combining the plurality of target component implementation codes based on the business template to obtain the page implementation code, the method further includes: receiving evaluation information for the page implementation code; Adjusting the writing rules based on the evaluation information; and Based on the adjusted writing rules, the page implementation code is modified.
8. An electronic device, characterized in that: include: a memory storing execution instructions; as well as A processor, wherein the processor executes the execution instruction stored in the memory, so that the processor executes the code generation method according to any one of claims 1 to 7.
9. A readable storage medium, characterized in that: The readable storage medium stores execution instructions, which are used to implement the code generation method according to any one of claims 1 to 7 when executed by a processor.
10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the code generation method according to any one of claims 1 to 7 is implemented.