Output text-oriented template code modification method and system based on deep learning
By constructing an output text-oriented template code modification method based on deep learning and using the Transformer architecture for multi-source information modeling and context understanding, automatic synchronization of output text editing and template code is achieved, solving the problems of frequent switching and manual logic tracking in existing template development, and improving development efficiency and accuracy.
Patent Information
- Application Number
- CN202510701075.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-28
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2045-05-28
AI Technical Summary
Existing template development methods are difficult to meet the requirements of efficiency and intuitiveness. Developers need to frequently switch between template code and output text, manually track logic and run code repeatedly. The process is cumbersome and error-prone, especially when debugging is complex when nested conditions or multi-layer loops are involved.
An output text-oriented template code modification method based on deep learning is adopted. By constructing a two-stage bidirectional framework, structured mapping and automatic synchronization between output text editing and template code are achieved. The encoder-decoder structure of the Transformer architecture is used for multi-source information modeling and context understanding, generating structured update instructions and automatically synchronizing template code.
It significantly improves the efficiency and accuracy of intelligent conversion from natural editing behavior to code structure modification, simplifies the template editing process, reduces the error rate, and meets the intelligent modification needs in complex template scenarios.
Smart Images

Figure CN120215912B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer software engineering, and in particular to a method and system for modifying output text-oriented template code based on deep learning. Background Art
[0002] In modern software development, templates are widely used to automate the generation of various artifacts, improving development efficiency and consistency. Templates are widely adopted not only in model-driven development frameworks like Acceleo and XTend, but also play a key role in user interface design tools like Vue, React, and Angular, document generation tools like Markdown, LaTeX, and Pandoc, and configuration file generation tools like Dhall. These template technologies significantly simplify the development process and improve software engineering productivity.
[0003] Although template code is typically short, often consisting of only a few hundred lines, it contains a variety of control structures, such as variable bindings, conditional statements, assignments, and function calls. In traditional template development, developers rely on an iterative workflow: after writing or modifying the template code, they execute the code to generate output text, and then verify the correctness of the template by checking the output. If the output does not meet expectations, they need to return to the template code, identify the problem, make adjustments, and then run the code again to confirm the effect of the changes. Because the correspondence between template code and generated output text is not always intuitive, locating and correcting errors becomes a complex and time-consuming task. For example, in Mustache templates, variable assignments and uses may be far apart, requiring backtracking through multiple variable bindings to modify specific output content, which increases debugging complexity. Especially when templates involve nested conditionals or multiple layers of loops, tracking changes in variables and control structures is time-consuming and error-prone.
[0004] In summary, current template development methods struggle to meet the demands for efficiency and intuitiveness. Developers must frequently switch between template code and output, manually tracking logic and repeatedly running code, a tedious and error-prone process. Therefore, there is an urgent need for a deep learning-based template code modification method that is output-text-oriented and allows developers to directly edit the output text generated by the template. This would significantly simplify the template development process and improve development efficiency, accuracy, and intelligence. Summary of the Invention
[0005] To solve the above problems, the present invention proposes an output text-oriented template code modification method based on deep learning. With the output text as the center, by constructing a two-stage bidirectional framework including a deep learning module, it realizes structured mapping and automatic synchronization between output text editing and template code, thereby improving the intelligence and automation of template development.
[0006] The specific plan is as follows:
[0007] A deep learning-based output text-oriented template code modification method, comprising:
[0008] S1, the template code to be modified is processed by the template code conversion module to perform semantic normalization processing to obtain the core language representation of the semantic norm;
[0009] S2: Input the core language representation of the semantic specification into the forward computation phase of the two-stage bidirectional framework. Through forward computation, the core language representation of the semantic specification is converted into an initial structured intermediate representation. The variable declarations and assignment expressions in the initial structured intermediate representation are converted into functional structures. Based on the functional structures, a final structured intermediate representation is generated, and metadata information of the final structured intermediate representation is recorded. The final structured intermediate representation is converted into output text.
[0010] S3, receiving an edit operation on the output text, obtaining the edited output text, generating an edit instruction based on the edited output text, and parsing the edit instruction into a corresponding update operation; the update operation includes the edited output text content and the operation type;
[0011] S4: Input the edited output text content, operation type, and metadata information into the deep learning module, predict the structured update instructions through the deep learning module, and fuse the structured update instructions into the structured intermediate representation to obtain the fused structured intermediate representation;
[0012] S5, through the backpropagation stage in the two-stage bidirectional framework, performs functional structure expansion processing on the fused structured intermediate representation to obtain the restored structured intermediate representation, de-evaluates the restored structured intermediate representation to obtain the restored core language representation, and converts the restored core language representation into the final modified template code.
[0013] Said S1 specifically includes:
[0014] S11, receiving the template code to be modified;
[0015] S12, performing syntax analysis and structural parsing operations on the template code, identifying and extracting variable declarations, assignment statements, and control structures in the template code; the control structures include conditional judgments and loop bodies;
[0016] S13 converts variable declarations, assignment statements, and control structures into a standardized core language representation, adds variable binding information and scope markers to the core language representation to clarify the life cycle and visible range of the variables, and outputs a semantically standardized core language representation.
[0017] Furthermore, the S2 specifically includes:
[0018] S21, performing line-by-line parsing of the semantically standardized core language representation to obtain an initial structured intermediate representation and recording execution trajectory information; the execution trajectory information includes the code execution order, conditional branch paths, and loop expansion; during the line-by-line parsing process, extracting and establishing the static code structure and dynamic execution path of the core language representation, the dynamic execution path including the actual flow path of conditional judgments and loops; converting variable declarations and assignment statements in the initial structured intermediate representation into functional structures with attached semantic labels, and recording the binding relationships between variables and the semantic side effects that may be induced;
[0019] S22, generating a final structured intermediate representation based on the static code structure and the dynamic execution path; the final structured intermediate representation includes function calls, variable usage, and control structures;
[0020] S23: Embed control flow markers in the final structured intermediate representation and record metadata information in the structured intermediate representation; the metadata information includes the life cycle, scope, expression type, and semantic label of the variable; the control flow markers are used to identify the logical start and end positions, conditional expressions, and branch jump relationships of each control structure in the structured intermediate representation;
[0021] S24, performing a destructuring operation on the structured intermediate representation to obtain an output text; the output text supports editing operations.
[0022] Furthermore, the S3 specifically includes:
[0023] S31, receiving an editing operation performed by a user based on the output text, wherein the editing operation includes inserting text, deleting text, and replacing text;
[0024] S32, determine the number of editing operations; if the number is equal to one, take the received editing operation as input, parse and convert it into a structured update operation, extract and record the corresponding operation type, target location and operation content; if there is more than one, parse multiple editing instructions and convert them into structured update operations, and perform semantic consistency verification and sequential relationship analysis at the same time, perform batch fusion processing based on the analysis results, and generate an ordered set of update operations.
[0025] Furthermore, the S4 specifically includes:
[0026] S41: Inputting the edited output text content, operation type, and metadata information recorded in the structured intermediate representation as multi-source inputs into a deep learning module; the deep learning module is built based on the Transformer architecture and adopts an encoder-decoder structure, wherein the encoder semantically encodes the multi-source inputs and the decoder generates corresponding structured update instructions based on the context; the structured update instructions include modifying variable assignments, adjusting loop structures, and replacing or deleting control statements;
[0027] S42, fuses the structured update instruction into the structured intermediate representation, introduces a functional structure with semantic labels during the fusion process to ensure the structural consistency of the binding relationship between variables and the semantic side effect information during the fusion process, and at the same time refers to the control flow markers embedded in the structured intermediate representation to locate and verify the control structure corresponding to the structured update instruction, ensure the integrity of the fusion result in the control structure and the consistency of the execution path, and obtain the fused structured intermediate representation.
[0028] Furthermore, in S5, through the back-propagation stage in the two-stage bidirectional framework, a functional structural expansion process is performed on the fused structured intermediate representation to obtain a restored structured intermediate representation. The restored structured intermediate representation is then de-evaluated to obtain a restored core language representation, specifically including:
[0029] S51, receiving the fused structured intermediate representation as input, and performing functional structural expansion processing to reduce the semantic markup used to represent variable assignments and dependencies in the structured intermediate representation into explicit variable declaration statements and assignment statements; during the reduction process, the nested grammatical structure is eliminated through a structural flattening operation to generate a reduced structured intermediate representation that conforms to grammatical specifications;
[0030] S52, perform de-evaluation processing on the explicit variable declaration statements and assignment statements in the restored structured intermediate representation, restore the computational structure of each declaration statement and assignment statement based on the execution trajectory information recorded in the forward calculation stage and the control flow markers embedded in the structured intermediate representation, and reconstruct the conditional judgment statements and loop structures in the control flow, and output the restored core language representation.
[0031] Furthermore, the restored core language representation is converted into the final modified template code, specifically including:
[0032] The control structure expressed in the restored core language is restored into the corresponding conditional branch statements and loop statements in the surface language. The variable declarations and assignment operations in the restored core language are mapped into grammatical forms with corresponding semantics in the surface language. The final template code output is generated based on the conditional branch statements, loop statements, variable declarations, and assignment operations converted into the surface language.
[0033] On the other hand, a deep learning-based output text-oriented template code modification system includes:
[0034] A semantic normalization module is used to perform semantic normalization processing on the template code to be modified through the template code conversion module to obtain a core language representation of the semantic norm;
[0035] The output text conversion module is used to input the core language representation of the semantic specification into the forward calculation stage of the two-stage bidirectional framework, convert the core language representation of the semantic specification into an initial structured intermediate representation through forward calculation, convert the variable declarations and assignment expressions in the initial structured intermediate representation into a functional structure, generate the final structured intermediate representation based on the functional structure, and record metadata information of the final structured intermediate representation; and convert the final structured intermediate representation into output text;
[0036] An update operation acquisition module is configured to receive an edit operation on an output text, obtain the edited output text, generate an edit instruction based on the edited output text, and parse the edit instruction into a corresponding update operation; the update operation includes the content of the edited output text and the operation type;
[0037] A fusion module is used to input the edited output text content, operation type and metadata information into the deep learning module, obtain structured update instructions through prediction by the deep learning module, and fuse the structured update instructions into the structured intermediate representation to obtain a fused structured intermediate representation;
[0038] The template code modification module is used to perform functional structure expansion processing on the fused structured intermediate representation through the backpropagation stage in the two-stage bidirectional framework to obtain the restored structured intermediate representation, de-evaluate the restored structured intermediate representation to obtain the restored core language representation, and convert the restored core language representation into the final modified template code.
[0039] The present invention adopts the above technical solution and has the following beneficial effects:
[0040] (1) The present invention normalizes the template code represented by the surface language into the core language through the template code conversion module, unifies its semantic structure and control logic, and effectively reduces the complexity of subsequent in-depth analysis and processing;
[0041] (2) The present invention adopts the forward computation phase in a two-phase bidirectional framework to generate a structured intermediate representation by simulating the evaluation process of the template code and embedding metadata information such as control structures and variable bindings, thus providing precise contextual support for structured update operations.
[0042] (3) This invention introduces a deep learning module based on the Transformer architecture, which uses its multi-source information modeling and context understanding capabilities to convert user editing instructions on the output text into structured update instructions, significantly improving the efficiency and accuracy of the intelligent conversion from natural editing behavior to code structure modification;
[0043] (4) In the back-propagation phase, the present invention restores the structured update results obtained by deep learning prediction into core language code through functional structure expansion and de-evaluation processing, and supports semantic reconstruction of variable declarations, assignment statements, and control flow structures, achieving high-fidelity modification and synchronization of template code;
[0044] (5) The present invention ultimately restores the modified core language representation to the surface language template code, ensuring that the output result complies with the grammatical specifications and engineering environment requirements of the original template language, thereby simplifying the template editing process, improving development efficiency, reducing the error rate, and meeting the intelligent modification needs in complex template scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 This is a flow chart of a method for modifying output text-oriented template code based on deep learning according to an embodiment of the present invention;
[0046] Figure 2 This is a diagram of an output text-oriented template code modification system based on deep learning according to an embodiment of the present invention;
[0047] Figure 3 This is a two-stage bidirectional framework diagram of the output text-oriented template code modification method based on deep learning in an embodiment of the present invention. DETAILED DESCRIPTION
[0048] The present invention will be described in further detail below with reference to the examples and accompanying drawings, but the embodiments of the present invention are not limited thereto. Figure 1 As shown, the output text-oriented template code modification method based on deep learning of the present invention includes:
[0049] S1, the template code to be modified is semantically normalized through the template code conversion module to obtain the core language representation of the semantic norm.
[0050] Specifically, the S1 includes:
[0051] S11, receiving the template code to be modified as input;
[0052] S12, performing syntax analysis and structural parsing operations on the template code, identifying and extracting variable declarations, assignment statements, and control structures in the template code; the control structures include conditional judgments and loop bodies;
[0053] S13 converts variable declarations, assignment statements, and control structures into a standardized core language representation, adds variable binding information and scope markers to the core language representation to clarify the life cycle and visible range of the variables, and outputs a semantically standardized core language representation.
[0054] S2 inputs the semantically standardized core language representation into the forward computation phase of the two-stage bidirectional framework, obtains the structured intermediate representation of the core language representation through forward computation, and records the metadata information of the structured intermediate representation; converts the structured intermediate representation into output text.
[0055] Specifically, the S2 includes:
[0056] S21, performing line-by-line parsing of the semantically standardized core language representation to obtain an initial structured intermediate representation and recording execution trajectory information; the execution trajectory information includes the code execution order, conditional branch paths, and loop expansion; during the line-by-line parsing process, extracting and establishing the static code structure and dynamic execution path of the core language representation, the dynamic execution path including the actual flow path of conditional judgments and loops; converting variable declarations and assignment statements in the initial structured intermediate representation into functional structures with attached semantic labels, and recording the binding relationships between variables and the semantic side effects that may be induced;
[0057] S22, generating a final structured intermediate representation based on the static code structure and the dynamic execution path; the final structured intermediate representation includes function calls, variable usage, and control structures;
[0058] S23: Embed control flow markers in the final structured intermediate representation and record metadata information in the structured intermediate representation; the metadata information includes the life cycle, scope, expression type, and semantic label of the variable; the control flow markers are used to identify the logical start and end positions, conditional expressions, and branch jump relationships of each control structure in the structured intermediate representation;
[0059] S24, performing a destructuring operation on the structured intermediate representation to obtain an output text; the output text supports editing operations.
[0060] S3, receiving an editing operation on the output text, obtaining the edited output text, generating an editing instruction based on the edited output text, and parsing the editing instruction into a corresponding update operation; the update operation includes the edited output text content and the operation type.
[0061] Specifically, the S3 includes:
[0062] S31, receiving an editing operation performed by a user based on the output text, wherein the editing operation includes inserting text, deleting text, and replacing text;
[0063] S32, determine the number of editing operations; if the number is equal to one, take the received editing operation as input, parse and convert it into a structured update operation, extract and record the corresponding operation type, target location and operation content; if there is more than one, parse multiple editing instructions and convert them into structured update operations, and perform semantic consistency verification and sequential relationship analysis at the same time, perform batch fusion processing based on the analysis results, and generate an ordered set of update operations.
[0064] S4, inputs the edited output text content, operation type and metadata information into the deep learning module, obtains the structured update instructions through the deep learning module prediction, fuses the structured update instructions into the structured intermediate representation, and obtains the fused structured intermediate representation.
[0065] Specifically, the S4 includes:
[0066] S41: Input the edited output text content, operation type, and metadata information recorded in the structured intermediate representation into a deep learning module; the deep learning module is built based on the Transformer architecture and adopts an encoder-decoder structure, wherein the encoder performs semantic encoding on multi-source inputs, and the decoder generates corresponding structured update instructions based on the context; the structured update instructions include modifying variable assignments, adjusting loop structures, and replacing or deleting control statements; wherein the encoder is composed of several layers of multi-head attention mechanisms and feedforward neural networks, and the input is the text content to be edited, the operation type, and metadata information, and vector representation fusion is performed through positional encoding; the decoder is also composed of multiple layers of attention and feedforward networks, and generates corresponding structured update instructions based on the context through a cross-attention mechanism of self-attention and encoder output;
[0067] S42, fuses the structured update instruction into the structured intermediate representation, introduces a functional structure with semantic labels during the fusion process to ensure the structural consistency of the binding relationship between variables and the semantic side effect information during the fusion process, and at the same time refers to the control flow markers embedded in the structured intermediate representation to locate and verify the control structure corresponding to the structured update instruction, ensure the integrity of the fusion result in the control structure and the consistency of the execution path, and obtain the fused structured intermediate representation.
[0068] The functional structure with semantic tags introduced in this embodiment can be understood as a labeled Lambda application, which is used to represent variable declaration and assignment to achieve consistent control of side effects. The updated computational structured output is subsequently de-Lambda-applied (functional structure expansion) and de-evaluated, and then the core language representation is rebuilt and finally converted into the modified template program code.
[0069] S5, through the backpropagation stage in the two-stage bidirectional framework, performs functional structure expansion processing on the fused structured intermediate representation to obtain the restored structured intermediate representation, de-evaluates the restored structured intermediate representation to obtain the restored core language representation, and converts the restored core language representation into the final modified template code.
[0070] Specifically, in S5, through the backpropagation stage in the two-stage bidirectional framework, functional structural expansion is performed on the fused structured intermediate representation to obtain the restored structured intermediate representation. The restored structured intermediate representation is then de-evaluated to obtain the restored core language representation, specifically including:
[0071] S51, receiving the fused structured intermediate representation as input, and performing functional structural expansion processing to reduce the semantic markup used to represent variable assignments and dependencies in the structured intermediate representation into explicit variable declaration statements and assignment statements; during the reduction process, the nested grammatical structure is eliminated through a structural flattening operation to generate a reduced structured intermediate representation that conforms to grammatical specifications;
[0072] S52, perform de-evaluation processing on the explicit variable declaration statements and assignment statements in the restored structured intermediate representation, restore the computational structure of each declaration statement and assignment statement based on the execution trajectory information recorded in the forward calculation stage and the control flow markers embedded in the structured intermediate representation, and reconstruct the conditional judgment statements and loop structures in the control flow, and output the restored core language representation.
[0073] Specifically, the restored core language representation is converted into the final modified template code, including:
[0074] The control structure represented by the restored core language is restored to the corresponding conditional branch statements and loop statements in the surface language, and the variable declarations and assignment operations in the restored core language are mapped to grammatical forms with corresponding semantics in the surface language. The final template code output is generated based on the conditional branch statements, loop statements, variable declarations and assignment operations converted into the surface language.
[0075] Specifically, the template program conversion process in this embodiment can be performed as follows: receiving an input template program; parsing logical elements such as variable declarations and control structures in the template program; propagating the parsed results into a core language representation, describing the semantics of the template program using standardized terminology (e.g., constants, declarations, assignments, conditionals, and loops); adding variable bindings and scope tags to ensure semantic consistency within the core language representation; and generating plain text output through forward computation based on the above method. The process includes: executing the core language program and recording the program execution trajectory; converting variable declarations and assignments into a labeled Lambda application format, recording variable bindings and side effect information; generating an intermediate representation containing control flow tags; and destructuring the computational structured output (i.e., the structured intermediate representation) to generate the final plain text output. The subsequent process of receiving and parsing text editing instructions includes: receiving user editing instructions for the plain text output, such as inserting new text, deleting specified text, or replacing existing text; parsing the editing instructions into update operations, recording the operation type, target location, and operation content; and fusing batches of editing instructions to generate an ordered set of update operations. The backpropagation and backtranslation process then involves propagating the edit operation to the corresponding portion of the computational structured output using a fusion algorithm based on the target location and content of the edit operation. De-lambda application processing (de-lambda application processing is functional structure expansion) is performed on the updated computational structured output, reducing the marked lambda application to variable declarations or assignment statements, and eliminating nested sequences through flattening. De-evaluation processing is performed to restore the declaration and assignment computation structure based on the forward computation execution trajectory, and conditional statements and loop structures are rebuilt to generate an updated core language representation. Finally, the core language control structure is reduced to the conditional branches and loop instructions of the surface language. Variable declarations and assignments are converted to the corresponding syntax of the surface language. The corresponding template program code is modified.
[0076] In general, during the forward computation phase, the core language program is evaluated to generate a computationally structured output. This computationally structured output serves as an intermediate representation, preserving the execution traces and control structure markers of the template program, including information about conditional branches and loop unrolling. Subsequently, the computationally structured output is destructured and output as plain text. During the backward propagation phase, user edits to the plain text output are parsed as update operations, which are propagated to the computationally structured output using a fusion algorithm to generate an updated computationally structured output. The updated computationally structured output is then de-lambda-applied and de-evaluated, restoring declaration and assignment computational structures and reconstructing the updated core language representation. By capturing program execution traces and control statement markers, the computationally structured output supports accurate propagation of update operations and can recover elements lost during the evaluation phase, such as alternative paths for conditional branches, during the de-evaluation process.
[0077] Specifically, the core of the deep learning-based output text-oriented template code modification method proposed in this embodiment is to build a bidirectional transformation mechanism that supports reverse mapping from output text and automatically updates the template code. For example, in web design, traditional methods require directly modifying the template code to adjust the web page content, which is complex and error-prone. However, this method allows developers to directly edit the content displayed on the web page, such as modifying text, adjusting list items, etc. The system can automatically identify these changes and intelligently update the corresponding template code, achieving synchronous modification of the output content and template code. For example, in a scenario where a Mustache template is used to generate a README document, the template may contain variables such as version = "2.0.0" and an API list endpoints = ["add_attachment"]. After running the template, the output README will display "Installation version: 2.0.0" and "API: add_attachment". When the user wants to modify it to "2.1.5" and "add_details", the traditional method requires returning to the template to manually locate and modify the corresponding variables or list contents. The present invention supports users to modify the above content directly in the generated README text. The system can automatically identify the changes, locate the relevant code position in the template, and complete the synchronous update of the template code, thereby greatly simplifying the operation process and improving the efficiency and reliability of template maintenance.
[0078] like Figure 2 As shown, this embodiment also discloses an output text-oriented template code modification system based on deep learning, including:
[0079] A semantic normalization module 21 is configured to perform semantic normalization processing on the template code to be modified through the template code conversion module to obtain a semantically normalized core language representation;
[0080] The output text conversion module 22 is configured to input the core language representation of the semantic specification into the forward computation phase of the two-phase bidirectional framework, convert the core language representation of the semantic specification into an initial structured intermediate representation through forward computation, convert variable declarations and assignment expressions in the initial structured intermediate representation into a functional structure, generate a final structured intermediate representation based on the functional structure, and record metadata information of the final structured intermediate representation; and convert the final structured intermediate representation into output text.
[0081] An update operation acquisition module 23 is configured to receive an edit operation on the output text, obtain the edited output text, generate an edit instruction based on the edited output text, and parse the edit instruction into a corresponding update operation; the update operation includes the edited output text content and the operation type;
[0082] A fusion module 24 is configured to input the edited output text content, operation type, and metadata information into the deep learning module, obtain structured update instructions through prediction by the deep learning module, and fuse the structured update instructions into the structured intermediate representation to obtain a fused structured intermediate representation;
[0083] The template code modification module 25 is used to perform functional structure expansion processing on the fused structured intermediate representation through the back propagation stage in the two-stage bidirectional framework to obtain a restored structured intermediate representation, de-evaluate the restored structured intermediate representation to obtain a restored core language representation, and convert the restored core language representation into the final modified template code.
[0084] In addition, if Figure 3 As shown, this embodiment also discloses a two-stage bidirectional framework diagram of an output text-oriented template code modification method based on deep learning, and the two-stage bidirectional framework includes two main stages: a forward calculation stage and a back propagation stage.
[0085] During the forward computation phase, the core language representation is used to generate a structured intermediate representation (SIR), which contains control flow markers and metadata to preserve the code's semantics. At the same time, variable declarations and assignment expressions in the SIR are converted into functional structures. Based on this, a destructuring process is performed to generate preliminary output text.
[0086] The output text can be edited by the user, resulting in an edited output text. The edited content, along with the edit operation type and associated metadata, is fed into the deep learning module. Based on this information, the module generates structured update instructions, which are used to update the structured intermediate representation and form a fused structured intermediate representation.
[0087] In the backpropagation phase, the functional structure expansion is performed on the fused structured intermediate representation to restore the functional structure used to represent variable declaration, assignment semantics and their dependencies in the forward calculation phase, thereby reducing them to explicit variable declaration statements and assignment statements; then, de-evaluation is performed based on the expanded structured intermediate representation, and the computational structure of each statement is restored according to the execution trajectory information and control flow markers recorded in the forward phase, and the conditional statements and loop structures in the control flow are reconstructed, finally generating the restored core language representation.
[0088] The specific implementation of the output text-oriented template code modification system based on deep learning is the same as the output text-oriented template code modification method based on deep learning, and will not be repeated in this embodiment.
[0089] Although the present invention has been particularly shown and described in conjunction with preferred embodiments, it will be understood by those skilled in the art that various changes in form and details may be made to the present invention without departing from the spirit and scope of the invention as defined in the appended claims, and all such changes are within the scope of protection of the present invention.
Claims
1. A method for modifying output text-oriented template code based on deep learning, characterized in that: include: S1, the template code to be modified is processed by the template code conversion module to perform semantic normalization processing to obtain the core language representation of the semantic norm; S2: Input the core language representation of the semantic specification into the forward computation phase of the two-stage bidirectional framework. Through forward computation, the core language representation of the semantic specification is converted into an initial structured intermediate representation. The variable declarations and assignment expressions in the initial structured intermediate representation are converted into functional structures. Based on the functional structures, the final structured intermediate representation is generated, and metadata information of the final structured intermediate representation is recorded. Convert the final structured intermediate representation into output text; S3, receiving an edit operation on the output text, obtaining the edited output text, generating an edit instruction based on the edited output text, and parsing the edit instruction into a corresponding update operation; the update operation includes the edited output text content and the operation type; S4: Input the edited output text content, operation type, and metadata information into the deep learning module, predict the structured update instructions through the deep learning module, and fuse the structured update instructions into the structured intermediate representation to obtain the fused structured intermediate representation; S5, through the back-propagation stage in the two-stage bidirectional framework, performs functional structural expansion processing on the fused structured intermediate representation to obtain a restored structured intermediate representation, de-evaluates the restored structured intermediate representation to obtain a restored core language representation, and converts the restored core language representation into the final modified template code; Specifically, the S2 includes: S21, performing line-by-line parsing of the semantically standardized core language representation to obtain an initial structured intermediate representation and recording execution trajectory information; the execution trajectory information includes the code execution order, conditional branch paths, and loop expansion; during the line-by-line parsing process, extracting and establishing the static code structure and dynamic execution path of the core language representation, the dynamic execution path including the actual flow path of conditional judgments and loops; converting variable declarations and assignment statements in the initial structured intermediate representation into functional structures with attached semantic labels, and recording the binding relationships between variables and the semantic side effects that may be induced; S22, generating a final structured intermediate representation based on the static code structure and the dynamic execution path; the final structured intermediate representation includes function calls, variable usage, and control structures; S23: Embed control flow markers in the final structured intermediate representation and record metadata information in the structured intermediate representation; the metadata information includes the life cycle, scope, expression type, and semantic label of the variable; the control flow markers are used to identify the logical start and end positions, conditional expressions, and branch jump relationships of each control structure in the structured intermediate representation; S24, performing a destructuring operation on the structured intermediate representation to obtain an output text; the output text supports editing operations.
2. The method for modifying output text-oriented template code based on deep learning according to claim 1, characterized in that: Said S1 specifically includes: S11, receiving the template code to be modified; S12, performing syntax analysis and structural parsing operations on the template code, identifying and extracting variable declarations, assignment statements, and control structures in the template code; the control structures include conditional judgments and loop bodies; S13 converts variable declarations, assignment statements, and control structures into a standardized core language representation, adds variable binding information and scope markers to the core language representation to clarify the life cycle and visible range of the variables, and outputs a semantically standardized core language representation.
3. The method for modifying output text-oriented template code based on deep learning according to claim 1, characterized in that: Said S3 specifically includes: S31, receiving an editing operation performed by a user based on the output text, wherein the editing operation includes inserting text, deleting text, and replacing text; S32, determine the number of editing operations; if the number is equal to one, take the received editing operation as input, parse and convert it into a structured update operation, extract and record the corresponding operation type, target location and operation content; if there is more than one, parse multiple editing instructions and convert them into structured update operations, and perform semantic consistency verification and sequential relationship analysis at the same time, perform batch fusion processing based on the analysis results, and generate an ordered set of update operations.
4. The method for modifying output text-oriented template code based on deep learning according to claim 1, characterized in that: Said S4 specifically includes: S41: Inputting the edited output text content, operation type, and metadata information recorded in the structured intermediate representation as multi-source inputs into a deep learning module; the deep learning module is built based on the Transformer architecture and adopts an encoder-decoder structure, wherein the encoder semantically encodes the multi-source inputs and the decoder generates corresponding structured update instructions based on the context; the structured update instructions include modifying variable assignments, adjusting loop structures, and replacing or deleting control statements; S42, fuses the structured update instruction into the structured intermediate representation, introduces a functional structure with semantic labels during the fusion process to ensure the structural consistency of the binding relationship between variables and the semantic side effect information during the fusion process, and at the same time refers to the control flow markers embedded in the structured intermediate representation to locate and verify the control structure corresponding to the structured update instruction, ensure the integrity of the fusion result in the control structure and the consistency of the execution path, and obtain the fused structured intermediate representation.
5. The method for modifying output text-oriented template code based on deep learning according to claim 2, characterized in that: In S5, through the backpropagation stage in the two-stage bidirectional framework, the fused structured intermediate representation is subjected to functional structural expansion processing to obtain the restored structured intermediate representation. The restored structured intermediate representation is then de-evaluated to obtain the restored core language representation, specifically including: S51, receiving the fused structured intermediate representation as input, and performing functional structural expansion processing to reduce the semantic markup used to represent variable assignments and dependencies in the structured intermediate representation into explicit variable declaration statements and assignment statements; during the reduction process, the nested grammatical structure is eliminated through a structural flattening operation to generate a reduced structured intermediate representation that conforms to grammatical specifications; S52, perform de-evaluation processing on the explicit variable declaration statements and assignment statements in the restored structured intermediate representation, restore the computational structure of each declaration statement and assignment statement based on the execution trajectory information recorded in the forward calculation stage and the control flow markers embedded in the structured intermediate representation, and reconstruct the conditional judgment statements and loop structures in the control flow, and output the restored core language representation.
6. The method for modifying output text-oriented template code based on deep learning according to claim 5, characterized in that: Convert the restored core language representation into the final modified template code, including: The control structure represented by the restored core language is restored to the corresponding conditional branch statements and loop statements in the surface language, and the variable declarations and assignment operations in the restored core language are mapped to grammatical forms with corresponding semantics in the surface language. The final template code output is generated based on the conditional branch statements, loop statements, variable declarations and assignment operations converted into the surface language.
7. An output text-oriented template code modification system based on deep learning, characterized in that: include: A semantic normalization module is used to perform semantic normalization processing on the template code to be modified through the template code conversion module to obtain a core language representation of the semantic norm; The output text conversion module is used to input the core language representation of the semantic specification into the forward calculation stage of the two-stage bidirectional framework, convert the core language representation of the semantic specification into an initial structured intermediate representation through forward calculation, convert the variable declarations and assignment expressions in the initial structured intermediate representation into a functional structure, generate the final structured intermediate representation based on the functional structure, and record metadata information of the final structured intermediate representation; Convert the final structured intermediate representation into output text; An update operation acquisition module is configured to receive an edit operation on an output text, obtain the edited output text, generate an edit instruction based on the edited output text, and parse the edit instruction into a corresponding update operation; the update operation includes the content of the edited output text and the operation type; A fusion module is used to input the edited output text content, operation type and metadata information into the deep learning module, obtain structured update instructions through prediction by the deep learning module, and fuse the structured update instructions into the structured intermediate representation to obtain a fused structured intermediate representation; The template code modification module is used to perform functional structural expansion processing on the fused structured intermediate representation through the backpropagation phase in the two-stage bidirectional framework to obtain a restored structured intermediate representation, de-evaluate the restored structured intermediate representation to obtain a restored core language representation, and convert the restored core language representation into the final modified template code; Specifically, the output text conversion module specifically includes: The semantically standardized core language representation is parsed line by line to obtain an initial structured intermediate representation and record execution trajectory information; the execution trajectory information includes the code execution order, conditional branch paths, and loop expansion. During the line-by-line parsing process, the static code structure and dynamic execution path of the core language representation are extracted and established, and the dynamic execution path includes the actual flow path of conditional judgments and loops. The variable declarations and assignment statements in the initial structured intermediate representation are converted into functional structures with attached semantic labels, and the binding relationships between variables and the semantic side effects that may be caused are recorded. Generating a final structured intermediate representation based on the static code structure and the dynamic execution path; the final structured intermediate representation includes function calls, variable usage, and control structures; Embed control flow markers in the final structured intermediate representation and record metadata information in the structured intermediate representation; the metadata information includes the life cycle, scope, expression type and semantic label of the variable; the control flow markers are used to identify the logical start and end positions, conditional expressions and branch jump relationships of each control structure in the structured intermediate representation; A destructuring operation is performed on the structured intermediate representation to obtain an output text; the output text supports editing operations.
Citation Information
Patent Citations
Java method annotation instant automatic updating method based on data flow analysis and attention mechanism
CN115826988A