Program conversion method and device, electronic equipment and storage medium
By parsing and formatting the class names and dependencies of the program files and inputting them into the generative pre-trained model, the problem of low program conversion efficiency in independent site maintenance is solved, and a more efficient and accurate program conversion process is achieved.
Patent Information
- Application Number
- CN202411120490.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-14
- Publication Date
- 2024-12-06
AI Technical Summary
During the maintenance of independent sites, program conversion efficiency is low, resulting in low maintenance efficiency.
By parsing the class name and dependencies of the program file, update the prompt data according to the preset formatting strategy, and input it into the generative pre-trained model to generate new program files, improving the accuracy and efficiency of program conversion.
Improve the accuracy and efficiency of program conversion, ensure that the generated new program files comply with the syntax rules of the target programming language, and reduce the probability of errors during the conversion process.
Smart Images

Figure CN119088402A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of independent stations, and in particular to a program conversion method, device, electronic device and storage medium. Background Art
[0002] At present, in the process of independent site maintenance, in order to improve the operation and maintenance efficiency of the independent site, the programming language corresponding to the program architecture in the independent site is usually converted to other programming languages according to the maintenance requirements of the independent site, so as to realize the redevelopment of the independent site and ensure that the underlying programming language of the independent site is easy to expand, thereby improving the efficiency of independent site operation and maintenance. At present, developers are usually required to convert the underlying code of the independent site according to the existing program architecture in the independent site. This method is time-consuming and leads to low maintenance efficiency of the independent site. Summary of the invention
[0003] In view of the above, it is necessary to propose a program conversion method, device, electronic device and storage medium to solve the technical problem of low efficiency of program conversion.
[0004] The present application provides a program conversion method, which is applied to an electronic device. The method includes: when a first program file meets a preset condition, parsing the class name and the dependency relationship of the first program file; formatting the class name and the dependency relationship according to a preset prompt template to obtain prompt data; updating the prompt data according to a preset formatting strategy to obtain the updated prompt data; inputting the updated prompt data into a generative pre-trained model to obtain a second program file.
[0005] In some embodiments, the preset formatting strategy includes any one or more of the following: determining the first code corresponding to the first program file according to the dependency relationship; determining the corresponding second code according to the first code; parsing the second code to obtain definition data of the second code; inputting the definition data into the prompt data; wherein the second code is a code that conforms to the grammatical rules of the second program file; determining the name of the program package in the first program file, and inputting the name of the program package into the prompt data; determining the name of the first program package corresponding to the first program file according to the dependency relationship, and determining the name of the second program package according to the name of the first program package, wherein the name of the second program package satisfies the naming rules of the second program file; inputting the name of the second program package into the prompt data; dividing the first program file into multiple batches of first sub-codes; determining the class definition code and the function definition code in any batch of the first sub-codes; determining the corresponding second sub-code in the second program file according to the prompt data corresponding to the class definition code, and determining the corresponding second sub-code in the second program file according to the prompt data corresponding to the function definition code; until all the second sub-codes in the second program file are obtained.
[0006] In some embodiments, the preset conditions include one or more of the following: the names of any two parameters in the program package of the first program file are not the same; the names of any two enumeration class codes in the program package of the first program file are not the same; the program package does not include the first symbol; when the number of the program packages is multiple, there is no circular dependency between the multiple program packages.
[0007] In some embodiments, the method further includes: when any one of the program packages includes the first symbol, replacing the first symbol in the any one of the program packages with a preset code.
[0008] In some embodiments, inputting the updated prompt data into the generative pre-trained model includes: when there are multiple first program files, determining the number of dependencies corresponding to each first program file; and inputting the corresponding updated prompt data into the generative pre-trained model in order of the number of dependencies from small to large.
[0009] In some embodiments, the inputting the updated prompt data to the generative pre-trained model includes: when the number of the first program files is multiple, dividing the multiple first program files into different batches; wherein each batch includes at least one first program file; inputting the updated prompt data corresponding to the first program files of any batch into the generative pre-trained model to obtain the second program files corresponding to the first program files of any batch; when it is determined that there is no file error in the corresponding second program file, inputting the updated prompt data corresponding to the first program files of the next batch into the generative pre-trained model until the second program files corresponding to each first program file are obtained.
[0010] In some embodiments, formatting the class name and the dependency relationship according to a preset prompt template to obtain prompt data includes: determining placeholders corresponding to the class name and the dependency relationship in the preset prompt template; replacing the placeholders with the corresponding class name and the prompt template to obtain the prompt data.
[0011] An embodiment of the present application also provides a program conversion device, which includes: a parsing module, which is used to parse the class name and dependency relationship of the first program file when the first program file meets preset conditions; a formatting module, which is used to format the class name and the dependency relationship according to a preset prompt template to obtain prompt data; the formatting module is also used to update the prompt data according to a preset formatting strategy to obtain the updated prompt data; and a conversion module is used to input the updated prompt data into a generative pre-trained model to obtain a second program file.
[0012] An embodiment of the present application also provides an electronic device, comprising: a memory storing at least one instruction; and a processor executing the instructions stored in the memory to implement the program conversion method.
[0013] An embodiment of the present application also provides a computer-readable storage medium, in which at least one instruction is stored. The at least one instruction is executed by a processor in an electronic device to implement the program conversion method.
[0014] It can be seen from the above technical solutions that the embodiment of the present application determines whether the first program file has a high accuracy when performing program conversion according to preset conditions. When the first program file meets the preset conditions, it indicates that the accuracy of program conversion of the first program file is high at this time. Therefore, the class name and dependency relationship of the first program file can be parsed, and the class name and dependency relationship can be formatted according to the prompt template to obtain prompt data. In this way, it can be ensured that the class name and dependency relationship of the first program file can be understood by the generative model with program conversion function. Then, the prompt data is updated according to the formatting strategy to obtain updated prompt data, thereby adjusting the content of the prompt data, which can further improve the accuracy of program conversion, and finally input the updated prompt data into the generative pre-training model to obtain the second program file, thereby improving the efficiency of program conversion. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 This is an application scenario diagram of a program conversion method provided in one embodiment of the present application.
[0016] Figure 2 It is a flowchart of a program conversion method provided by an embodiment of the present application.
[0017] Figure 3 It is a flowchart of a method for inputting prompt data according to the number of dependencies provided by an embodiment of the present application.
[0018] Figure 4 It is a flowchart of a method for inputting multiple first program files in batches provided by an embodiment of the present application.
[0019] Figure 5 It is a functional module diagram of a program conversion device provided in one embodiment of the present application.
[0020] Figure 6 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0021] In order to more clearly understand the purpose, features and advantages of the present application, the present application is described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be noted that, in the absence of conflict, the embodiments of the present application and the features in the embodiments can be combined with each other. In the following description, many specific details are set forth to facilitate a full understanding of the present application, and the embodiments described are only a part of the embodiments of the present application, rather than all of the embodiments.
[0022] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0023] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those generally understood by those skilled in the art to which the present application belongs. The terms used herein in the specification of the present application are only for the purpose of describing specific embodiments and are not intended to limit the present application. The term "and / or" used herein includes any and all combinations of one or more of the related listed items.
[0024] The embodiment of the present application provides a program conversion method, which can be applied to one or more electronic devices. The electronic device is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to a microprocessor, an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field-programmable gate array (Field-Programmable Gate Array, FPGA), a digital processor (Digital Signal Processor, DSP), an embedded device, etc.
[0025] An electronic device can be any electronic product that can interact with a customer, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), a game console, an interactive network television (IPTV), a smart wearable device, etc.
[0026] The electronic device may also include a network device and / or a client device, wherein the network device includes, but is not limited to, a single network server, a server group consisting of multiple network servers, or a cloud consisting of a large number of hosts or network servers based on cloud computing.
[0027] The network where the electronic device is located includes but is not limited to the Internet, wide area network, metropolitan area network, local area network, virtual private network (VPN), etc.
[0028] like Figure 1As shown, a program conversion method provided by the present application can be applied to an electronic device 100, and the electronic device 100 is communicatively connected with a server 200. The electronic device 100 is used to obtain a first program file and a preset formatting strategy from the server 200, and when the first program file meets a preset condition, parse the class name and dependency relationship of the first program file; format the class name and the dependency relationship according to a preset prompt template to obtain prompt data; update the prompt data according to the preset formatting strategy to obtain the updated prompt data; input the updated prompt data into the generative pre-trained model to obtain a second program file.
[0029] like Figure 2 , is a flowchart of a program conversion method provided by an embodiment of the present application. According to different requirements, the order of the steps in the flowchart can be changed, and some steps can be omitted. A program conversion method provided by an embodiment of the present application includes the following steps.
[0030] S20, when the first program file meets a preset condition, parsing the class name and dependency relationship of the first program file.
[0031] In one embodiment of the present application, in order to improve the operation and maintenance efficiency of the independent site during the maintenance of the independent site, the programming language corresponding to the program architecture in the independent site can be converted into other programming languages, thereby realizing the redevelopment of the independent site and ensuring that the underlying programming language of the independent site is easy to expand, thereby improving the efficiency of the operation and maintenance of the independent site. Specifically, the program architecture in the independent site can be a collection of first program files written in a first programming language, and other programming languages can be used to write program files with the same functions as the first program files. For example, a program file with the same functions as the first program file can be a second program file written in a second programming language. Among them, the first programming language and the second programming language corresponding to the program architecture in the independent site can be any programming language, and this application does not limit this.
[0032] Exemplarily, due to the cross-platform, security and high concurrent processing capabilities of the Java language, the first programming language used to build the program framework in some independent sites can be the Java language. Among them, the cross-platform nature of the Java language refers to the fact that programs written in the Java language can run on a Java virtual machine (JVM), so programs written in the Java language have the characteristics of "Write Once, Run Anywhere, WORA". Since the JVM can run on any operating system that supports it, independent sites written in Java can be deployed and run on different platforms without any modification or recompilation. The security of the Java language refers to the fact that the Java language avoids the risks brought by the syntax of pointers and memory release, and can avoid memory leaks and dangling pointers during program operation. Failures caused by the program. In addition, the Java code needs to be checked by the bytecode verifier before running, which further enhances the security of the program. Therefore, independent sites using Java as the underlying language have greater advantages in anti-tampering and anti-virus. Since the Java language includes a rich framework and library, Java can efficiently handle high concurrent requests, so the high concurrent processing capabilities of the Java language can improve the efficiency of independent sites when handling a large number of user visits. In addition, Java is an object-oriented programming language that supports encapsulation, inheritance, and polymorphism, making Java code easy to modularize, maintain, and expand. Therefore, when developing independent sites, the above features of Java can improve development efficiency and code quality. Java includes a variety of open source frameworks, libraries, and tools that can provide complete code support for program developers, thereby improving the efficiency of building independent sites. Java automatically manages memory through a garbage collection mechanism, which can avoid memory leaks.
[0033] In one embodiment of the present application, the function of the second program file is the same as that of the first program file, and the second program language used to write the second program file is different from the first program language. In the process of maintaining, updating or upgrading the independent site, in order to adjust the function of the program module in the independent site, the developer usually converts the first program file written in the first program language into the second program file written in the second program language, thereby adjusting the function of the independent site based on the characteristics of the second program language, which can improve the operation and maintenance efficiency of the independent site.
[0034] Exemplarily, when the first programming language is Java, the second programming language may be Go. Specifically, compared to Java, Go has the following advantages: higher concurrency performance and lightweight threads (Goroutine). Go introduces Goroutine as a concurrent executor. Compared to Java threads, Goroutine is lighter, with lower creation and destruction overhead. Thousands of Goroutines can be run simultaneously without wasting system resources. Go's channel mechanism can provide a safe and efficient concurrent communication method, which can avoid common concurrency problems such as race conditions and deadlocks. Go has higher program execution efficiency. It uses a concurrent mark and sweep algorithm for garbage collection, which can perform garbage collection without blocking program execution, reducing program pause time and improving execution efficiency. Go has an efficient compiler and runtime system that can compile code into native machine code and supports Just-In-Time compilation. Compilation) and static compilation (Ahead-Of-Time Compilation) and other optimization technologies; the readability and simplicity of Go language code are more optimized than Java language, and the efficiency of program maintenance can be improved through standardized code format and document comments; Go language adopts programming ideas and technologies such as modularization, automated testing, automated construction, and strong type checking, which can improve the productivity of developers and make the code in independent sites easier to understand and maintain; Compared with Java language, Go language has a wider range of application scenarios, and Go language is portable and can be applied to a variety of computer system environments, such as Web applications, distributed systems, cloud computing, network servers and other environments. And compared with Java language, Go language has a variety of standard code libraries, in which the functions implemented by the code cover the fields of network construction, data processing, data encryption, etc., ensuring that developers can quickly build various functional modules based on the standard code library of Go language when developing applications in independent sites, thereby improving the efficiency of independent site development. Go language also supports cross-platform compilation. Specifically, the compiler of Go language can run on multiple platforms and can compile binary programs that do not depend on the operating system, so as to ensure that programs developed based on Go language can run on different operating systems. Compared with Java, Go also provides optimization technologies such as memory allocator and pointer analyzer through memory allocator (Allocator) and pointer analyzer (PointerAnalysis), further improving the efficiency of memory management.
[0035] In one embodiment of the present application, before converting the programming language corresponding to the program architecture in the independent site, in order to ensure the efficiency of the conversion of the current programming language in the independent site, the code in the program file in the independent site may be checked. When the program file meets the preset conditions, it indicates that the probability of errors occurring in the program file to be converted in the independent site during the conversion process is low, and the efficiency of converting the program file to other programming languages is high.
[0036] In one embodiment of the present application, the preset conditions include one or more of the following: the names of any two parameters in the program package of the first program file are not the same; the names of any two enumeration class codes in the program package of the first program file are not the same; the program package does not include the first symbol; when the number of the program packages is multiple, there is no circular dependency between the multiple program packages.
[0037] Among them, when two or more parameter names in the first program file are the same, the readability and maintainability of the first program file will be reduced. If multiple parameter names are repeated and multiple parameters have different meanings or functions in different contexts, semantic confusion may be caused when reading and maintaining the code. And when multiple parameter names are the same, it may cause difficulties in code reuse and expansion, and errors may be introduced in multiple large projects due to misleading parameter names. In addition, when the parameter names of multiple parameters in the program file are the same, developers are usually required to make detailed comments on the parameters with the same name in the program file to clearly explain the role and expected value of each parameter, which increases the maintenance burden of the program file. At the same time, in the later operation and maintenance, the operation and maintenance personnel are also required to correctly understand the code according to the comments, thereby causing low efficiency in code maintenance. When the parameter names of multiple parameters in the program file are the same, the reconstruction complexity of the first program file may be high. When the parameters with the same name need to be reconstructed (such as changing the name or type), the complexity of the reconstruction will increase because the names of the parameters are the same and the parameters are distributed in different parts of the program file, and the probability of errors in the reconstruction process may increase due to the same parameter names. Therefore, when the names of any two parameters in the program package of the first program file are the same, it indicates that a code error may occur when converting the first program file into the second program file. The conversion process can be terminated and the corresponding warning information can be output to inform the operation and maintenance personnel to correct the parameter names in the first program file; when the names of any two parameters in the program package of the first program file are different, it indicates that the probability of error in the parameter name is low during the conversion of the first program file. Therefore, the class name and dependency relationship of the first program file can be parsed to carry out the program file conversion process.
[0038] Among them, when the names of any two enumeration class codes in the program package of the first program file are the same, similar problems as mentioned above may occur during the conversion of the first program file, resulting in errors in the conversion of the program file. Therefore, when the names of any two enumeration class codes in the program package of the first program file are the same, it indicates that a code error may occur when converting the first program file to the second program file. The conversion process can be terminated and corresponding warning information can be output to inform the operation and maintenance personnel to correct the name of the enumeration class code in the first program file; when the names of any two enumeration class codes in the program package of the first program file are different, it indicates that during the conversion of the first program file, the probability of a program file conversion error caused by the name of the enumeration class code is low. Therefore, the class name and dependency relationship of the first program file can be parsed to perform the program file conversion process.
[0039] Wherein, when the first program language is Java language, the first symbol can be a "*" symbol. The "*" symbol can be used to represent a multiplication operator in Java language, indicating the result of multiplying two numbers; it can also be used as a wildcard to represent an unknown type in Java language. When the "*" symbol is used as a wildcard, it can be used to create flexible generic code to ensure that the parameterized type in the class code, interface code or method code in Java language has high flexibility; the "*" symbol can also be a wildcard in the annotation of Java language, used to indicate that a certain annotation can be applied to any element type (such as method, parameter, field, etc.); the "*" symbol in Java language can also be used as a bit operator. When the first program file is a program file written in Java language and there is a "*" symbol therein, it indicates that some codes in the first program file may have wildcards, so the meaning of some codes in the first program file is unclear, and errors may occur in the process of converting the first program file, so the conversion process can be terminated and the corresponding warning information can be output to inform the operation and maintenance personnel to correct the first symbol in the first program file. For example, when the first symbol is used to represent a multiplication operator, the Java code where the first symbol is located can be annotated; when the first symbol is used to represent a wildcard, the first symbol can be replaced with a preset code, where the preset code can be a variable name, used to represent the specific variable referred to by the first symbol; it can also be a data storage address, used to represent the data storage address referred to by the first symbol.
[0040] Wherein, when there are multiple program packages in the first program file, each program package is used to implement a specific function, and the functions corresponding to the multiple program packages are combined with each other to implement a complete code logic. In the Java language, when there is a circular dependency between multiple program packages, it may cause problems in the maintainability, compilation process, modularization and testing of the first program file. Specifically, problems between multiple packages may lead to compilation problems, which in turn lead to compilation errors. When the dependencies between packages are dynamically resolved through the classpath, compilation problems may occur. It may also lead to increased coupling. When circular dependencies appear between multiple packages, it may lead to high coupling between codes, resulting in reduced independence between code modules, making it more difficult to modify and maintain the code. When any code module changes, it may affect multiple other code modules, which will increase the risk and cost of modification. In addition, circular dependencies between multiple packages may make it difficult to reconstruct program files. When it is necessary to reconstruct or optimize the code, due to the tight coupling between code modules, modifications to any module may affect other modules, making the reconstruction work complicated and error-prone. Circular dependencies between multiple packages may increase the difficulty of code testing. As the amount of code in Java programs increases, the code will be divided into multiple independent generation modules, and the code modules in packages with circular dependencies cannot be separated or reorganized, resulting in modularization difficulties. Therefore, when there is a circular dependency problem among multiple program packages of the first program file, it indicates that a code error may occur when converting the first program file into the second program file. The conversion process can be terminated and the corresponding warning information can be output to inform the operation and maintenance personnel to correct the dependency relationship of the multiple program packages in the first program file; when there is no circular dependency among the multiple program packages of the first program file, it indicates that the probability of code errors occurring during the conversion of the first program file is low, so the class name and dependency relationship of the first program file can be parsed to carry out the program file conversion process.
[0041] In an embodiment of the present application, the method further includes: when any program package includes the first symbol, replacing the first symbol in the any program package with a preset code. Specifically, when the first symbol is a wildcard, the preset code can be a variable name, used to represent the specific variable referred to by the first symbol; or it can be a data storage address, used to represent the data storage address referred to by the first symbol.
[0042] In one embodiment of the present application, when the first program file meets the above-mentioned preset conditions, it indicates that the probability of an error occurring in the process of converting the first program file to the second program file is low, so the first program file can be parsed to obtain the class name and dependency relationship therein, and the first program file is converted based on the class name and dependency relationship. Wherein, the class name refers to the identifier that defines the class in Java. In Java, a class is a blueprint or template used to define an object, which contains information describing the state (attributes) and behavior (methods) of the object. The class name follows a specific naming rule, usually CamelCase with the first letter capitalized, to distinguish between keywords and variable names in Java. For example, Person, Car, Student, etc. are all valid class names. The class name is used to reference the class in a Java program and to create an instance (object) of the class. For example, if you have a class named Person, you can create a new instance of the Person class through new Person(). A dependency refers to a class (or component) that depends on another class (or component) to complete its function. In Java, this dependency is usually reflected in the following ways: method call, a method of a class calls a method of an instance of another class; inheritance, a class (subclass) inherits from another class (parent class), thereby inheriting the properties and methods of the parent class; interface implementation, when a class implements an interface, it needs to implement all methods defined in the interface; field reference, a field (property) of a class is an instance of another class; dependencies can be direct (such as directly calling a method of another class) or indirect (such as through an interface or abstract class). When designing and implementing Java programs, managing dependencies is very important because it directly affects the modularity, maintainability, and scalability of the program.
[0043] S21, formatting the class name and the dependency relationship according to a preset prompt template to obtain prompt data.
[0044] In one embodiment of the present application, in order to improve the efficiency and accuracy of program conversion, the class name and the dependency relationship can be formatted according to a preset prompt template to obtain prompt data. This ensures that the generative model running in the independent site can accurately understand the code logic in the first program file and the requirements of program conversion, thereby improving the efficiency and accuracy of program conversion.
[0045] In one embodiment of the present application, the class name and the dependency are formatted according to a preset prompt template to obtain prompt data, including: determining the placeholders corresponding to the class name and the dependency in the preset prompt template; replacing the placeholders with the corresponding class name and the prompt template to obtain the prompt data; wherein the pre-stored prompt template includes example prompts, and the example prompts are used to characterize the syntax and format corresponding to the converted program (for example, the syntax and format corresponding to the second programming language). Exemplarily, the prompt template includes background prompts, task prompts, and example prompts, and the content of the prompt template can be: "Background prompts: You are an outstanding software engineer, and you are proficient in converting Java code into Go code; Task prompts: Please convert the input program into an output program according to the following conversion rules. The input program includes: ```{{code}}```; the conversion rules include: ```{{conversion rules}}```; example prompts: Please return to the program written in Go language, and the syntax and format of Go language are as follows: ```{{Go language syntax rules}}```". In this hint template, the placeholders are ```{{code}}```, ```{{conversion rule}}```, and ```{{Go language syntax rule}}```.
[0046] Exemplarily, when the name of the first program file to be converted is "Program A", the conversion rules include: "Please use field tags to keep the original case when converting to JSON; if the code depends on other classes in the project, please use the package name +. + structure name to reference in Go, so as to avoid reference errors; if there is Java dependency injection in the code, please explicitly pass the dependency through function parameters; there are explanations and suggestions in the conversion, which can be supplemented concisely", and the Go language grammar rules include: "Grammar Rule A, Grammar Rule B and Grammar Rule C". The placeholder in the pre-stored prompt template can be replaced with the name of the first program file to obtain prompt data. Exemplarily, the content of the prompt data includes: "Background prompt: You are an outstanding software engineer who is proficient in converting Java code into Go code; Task prompt: Please convert the input program into the output program according to the following conversion rules. The input program includes: Program A; Conversion rules include: Please use field tags to keep the original case when converting to JSON; If the code depends on other classes in the project, please use the package name +. + structure name to reference in Go, which can avoid reference errors; If there is Java dependency injection in the code, please explicitly pass the dependency through function parameters; There are explanations and suggestions in the conversion, which can be supplemented concisely; Example prompt: Please return to the program written in Go language. The syntax and format of Go language are as follows: Syntax rule A, syntax rule B and syntax rule C".
[0047] In this way, the class name and dependency relationship of the first program file are formatted using the prompt template to obtain formatted prompt data, which makes it easier for the generative pre-trained model to understand the content in the prompt data, thereby improving the efficiency and accuracy of converting the first program file into the second program file based on the prompt data using the generative pre-trained model in the independent site.
[0048] In one embodiment of the present application, the generative pre-trained model can be any model with text generation function. For example, the generative pre-trained model can be a generative pre-trained model (Generative Pretrained Transformer, GPT), or a large language model of Meta artificial intelligence (Large Language Model MetaAI, LLaMa), which is not limited in the present application. Among them, the input of the generative pre-trained model is prompt data, and the output is a second program file corresponding to the prompt data.
[0049] S22, updating the prompt data according to a preset formatting strategy to obtain the updated prompt data.
[0050] In one embodiment of the present application, in order to improve the accuracy of the subsequent generation of the second program file, the prompt data can be updated according to a preset formatting strategy, thereby improving the quality of the prompt data and ensuring that the code logic in the second program file generated by the generative pre-trained model according to the prompt data is the same as the code logic in the first program file.
[0051] In an embodiment of the present application, the preset formatting strategy includes any one or more of the following:
[0052] Determine the first code corresponding to the first program file according to the dependency relationship, determine the second code corresponding to the first code according to the first code, parse the second code, obtain definition data of the second code, and input the definition data into the prompt data, wherein the second code is a code that conforms to the grammatical rules of the second program file; determine the name of the program package in the first program file, and input the name of the program package into the prompt data; determine the name of the first program package corresponding to the first program file according to the dependency relationship, determine the name of the second program package according to the name of the first program package, wherein the name of the second program package satisfies the naming rules of the second program file, and input the name of the second program package into the prompt data; divide the first program file into multiple batches of first sub-codes, determine the class definition code and the function definition code in any batch of the first sub-codes, determine the corresponding second sub-code in the second program file according to the prompt data corresponding to the class definition code, and determine the corresponding second sub-code in the second program file according to the prompt data corresponding to the function definition code, until all the second sub-codes in the second program file are obtained.
[0053] Among them, the first program file can be a program file written in Java language, the first code can be a class code in the first program file, and the second code corresponding to the first code can be a code written in other programming languages (for example, Go language) with the same function as the class code in the first program file; the definition data of the second code is used to describe the function of the second code in detail.
[0054] The second program package may be a set of codes written in other programming languages (eg, Go language) and having the same functions as the first program package.
[0055] Exemplarily, the first program file can be divided according to the number of lines of code in the first program file. For example, every 200 lines of code in the first program file can be divided into a batch of first sub-codes, and the class definition code and function definition code in each batch of first sub-codes can be determined. In this way, the functions of the first sub-codes of the batch can be characterized according to the class definition code and the function definition code, and the amount of code can be reduced each time the program conversion is performed, thereby improving the accuracy of the program conversion.
[0056] S23, input the updated prompt data into the generative pre-training model to obtain a second program file.
[0057] In one embodiment of the present application, when there are multiple first program files, in order to ensure the accuracy of the second program file generated by the generative pre-trained model according to the prompt data and avoid the logic errors or syntax errors in the code in the second program file that may have a negative impact on the function of the independent site, the order of inputting the updated prompt data into the generative pre-trained model can be determined according to the number of dependencies of the first program file. For specific methods for determining the order of inputting prompt data according to the number of dependencies, please refer to Figure 3 The corresponding detailed description.
[0058] In one embodiment of the present application, multiple first program files can also be input into the generative pre-training model in multiple batches. For specific methods of inputting multiple first program files in batches, please refer to Figure 4 The corresponding detailed description.
[0059] In an embodiment of the present application, the method further includes: after obtaining the second program file, storing the second program file in a pre-built project folder according to the name of the second program file.
[0060] It can be seen from the above technical solutions that the embodiment of the present application determines whether the first program file has a high accuracy when performing program conversion according to preset conditions. When the first program file meets the preset conditions, it indicates that the accuracy of program conversion of the first program file is high at this time. Therefore, the class name and dependency relationship of the first program file can be parsed, and the class name and dependency relationship can be formatted according to the prompt template to obtain prompt data. In this way, it can be ensured that the class name and dependency relationship of the first program file can be understood by the generative model with program conversion function. Then, the prompt data is updated according to the formatting strategy to obtain updated prompt data, thereby adjusting the content of the prompt data, which can further improve the accuracy of program conversion, and finally input the updated prompt data into the generative pre-training model to obtain the second program file, thereby improving the efficiency of program conversion.
[0061] like Figure 3 , is a flow chart of a method for inputting prompt data according to the number of dependency relationships provided by an embodiment of the present application. According to different requirements, the order of the steps in the flow chart can be changed, and some steps can be omitted. The method for inputting prompt data according to the number of dependency relationships provided by an embodiment of the present application includes the following steps.
[0062] S30: When there are multiple first program files, determine the number of dependency relationships corresponding to each first program file.
[0063] In one embodiment of the present application, when the number of dependencies of a program file (for example, a program file written in Java language) is large, it indicates that the complexity of the first program file is high, and it needs to rely on multiple external libraries or modules to realize its functions, which increases the difficulty of code understanding and maintenance; and too many dependencies may lead to an increase in the coupling degree between modules. A highly coupled program file means that changing a module may require changing many other related modules, which increases the maintenance cost of the system and the risk of error. And as the number of dependencies increases, the compilation and deployment process of the project may become more complicated. In addition, more dependencies also mean greater security risks, and some dependencies may contain security vulnerabilities. And when a program file depends on multiple external libraries, its testing difficulty may be increased accordingly, and the difficulty of reusing the program file in other projects will increase. Therefore, when the number of dependencies in the first program file is large, the updated prompt data corresponding to the first program file can be preferentially converted, thereby increasing the fault tolerance of program conversion.
[0064] S31, inputting the corresponding updated prompt data into the generative pre-training model according to the order of the number of the dependency relationships from small to large.
[0065] like Figure 4 , is a flow chart of a method for inputting multiple first program files in batches provided by an embodiment of the present application. According to different requirements, the order of the steps in the flow chart can be changed, and some steps can be omitted. The method for inputting multiple first program files in batches provided by an embodiment of the present application includes the following steps.
[0066] S40: When there are multiple first program files, divide the multiple first program files into different batches; wherein each batch includes at least one first program file.
[0067] S41, inputting the updated prompt data corresponding to the first program file of any batch into the generative pre-training model to obtain the second program file corresponding to the first program file of any batch.
[0068] S42, when it is determined that there is no file error in the corresponding second program file, input the updated prompt data corresponding to the next batch of first program files into the generative pre-training model until the second program file corresponding to each first program file is obtained.
[0069] In one embodiment of the present application, in order to improve the efficiency of program conversion, when the updated prompt data corresponding to each batch of the first program file is processed, it can be determined whether the code in the corresponding second program file has a syntax error or a logic error. When it is determined that there is no file error in the second program file, the updated prompt data corresponding to the first program file of the next batch is processed. In this way, the quality of the input second program file can be continuously ensured during the program conversion process, thereby improving the accuracy of the program conversion.
[0070] See also Figure 5 , Figure 5 1 is a functional module diagram of a program conversion device provided in an embodiment of the present application. A program conversion device 51 includes a parsing module 510, a formatting module 511 and a conversion module 512. The module / unit referred to in the present application refers to a series of computer-readable instruction segments that can be executed by the processor 13 and can complete fixed functions, which are stored in the memory 12. In this embodiment, the functions of each module / unit will be described in detail in subsequent embodiments.
[0071] The parsing module 510 is used to parse the class name and dependency relationship of the first program file when the first program file meets a preset condition.
[0072] The formatting module 511 is used to format the class name and the dependency relationship according to a preset prompt template to obtain prompt data.
[0073] The formatting module 511 is further configured to update the prompt data according to a preset formatting strategy to obtain the updated prompt data.
[0074] The conversion module 512 is used to input the updated prompt data into the generative pre-training model to obtain a second program file.
[0075] See also Figure 6 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. The electronic device 100 includes a memory 12 and a processor 13. The memory 12 is used to store computer-readable instructions, and the processor 13 is used to execute the computer-readable instructions stored in the memory to implement a program conversion method described in any of the above embodiments.
[0076] In an embodiment of the present application, the electronic device 100 further includes a bus, a computer program stored in the memory 12 and executable on the processor 13, such as a program conversion program.
[0077] Figure 6 Only the electronic device 100 having the memory 12 and the processor 13 is shown, and those skilled in the art can understand that Figure 6The structure shown does not constitute a limitation on the electronic device 100 , and the electronic device 100 may include fewer or more components than shown in the figure, or combine some components, or arrange the components differently.
[0078] Combination Figure 2 , the memory 12 in the electronic device 100 stores multiple computer-readable instructions to implement a program conversion method, and the processor 13 can execute the multiple instructions to achieve: when the first program file meets the preset conditions, parse the class name and the dependency relationship of the first program file; format the class name and the dependency relationship according to the preset prompt template to obtain prompt data; update the prompt data according to the preset formatting strategy to obtain the updated prompt data; input the updated prompt data into the generative pre-trained model to obtain the second program file.
[0079] Specifically, the specific implementation method of the processor 13 for the above instructions can refer to Figure 2 The description of the relevant steps in the corresponding embodiments will not be repeated here.
[0080] Those skilled in the art will appreciate that the schematic diagram is merely an example of the electronic device 100 and does not constitute a limitation on the electronic device 100. The electronic device 100 may be a bus-type structure or a star-type structure. The electronic device 100 may also include more or less other hardware or software than shown in the diagram, or a different arrangement of components. For example, the electronic device 100 may also include input and output devices, network access devices, etc.
[0081] It should be noted that the electronic device 100 is only an example, and other existing or future electronic products that are suitable for the present application should also be included in the protection scope of the present application and included here by reference.
[0082] Among them, the memory 12 includes at least one type of readable storage medium, and the readable storage medium can be non-volatile or volatile. The readable storage medium includes flash memory, mobile hard disk, multimedia card, card-type memory (for example: SD or DX memory, etc.), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 12 can be an internal storage unit of the electronic device 100, such as a mobile hard disk of the electronic device 100. In other embodiments, the memory 12 can also be an external storage device of the electronic device 100, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 100. The memory 12 can not only be used to store application software and various types of data installed in the electronic device 100, such as a code of a program conversion program, etc., but also can be used to temporarily store data that has been output or is to be output.
[0083] In some embodiments, the processor 13 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips. The processor 13 is the control core (Control Unit) of the electronic device 100, and uses various interfaces and lines to connect various components of the entire electronic device 100, and executes various functions and processes data of the electronic device 100 by running or executing programs or modules stored in the memory 12 (for example, executing a program conversion program, etc.), and calling data stored in the memory 12.
[0084] The processor 13 executes the operating system of the electronic device 100 and various installed applications. The processor 13 executes the applications to implement the steps in the above embodiments, for example Figure 2 Steps shown.
[0085] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory 12 and executed by the processor 13 to complete the present application. The one or more modules / units may be a series of computer-readable instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program in the electronic device 100. For example, the computer program may be divided into a parsing module 510, a formatting module 511, and a conversion module 512.
[0086] The above-mentioned integrated unit implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a computer device, or a network device, etc.) or a processor to execute a part of a program conversion method described in each embodiment of the present application.
[0087] If the module / unit integrated in the electronic device 100 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also instruct the relevant hardware devices to complete through a computer program. The computer program can be stored in a computer-readable storage medium, and when the computer program is executed by the processor, the steps of each of the above-mentioned method embodiments can be implemented.
[0088] The computer program includes computer program code, which may be in source code form, object code form, executable file or some intermediate form, etc. The computer readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory and other memory, etc.
[0089] Furthermore, the computer-readable storage medium may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function, etc.; the data storage area may store data created according to the use of the blockchain node, etc.
[0090] The bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. Figure 6 Only one arrow is used in the figure, but it does not mean that there is only one bus or one type of bus. The bus is configured to realize the connection and communication between the memory 12 and at least one processor 13, etc.
[0091] An embodiment of the present application also provides a computer-readable storage medium (not shown), in which computer-readable storage medium is stored computer-readable instructions, and the computer-readable instructions are executed by a processor in an electronic device to implement a program conversion method described in any of the above embodiments.
[0092] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
[0093] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0094] In addition, each functional module in each embodiment of the present application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0095] In addition, it is obvious that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the specification can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any specific order.
[0096] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present application and are not intended to limit it. Although the present application has been described in detail with reference to the preferred embodiments, a person of ordinary skill in the art should understand that the technical solution of the present application may be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present application.
Claims
1. A program conversion method, It is characterized in that The method comprises: If the first program file meets the preset condition, parsing the class name and dependency relationship of the first program file; Formatting the class name and the dependency relationship according to a preset prompt template to obtain prompt data; Update the prompt data according to a preset formatting strategy to obtain the updated prompt data; The updated prompt data is input into the generative pre-training model to obtain a second program file.
2. The program conversion method according to claim 1, It is characterized in that The preset formatting strategy includes any one or more of the following: Determine the first code corresponding to the first program file according to the dependency relationship; determine the second code corresponding to the first code according to the first code; parse the second code to obtain definition data of the second code; input the definition data into the prompt data; wherein the second code is a code that conforms to the grammatical rules of the second program file; determining a name of a program package in the first program file, and inputting the name of the program package into the prompt data; Determine the name of the first program package corresponding to the first program file according to the dependency relationship, and determine the name of the second program package according to the name of the first program package, wherein the name of the second program package satisfies the naming rule of the second program file; input the name of the second program package into the prompt data; Divide the first program file into multiple batches of first subcodes; determine the class definition code and the function definition code in any batch of first subcodes; determine the corresponding second subcode in the second program file according to the prompt data corresponding to the class definition code, and determine the corresponding second subcode in the second program file according to the prompt data corresponding to the function definition code; until all the second subcodes in the second program file are obtained.
3. The program conversion method according to claim 1, It is characterized in that The preset conditions include one or more of the following: The names of any two parameters in the program package of the first program file are different; The names of any two enumeration class codes in the program package of the first program file are different; The program package does not include a first symbol; When there are multiple program packages, there is no circular dependency relationship between the multiple program packages.
4. The program conversion method according to claim 3, It is characterized in that The method further comprises: When any one of the program packages includes the first symbol, the first symbol in the any one of the program packages is replaced with a preset code.
5. The program conversion method according to claim 1, It is characterized in that The inputting the updated prompt data into the generative pre-trained model comprises: When there are multiple first program files, determine the number of dependency relationships corresponding to each first program file; According to the order of the number of the dependencies from small to large, the corresponding updated prompt data is input into the generative pre-training model.
6. The program conversion method according to claim 1, It is characterized in that The inputting the updated prompt data into the generative pre-trained model comprises: When there are multiple first program files, divide the multiple first program files into different batches; wherein each batch includes at least one first program file; Inputting updated prompt data corresponding to any batch of first program files into the generative pre-training model to obtain the second program file corresponding to any batch of first program files; When it is determined that there is no file error in the corresponding second program file, the updated prompt data corresponding to the next batch of first program files is input into the generative pre-training model until the second program file corresponding to each first program file is obtained.
7. The program conversion method according to claim 1, It is characterized in that The class name and the dependency relationship are formatted according to a preset prompt template to obtain prompt data including: Determining placeholders corresponding to the class name and the dependency relationship in the preset prompt template; The placeholder is replaced with the corresponding class name and the prompt template to obtain the prompt data.
8. A program conversion device, It is characterized in that The device comprises a module for implementing the program conversion method according to any one of claims 1 to 7, and the device comprises: A parsing module, used for parsing the class name and dependency relationship of the first program file when the first program file meets a preset condition; A formatting module, used for formatting the class name and the dependency relationship according to a preset prompt template to obtain prompt data; The formatting module is further used to update the prompt data according to a preset formatting strategy to obtain the updated prompt data; The conversion module is used to input the updated prompt data into the generative pre-training model to obtain a second program file.
9. An electronic device, It is characterized in that The electronic device comprises a processor and a memory, and the processor is used to implement the program conversion method according to any one of claims 1 to 7 when executing a computer program stored in the memory.
10. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the program conversion method according to any one of claims 1 to 7 is implemented.
