Java code generation system based on UML class diagram and large language model

Through a Java code generation system based on UML class diagrams and large language models, the problem of low efficiency and incompatibility of code conversion to Java in the existing technology is solved, and efficient and automated code generation is achieved, ensuring the code correctness and consistency.

CN119166152APending Publication Date: 2024-12-20UNIV OF ELECTRONICS SCI & TECH OF CHINA
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411201920.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-29
Publication Date
2024-12-20

AI Technical Summary

Technical Problem

The existing technology cannot quickly and accurately convert UML class diagrams into Java code, resulting in low software development efficiency, and the generated code does not meet the requirements, making it difficult to expand and maintain.

Method used

Design a Java code generation system based on UML class diagrams and large language models, including format conversion modules, data set construction modules, fine-tuning modules and code generation modules. By analyzing UML class diagrams, building data sets, fine-tuning large language models, generate Java code that complies with specifications.

Benefits of technology

It improves the degree of automation from UML class diagrams to Java code, ensures the correctness and consistency of generated codes, and overcomes the technical difficulties of the large language model's limited understanding of UML language and complexity and diversity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119166152A_ABST
    Figure CN119166152A_ABST
Patent Text Reader

Abstract

The invention discloses a Java code generation system based on a UML (Unified Modeling Language) class diagram and a large language model, relates to the technical field of software development, and solves the technical problem that the UML class diagram cannot be quickly and accurately converted into a Java code to improve the software development efficiency in the prior art. The system comprises a format conversion module used for converting an imported UML class diagram into a standard format; the data set construction module is used for collecting UML class diagram files in a standard format and corresponding Java codes and constructing a data set; the fine tuning module is used for performing fine tuning on the large language model by utilizing the data set and evaluating the accuracy, the code structure and the quality of the fine-tuned large language model according to an evaluation strategy; a trained large language model is deployed in the code generation module, and the code generation module is used for generating Java codes from UML class diagram files in a standard format; according to the method, the automation degree from the UML class diagrams to the Java codes is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software development, and in particular to a Java code generation system based on a UML class diagram and a large language model. Background Art

[0002] Unified Modeling Language (UML) is widely used in software engineering to describe the structure and behavior of a system. UML class diagrams can help developers clearly represent the classes, attributes, methods, and relationships between classes of a system. Traditional methods of converting UML models into code mainly rely on developers to write code manually or use simple code generation tools. However, these tools are usually based on specific templates and rules, but lack a deep understanding of the complex class diagram structure and semantics, resulting in the generated code often not meeting development requirements and being difficult to expand and maintain. Some methods generate code by parsing UML models in XML format, but the XML files generated by existing UML tools usually contain a lot of redundant and complex information, which increases the workload from design to implementation. Summary of the invention

[0003] In order to solve the problems existing in the above-mentioned prior art, the present invention provides a Java code generation system based on UML class diagram and large language model, which solves the technical problem that the prior art cannot quickly and accurately convert UML class diagram into Java code to improve software development efficiency.

[0004] A Java code generation system based on UML class diagram and large language model, including a format conversion module, a data set construction module, a fine-tuning module and a code generation module;

[0005] The format conversion module is used to convert the imported UML class diagram into a standard format;

[0006] The data set construction module is used to collect UML class diagram files in a standard format and corresponding Java codes and construct a data set;

[0007] The fine-tuning module is used to fine-tune the large language model using the data set and evaluate the accuracy, code structure and quality of the fine-tuned large language model according to the evaluation strategy;

[0008] The code generation module deploys a trained large language model to generate Java code from a UML class diagram file in a standard format.

[0009] Furthermore, the format conversion module includes a parsing submodule and a unifying submodule. The parsing submodule is used to parse the UML class diagram, and the parsing process includes extracting classes, attributes, methods, modifiers and inter-class relationships; the unifying submodule is used to fill the parsed data into a template to obtain an XML file in a standard format.

[0010] Furthermore, the data set construction module includes a UML class diagram file collection submodule and a code generation submodule. The UML class diagram file collection submodule is used to collect UML class diagrams converted into a standard format, and the code generation submodule is used to automatically generate Java code based on an un-fine-tuned large language model, and then interact with the user to normalize the generated Java code, and the normalized code is matched one-to-one with the corresponding UML class diagram file to obtain a mapping data set.

[0011] Furthermore, the fine-tuning module includes a training submodule and a testing submodule. The training submodule is used to fine-tune the large language model according to the training set and evaluate the trained large language model according to the evaluation strategy. The testing submodule is used to test the fine-tuned model according to the test set. The testing process includes: using the large language models before and after fine-tuning to generate Java code from the UML class diagram file in the test set, and judging the performance of the fine-tuned large language model according to the ability of the two models to generate Java code. The training set and the test set are obtained from the data set.

[0012] Furthermore, the evaluation aspects of the evaluation strategy include: a class in the class diagram exists in the source code; each attribute and method of the class; the specific implementation of each method; modifiers of elements; and relationships between classes.

[0013] Furthermore, it includes a training state and a working state. When in the training state, the format conversion module is used to generate the data required for data set construction, the data set construction module and the fine-tuning module operate normally, and the code generation module is suspended; when in the working state, the format conversion module is used to convert the UML class diagram file to be converted into a standard format, the code generation module operates normally, and the data set construction module and the fine-tuning module are suspended.

[0014] Furthermore, the code generation module receives user feedback in real time, analyzes the accuracy of the generated code according to the user feedback, and enters a training state when the accuracy is lower than a threshold.

[0015] The beneficial effects of the present invention include: effectively improving the degree of automation from UML class diagram to Java code implementation, and using the DOM4J library and the FreeMarker template engine to convert the UML class diagram file into an XML file in a unified format, so as to facilitate the large language model to generate Java code; and fine-tuning the large language model by making a mapping data set between the class diagram XML file and the corresponding Java code, ensuring that the Java code generated by the large language model complies with the class diagram specification.

[0016] The technical difficulties that the large language model cannot directly generate usable Java code from the UML class diagram and cannot guarantee the correctness and consistency of the generated code are overcome due to the large language model's limited understanding of the UML language and the complexity and diversity of the UML class diagram. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 This is an example of a UML class diagram file in the initial format involved in this embodiment.

[0018] Figure 2 This is an example of a UML class diagram file in a standard format involved in this embodiment.

[0019] Figure 3 An example of Java code generated for a large model before fine-tuning it to a standard format UML class diagram.

[0020] Figure 4 This is an example of a complex UML class diagram fragment involved in this embodiment.

[0021] Figure 5 An example of Java code generated for fine-tuning the previous large model for a complex UML class diagram fragment.

[0022] Figure 6 An example of Java code generated for a large model fine-tuned for a complex UML class diagram fragment.

[0023] Figure 7 These are two working state diagrams of a Java code generation system based on UML class diagram and large language model. DETAILED DESCRIPTION

[0024] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.

[0025] A Java code generation system based on UML class diagram and large language model, including a format conversion module, a data set construction module, a fine-tuning module and a code generation module;

[0026] The format conversion module is used to convert the imported UML class diagram into a standard format;

[0027] The UML class diagram is drawn by the UML tool Enterprise Architect and exported as an XML format file.

[0028] The data set construction module is used to collect UML class diagram files in a standard format and corresponding Java codes and construct a data set;

[0029] The fine-tuning module is used to fine-tune the large language model using the data set and evaluate the accuracy, code structure and quality of the fine-tuned large language model according to the evaluation strategy;

[0030] The code generation module deploys a trained large language model to generate Java code from a UML class diagram file in a standard format.

[0031] In another embodiment, the format conversion module includes a parsing submodule and a unifying submodule. The parsing submodule is used to parse the UML class diagram, and the parsing process includes extracting classes, attributes, methods, modifiers and relationships between classes; the unifying submodule is used to fill the parsed data into a template to obtain an XML file in a standard format.

[0032] The parsing submodule parses the UML class diagram through DOM4J, and the unification submodule obtains an XML file in a standard format by filling in a predefined Freemarker template.

[0033] In another embodiment, the data set construction module includes a UML class diagram file collection submodule and a code generation submodule. The UML class diagram file collection submodule is used to collect UML class diagrams converted into a standard format, and the code generation submodule is used to automatically generate Java code based on an un-fine-tuned large language model, and then interact with the user to normalize the generated Java code, and the normalized code is matched one-to-one with the corresponding UML class diagram file to obtain a mapping data set.

[0034] For standard XML files, the large language model without fine-tuning can also generate corresponding Java code, but for complex UML class diagrams, the code generated by the large language model without fine-tuning usually does not meet the class diagram specifications and has code errors. The present invention constructs a mapping data set of XML format UML class diagrams and corresponding Java codes through manual correction for subsequent large language model fine-tuning training.

[0035] In another embodiment, the fine-tuning module includes a training submodule and a testing submodule. The training submodule is used to fine-tune the large language model according to the training set and evaluate the trained large language model according to the evaluation strategy. The testing submodule is used to test the fine-tuned model according to the test set. The testing process includes: using the large language models before and after fine-tuning to generate Java code from the UML class diagram file in the test set, and judging the performance of the fine-tuned large language model based on the ability of the two models to generate Java code. The training set and the test set are obtained from the data set.

[0036] In another embodiment, the evaluation aspects of the evaluation strategy include: a class in a class diagram exists in source code; each attribute and method of the class; the specific implementation of each method; modifiers of elements; and relationships between classes.

[0037] A specific Java code generation system based on UML class diagram and large language model generates code by working as follows: Figure 7 shown.

[0038] Take a class diagram with two classes as an example. The Teacher class has two attributes: subject and age. The Student class has three attributes: grade, ID, name and one operation: study(). The Teacher class and the Student class have an association relationship.

[0039] a. For this class diagram, use the UML tool Enterprese Architect to draw the class diagram and then export it to an XML file. Figure 1 As shown;

[0040] b. Use DOM4J to parse and fill in the predefined Freemarker template to get the XML file such as Figure 2 As shown;

[0041] c. For XML files in this format, the large model is easy to generate corresponding Java code, but for complex UML class diagrams, the code generated by the large model usually does not meet the class diagram specifications and has code errors. The present invention constructs a mapping data set of UML class diagrams in XML format and corresponding Java codes for fine-tuning training of the large model through manual correction. The fine-tuned large model shows good performance. For the above class diagram, Java code is generated as follows: Figure 3 As shown;

[0042] d. To illustrate the role of building a data set and fine-tuning the model, a complex UML class diagram is used as an example. Figure 4 As shown in the figure, its unified XML format is as follows. This fragment describes "Transportab le" "Trackab le"

[0043] The definitions of two interfaces and two classes, "Entity" and "Veh ic le", are included. The Veh ic le class inherits from the Entity class and implements the Transportab le and Trackab le interfaces. The code snippet generated by the unadjusted CodeL la ama model is as follows: Figure 5 As shown; the code snippet generated by the fine-tuned CodeL l ama model is as follows Figure 6 As shown;

[0044] e. By checking and comparing the codes generated by the two models, it can be found that the code generated by the large model before fine-tuning ignores the definition of the interface, does not write the class constructor, and does not attempt to write the specific implementation of the overridden method, while the code generated by the large model after fine-tuning meets the requirements.

[0045] In another embodiment, it includes a training state and a working state. When in the training state, the format conversion module is used to generate the data required for data set construction, the data set construction module and the fine-tuning module operate normally, and the code generation module is suspended; when in the working state, the format conversion module is used to convert the UML class diagram file to be converted into a standard format, the code generation module operates normally, and the data set construction module and the fine-tuning module are suspended.

[0046] In another embodiment, the code generation module receives user feedback in real time, analyzes the accuracy of the generated code according to the user feedback, and enters a training state when the accuracy is lower than a threshold.

[0047] The above-mentioned embodiments only express the specific implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the protection scope of the present application. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the technical solution concept of the present application, and these all belong to the protection scope of the present application.

Claims

1. A Java code generation system based on UML class diagram and large language model, characterized in that: Includes format conversion module, data set construction module, fine-tuning module and code generation module; The format conversion module is used to convert the imported UML class diagram into a standard format; The data set construction module is used to collect UML class diagram files in a standard format and corresponding Java codes and construct a data set; The fine-tuning module is used to fine-tune the large language model using the data set and evaluate the accuracy, code structure and quality of the fine-tuned large language model according to the evaluation strategy; The code generation module deploys a trained large language model to generate Java code from a UML class diagram file in a standard format.

2. A Java code generation system based on UML class diagram and large language model according to claim 1, characterized in that: The format conversion module includes a parsing submodule and a unifying submodule. The parsing submodule is used to parse the UML class diagram, and the parsing process includes extracting classes, attributes, methods, modifiers and inter-class relationships; the unifying submodule is used to fill the parsed data into a template to obtain an XML file in a standard format.

3. A Java code generation system based on UML class diagram and large language model according to claim 1, characterized in that: The data set construction module includes a UML class diagram file collection submodule and a code generation submodule. The UML class diagram file collection submodule is used to collect UML class diagrams converted into a standard format. The code generation submodule is used to automatically generate Java code based on an un-fine-tuned large language model, and then interact with the user to normalize the generated Java code, and the normalized code is matched one-to-one with the corresponding UML class diagram file to obtain a mapping data set.

4. A Java code generation system based on UML class diagram and large language model according to claim 1, characterized in that: The fine-tuning module includes a training submodule and a testing submodule. The training submodule is used to fine-tune the large language model according to the training set and evaluate the trained large language model according to the evaluation strategy. The testing submodule is used to test the fine-tuned model according to the test set. The testing process includes: using the large language models before and after fine-tuning to generate Java code from the UML class diagram file in the test set, and judging the performance of the fine-tuned large language model according to the ability of the two models to generate Java code. The training set and the test set are obtained from the data set.

5. A Java code generation system based on UML class diagram and large language model according to claim 1, characterized in that: The evaluation aspects of the evaluation strategy include: a class in the class diagram exists in the source code; each attribute and method of the class; the specific implementation of each method; the modifier of the element; and the relationship between classes.

6. A Java code generation system based on UML class diagram and large language model according to claim 1, characterized in that: It includes training state and working state. When in the training state, the format conversion module is used to generate the data required for data set construction, the data set construction module and the fine-tuning module run normally, and the code generation module is suspended; when in the working state, the format conversion module is used to convert the UML class diagram file that needs to be converted into a standard format, the code generation module runs normally, and the data set construction module and the fine-tuning module are suspended.

7. A Java code generation system based on UML class diagram and large language model according to claim 6, characterized in that: The code generation module receives user feedback in real time, analyzes the accuracy of the generated code according to the user feedback, and enters a training state when the accuracy is lower than a threshold.

Citation Information

Cited By

  • Computing power scheduling engine generation method based on large programming model and electronic equipment

    CN119960740A