CN-122018871-A - Code generation method, device, storage medium, and program product
Abstract
The embodiment of the disclosure provides a code generation method, a device, a storage medium and a program product. The method comprises the steps of obtaining first data corresponding to source codes, wherein the first data comprises a first incidence relation, the first incidence relation indicates a mapping relation between nodes in a first knowledge graph and nodes in a second knowledge graph, the first knowledge graph corresponds to a first version corresponding to the source codes, the second knowledge graph corresponds to a second version corresponding to the source codes, and the first data is input into a first model to obtain target codes under the second version. According to the method provided by the embodiment of the disclosure, the first association relationship is introduced as the structural semantic guidance, and is input into the generation model, so that the accuracy and controllability of version migration can be effectively improved.
Inventors
- Kang Jiaqin
- QI GUILIN
- LU YUCHEN
- JIANG BO
- SUN NINGYUAN
Assignees
- 北京字跳网络技术有限公司
- 东南大学
Dates
- Publication Date
- 20260512
- Application Date
- 20260129
Claims (13)
- 1. A code generation method, comprising: The method comprises the steps of obtaining first data corresponding to a first code, wherein the first data comprises a first association relation, the first association relation indicates a mapping relation between nodes in a first knowledge graph and nodes in a second knowledge graph, the first knowledge graph corresponds to a first version corresponding to the first code, and the second knowledge graph corresponds to a second version corresponding to the first code; And inputting the first data into a first model to obtain a second code under the second version.
- 2. The method of claim 1, wherein the mapping relationship comprises at least one of node splitting, node merging, renaming, reserving, and adding parameters.
- 3. The method of claim 1, wherein the first data further comprises at least one of a first code, a second version information.
- 4. A method according to any one of claims 1-3, the method further comprising: Acquiring a first knowledge graph of a first version and a second knowledge graph of a second version corresponding to the first code; Searching the first knowledge graph according to the first code to determine a first subgraph; Searching the second knowledge graph according to the first code to determine a second sub-graph; And mapping the first sub-graph and the second sub-graph to obtain a first association relation.
- 5. The method of claim 4, the mapping the first sub-graph and the second sub-graph to obtain a first association relationship, comprising: For each first node in a first sub-graph, if a second node in the second sub-graph has a semantic equivalent relationship with the first node, the first node and the second node are in one-to-one correspondence, if a third node in the second sub-graph has a semantic conversion relationship with the first node, an intermediate node is created, the first node and the third node are associated through the intermediate node, the intermediate node is used for representing the semantic conversion relationship, and the semantic conversion relationship comprises at least one of a function splitting relationship, a function merging relationship and a parameter adaptation relationship.
- 6. A method according to any of claims 1-3, said inputting said first data into a first model, obtaining a second code in said second version, comprising: inputting the first association relation into a second model to obtain path information, wherein the path information comprises processing sequences and operation types of a plurality of processing steps; And inputting the path information into the first model to obtain a second code under the second version.
- 7. The method of claim 6, the path information comprising at least one of: descriptive information for each processing step based on the natural language description; Descriptive information of each processing step based on the control token; Based on descriptive information of the process steps of the structured description.
- 8. The method of claim 6, wherein the path information includes descriptive information for each processing step based on the structured description, wherein the inputting the path information into the first model, obtaining the second code in the second version, comprises: Converting the path information into description information in a target format, wherein the target format comprises at least one of natural language description and a control token; and inputting the path description of the target format into the first model to obtain a second code under the second version.
- 9. The method of claim 6, the inputting the path information into the first model to obtain the second code under the second version, comprising: And inputting the path information into the first model to obtain a plurality of intermediate codes corresponding to the processing steps and second codes under the second version.
- 10. A code generating apparatus comprising: The system comprises an acquisition module, a first code generation module and a second code generation module, wherein the acquisition module is used for acquiring first data corresponding to a first code, the first data comprises a first association relation, the first association relation comprises a mapping relation between nodes in a first knowledge graph and nodes in a second knowledge graph, the first knowledge graph corresponds to a first version corresponding to the first code, and the second knowledge graph corresponds to a second version corresponding to the first code; And the input module is used for inputting the first data into a first model to obtain a second code under the second version.
- 11. An electronic device includes a processor and a memory; The memory stores computer-executable instructions; The processor executing computer-executable instructions stored in the memory, causing the processor to perform the code generation method of any one of claims 1 to 9.
- 12. A computer readable storage medium having stored therein computer executable instructions which, when executed by a processor, implement the code generation method of any of claims 1 to 9.
- 13. A computer program product comprising a computer program which, when executed by a processor, implements the code generation method of any of claims 1 to 9.
Description
Code generation method, device, storage medium, and program product Technical Field The embodiment of the disclosure relates to the technical field of computers, in particular to a code generation method, a device, a storage medium and a program product. Background With the rapid development of software technology, various types of components on which software systems rely, including but not limited to programming libraries, frameworks, application programming interfaces (Application Programming Interface, APIs), software development kits (Software Development Kit, SDKs), and even programming languages themselves, may be in the process of rapid iteration and evolution. Resulting in software assets (e.g., source code) developed based on old version dependencies, may not be directly compatible for operation in a new version environment. Disclosure of Invention The embodiment of the disclosure provides a code generation method, a device, a storage medium and a program product, so as to improve the accuracy of code migration and reduce the cost. In a first aspect, an embodiment of the present disclosure provides a code generation method, including: The method comprises the steps of obtaining first data corresponding to a first code, wherein the first data comprises a first association relation, the first association relation indicates a mapping relation between nodes in a first knowledge graph and nodes in a second knowledge graph, the first knowledge graph corresponds to a first version corresponding to the first code, and the second knowledge graph corresponds to a second version corresponding to the first code; And inputting the first data into a first model to obtain a second code under the second version. In a second aspect, an embodiment of the present disclosure provides a code generating apparatus including: The system comprises an acquisition module, a first code generation module and a second code generation module, wherein the acquisition module is used for acquiring first data corresponding to a first code, the first data comprises a first association relation, the first association relation comprises a mapping relation between nodes in a first knowledge graph and nodes in a second knowledge graph, the first knowledge graph corresponds to a first version corresponding to the first code, and the second knowledge graph corresponds to a second version corresponding to the first code; And the input module is used for inputting the first data into a first model to obtain a second code under the second version. In a third aspect, an embodiment of the present disclosure provides an electronic device, including a processor and a memory; The memory stores computer-executable instructions; The processor executes computer-executable instructions stored in the memory to cause the at least one processor to perform the code generation method as described above in the first aspect and the various possible designs of the first aspect. In a fourth aspect, embodiments of the present disclosure provide a computer-readable storage medium having stored therein computer-executable instructions which, when executed by a processor, implement the code generation method as described above in the first aspect and the various possible designs of the first aspect. In a fifth aspect, embodiments of the present disclosure provide a computer program product comprising a computer program which, when executed by a processor, implements the code generation method according to the first aspect and the various possible designs of the first aspect. The method includes obtaining first data corresponding to a first code, wherein the first data comprises a first association relationship, the first association relationship indicates a mapping relationship between nodes in a first knowledge graph and nodes in a second knowledge graph, the first knowledge graph corresponds to a first version corresponding to the first code, the second knowledge graph corresponds to a second version corresponding to the first code, the first data is input into a first model, and the second code under the second version is obtained. According to the method provided by the embodiment of the disclosure, the first association relationship is introduced as the structural semantic guidance, and is input into the generation model, so that the accuracy and controllability of version migration can be effectively improved. Dependency on massive annotation data can be reduced, and the generated second code is compatible with grammar and maintains semantic consistency through changing relations (such as splitting and parameter addition) among explicit modeling versions, so that migration cost is reduced. Drawings In order to more clearly illustrate the embodiments of the present disclosure or the solutions in the prior art, a brief description will be given below of the drawings that are needed in the embodiments or the description of the prior art, it being obvious that