Code modification method, system and equipment based on CURD scene and medium
Through the code modification method based on the CURD scenario, the data model of business requirements is obtained, the function call relationship is analyzed, and business code fragments are generated and merged, which solves the problem that programming assistant tools cannot understand business requirements, and achieves efficient and accurate code modification and quality improvement.
Patent Information
- Application Number
- CN202510293271.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-13
- Publication Date
- 2025-07-25
AI Technical Summary
When existing programming assistant tools handle business needs, it is difficult to understand complex code programming logic and business needs, resulting in inaccurate code generated and affect development efficiency and code quality.
Based on the CURD scenario, by obtaining the data model of business requirements, analyzing the function call relationship in the code file, generating business code snippets, and merging them into the code file, ensuring that the code modification is closely connected with business requirements, focusing on the core part of business logic.
It improves the efficiency and quality of code modification, ensures the clear and easy-to-understand code, has high reusability, reduces interference from irrelevant code, and improves development efficiency and code quality.
Smart Images

Figure CN120371307A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the technical field of code development, and particularly relates to a code modification method, system, device, and medium based on the CURD scenario. Background Art
[0002] With the booming rise of artificial intelligence and big data technologies, intelligent coding assistance tools are increasingly widely used in the field of software development, becoming an important means to improve development efficiency and reduce error rates. Currently, advanced programming assistants such as Github Copilot and Tongyi Lingma of Alibaba Cloud have emerged in the market. Relying on the powerful capabilities of large models, these programming assistant tools can intelligently provide line-level or function-level code and document continuation services in the user's coding work environment, greatly promoting the improvement of coding efficiency and being widely used in various programming environments.
[0003] Although the above programming assistants can automatically generate code, developers often need to spend more time reviewing and modifying this code to ensure its quality and security. At the same time, the technical level of programming assistants still has certain limitations. For the addition or deletion of business requirements in actual development operations, programming assistants are unable to fully understand complex code programming logic and context logic in business requirements to a certain extent, resulting in inaccurate or unexpected generated code, usually requiring manual modification, thus affecting development efficiency and code quality.
[0004] Therefore, this application proposes a code modification method that can handle business requirements to further improve development efficiency and code quality. Summary of the Invention
[0005] The embodiments of this application provide a code modification method, system, device, and medium based on the CURD scenario, which can handle code modification of business requirements and further improve development efficiency and code quality.
[0006] In a first aspect, the embodiments of this application provide a code modification method based on the CURD scenario, including:
[0007] Obtain the business requirements for code modification, and based on the business requirements, obtain the data model required for code modification;
[0008] Based on the data model, obtain the code files related to the CURD scenario during code modification;
[0009] Analyze the call relationships between the functions related to the CURD scenario in the code files and construct a function call graph;
[0010] Generate business code snippets based on the business requirements and the data model, and merge and modify the business code snippets into the code file.
[0011] Further, obtaining the business requirements for code modification and obtaining the data model for code modification according to the business requirements includes:
[0012] Perform word segmentation on the business requirements according to a pre-constructed word segmentation dictionary to obtain a first vocabulary set;
[0013] Use natural language processing technology to perform part-of-speech tagging on the first vocabulary set to obtain a second vocabulary set;
[0014] Use entity naming technology to obtain the named entities of the second vocabulary set and generate a named entity list;
[0015] Based on a pre-trained attribute extraction model, analyze the attribute relationships between the named entities in the named entity list to generate an entity attribute relationship table;
[0016] Map the entity attribute relationship table to the business domain knowledge graph to obtain the conceptual relationships of the entity attributes in the business domain knowledge graph;
[0017] Based on the conceptual relationships, construct an attribute information table and generate a data model information list.
[0018] Further, after obtaining the data model required for code modification, it further includes:
[0019] Obtain the metadata information of the data model and construct a data model dependency graph between multiple data models. The metadata information includes table structure, field attributes, and primary and foreign key relationships;
[0020] Use a rule-based information extraction algorithm to obtain the structured information in the business requirements. The structured information includes business conditions and business information.
[0021] Further, the CURD scenario is a scenario in which operations such as creating, reading, updating, or deleting data are performed in the business requirements;
[0022] Obtaining the code file related to the CURD scenario when modifying the code based on the data model includes:
[0023] Obtain a list of target files related to the data model from the CURD code directory structure;
[0024] Determine whether each target file in the target file list contains at least one operation type in the CURD scenario, and generate a code file list, where the code file list includes front-end code files and back-end code files.
[0025] Further, analyze the call relationships between the functions related to the CURD scenario in the code files, and construct a function call graph, including:
[0026] Traverse each code line in the code files, extract the interface information of each function method in each code file, and generate an interface definition file, where the interface information includes the function name, the file where the function is located, and the interface call information;
[0027] Through static analysis methods, analyze the call relationships between function methods, obtain a list of function information for any function calling other functions, and construct a function call graph.
[0028] Further, after constructing the function call graph, it also includes:
[0029] Traverse each function, obtain the code segments in the function that involve the CURD scenario, and extract the data models in the code segments;
[0030] Establish a mapping relationship between the function and the data model;
[0031] Based on the function call graph and the mapping relationship, establish a data call dynamic resource library, where the data call dynamic resource library includes dynamic information data generated when different data models are called.
[0032] Further, generate business code segments based on the business requirements and the data model, and merge and modify the business code segments into the code files, including:
[0033] Based on the data model and the function call graph, use rule-based code generation technology to generate code frameworks related to the business requirements in each code file, where the code frameworks include code structures and interface calls;
[0034] In the code framework, generate new function code segments according to the structured information in the business requirements;
[0035] Based on the code framework and the new function code segments, generate business code segments;
[0036] Encapsulate the business code segments into patch files, and modify the code files by calling the patch files.
[0037] Second aspect, an embodiment of the present application provides a code modification system based on CURD scenarios, including:
[0038] The first processing module: used to obtain the business requirements for code modification, and according to the business requirements, obtain the data model required for code modification;
[0039] The second processing module: used to obtain the code files related to the CURD scenario when modifying the code based on the data model;
[0040] The third processing module: used to analyze the call relationship between the functions related to the CURD scenario in the code file and construct a function call graph;
[0041] The fourth processing module: used to generate business code snippets based on the business requirements and the data model, and merge and modify the business code snippets into the code file.
[0042] Third aspect, an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the above-mentioned code modification method based on CURD scenarios.
[0043] Fourth aspect, an embodiment of the present application provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements the above-mentioned code modification method based on CURD scenarios.
[0044] The beneficial effects of the embodiments of the present application compared with the prior art are:
[0045] A code modification method based on CURD scenarios of the present application ensures the close connection between code modification and business requirements by obtaining the business requirements for code modification. At the same time, according to the data model obtained from the business requirements, it can accurately locate the code files that need to be modified, improving the efficiency of code modification. In addition, by identifying the code files related to the CURD scenario, this solution can focus on the core part of the business logic, avoiding the interference of irrelevant code, making the code clearer and easier to understand. In addition, the business code snippets generated based on the business requirements and the data model have high reusability, improving the development efficiency and quality of the code. Description of the Drawings
[0046] To more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0047] Figure 1 is a schematic flowchart of a code modification method based on the CURD scenario provided by an embodiment of the present invention;
[0048] Figure 2 is a schematic structural diagram of a code modification system based on the CURD scenario provided by an embodiment of the present invention;
[0049] Figure 3 is a schematic structural diagram of a computer device provided by an embodiment of the present invention. Detailed implementation manners
[0050] In the following description, specific details such as specific system structures and technologies are presented for the purpose of illustration rather than limitation, so as to thoroughly understand the embodiments of the present application. However, those skilled in the art should clearly understand that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from interfering with the description of the present application.
[0051] It should be understood that when used in the specification and claims of the present application, the term "comprising" indicates the presence of the described features, wholes, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.
[0052] It should also be understood that the term "and / or" used in the specification and claims of the present application refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0053] As used in the specification and claims of the present application, the term "if" can be interpreted as "when...", "once", "in response to determining", or "in response to detecting" according to the context. Similarly, the phrase "if determined" or "if [the described condition or event] is detected" can be interpreted as meaning "once determined", "in response to determining", "once [the described condition or event] is detected", or "in response to detecting [the described condition or event]" according to the context.
[0054] In addition, in the description of the specification and the appended claims of the present application, the terms "first", "second", "third", etc. are only used for distinguishing descriptions and cannot be construed as indicating or implying relative importance.
[0055] The reference to "one embodiment" or "some embodiments" etc. described in the specification of the present application means that a specific feature, structure, or characteristic described in connection with that embodiment is included in one or more embodiments of the present application. Thus, statements such as "in one embodiment", "in some embodiments", "in other some embodiments", "in still other embodiments", etc. that appear in different places in this specification do not necessarily all refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "comprise", "include", "have" and their variants all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0056] Please refer to Figure 1 As shown, the present invention is a code modification method based on CURD scenarios, including the following steps:
[0057] S100. Obtain the business requirements for code modification, and based on the business requirements, obtain the data model required for code modification;
[0058] In some of the embodiments, the above step S100 includes:
[0059] Perform word segmentation processing on the business requirements according to a pre-constructed word segmentation dictionary to obtain a first vocabulary set;
[0060] Use natural language processing technology to perform part-of-speech tagging processing on the first vocabulary set to obtain a second vocabulary set;
[0061] Use entity naming technology to obtain the named entities of the second vocabulary set and generate a named entity list;
[0062] Based on a pre-trained attribute extraction model, analyze the attribute relationships between the named entities in the named entity list to generate an entity attribute relationship table;
[0063] Map the entity attribute relationship table to a business domain knowledge graph to obtain the conceptual relationship of the entity attribute relationship in the business domain knowledge graph;
[0064] Based on the conceptual relationship, construct an attribute information table and generate a data model information list.
[0065] In this embodiment, by setting up a requirement modification module, the user inputs requirement description text in the requirement modification module as business requirements, extracts information from the business requirements as original data, and performs word segmentation processing on the original data according to a pre-constructed word segmentation dictionary to obtain a first vocabulary set. Among them, the word segmentation dictionary can include common words and professional terms in the business field, etc., to ensure the accuracy and integrity of word segmentation. For the first vocabulary set, part-of-speech tagging processing is performed using natural language processing technology to obtain a second vocabulary set with part-of-speech tag information. Among them, part-of-speech tagging can assign a part-of-speech tag to each word, such as noun, verb, adjective, etc., which helps subsequent entity recognition and attribute extraction. Then, entity recognition technology is used to extract named entities in the second vocabulary set, such as person names, place names, organization names, etc., to determine a named entity list.
[0066] In this embodiment, according to the named entity list, based on a pre-trained attribute extraction model, the attribute relationships between entities are analyzed, such as the "purchase" relationship between "user" and "order", etc., to obtain an entity attribute relationship data table. The entity attribute relationship data table is mapped to a pre-constructed business domain knowledge graph to obtain the conceptual relationships of entity attribute relationships in the business domain knowledge graph. It can be understood that in the business domain knowledge graph, there are connections or associations formed between different entities in different business domains based on certain attributes or features. Therefore, by mapping the entity attribute relationship data table to the business domain knowledge graph, the internal connections and logical structures between entities in the corresponding business domain can be reflected.
[0067] In one embodiment, the user inputs the business requirement "When adding a new course, if the teacher is male and the number of courses taught by the teacher (including the new course) is greater than 5, give an error prompt; if the teacher is female and the number of courses taught by the teacher (including the new course) is greater than 4, give an error prompt" through the requirement modification module. The business requirement is subjected to word segmentation processing according to a pre-constructed word segmentation dictionary to obtain a first vocabulary set, such as {when, add, course, if, is, male teacher, correspond to, the, teacher, of, taught, course number, include, new course, greater than, 5, give, error prompt, female teacher, 4}. It can be understood that the word segmentation results vary due to different word segmentation dictionaries and algorithms.
[0068] Using natural language processing technology, perform part-of-speech tagging on the above first vocabulary set to obtain a second vocabulary set, namely {when / p(preposition), new / v(verb), course / n(noun), when / n(adverbial component), if / c(conjunction), for / v(verb), male teacher / n(noun), corresponding / v(verb), the / r(pronoun), teacher / n(noun), of / u(auxiliary word), teaching / v(verb), course number / n(noun), including / v(verb), new / v(verb), course / n(noun), greater than / v(verb), 5 / m(numeral), give / v(verb), error prompt / n(noun), female teacher / n(noun), 4 / m(numeral)}.
[0069] Using entity naming technology, obtain the named entities of the above second vocabulary set, generate a named entity list. In this embodiment, the named entity list: [male teacher, female teacher, course number]. Analyze the attribute relationships between the named entities in the named entity list, generate an entity attribute relationship table. For example, in this embodiment, the relationship between male teachers or female teachers and the number of teaching courses. For courses, obtain their relationship with the thresholds 4 or 5 in the above business requirements. For the "male teacher", "female teacher", and "course number" in the named entity list, map them to the knowledge graph in the education field. For example, map male teachers and female teachers to the teacher node, and map the course number to the course quantity node. Among them, "male teacher" and "female teacher" are entity nodes, "course number" is an attribute node, and the relationship between the entity node and the attribute node is an attribute relationship. Based on this, generate the following attribute information table:
[0070]
[0071] Through the above attribute information table, obtain the following data model information list:
[0072]
[0073]
[0074] Based on the above data model information list, the main data models involved in the above business requirements are obtained, including Teacher and Course. In some embodiments, an optional business prompt (Message) data model can be generated according to needs in the data model information list to provide business prompts for the business requirements and offer standardized prompt information for subsequent design and development of the business requirements, ensuring that the system can perform correct logical processing and error prompts according to the business requirements. It can be understood that the above data model information list details the main attributes and fields of each data model, including the ID for unique identification, basic information (such as name, gender, course name, etc.), association information (such as teacher ID associated with the course, course ID associated with the teacher), and calculation fields (such as the total number of taught courses), etc., to ensure that all scenarios and situations in the business requirements can be comprehensively covered.
[0075] In some of these embodiments, after obtaining the data model required for code modification, it further includes:
[0076] Obtain the metadata table information and construct a relationship dependency graph of the metadata table information, where the metadata table information includes metadata tables and table structure information;
[0077] Adopt a rule-based information extraction algorithm to obtain the structured information in the business requirements, where the structured information includes business conditions and business information.
[0078] In this embodiment, the metadata table information is the information of each metadata table extracted from the database, specifically including metadata tables and the table structure information corresponding to each metadata table. Among them, the table structure information includes table name, main fields, field attributes, data types, and primary and foreign key relationships, etc.
[0079] In this embodiment, a table structure of each metadata table is constructed based on the metadata table information. Specifically, the field attribute information of each main field in the metadata table is obtained, such as whether null values are allowed, default values, constraints, etc., and the attribute values and field attribute information of each field are mapped to the above table structure to ensure that each field has a corresponding attribute representation in the table structure. At the same time, in the table structure, according to the field attributes (such as primary key constraints), it is determined which field is the primary key, and according to foreign key constraints, which fields are foreign keys, thereby establishing the association relationship between each metadata table. Specifically, if there are foreign key constraints, the relationship type and dependency strength between each metadata table are directly determined according to the foreign keys. For the relationship type, it includes one-to-one, one-to-many, and many-to-many. For the dependency strength, it usually includes strong association and weak association. Specifically, for a strong association, when two metadata tables are associated through foreign key constraints, it usually represents a relatively strong dependency relationship. When two metadata tables are associated through non-primary key fields or through a certain business logic connection, such as having similar semantic tags or field data types between two metadata tables, and the relationship is usually determined by similarity, it is considered that there is a weak relationship type between the two metadata tables, that is, a weak association.
[0080] In this embodiment, a graph algorithm is used to label the relationship type and dependency strength information in the graph to generate a relationship dependency graph between multiple metadata tables. According to the data models involved in the business requirements, the association relationship between each data model and other data models in the business requirements is determined, thereby ensuring the integrity and consistency of the data between each data model.
[0081] In this embodiment, natural language processing technology is used to perform semantic analysis on the business requirements to obtain the semantic representation of the business requirements. Taking the above example of "when adding a new course, if it is a male teacher, the number of teaching courses corresponding to this teacher (including the new course) is greater than 5, an error message is given; if it is a female teacher, the number of teaching courses corresponding to this teacher (including the new course) is greater than 4, an error message is given", the business logic of "when adding a new course, an error message is given according to the teacher's gender and the number of teaching courses (including the new course)" in the business requirements is extracted, which is the semantic representation of this business requirement. A rule-based information extraction algorithm is used to extract the structured information related to the data model from the business requirements, such as business conditions and business information, etc. The business information in the above embodiment is "teacher gender", "number of teaching courses (including the new course)", and "error message condition", where the error message condition is the business condition, specifically "the number of teaching courses of male teachers is greater than 5" and "the number of teaching courses of female teachers is greater than 4".
[0082] In some embodiments, it is also necessary to check the rationality and integrity of the structured information to determine whether there is ambiguous or incomplete information. If so, a list of clarification questions is generated, and an inquiry message is sent to the user to obtain the user's feedback on the clarification questions. Then, further semantic analysis is performed to extract key information and update the business requirements to generate structured information.
[0083] S200. Based on the data model, obtain the code files related to the CURD scenario when modifying the code;
[0084] In some of these embodiments, the CURD scenario is a scenario in which data is created, read, updated, or deleted in business requirements;
[0085] In the actual business development process, the CURD scenario is universal. Whether it is processing user information, commodity information, or any other data, CURD operations are almost always involved. Among them, CURD represents four basic data operations: Create, Read, Update, and Delete. Correspondingly, the CURD scenario is a scenario in which data is created, read, updated, or deleted in business requirements. Therefore, in this embodiment, when modifying the code file according to business requirements, the corresponding code directory structure of the data model is obtained through the CURD scenario, and then the code position to be modified can be quickly located, thereby improving the development efficiency and reducing errors caused by unclear code positions.
[0086] It can be understood that in software development, the code directory structure for implementing CURD operations may vary according to different programming languages and frameworks. During the development process, developers can pre-agree on the code directory structure corresponding to the CURD scenario by selecting the corresponding programming language, thereby standardizing the code directory structure. With a standardized CURD code directory structure, it is helpful for team members to maintain consistent development habits, improve the readability and maintainability of the code, and facilitate quickly locating the code position to be modified later.
[0087] Among them, the above step S200 includes:
[0088] Obtain a list of target files related to the data model from the code directory structure of the CURD scenario;
[0089] Judge whether each target file in the list of target files contains at least one operation type in the CURD scenario, and generate a list of code files, where the list of code files includes front-end code files and back-end code files.
[0090] In this embodiment, the CURD code directory structure in the parsing business scenario is analyzed to clarify the functions of each file and directory, and the files and directories closely related to the data model of the business requirements are identified. Specifically, according to the name of the data model, file naming convention or specific marker, the target file list related to it is filtered out from the directory. The above target file list usually includes backend logic files and frontend interaction files. Among them, the backend logic includes controller, service layer and data access layer files, and the frontend interaction includes view templates and API call files. Each target file in the above target file list is carefully analyzed to find out whether it contains the code implementation of CURD operations. Usually, regular expressions, code parsing libraries or custom rules are used for identification. Then, according to the identification results, the files containing CURD operations are classified into the frontend code file list and the backend code file list respectively. The frontend file list usually includes HTML, CSS and JavaScript, etc., which are used for user interaction and page rendering; while the backend file list usually includes logic processing files written in languages such as Python, Java and Go, which are determined according to the programming language selected by the developer.
[0091] Taking the Teacher data model in the above embodiment as an example, traverse the CURD code directory, read the file and subdirectory information, identify the files related to the Teacher model according to the file naming, and at the same time search for the controller, service layer and data access layer files containing the word "Teacher" in the backend directory, and search for the view templates and API call files related to Teacher in the frontend directory. Record the file paths and names of the filtered files, such as filtering out files like TeacherController.go, TeacherService.go or TeacherView.html. Analyze each filtered file, use a code parsing library (such as an AST parser) or regular expressions to match the keywords of CURD operations, and record the types of CURD operations included in each file. For example, identify methods such as create_teacher, get_teacher, update_teacher, delete_teacher in TeacherController.go, and classify the code files of the identified CURD operation types into the frontend code file and backend code file lists according to the functional types.
[0092] In some embodiments, the frontend code file list and the backend code file list can be further refined and classified. For example, the backend code file list is divided into a controller, a service layer and a data access layer, while the frontend code file list is divided into view templates and API call files.
[0093] S300. Analyze the call relationships between the functions related to the CURD scenario in the code file, and construct a function call graph;
[0094] In some embodiments, the above step S300 includes:
[0095] Traverse each line of code in the code file, extract the interface information of each function method in each code file, and generate an interface definition file. The interface information includes the function name, the file where the function is located, and the interface call information;
[0096] Through static analysis methods, analyze the call relationships between function methods, obtain a list of function information for any function calling other functions, and construct a function call graph.
[0097] In this embodiment, a static analysis tool such as cflow, codeviz, doxygen, etc. is used to parse the code in each code file and generate function call relationship information. Specifically, the above static analysis tool is used to traverse each line of code in the code file, extract the interface information of each function. Among them, the interface information includes the function name, the file where the function is located, and the interface call information. The file where the function is located is used to label the corresponding function for easy quick search of the function. Then, analyze the call relationships of each function calling other functions. The call relationships include function call chains, call frequencies, and call orders, etc. Organize the analyzed function call relationship information into a list form, including the calling function name, the called function name, and the call location, etc. According to the above function information list, construct a function call graph of the mutual call relationships between functions. Through this function call graph, the call relationships and hierarchical structures between functions can be clearly displayed.
[0098] In some embodiments, after constructing the function call graph, it further includes:
[0099] Traverse each function, obtain the code segments related to the CURD scenario in the function, and extract the data models in the code segments;
[0100] Establish a mapping relationship between the function and the data model;
[0101] Based on the function call graph and the mapping relationship, establish a data call dynamic resource library. The data call dynamic resource library includes dynamic information data generated when different data models are called.
[0102] In this embodiment, traverse the code segments related to the CURD scenario inside each function, record the corresponding information of the database access functions and SQL statements used therein, extract the SQL operation table names in the functions, and establish a mapping relationship between the SQL operation table names and the data models.
[0103] In this embodiment, a dynamic data call resource library is established. Specifically, during the operation of the business scenario, dynamic information data related to the SQL operation table name generated by it is recorded, and then the above-mentioned dynamic data call resource library is generated. According to the mapping relationship between the SQL operation table name and the data model, the dynamic information data corresponding to the data model can be obtained. The above-mentioned dynamic information data includes table name, CURD scenario, operation time, operation result, etc.
[0104] It can be understood that through the above-mentioned dynamic data call resource library, when the business scenario needs to call data, it can quickly locate the corresponding data model and data source through the SQL operation table name, thereby improving the efficiency of data call. At the same time, it can reduce the error rate caused by manually searching and matching data models, improve the accuracy of data call, and significantly enhance the data processing ability of the business scenario, optimize the mapping relationship between the data model and SQL operation, improve the efficiency and accuracy of data call, and support data analysis and decision-making.
[0105] S400. Generate business code snippets based on the business requirements and the data model, and merge and modify the business code snippets into the code file.
[0106] In some of these embodiments, the above step S400 includes:
[0107] Based on the data model and the function call graph, use rule-based code generation technology to generate a code framework related to the business requirements in each code file. The code framework includes a code structure and interface calls;
[0108] In the code framework, generate new function code snippets according to the structured information in the business requirements;
[0109] Generate business code snippets based on the code framework and the new function code snippets;
[0110] Package the business code snippets into a patch file, and modify the code file by calling the patch file.
[0111] Taking the above "when adding a new course, if it is a male teacher and the number of teaching courses corresponding to the teacher (including the new course) is greater than 5, give an error prompt; if it is a female teacher and the number of teaching courses corresponding to the teacher (including the new course) is greater than 4, give an error prompt" as an example, through the data model and function call relationship, key functions related to the business requirements are determined, such as obtaining teacher information, obtaining the number of teaching courses of the teacher, and adding a new course, etc. At the same time, the function call relationship between the above key functions is obtained, such as when adding a new course, it is necessary to first call the function of obtaining the number of teaching courses of the teacher, and then judge whether to give an error prompt according to gender and the number of courses.
[0112] In this embodiment, the code framework is designed to design the code structure, which usually includes a business logic layer, a data access layer, etc., and interface calls are defined in the business logic layer, such as the AddCourseInterface for adding courses. Based on this, a code framework including the code structure and interface calls is generated. In some of these embodiments, the code framework should also include necessary comments and documentation to facilitate subsequent development and maintenance.
[0113] In this embodiment, using the structured information in the business requirements obtained in the above steps, a code generator is employed to automatically generate corresponding new function code snippets according to the business logic contained in the structured information, the interface call relationships of the key functions in the code framework, and the data model information list of the data model, and insert the new function code snippets at the corresponding positions in the code framework, thereby generating business code snippets. It can be understood that the new function code snippets contain the corresponding gender judgment logic, the calculation logic of the number of teaching courses, and the error prompt generation logic.
[0114] In this embodiment, the above business code snippets are encapsulated into a patch file. During the application process, the developer selects the corresponding patch file and adds the above business code snippets to the corresponding code file, thereby realizing the modification of the code file. Specifically, encapsulating the business code snippets into a patch file makes code management more modular. For different business requirements, the developer can create independent patch files for specific functions based on the above steps, which is convenient for subsequent maintenance and reuse. In some of these embodiments, for each generated patch file, the corresponding business requirements, modification content, and version number are recorded, making the version management of the code clearer. The developer can easily track the change history of each code snippet, which is convenient for subsequent debugging and repair. When a problem occurs in the business system, the developer can quickly locate the code snippet that may cause the problem by viewing the applied patch files, which helps to accelerate the problem-solving process and improve the stability and reliability of the business system.
[0115] In some embodiments, the abstract syntax tree analysis technique is adopted to parse the syntax structure of the new function code snippet, judge the syntax correctness of the new function code snippet according to the preset syntax rule library, and automatically correct the identified syntax errors. In addition, the symbolic execution technique is adopted to generate test cases for the new function code. Through unit testing, the branch coverage rate and statement coverage rate of the code are verified to ensure the correctness of the basic functions. At the same time, after integrating the new function code snippet that passes the unit test into the code file, the incremental integration test method is adopted to test the interaction and connection between the new function code snippet and the original code snippet in the code file, and verify the overall function after system integration. For the system that passes the test, a static code analysis tool is used to check the code quality, including indicators such as code complexity and code duplication rate, optimize and refactor the code quality problems, and improve the maintainability of the code.
[0116] Please refer to Figure 2 As shown in the figure, the present invention also provides a code modification system based on the CURD scenario, and the system includes:
[0117] The first processing module 201: is used to obtain the business requirements for code modification, and obtain the data model required for code modification according to the business requirements;
[0118] The second processing module 202: is used to obtain the code files related to the CURD scenario during code modification based on the data model;
[0119] The third processing module 203: is used to analyze the call relationship between the functions related to the CURD scenario in the code file and construct a function call graph;
[0120] The fourth processing module 204: is used to generate business code snippets based on the business requirements and the data model, and merge and modify the business code snippets into the code file.
[0121] It can be understood that the content in the embodiments of the code modification method based on the CURD scenario as Figure 1 shown is applicable to the embodiments of the code modification system based on the CURD scenario of the present invention. The functions specifically implemented in the embodiments of the code modification system based on the CURD scenario of the present invention are the same as those in the embodiments of the code modification method based on the CURD scenario as Figure 1 shown, and the beneficial effects achieved are also the same as those achieved in the embodiments of the code modification method based on the CURD scenario as Figure 1 shown.
[0122] It should be noted that the information interaction, execution process, etc. between the above systems, due to the same concept as the embodiments of the method of the present invention, for their specific functions and the technical effects brought, please refer to the method embodiment part for details, and will not be elaborated here.
[0123] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above division of each functional unit and module is used as an example. In actual applications, the above functions can be allocated to different functional units and modules according to needs, that is, the internal structure of the system can be divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment can be integrated into a processing unit, or each unit can exist physically alone, 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 a software functional unit. In addition, the specific names of each functional unit and module are only for the convenience of mutual distinction and do not limit the protection scope of this application. The specific working process of the units and modules in the above system can refer to the corresponding process in the foregoing method embodiment and will not be elaborated herein.
[0124] Please refer to Figure 3 As shown, an embodiment of the present invention further provides a computer device 3, including: a memory 302, a processor 301, and a computer program 303 stored on the memory 302. When the computer program 303 is executed on the processor 301, it implements the CURD scenario-based code modification method described in any one of the above methods.
[0125] The computer device 3 can be a computing device such as a desktop computer, a notebook, a palm computer, and a cloud server. The computer device 3 may include, but is not limited to, a processor 301 and a memory 302. Those skilled in the art can understand that Figure 3 merely an example of the computer device 3, which does not constitute a limitation on the computer device 3, and may include more or fewer components than shown in the figure, or combine some components, or different components. For example, it may also include input and output devices, network access devices, etc.
[0126] The so-called processor 301 may be a central processing unit (CPU), and the processor 301 may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0127] In some embodiments, the memory 302 may be an internal storage unit of the computer device 3, such as a hard disk or memory of the computer device 3. In other embodiments, the memory 302 may also be an external storage device of the computer device 3, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc., equipped on the computer device 3. Further, the memory 302 may also include both the internal storage unit and the external storage device of the computer device 3. The memory 302 is used to store an operating system, application programs, a BootLoader, data, and other programs, such as the program code of the computer program. The memory 302 may also be used to temporarily store data that has been output or is to be output.
[0128] An embodiment of the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is run by a processor, it implements the method for modifying code based on a CURD scenario as described in any one of the above methods.
[0129] In this embodiment, if the integrated unit 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, to implement all or part of the processes in the above embodiment methods of the present application, a computer program can be used to instruct relevant hardware to complete. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, it can implement the steps of the above various method embodiments. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, an executable file, or some intermediate form, etc. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the photographing device / computer device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk, or an optical disc, etc. In some jurisdictions, according to legislation and patent practice, the computer-readable medium may not be an electrical carrier signal and a telecommunication signal.
[0130] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A code modification method based on CURD scenarios, characterized in that, Including: Obtain the business requirements for code modification, and according to the business requirements, obtain the data model required for code modification; Based on the data model, obtain the code files related to the CURD scenario during code modification; Analyze the call relationships between the functions related to the CURD scenario in the code files, and construct a function call graph; Based on the business requirements and the data model, generate business code snippets, and merge and modify the business code snippets into the code files.
2. The method according to claim 1, wherein The obtaining of the business requirements for code modification, and according to the business requirements, obtaining the data model for code modification includes: Perform word segmentation processing on the business requirements according to a pre-constructed word segmentation dictionary to obtain a first vocabulary set; Use natural language processing technology to perform part-of-speech tagging processing on the first vocabulary set to obtain a second vocabulary set; Use entity naming technology to obtain the named entities of the second vocabulary set and generate a named entity list; Based on a pre-trained attribute extraction model, analyze the attribute relationships between the named entities in the named entity list and generate an entity attribute relationship table; Map the entity attribute relationship table to a business domain knowledge graph to obtain the conceptual relationship of the entity attribute relationship in the business domain knowledge graph; Based on the conceptual relationship, construct an attribute information table and generate a data model information list.
3. The method according to claim 2, wherein After obtaining the data model required for code modification, it further includes: Obtain the metadata information of the data model, and construct a data model dependency graph between multiple data models. The metadata information includes table structure, field attributes, and primary and foreign key relationships; Use a rule-based information extraction algorithm to obtain the structured information in the business requirements. The structured information includes business conditions and business information.
4. The method according to claim 1, wherein The CURD scenario is a scenario in business requirements for creating, reading, updating, or deleting data; The obtaining, based on the data model, of the code files related to the CURD scenario during code modification includes: Obtain a list of target files related to the data model from the CURD code directory structure; Judge whether each target file in the target file list contains at least one operation type in the CURD scenario, and generate a code file list. The code file list includes front-end code files and back-end code files.
5. The method according to claim 1, wherein The analyzing of the call relationships between the functions related to the CURD scenario in the code files and constructing a function call graph includes: Traverse each code line in the code files, extract the interface information of each function method in each code file, and generate an interface definition file. The interface information includes function name, file where the function is located, and interface call information; Through static analysis methods, analyze the call relationships between function methods, obtain a list of function information for any function calling other functions, and construct a function call graph.
6. The method according to claim 5, wherein After constructing the function call graph, it further includes: Traverse each function, obtain the code snippets in the function related to the CURD scenario, and extract the data models in the code snippets; Establish a mapping relationship between the function and the data model; Based on the function call graph and the mapping relationship, a dynamic data call repository is established, and the dynamic data call repository includes dynamic information data generated when different data models are called.
7. The method according to claim 1, characterized in that The generating business code snippets based on the business requirements and the data model and merging and modifying the business code snippets into the code file includes: Based on the data model and the function call graph, using rule-based code generation technology, generating a code framework related to the business requirements in each code file, where the code framework includes a code structure and interface calls; In the code framework, generating new function code snippets according to the structured information in the business requirements; Based on the code framework and the new function code snippets, generating business code snippets; Encapsulating the business code snippets into a patch file and modifying the code file by calling the patch file.
8. A code modification system based on CURD scenarios, characterized in that Including: The first processing module: used to obtain the business requirements for code modification and obtain the data model required for code modification according to the business requirements; The second processing module: used to obtain the code file related to the CURD scenario during code modification based on the data model; The third processing module: used to analyze the call relationship between the functions related to the CURD scenario in the code file and construct a function call graph; The fourth processing module: used to generate business code snippets based on the business requirements and the data model and merge and modify the business code snippets into the code file.
9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, the method described in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, the method described in any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Game function development system and method based on natural language instruction
CN120560648A
Game function development system and method based on natural language instructions
CN120560648B
Enterprise number asking system and method based on combination of large language model and NL2SQL
CN121166718A