Code conversion system and method, electronic equipment and storage medium

By designing a code conversion system, using the combination of large models and knowledge bases, the problem of weak code conversion effect in the existing technology is solved, and reliable conversion of any project-level code in any programming language is achieved, which significantly improves the code conversion effect.

CN119829066APending Publication Date: 2025-04-15KYLAND TECH CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411905944.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-23
Publication Date
2025-04-15

AI Technical Summary

Technical Problem

The existing code conversion scheme implemented by large models can only be converted to a single file, and the conversion idea is line-to-line, which leads to the weak effect of the trained large models in project-level code conversion and poor code conversion effect.

Method used

A code conversion system is designed to obtain code engineering projects through the project input module, the data preprocessing module creates a knowledge base and splits the project files, the function analysis module determines the function list of the code engineering project, and the code conversion output module generates target conversion code based on the function list. This system circumvents the idea of ​​line-to-line code conversion through the combination of a generalized framework and large models, and realizes reliable conversion of any project-level code in any programming language.

Benefits of technology

It realizes reliable conversion of any project-level code in any programming language, avoids the problem of code failure caused by direct sentence-by-sentence conversion of large models, and significantly improves the code conversion effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119829066A_ABST
    Figure CN119829066A_ABST
Patent Text Reader

Abstract

The invention discloses a code conversion system and method, electronic equipment and a storage medium, and belongs to the technical field of artificial intelligence, and the code conversion system comprises a project input module which is used for obtaining a code engineering project containing a project file, and the code engineering project is written by a first programming language; the data preprocessing module is used for creating a knowledge base corresponding to a code engineering project and splitting a project file into a plurality of split texts; the function analysis module is used for determining a function list of the code engineering project according to the knowledge base, the split text and the first programming language, and the function list comprises a plurality of functions achieved by the code engineering project and calling relations among the functions; and the code conversion output module is used for generating a target conversion code corresponding to the code engineering project according to the function list and the second programming language, so that reliable conversion of any project-level code of any programming language can be realized, and the code conversion effect is relatively good.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of artificial intelligence technology, and in particular relates to a code conversion system, method, electronic device and storage medium. Background Art

[0002] Transcoding is the process of converting a piece of code from one form or language to another. With the continuous leaps in artificial intelligence technology, transcoding technology can be achieved using large models.

[0003] Currently, due to limitations in large models' text input methods, input context length limitations, and memory-forgetting issues, existing code conversion solutions using large models can only convert single files, and the conversion strategy is line-by-line. Implementing this conversion method requires pre-collecting large numbers of paired or even grouped code groups containing the same functionality in different languages, and then training the large model to improve its conversion capabilities. However, when the trained large model is used to convert project-level code, the input and output of a single text file results in a loss of project structure information, making the large model ineffective at project-level code conversion and resulting in poor code conversion results. Summary of the Invention

[0004] The present application aims to solve at least one of the technical problems existing in the prior art. To this end, the present application proposes a code conversion system, method, electronic device, and storage medium that can achieve reliable conversion of any project-level code in any programming language with good code conversion effect.

[0005] In a first aspect, the present application provides a code conversion system, comprising:

[0006] A project input module, configured to obtain a code engineering project including a project file, wherein the code engineering project is written in a first programming language;

[0007] A data preprocessing module is used to create a knowledge base corresponding to the code engineering project and split the project file into multiple split texts;

[0008] a function parsing module, configured to determine a function list of the code engineering project based on the knowledge base, the split text, and the first programming language, the function list including a plurality of functions implemented by the code engineering project and a calling relationship between the functions;

[0009] The code conversion output module is used to generate a target conversion code corresponding to the code engineering project according to the function list and the second programming language, wherein the target conversion code is written in the second programming language.

[0010] In some embodiments, the data preprocessing module includes:

[0011] A knowledge base creation unit is configured to call a code-to-graph model to create a knowledge graph corresponding to the code engineering project; convert nodes and edges in the knowledge graph into knowledge texts, and use all the knowledge texts as the knowledge base corresponding to the code engineering project;

[0012] The text splitting unit is used to split the project file into multiple split texts according to the number of lines, and the number of lines of each split text is not greater than a preset number of lines.

[0013] In some embodiments, the function parsing module is used to:

[0014] Based on the retrieval model and the function parsing model, a function list of the code engineering project is determined according to the split text, the knowledge base and the first programming language.

[0015] In some embodiments, the function parsing module is used to:

[0016] Invoking a retrieval model to retrieve knowledge text related to the split text from the knowledge base;

[0017] Based on the prompt project, according to the split text, the retrieved knowledge text and the first programming language, a function analysis model is called to generate a function list of the code engineering project.

[0018] In some embodiments, the code conversion output module is used to:

[0019] Based on the test case generation big model, the code generation big model, the executor and the debugging big model, the target conversion code corresponding to the code engineering project is generated according to the function list and the second programming language.

[0020] In some embodiments, the code conversion output module includes:

[0021] A test case generation unit is configured to generate a test case for each of the functions by calling a test case generation model based on the prompt engineering, the function list and the second programming language;

[0022] a code generation unit, configured to call a code generation macromodel to write program codes and execution commands for all the functions in the second programming language based on the prompt engineering and the function list and the test cases;

[0023] The code execution debugging unit is used to organize the program code into a folder, and call the executor to execute the program code in the folder according to the execution command, and call the debugging model to adjust the program code in an iterative manner according to the execution result and the test case.

[0024] In a second aspect, the present application provides a code conversion method, which is applied to any of the above-mentioned code conversion systems, and the code conversion method includes:

[0025] Obtaining a code engineering project including a project file, wherein the code engineering project is written in a first programming language;

[0026] Creating a knowledge base corresponding to the code engineering project, and splitting the project file into multiple split texts;

[0027] Determining a function list of the code engineering project based on the knowledge base, the split text, and the first programming language, the function list including a plurality of functions implemented by the code engineering project and a calling relationship between the functions;

[0028] A target conversion code corresponding to the code engineering project is generated according to the function list and the second programming language, wherein the target conversion code is written in the second programming language.

[0029] In some embodiments, creating a knowledge base corresponding to the code engineering project and splitting the project file into multiple split texts includes:

[0030] Calling the code-to-graph model to create a knowledge graph corresponding to the code engineering project;

[0031] Convert the nodes and edges in the knowledge graph into knowledge texts, and use all the knowledge texts as the knowledge base corresponding to the code engineering project;

[0032] The project file is split into multiple split texts according to the number of lines, and the number of lines of each split text is not greater than a preset number of lines.

[0033] In some embodiments, determining the function list of the code engineering project based on the knowledge base, the split text, and the first programming language includes:

[0034] Based on the retrieval model and the function parsing model, a function list of the code engineering project is determined according to the split text, the knowledge base and the first programming language.

[0035] In some embodiments, determining the function list of the code engineering project based on the retrieval model and the function parsing model according to the split text, the knowledge base, and the first programming language includes:

[0036] Invoking a retrieval model to retrieve knowledge text related to the split text from the knowledge base;

[0037] Based on the prompt project, according to the split text, the retrieved knowledge text and the first programming language, a function analysis model is called to generate a function list of the code engineering project.

[0038] In some embodiments, generating target conversion code corresponding to the code engineering project based on the function list and the second programming language includes:

[0039] Based on the test case generation big model, the code generation big model, the executor and the debugging big model, the target conversion code corresponding to the code engineering project is generated according to the function list and the second programming language.

[0040] In some embodiments, generating a large model based on test cases, a large model for code generation, an executor, and a large model for debugging, and generating target conversion code corresponding to the code engineering project according to the function list and the second programming language, includes:

[0041] Based on the prompt engineering, according to the function list and the second programming language, calling the test case generation model to generate a test case for each of the functions;

[0042] Based on the prompt engineering, according to the function list and the test case, calling the code generation macro model to write the program code and execution commands of all the functions in the second programming language;

[0043] The program codes are organized into a folder, and an executor is called to execute the program codes in the folder according to the execution command, and according to the execution result and the test case, a debugging model is called to adjust the program codes in the folder in an iterative manner.

[0044] In a third aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements any of the above-mentioned code conversion methods when executed by a processor.

[0045] In a fourth aspect, the present application provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any of the above-described code conversion methods when executing the program.

[0046] In a fifth aspect, the present application provides a computer program product, comprising a computer program, which implements any of the above-mentioned code conversion methods when executed by a processor.

[0047] The code conversion system, method, storage medium, electronic device, and computer program product provided in the embodiments of the present application obtain a code engineering project including a project file through a project input module, wherein the code engineering project is written in a first programming language; create a knowledge base corresponding to the code engineering project through a data preprocessing module, and split the project file into multiple split texts; determine a function list of the code engineering project based on the knowledge base, the split texts, and the first programming language through a function parsing module, wherein the function list includes a number of functions implemented by the code engineering project and the calling relationships between the functions; and generate a target conversion code corresponding to the code engineering project based on the function list and a second programming language through a code conversion output module, wherein the target conversion code is written in the second programming language. That is, a code conversion system with a universal framework is designed, and project data is converted into two parts, namely a knowledge base and short text, which are provided to a large model for function parsing and function code implementation, thereby avoiding the line-by-line code conversion approach and achieving reliable conversion of any project-level code in any programming language, with good code conversion effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] In order to more clearly illustrate the technical solution of the present invention, the following briefly introduces the drawings required for use in the description of the present invention. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0049] Figure 1 Schematic diagram of the structure of the code conversion system provided in the embodiment of the present application;

[0050] Figure 2 1 is a schematic diagram of a process framework for code conversion by a code conversion system provided in an embodiment of the present application;

[0051] Figure 3 This is another schematic diagram of a process framework for code conversion by the code conversion system provided in an embodiment of the present application;

[0052] Figure 4 Schematic diagram of the code conversion method provided in the embodiment of the present application;

[0053] Figure 5 is a structural diagram of an electronic device provided in an embodiment of the present application;

[0054] Figure 6 This is a schematic diagram of the hardware structure of the electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0055] The following describes in detail embodiments of the present application. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application and are not to be construed as limiting the present application.

[0056] Existing code conversion solutions using large models can only convert single files, and the conversion strategy is line-by-line. This conversion method requires collecting a large number of pairs or even groups of code groups containing the same function in different languages ​​in advance, and then training the large model to improve its conversion capabilities. This code conversion solution has the following drawbacks and problems:

[0057] 1. Due to the seesaw effect between the versatility and specificity of the model, it is easy for a large model to be trained to perform well in only one or a few languages, but perform poorly in other languages.

[0058] 2. Due to the differences in common libraries, functions, syntactic sugar, and other features between different languages, sentence-by-sentence conversion can easily cause large models to "fabricate" functions or methods to achieve semantic rationality, but in reality the converted code may not run.

[0059] 3. Since the large model itself only supports the input and output of single text files, the project structure information will be lost when converting project-level code projects, resulting in the large model's insufficient understanding of the calling relationships between different files, and poor effect on project-level code conversion.

[0060] To solve at least one of the above technical problems, embodiments of the present application provide a code conversion system, method, storage medium, electronic device, and computer program product.

[0061] See Figure 1 and Figure 2 , Figure 1 1 is a schematic diagram of the structure of the code conversion system 100 provided in an embodiment of the present application. Figure 2The present invention provides a schematic diagram of a process framework for code conversion by a code conversion system 100 according to an embodiment of the present invention. The code conversion system 100 includes: a project input module 101 for acquiring a code engineering project including a project file, the code engineering project being written in a first programming language; a data preprocessing module 102 for creating a knowledge base corresponding to the code engineering project and splitting the project file into multiple split texts; a function parsing module 103 for determining a function list of the code engineering project based on the knowledge base, the split texts, and the first programming language, the function list including a number of functions implemented by the code engineering project and the call relationships between the functions; and a code conversion output module 104 for generating a target conversion code corresponding to the code engineering project based on the function list and a second programming language, the target conversion code being written in the second programming language.

[0062] The project input module 101 provides interfaces for user input, including the project file of the code engineering project, the source language (first programming language) used in the project, the libraries used in the project, and the target language (second programming language) to be converted. The project file refers to the collection of various files that make up a software project, such as source code files, configuration files, build files, dependency management files, and test files.

[0063] Considering that the essence of code conversion is to implement a function implemented in one language in another, the code conversion system 100 in this embodiment implements code conversion in two main steps: 1. Understanding the original project code and sorting out its intended functions; 2. Based on the intended functions, instructing the macromodel to implement them in the target language. By splitting the code conversion task into these two steps, the input to the code generation macromodel becomes a matter of implementing a specific function in a specific language. This avoids the problem of having the macromodel directly convert code sentence by sentence, and avoids the situation where the macromodel, through direct semantics-based sentence-by-sentence conversion, creates "fabricated" functions or methods that may be semantically reasonable but in fact fail to execute the converted code.

[0064] Specifically, the code conversion system 100 adopts a universal, node-based, component-based, and detachable and replaceable module framework. Each module in the system calls the required component type according to actual needs. For example, for large model components, including different types such as functional analysis large models, code generation large models, and code debugging large models, different modules can call different types of large models, and for the same type of large models, they can be flexibly replaced according to the source language or target language, and it is preferred to select a large model with better performance in the source language or target language.

[0065] Among them, step 1 is mainly implemented through the data preprocessing module 102 and the function analysis module 103. In order to achieve the universality of step 1, the data preprocessing module 102 receives the original project data and stipulates that the function analysis module 103 is output according to a normative structure (i.e., a function list). The content of the normative structure describes the overall code structure of the project and the functional points implemented. Step 2 is mainly implemented by the code conversion output module 104, which writes a complete set of business flows through an agent, simulating the process of manually writing code, such as writing test cases, generating code, compiler and executor execution, etc., and also designs a process for correcting the corresponding code according to the execution results or errors. In this process, an iterative method is used to loop the entire process until the execution result meets the requirements.

[0066] Furthermore, in the process of implementing step 1, the data preprocessing module 102 needs to solve the problem that the long text code input exceeds the length limit of the large model and the text form cannot well represent the directory relationship between codes. To this end, the data preprocessing module 102 specifically includes:

[0067] The knowledge base creation unit 1021 is used to call the code-to-graph model to create a knowledge graph corresponding to the code engineering project; convert the nodes and edges in the knowledge graph into knowledge text, and use all the knowledge text as the knowledge base corresponding to the code engineering project;

[0068] The text splitting unit 1022 is used to split the project file into multiple split texts according to the number of lines, and the number of lines of each split text is not greater than a preset number of lines.

[0069] Among them, in order to solve the problem that text input will lose the structural information of the project-level code, the knowledge base creation unit 1021 can first convert the entire project data into a knowledge graph through an external code-to-graph model (such as the code2flow component), and then splice the knowledge graph into text through custom text rules, thereby ensuring that the input data provided to the large model is text while maintaining the structural information of the project-level code. At the same time, in order to solve the problem of long text code input, the text splitting unit 1022 can split the project file into multiple short texts (split text) according to the maximum allowed number of lines of the large model. That is, the data preprocessing module 102 ultimately generates two parts of data, one part is the knowledge base constructed for the entire project, this part of the data covers the project structure information, and the other part is the short texts into which the project file is split, this part of the data meets the short text input requirements of the large model.

[0070] Furthermore, in the process of implementing step 1, the function analysis module 103 calls the two components of the large model and the search model, and requires the large model to output the analysis results according to a standardized structure (i.e., a function list). In other words, the function analysis module 103 is used to:

[0071] Based on the retrieval model and the function parsing model, a function list of the code engineering project is determined according to the split text, the knowledge base and the first programming language.

[0072] Please continue to see Figure 1 、 Figure 2 and Figure 3 , Figure 3 This is another schematic diagram of the transcoding process framework of the transcoding system 100 provided in an embodiment of the present application. The function parsing module 103 utilizes two types of components: a retrieval model and a large function parsing model. The large function parsing model is an LLM (Large Language Model). The LLM can perform a variety of natural language processing tasks, such as text generation, question-answering, translation, summarization, and sentiment analysis, and has powerful understanding and analysis capabilities, such as GPT and BERT. The retrieval model can be a qwen-rag (retrieval-enhanced generation) retrieval module.

[0073] Furthermore, the function analysis module 103 is specifically used to:

[0074] Calling the retrieval model to retrieve knowledge text related to the split text from the knowledge base;

[0075] Based on the prompt project, according to the split text, the retrieved knowledge text and the first programming language, the function analysis model is called to generate a function list of the code engineering project.

[0076] The retrieval model retrieves contextual information related to the split text from the knowledge base and provides it as additional knowledge to the Functional Analysis LLM. The Functional Analysis LLM then analyzes the original project's functional points based on this additional knowledge and the original split text. Through a custom prompt, the Functional Analysis LLM is controlled to output the project's functional description in a specified list format. Preferably, the Functional Analysis LLM can select a large language model that performs well in the first programming language.

[0077] For example, in Figure 2 and Figure 3 In the code, after the user enters the original project data, the entire project data is first converted into a knowledge graph through the plug-in code-to-graph model, and then the knowledge graph is converted into a text-based knowledge base through custom text rules. At the same time, the project file is split into multiple split texts. The knowledge text in the knowledge base is provided to the function parsing LLM as additional knowledge together with the split text. Then, the function parsing LLM parses the input content based on the custom prompt to obtain a function list. An example of this prompt can be:

[0078] Consider a project named {origin_language}. Its file directory structure is {tree directory}, where the location and content of each file are {position, content}, and the calling relationship between each file is {relationship}. The libraries used in the project include {origin_packages}. Based on the project content, please summarize the functions implemented by this project and the calling relationships between these functions as detailed as possible, and list the inputs and outputs of these functions in the following format: {input, output, description, relationship, etc...}. Furthermore, in the process of implementing step 2, the code conversion output module 104 is used to:

[0079] Based on the test case generation big model, the code generation big model, the executor and the debugging big model, the target conversion code corresponding to the code engineering project is generated according to the function list and the second programming language.

[0080] Among them, the implementation of step 2 needs to solve the problems of large-model control flow compilation, output normalization, compilation and execution of large-model generated content, and debugging. Large-model control flow compilation refers to ensuring that the generated code has the correct control structure and logical flow when using a large language model to generate or modify program code. In order to solve the problem of large-model control flow compilation, this embodiment uses an agent to write a complete set of processes that simulate manual code writing. When the code conversion output module 104 executes this process, it involves the calling of components such as the test case generation large model, the code generation large model, the executor, and the debug large model. The test case generation large model, the code generation large model, and the debug large model are all LLMs. Preferably, these LLMs can choose large language models that perform better in the target language (second programming language).

[0081] For example, in Figure 2 and Figure 3 In the code generation process, after the function parsing LLM generates a function list, the function list is provided to the test case generation LLM and the code generation LLM. Then, the test case generation LLM generates a test case for each function in the function list based on the custom prompt and the input function list, and provides the test case to the code generation LLM. An example of the prompt can be:

[0082] Consider a {dst language} project that requires the following functionality: {input, output, description, relationship, etc...}. The available libraries include {dst_packages}. Design test cases for each functionality and generate code files for each test case in the format {filename, content}.

[0083] Next, the code generation LLM generates the program code and execution commands for each function based on the input function list and test cases, combined with the customized prompt. An example of the prompt can be:

[0084] Given a {dst language} project, the required functions and their call relationships are as follows: {input, output, description, relationship, etc…}. The test cases for each function are [{filename, content},…]. The available libraries in the project include {dst_packages}. The implemented functions and their associated code are [{position, filename, content},…]. Select the next function to be implemented and implement it. The output format is {position, filename, content}. If all functions have been implemented, the execution command {command} and the terminator {EOF} are output according to the test case.

[0085] Next, the program code generated by the code generation LLM is organized into a folder based on position, filename, and content for the executor to call. The executor will execute the execution command generated by the code generation LLM in the root directory of the folder. Based on the execution command, the installation configuration instructions and code tasks of the execution environment are executed, and the execution results (such as error messages or normal output content) are output to the debug LMM for processing. The debug LMM then modifies and adjusts the program code in the folder based on the execution results and a customized prompt. An example of this prompt could be:

[0086] There is a {dst language} project. The functions it needs to implement and the calling relationship between the functions are: {input, output, description, relationship, etc...}. The test case for each function is [{filename, content},...] The libraries available in the project include {dst_packages}. The implemented functions and related codes are [{position, flename, content},...] The execution instruction is {command}. The output content after execution is {outputs}. Please determine whether the output content contains error information. Please adjust the implemented function code according to the error information. The output format is {position, flename, content}, and output the adjusted execution instruction {command}; if there is no error information, please output the {EOF} terminator. Further, the above-mentioned code conversion output module 104 specifically includes:

[0087] A test case generating unit 1041 is configured to generate a test case for each function based on the prompt engineering, the function list and the second programming language by calling a test case generating large model;

[0088] A code generation unit 1042 is configured to call a code generation model to write program codes and execution commands for all functions in the second programming language based on the prompt project, the function list, and the test case;

[0089] The code execution debugging unit 1043 is used to organize the program code into a folder, and call the executor to execute the program code in the folder according to the execution command, and call the debugging model to adjust the program code in an iterative manner according to the execution result and the test case.

[0090] The program code is written in the second programming language and is a section of code that implements the corresponding function, with each function corresponding to a section of program code. When implementing step 2, to improve the accuracy and executability of the generated code, the code conversion and output module 104 can use a step-by-step ReAct method (or an iterative method such as restarting), requiring the large model to follow the process of "generating test cases - generating corresponding executable code - calling the executor through Function Calling to execute the corresponding code - modifying the original code based on the execution results or errors" when implementing the function.

[0091] In order to solve the above-mentioned output normalization problem and make the conversion code finally output in the form of a project structure, a set of output formatting tools for large models was written. Through a custom prompt, the program code output by the large model can be organized into a folder and normalized into folders (project folders) according to the project structure.

[0092] In order to solve the above-mentioned problems of large model compilation, execution and debugging, a shell-based code executor was written. Through a custom prompt, the large model is specified to output the execution command to a specified file (such as a bash file) in the project folder, and the unified code executor interface provided by us for the large model is called in the form of function calling. The executor is called based on this interface, and then the code is corrected and rewritten according to the execution results output by the executor. The shell is a command line interpreter that provides an interface between the user and the operating system kernel. Through the shell, the user can enter commands to perform various tasks. A bash file usually refers to a file containing a bash script. A bash script is a text file that contains a series of commands that can be executed in the command line. By writing and running bash scripts, you can automate repetitive tasks, simplify complex operation processes, and improve work efficiency.

[0093] Please note that, please continue to refer to Figures 1 to 3 By generalizing the various framework nodes of the code conversion system 100, the integration and replacement of various components and nodes are facilitated, so that the components called at each node can be replaced as needed (for example, a suitable large model can be selected according to the source language and target language, and other components can be used to build the knowledge base, etc.). The universality of the system framework avoids the need for universal large models, reduces the cost of model training, and can bring out the performance of more models at a lower cost. To a certain extent, it solves the seesaw effect of large models, so that the code conversion system 100 can realize cross-language understanding and conversion of any programming language and any project-level code.

[0094] By introducing the construction of a knowledge base and a retrieval model based on rag technology, the problem of the inability to understand the project structure when inputting the model in text form can be solved. By parsing the functions to be implemented by the code engineering project and the calling relationship between each function, the problem of inputting the code to generate a large model becomes the use of a certain language to implement a certain function, avoiding the need for the large model to directly convert the code sentence by sentence, thereby greatly avoiding the situation where the converted code cannot run due to the way the model is constructed.

[0095] By introducing a shell-based code executor, the integration of code interpretation environments in various languages ​​is facilitated, allowing large models to be debugged and code modified using different languages. By writing a complete set of processes that simulate manually written code, the accuracy and executability of the generated code are improved.

[0096] As can be seen from the above, the code conversion system 100 provided in the embodiment of the present application obtains a code engineering project including a project file through the project input module 101, and the code engineering project is written in a first programming language; creates a knowledge base corresponding to the code engineering project through the data preprocessing module 102, and splits the project file into multiple split texts; determines a function list of the code engineering project based on the knowledge base, the split text and the first programming language through the function parsing module 103, and the function list includes several functions implemented by the code engineering project and the calling relationship between each function; generates a target conversion code corresponding to the code engineering project based on the function list and the second programming language through the code conversion output module 104, and the target conversion code is written in the second programming language, that is, by designing a code conversion system 100 with a universal framework, and converting project data into two parts of data, a knowledge base and short text, and providing them to a large model for function parsing and function code implementation, thereby avoiding the line-by-line code conversion idea, and realizing reliable conversion of any project-level code in any programming language, with good code conversion effect.

[0097] Based on the code conversion system described in the above embodiment, the present application embodiment also provides a code conversion method. Figure 4 , Figure 4 201-204 is a flow chart of a code conversion method provided in an embodiment of the present application. This code conversion method is applied to the code conversion system described in any of the above embodiments and can be executed by a functional module in the code conversion system. This code conversion method includes the following steps 201-204, wherein:

[0098] 201. Obtain a code engineering project including a project file, where the code engineering project is written in a first programming language;

[0099] 202. Create a knowledge base corresponding to the code engineering project, and split the project file into multiple split texts;

[0100] 203. Determine a function list of the code engineering project based on the knowledge base, the split text, and the first programming language, where the function list includes a plurality of functions implemented by the code engineering project and a calling relationship between the functions;

[0101] 204. Generate target conversion code corresponding to the code engineering project according to the function list and the second programming language, where the target conversion code is written in the second programming language.

[0102] In some embodiments, the above step 202 specifically includes:

[0103] Call the code-to-graph model to create the knowledge graph corresponding to the code engineering project;

[0104] Convert the nodes and edges in the knowledge graph into knowledge texts, and use all the knowledge texts as the knowledge base corresponding to the code engineering project;

[0105] Split the project file into multiple split texts according to the number of lines. The number of lines in each split text is not greater than the preset number of lines.

[0106] In some embodiments, the above step 203 specifically includes:

[0107] Based on the retrieval model and the function parsing model, a function list of the code engineering project is determined according to the split text, the knowledge base and the first programming language.

[0108] In some embodiments, the above step 203 specifically includes:

[0109] Calling the retrieval model to retrieve knowledge text related to the split text from the knowledge base;

[0110] Based on the prompt project, according to the split text, the retrieved knowledge text and the first programming language, the function analysis model is called to generate a function list of the code engineering project.

[0111] In some embodiments, step 204 specifically includes:

[0112] Based on the test case generation big model, the code generation big model, the executor and the debugging big model, the target conversion code corresponding to the code engineering project is generated according to the function list and the second programming language.

[0113] In some embodiments, step 204 specifically includes:

[0114] Based on the prompt engineering, according to the function list and the second programming language, the test case generation model is called to generate test cases for each function;

[0115] Based on the prompt engineering, according to the function list and the test case, calling the code generation big model to write the program code and execution command of all the functions in the second programming language;

[0116] The program code is organized into a folder, and the executor is called to execute the program code in the folder according to the execution command, and according to the execution result and the test case, the debugging model is called to adjust the program code in an iterative manner.

[0117] It should be noted that the specific details of each module unit in the above code conversion system have been described in detail in the embodiment of the above code conversion system and will not be repeated here.

[0118] From the above, it can be seen that the code conversion method provided in the embodiment of the present application obtains a code engineering project including a project file, which is written in a first programming language; creates a knowledge base corresponding to the code engineering project, and splits the project file into multiple split texts; determines a function list of the code engineering project based on the knowledge base, the split text and the first programming language, and the function list includes several functions implemented by the code engineering project and the calling relationship between each function; generates a target conversion code corresponding to the code engineering project based on the function list and the second programming language, and the target conversion code is written in the second programming language, that is, by designing a code conversion system with a universal framework, and converting project data into two parts of data, a knowledge base and short text, and providing them to a large model for function analysis and function code implementation, thereby avoiding the line-to-line code conversion idea, and realizing reliable conversion of any project-level code in any programming language, and the code conversion effect is good.

[0119] In some embodiments, as Figure 5 As shown, an embodiment of the present application further provides an electronic device 300, including a processor 301, a memory 302, and a computer program stored in the memory 302 and executable on the processor 301. When the program is executed by the processor 301, each process of the above-mentioned code conversion method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.

[0120] It should be noted that the electronic devices in the embodiments of the present application include the above-mentioned mobile electronic devices and non-mobile electronic devices.

[0121] Figure 6 A schematic diagram of the hardware structure of an electronic device implementing an embodiment of the present application.

[0122] The electronic device 400 includes but is not limited to: a radio frequency module 401, a network module 402, an audio output module 403, an item input module 404, a sensor 405, a display module 406, a user item input module 407, an interface module 408, a memory 409 and a processor 410 and other components.

[0123] In some embodiments, the processor 410 implements the following steps when executing the program:

[0124] Obtaining a code engineering project including a project file, where the code engineering project is written in a first programming language;

[0125] Create a knowledge base corresponding to the code engineering project and split the project file into multiple split texts;

[0126] Determining a function list of the code engineering project based on the knowledge base, the split text, and the first programming language, the function list including a plurality of functions implemented by the code engineering project and a calling relationship between the functions;

[0127] According to the function list and the second programming language, a target conversion code corresponding to the code engineering project is generated, where the target conversion code is written in the second programming language.

[0128] Furthermore, the processor 410 implements the following steps:

[0129] Call the code-to-graph model to create the knowledge graph corresponding to the code engineering project;

[0130] Convert the nodes and edges in the knowledge graph into knowledge texts, and use all the knowledge texts as the knowledge base corresponding to the code engineering project;

[0131] Split the project file into multiple split texts according to the number of lines. The number of lines in each split text is not greater than the preset number of lines.

[0132] Furthermore, the processor 410 implements the following steps:

[0133] Based on the retrieval model and the function parsing model, a function list of the code engineering project is determined according to the split text, the knowledge base and the first programming language.

[0134] Furthermore, the processor 410 implements the following steps:

[0135] Calling the retrieval model to retrieve knowledge text related to the split text from the knowledge base;

[0136] Based on the prompt project, according to the split text, the retrieved knowledge text and the first programming language, the function analysis model is called to generate a function list of the code engineering project.

[0137] Furthermore, the processor 410 implements the following steps:

[0138] Based on the test case generation big model, the code generation big model, the executor and the debugging big model, the target conversion code corresponding to the code engineering project is generated according to the function list and the second programming language.

[0139] In some embodiments, step 204 specifically includes:

[0140] Based on the prompt engineering, according to the function list and the second programming language, the test case generation model is called to generate test cases for each function;

[0141] Based on the prompt engineering, according to the function list and the test case, calling the code generation big model to write the program code and execution command of all the functions in the second programming language;

[0142] The program code is organized into a folder, and the executor is called to execute the program code in the folder according to the execution command, and according to the execution result and the test case, the debugging model is called to adjust the program code in an iterative manner.

[0143] Those skilled in the art will understand that the electronic device 400 may also include a power source (such as a battery) to power each component, and the power source may be logically connected to the processor 410 through a power management system, thereby implementing functions such as charging, discharging, and power consumption management through the power management system. Figure 6 The electronic device structure shown in the figure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently, which will not be repeated here.

[0144] It should be understood that in an embodiment of the present application, the project input module 404 may include a graphics processing unit (GPU) 4041 and a microphone 4042, and the graphics processing unit 4041 processes the image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The display module 406 may include a display panel 4061, and the display panel 4061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user project input module 407 includes a touch panel 4071 and at least one of other input devices 4072. The touch panel 4071 is also called a touch screen. The touch panel 4071 may include two parts: a touch detection device and a touch controller. Other input devices 4072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be repeated here.

[0145] The memory 409 can be used to store software programs and various data. The memory 409 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, applications or instructions required for at least one function (such as a sound playback function, an image playback function, etc.). In addition, the memory 409 may include a volatile memory or a non-volatile memory, or the memory 409 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct RAM bus random access memory (DRRAM). The memory 409 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.

[0146] Processor 410 may include one or more processing modules. Processor 410 integrates an application processor and a modem processor. The application processor primarily handles operations related to the operating system, user interface, and application programs, while the modem processor primarily processes wireless communication signals, such as a baseband processor. It is understood that the modem processor may not be integrated into processor 410.

[0147] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the above-mentioned code conversion method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0148] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer-readable storage medium, such as a computer read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0149] An embodiment of the present application further provides a computer program product, including a computer program, which implements the above-mentioned code conversion method when executed by a processor.

[0150] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer-readable storage medium, such as a computer read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0151] It should be noted that, in this article, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element. In addition, it should be noted that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in the opposite order according to the functions involved. For example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0152] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), including a number of instructions for enabling a terminal (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0153] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of this application, ordinary technicians in this field can also make many forms without departing from the purpose of this application and the scope of protection of the claims, all of which are within the protection of this application.

[0154] The terms "first," "second," and the like in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate, so that the embodiments of this application can be implemented in an order other than that illustrated or described herein, and that the objects distinguished by "first," "second," and the like are generally of the same type, and do not limit the number of objects; for example, the first object can be one or more. In addition, the term "and / or" in the specification and claims refers to at least one of the connected objects, and the character " / " generally indicates that the objects connected are in an "or" relationship.

[0155] In the description of this application, “plurality” means two or more.

[0156] Throughout this specification, reference to terms such as "one embodiment," "some embodiments," "illustrative embodiments," "examples," "specific examples," or "some examples" means that the specific features, structures, materials, or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.

[0157] Although the embodiments of the present application have been shown and described, those skilled in the art will appreciate that various changes, modifications, substitutions, and variations may be made to the embodiments without departing from the principles and intent of the present application, and that the scope of the present application is defined by the claims and their equivalents.

Claims

1. A code conversion system, characterized in that include: A project input module, used for acquiring a code engineering project including a project file, wherein the code engineering project is written in a first programming language; A data preprocessing module, used to create a knowledge base corresponding to the code engineering project and split the project file into multiple split texts; A function analysis module, used to determine a function list of the code engineering project according to the knowledge base, the split text and the first programming language, wherein the function list includes a number of functions implemented by the code engineering project and a calling relationship between the functions; The code conversion output module is used to generate a target conversion code corresponding to the code engineering project according to the function list and the second programming language, wherein the target conversion code is written in the second programming language.

2. The code conversion system according to claim 1, characterized in that The data preprocessing module comprises: A knowledge base creation unit is used to call the code-to-graph model to create a knowledge graph corresponding to the code engineering project; convert the nodes and edges in the knowledge graph into knowledge texts, and use all the knowledge texts as the knowledge base corresponding to the code engineering project; The text splitting unit is used to split the project file into multiple split texts according to the number of lines, and the number of lines of each split text is not greater than a preset number of lines.

3. The code conversion system according to claim 1, characterized in that The function analysis module is used to: Based on the retrieval model and the function parsing model, a function list of the code engineering project is determined according to the split text, the knowledge base and the first programming language.

4. The code conversion system according to claim 3, characterized in that The function analysis module is used to: Calling a retrieval model to retrieve knowledge text related to the split text from the knowledge base; Based on the prompt project, according to the split text, the retrieved knowledge text and the first programming language, the function analysis big model is called to generate a function list of the code engineering project.

5. The code conversion system according to any one of claims 1 to 4, characterized in that: The code conversion output module is used for: Based on the test case generation big model, the code generation big model, the executor and the debugging big model, the target conversion code corresponding to the code engineering project is generated according to the function list and the second programming language.

6. The code conversion system according to claim 5, characterized in that The code conversion output module includes: A test case generation unit, configured to generate a test case for each of the functions by calling a test case generation model based on the prompt engineering, the function list and the second programming language; A code generation unit, for calling a code generation macromodel to write program codes and execution commands of all the functions in the second programming language based on the prompt engineering and the function list and the test cases; The code execution debugging unit is used to organize the program code into a folder, and call the executor to execute the program code in the folder according to the execution command, and call the debugging large model to adjust the program code in an iterative manner according to the execution result and the test case.

7. A code conversion method, characterized in that: Applied to the code conversion system according to any one of claims 1 to 6, the code conversion method comprises: Acquire a code engineering project including a project file, wherein the code engineering project is written in a first programming language; Creating a knowledge base corresponding to the code engineering project, and splitting the project file into multiple split texts; Determine a function list of the code engineering project according to the knowledge base, the split text and the first programming language, wherein the function list includes a plurality of functions implemented by the code engineering project and a calling relationship between the functions; According to the function list and the second programming language, a target conversion code corresponding to the code engineering project is generated, and the target conversion code is written in the second programming language.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the code conversion method according to claim 7 is implemented.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the code conversion method according to claim 7 is implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the code conversion method according to claim 7 is implemented.

Citation Information

Cited By

  • Construction method and system for producing available code interpretation large model

    CN120872408A

  • A construction method and system of a production available code interpretation large model

    CN120872408B

  • Multi-source heterogeneous code conversion method and device for cross-language development

    CN121143797A