Software architecture code generation method and system based on large language model

By introducing natural language processing technology and clustering algorithms of large language models in software development, the problem of difficulty in accurately identifying complex semantics in the existing technology is solved, and more efficient software architecture code generation and optimization are achieved.

CN119597267APending Publication Date: 2025-03-11未分类(SHANGHAI) TECHNOLOGY CO LTD

Patent Information

Application Number
CN202411658389.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-20
Publication Date
2025-03-11

AI Technical Summary

Technical Problem

Existing automation requirements analysis methods are difficult to accurately identify complex semantics, especially when dealing with long sentences, polysemes and domain-specific terms, which leads to unclear division of functional modules, which increases the difficulty of software development.

Method used

Natural language processing technology based on large language models is adopted to analyze the demand information through adaptive semantic segmentation model and long-term short-term memory network, extract functional elements, and generate software architecture code through clustering algorithms and architectural hierarchical matching models.

Benefits of technology

Improves the accuracy of functional factor extraction, reduces manual intervention in the architecture design process, shortens development time, and ensures the correctness and maintainability of generated code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119597267A_ABST
    Figure CN119597267A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computer processing, in particular to a software architecture code generation method and system based on a large language model, and provides the following scheme: obtaining demand information input by a user, analyzing demands by using a natural language processing technology, and extracting functional elements; performing classification processing on the functional elements through a clustering algorithm to generate a functional module group; mapping the function module group to a system architecture layer, and generating an architecture diagram represented by UML (Unified Modeling Language); and generating a corresponding source code according to the UML graph, and optimizing the source code. The optimization strategy comprises static analysis of format problems and potential vulnerabilities in identification codes and performance optimization of complex functions. Through combination of the large language model and the automatic code generation and optimization technology, the software development efficiency is improved, manual intervention is reduced, and the correctness and maintainability of the generated code are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer processing technology, and in particular to a software architecture code generation method and system based on a large language model. Background Art

[0002] In the traditional software development process, the design of software architecture and the generation of code usually need to be manually written, which is time-consuming and prone to errors. Developers usually use the Unified Modeling Language (UML) to represent the architecture of the system, which is divided into multiple functional modules, but there is a large generation gap when converting these architectures into actual code. Especially in complex systems, the dependencies and functional aggregation between different modules need to be manually adjusted and coordinated, which greatly increases the difficulty of development.

[0003] In recent years, with the development of natural language processing technology (NLP) and machine learning models (such as large language models), automated software generation and optimization technology has received widespread attention. By analyzing user demand information through NLP technology, combined with clustering algorithms and model-driven development (MDD) technology, manual participation in software development can be greatly reduced and development efficiency can be improved. At the same time, the demand for code optimization is also growing. Automated code optimization tools can analyze the complexity of the code and propose performance improvement solutions.

[0004] For example, a Chinese patent with publication number CN116931916A discloses an application layer software development method, device, computer equipment and storage medium. The invention obtains the software architecture of the target application layer software, and the software architecture includes at least one software component; obtains the path of the software component; under the path of the software component, calls the target interface function to configure the software component to obtain the target software component; compiles all target software components in the software architecture to generate corresponding code and interface files; based on the code and interface files of the target software component, generates the target application layer software. The invention can solve the problem of manual adjustment of the configuration information of the application layer software component, which takes a long time for software development and has low development efficiency.

[0005] The above patents all have the problems raised by this background technology: most of the existing automated demand analysis methods are based on rules or simple natural language processing technology, which makes it difficult to accurately identify complex semantics, especially when it comes to long sentences, polysemous words and domain-specific terms. The accuracy is low, resulting in unclear division of subsequent functional modules. To solve the above problems, this application designs a software architecture code generation method and system based on a large language model. Summary of the invention

[0006] The technical problem to be solved by the present invention is to address the deficiencies of the prior art and provide a method and system for generating software architecture code based on a large language model, obtain the demand information input by the user, parse the demand information using natural language processing (NLP) technology, and extract functional elements; classify the functional elements through a clustering algorithm to generate a functional module group; map the functional module group to the system architecture layer to generate an architecture diagram represented by UML, including a class diagram, a component diagram, and a sequence diagram; generate the corresponding source code according to the UML diagram, and optimize the source code. The optimization strategy includes static analysis to identify format problems and potential vulnerabilities in the code, as well as performance optimization of complex functions. The present invention combines a large language model with automated code generation and optimization technology to improve software development efficiency, reduce manual intervention, and ensure the correctness and maintainability of the generated code.

[0007] To achieve the above object, the present invention provides the following technical solutions:

[0008] A method for generating software architecture code based on a large language model, the method comprising:

[0009] Receive demand information input by the user, analyze the demand information through NLP technology, and extract functional elements;

[0010] Classify the functional elements according to a clustering algorithm to generate a functional module group;

[0011] Mapping the functional module group to a corresponding system architecture layer, and generating an architecture diagram represented by UML through the system architecture layer;

[0012] According to the architecture diagram, corresponding source code is generated, and the source code is optimized according to a set optimization strategy.

[0013] The analyzing the demand information by using NLP technology includes:

[0014] Segment the demand information according to the adaptive semantic segmentation model, perform part-of-speech tagging on the segmentation results through the syntax tree generation algorithm, obtain candidate word sequences, and vectorize the candidate word sequences through the word embedding model;

[0015] The subject-verb-object core structure and modifying components in the candidate word sequence are identified through a tree structure based on dependency relationships, and the demand information is divided into a multi-layer semantic structure.

[0016] The multi-layer semantic structure is temporally modeled according to the long short-term memory network, the front-end dependency relationship between the models is analyzed, the relevance matrix is ​​calculated according to the front-end dependency relationship, the relevance matrix is ​​feature extracted through convolution operation, and the functional elements are output.

[0017] The adaptive semantic segmentation model comprises:

[0018] Encode the input demand information through a bidirectional long short-term memory network to obtain the semantic features of the input vocabulary in the context;

[0019] Calculating the structural complexity of the semantic feature, calculating a word segmentation window according to the structural complexity, and performing word segmentation processing on the demand information according to the word segmentation window;

[0020] During the word segmentation process, the word segmentation results are corrected through the conditional random field model.

[0021] The classifying process of the functional elements according to the clustering algorithm includes:

[0022] Obtain a requirement description template, perform preliminary clustering on the requirement description template according to a DBSCAN clustering algorithm, obtain core points, and determine the number of cluster center clusters according to the number of core points;

[0023] The core points after DBSCAN clustering are used as the initial center clusters of the K-means clustering algorithm, and the Euclidean distances from the functional elements to each of the initial center clusters are calculated;

[0024] Perform clustering according to the Euclidean distance, calculate the average clustering error of the initial central cluster, and update the central cluster according to the average clustering error;

[0025] A convergence condition is defined, and it is determined whether the central cluster after the update satisfies the convergence condition. If the convergence condition is not satisfied, the central cluster is continuously updated. If the convergence condition is satisfied, the functional module group is output.

[0026] Mapping the functional module group to the corresponding system architecture layer includes:

[0027] Based on the graph structure analysis algorithm, the dependency relationship of each functional module group is analyzed, and the dependency graph of the functional module group is constructed according to the dependency relationship. The interaction relationship between each functional module group and other module groups in the system is quantified to generate an inter-module dependency matrix, wherein the dependency relationship includes the data exchange frequency, function call path and logical dependency degree between modules;

[0028] Perform statistical analysis on the function call frequency and interaction delay of each functional module group, calculate the data call weight according to the analysis result, weight the call paths between each functional module group according to the data call weight, and calculate the data flow graph;

[0029] Calculate the function score of the function module group according to the inter-module dependency matrix and the data flow diagram, and divide the modules into different function types according to the function score, wherein the function types include data processing type, business logic type and interface type;

[0030] Build an architectural hierarchy matching model to map the functional types of the functional module group with the presentation layer, business logic layer, and data layer in the system architecture.

[0031] The generating of the architecture diagram represented by UML includes:

[0032] Generate UML class diagram based on the functional definition of functional module group and object-oriented design principles;

[0033] Generate a UML component diagram based on the allocation of the functional module groups in the architecture layer, wherein the UML component diagram is used to show the physical deployment of the modules;

[0034] A UML sequence diagram is generated according to the data flow diagram, and the UML sequence diagram is used to describe the dynamic interaction process between functional modules.

[0035] The optimization strategy includes:

[0036] Performing static analysis on the source code to identify formatting issues and potential vulnerabilities in the code;

[0037] Identify data processing functions, loop functions, and recursive functions in the code, analyze the complexity of the functions, and automatically reconstruct them using dynamic programming algorithms.

[0038] A software architecture code generation system based on a large language model, the system comprising a requirement parsing module, a function clustering module, an architecture mapping module, a code generation module and a code optimization module;

[0039] The demand analysis module is configured with a natural language analysis strategy, which is used to analyze the demand information through natural language processing technology, segment the demand information according to the adaptive semantic segmentation model, and perform part-of-speech tagging and semantic structure analysis through a syntax tree generation algorithm to extract functional elements;

[0040] The function clustering module is configured with a function aggregation strategy, which is used to classify the function elements after the demand analysis, perform cluster analysis on the function elements using a clustering algorithm and generate a function module group;

[0041] The architecture mapping module is used to analyze the function type of each module group according to the dependency, data flow and calling frequency of the function module group, and map it to the corresponding level of the system architecture;

[0042] The code generation module is used to generate a corresponding UML representation architecture diagram based on the functional module group, and generate source code according to the UML representation architecture diagram;

[0043] The code optimization module is used to optimize the code according to a preset optimization strategy.

[0044] The demand parsing module includes:

[0045] A word segmentation unit, used to segment the demand information according to an adaptive semantic segmentation model, wherein the word segmentation unit dynamically adjusts the word segmentation window based on a bidirectional long short-term memory network;

[0046] A part-of-speech tagging unit is used to tag the word segmentation results with parts of speech by using a syntax tree generation algorithm. The part-of-speech tagging unit identifies the subject-verb-object core structure and the modifying components by combining dependency analysis;

[0047] The semantic structure analysis unit is used to perform multi-layer semantic structure analysis on the word segmentation and part-of-speech tagged demand information through the long short-term memory network, identify the front-to-back dependency relationship between various functional elements, and generate a multi-layer semantic structure;

[0048] A functional element extraction unit is used to extract features from the extracted multi-layer semantic structure through a convolutional neural network and output the functional elements in the requirements;

[0049] The natural language parsing strategy includes dynamic word segmentation logic, dependency annotation logic and multi-layer semantic analysis logic;

[0050] The dynamic word segmentation strategy is configured in the word segmentation unit, and is used to adjust the word segmentation window size according to the complexity of the demand information, and perform word segmentation in combination with context information;

[0051] The dependency relationship annotation logic is configured in the part-of-speech tagging unit and is used to generate a subject-verb-object dependency relationship through a syntax tree;

[0052] The multi-layer semantic analysis logic is configured in the semantic structure analysis unit, and is used to process semantic structures at different levels in combination with the temporal modeling of the long short-term memory network.

[0053] The function clustering module comprises:

[0054] A preliminary clustering unit, used to perform preliminary clustering on the functional elements after demand analysis, wherein the preliminary clustering unit identifies core points in the functional elements based on the DBSCAN clustering algorithm and determines the initial clustering center according to the number of core points;

[0055] A cluster center updating unit is used to optimize the preliminary clustering results. The cluster center updating unit calculates the Euclidean distance from each functional element to the cluster center based on the K-means clustering algorithm, updates the cluster center according to the clustering average error, and iteratively optimizes the clustering results.

[0056] A clustering convergence judgment unit, used to judge whether the clustering process has reached a stable state. The clustering convergence judgment unit monitors the change of the clustering average error according to a preset convergence condition, determines the clustering convergence when the error is less than a predetermined threshold, and outputs a final functional module group;

[0057] The function module group output unit is used to output the final function module group after clustering convergence and use it as input for subsequent system architecture mapping;

[0058] The functional aggregation strategy includes:

[0059] A preliminary clustering logic, configured in the preliminary clustering unit, for identifying and clustering core functional elements according to a density threshold and a minimum number of points in a DBSCAN algorithm to form preliminary clusters;

[0060] The cluster center update logic is configured in the cluster center update unit, and is used to update the cluster center and optimize the clustering result by calculating the Euclidean distance and clustering error based on the K-means algorithm on the basis of preliminary clustering;

[0061] The convergence judgment logic is configured in the clustering convergence judgment unit and is used to judge whether the clustering is stable according to the set convergence conditions to ensure that the output function module group has consistency and rationality.

[0062] Compared with the prior art, the present invention has the following beneficial effects:

[0063] 1. The present invention can accurately identify the natural language requirements input by users by introducing an adaptive semantic segmentation model and a long short-term memory network (LSTM). The natural language processing technology based on a large language model can automatically extract complex semantic structures, subject-verb-object relationships, and modifying components, greatly improving the accuracy of functional element extraction, especially when processing long sentences, polysemous words, or complex requirements, with higher parsing capabilities.

[0064] 2. The present invention realizes the automatic process from requirement analysis to automatic generation of functional module groups, and then to mapping the module groups to the system architecture layer through the automated clustering algorithm and architecture hierarchy matching model. The system can automatically map the functional module groups to different system layers (such as presentation layer, business logic layer, data layer) based on the module dependencies, data flow and call logic, reducing manual intervention in the architecture design process and greatly shortening the development time. BRIEF DESCRIPTION OF THE DRAWINGS

[0065] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:

[0066] Figure 1This is a flow chart of a method for generating software architecture code based on a large language model according to Embodiment 1 of the present invention;

[0067] Figure 2 This is a schematic diagram of the steps for generating functional elements in Example 1 of the present invention;

[0068] Figure 3 This is a schematic diagram of the clustering process for the requirements description of Example 1 of the present invention;

[0069] Figure 4 This is a module diagram of a software architecture code generation system based on a large language model according to Example 2 of the present invention. DETAILED DESCRIPTION

[0070] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments.

[0071] Embodiment 1:

[0072] See also Figure 1 The present invention provides an embodiment: a method for generating software architecture code based on a large language model, wherein the method comprises the following specific steps:

[0073] S1: Obtain user demand input, use natural language processing technology to analyze the input content, identify and extract key functional points and demand elements;

[0074] In this step, the user interface first receives the demand information described in natural language, and then uses the natural language processing (NLP) technology driven by the large language model to pre-process the demand. The specific processing methods include word segmentation, part-of-speech tagging, and dependency analysis. After these processes, the key functional points and the main business logic involved in the user's needs can be identified to provide support for the subsequent functional division.

[0075] S2: further process the extracted functional elements, use clustering algorithm to classify, sort and organize the functional elements into multiple module groups with clear functional divisions;

[0076] In this step, the extracted functional elements are clustered and clustering algorithms (such as DBSCAN and K-means) are used to classify the functional elements according to their similarity and relevance. By analyzing the relationship between the functional elements, multiple module groups can be generated, which represent different functional areas of the system, and each module group has clear boundaries and functional definitions.

[0077] S3: Analyze the associations between functional modules, and map them to various levels of the system architecture according to the functional types, data exchange, and call logic of the modules to form a complete system structure;

[0078] In this step, the functional type (such as data processing, business logic or user interface) of each functional module is determined by analyzing the dependencies between functional modules, data exchange frequency and function call path. Based on this analysis result, each functional module is mapped to different levels of the system architecture, usually including the presentation layer, business logic layer and data layer. In this way, a complete system structure diagram can be generated.

[0079] S4: After the mapping is completed, UML diagrams are generated according to the division of the system architecture layer to show the static structure and dynamic interaction of the modules, including class diagrams, component diagrams, and sequence diagrams;

[0080] In this step, Unified Modeling Language (UML) diagrams are generated based on the mapped functional modules and system architecture levels. Specific diagrams include class diagrams (showing the module classes and their properties and methods), component diagrams (showing the deployment of modules in the physical system), and sequence diagrams (showing the dynamic interaction process between functional modules). These UML diagrams provide developers with static and dynamic views of the system to ensure a clear and visual architecture.

[0081] S5: Based on the generated UML diagram, the corresponding source code is automatically generated, and the optimization algorithm is applied to structure the code;

[0082] In this step, the system automatically generates source code corresponding to each functional module based on the generated UML diagram. The system converts the architecture model into code through model-driven development (MDD) technology. The generated source code will go through an automated code optimization process, including code structure optimization, performance improvement, and redundant code elimination. The system uses optimization algorithms (such as dynamic programming or static analysis tools) to ensure that the generated code is efficient, maintainable, and in line with best programming practices.

[0083] See also Figure 2 , a schematic diagram of the steps for generating functional elements in an embodiment of the present invention can effectively parse natural language requirements into structured functional elements. Adaptive word segmentation can cope with demand languages ​​of different complexities, making word segmentation more accurate. Dependency analysis helps the system identify the grammatical relationship between functions, making the functional division clearer and more reasonable. The timing modeling of LSTM ensures that the dependencies between functional elements can be correctly identified and captured, and the convolution operation further extracts and optimizes the associated features of the functional elements. This combination greatly improves the system's ability to parse complex requirements, ensuring that in the subsequent function clustering and code generation process, the functional modules can be accurately organized and processed. The specific steps of S1 are as follows:

[0084] S1.1: Segment the demand information according to the adaptive semantic segmentation model, perform part-of-speech tagging on the segmentation results through the syntax tree generation algorithm, obtain candidate word sequences, and vectorize the candidate word sequences through the word embedding model;

[0085] In this step, an adaptive semantic segmentation model is used for word segmentation. This model is based on a bidirectional long short-term memory network (Bi-LSTM) and dynamically adjusts the word segmentation window size to adapt to the semantic features of different contexts. Traditional word segmentation methods may ignore semantic changes in the context, resulting in word segmentation errors. In contrast, the adaptive word segmentation model can dynamically optimize word segmentation decisions by combining contextual information.

[0086] The word segmentation model processes input sequences based on Bi-LSTM, and processes long-distance dependency information through its internal memory units and forget gate mechanism. In the bidirectional LSTM structure, the model not only obtains semantic information from the forward context, but also obtains the backward context through the backward LSTM. This structure enables the word segmentation boundaries to be automatically adjusted according to the context semantics by increasing the memory capacity of the network layer. For complex demand descriptions, the size of the word segmentation window is dynamically adjusted by the semantic complexity. For example, in long sentences, the model will increase the window to process more information, while for short sentences or semantically clear fragments, the window will be reduced to ensure the accuracy of word segmentation;

[0087] After word segmentation, the syntactic tree generation algorithm is used to perform part-of-speech tagging on the word segmentation results, and dependency analysis is combined with tagging. Through syntactic tree analysis, the system can identify the subject-predicate-object structure of the sentence and its modifying components, and generate a candidate word sequence. Next, the system converts the candidate word sequence into a vector representation through a word embedding model (such as BERT, Word2Vec). The principle of the word embedding model is based on semantic similarity, mapping words with similar semantics to positions close to each other in the vector space. In this way, each word is mapped to a high-dimensional vector containing contextual semantic information;

[0088] In the specific implementation process, the demand information is first segmented by the adaptive semantic segmentation model. The adaptive semantic segmentation model is based on the bidirectional long short-term memory network (Bi-LSTM) to capture the semantic features of words in the context, thereby dynamically adjusting the segmentation boundaries. Different from the traditional fixed segmentation rules, the adaptive segmentation can automatically adjust the window size according to the complexity of the context, so as to meet the needs of different language scenarios.

[0089] For example, the user input requirement is: "The system needs to support multi-user online editing and real-time data synchronization." The system first performs word segmentation on the natural language input. The word segmentation model will identify "multi-user online editing" and "real-time data synchronization" as independent functional elements based on semantic information, rather than simple word splitting. In this process, the word segmentation results are tagged with parts of speech through the syntax tree generation algorithm, marking nouns, verbs, adjectives and other parts of speech, and then obtaining candidate word sequences.

[0090] Subsequently, word embedding models (such as Word2Vec or BERT) are used to vectorize these candidate word sequences, converting each word into a high-dimensional vector representation for subsequent semantic analysis. These vectors contain the semantic features and contextual relationships of the words. For example, the semantic association between the words "edit" and "synchronize" is represented as a close high-dimensional vector, while "multi-user" and "real-time" reflect the modified semantics of the function.

[0091] S1.2: Identify the subject-verb-object core structure and modifying components in the candidate word sequence through a tree structure based on dependency relationships, and divide the demand information into a multi-layer semantic structure;

[0092] This step uses the dependency parsing algorithm to build the sentence dependency tree. The core idea of ​​dependency parsing is to identify the grammatical dependencies between words in a sentence, such as the relationship between the subject, predicate and object, and the modification relationship between words. Through dependency parsing, the system divides complex demand information into multiple semantic levels. Each level represents a different semantic role. For example, the subject, predicate and object constitute the core semantic layer of the sentence, while the modifying components constitute the secondary semantic layer.

[0093] For example, in the sentence "The system needs to support multi-user online editing", dependency analysis can identify "system" as the subject, "support" as the predicate verb, and "multi-user online editing" as the compound component of the object.

[0094] Through this dependency tree, the system can divide multiple levels of semantic structures, mainly including the core functional semantic layer (subject-verb-object relationship) and the auxiliary semantic layer (modifying components). These semantic structures help to separate the functional requirements of different levels in the system. For example, "supporting multi-user online editing" will be regarded as a core function, while "real-time data synchronization" will be identified as a functional point that needs further association.

[0095] S1.3: Performing temporal modeling on the multi-layer semantic structure according to the long short-term memory network, analyzing the front-end dependency relationship between the models, calculating the relevance matrix according to the front-end dependency relationship, performing feature extraction on the relevance matrix through convolution operation, and outputting functional elements;

[0096] In this step, LSTM is used to perform time series modeling on the semantic structure. The LSTM model processes long-distance dependency information through memory and forgetting mechanisms, and can capture the long-term dependencies between functional elements in the requirement information. For example, multiple functional requirements may appear scattered in the requirement document, but their logical order is closely related. Through LSTM time series modeling, the system can identify these hidden front-end dependencies;

[0097] For example, the function of "supporting multi-user online editing" may depend on "user login" and "authority control", and LSTM can identify the potential correlation between these functions through time series modeling.

[0098] The system then constructs a functional relevance matrix. The relevance matrix is ​​a numerical representation of the dependencies between functional elements. Each element in the matrix represents the degree of correlation between two functional elements, and the higher the value, the stronger the dependency between the two functional elements. Through convolution operations, the system can extract and enhance the features in the relevance matrix, ensuring that functional elements with higher dependencies can be prioritized in subsequent steps.

[0099] Assume that the user input requirement is "the system should allow administrators to manage users in the console, and users should be able to collaboratively edit documents in real time." Through LSTM time series modeling, the system can identify the weak dependency between the two functions of "administrators managing users" and "users collaboratively editing documents in real time", and at the same time identify the "user management" and "collaborative editing" functions as two independent highly correlated functions. Ultimately, the correlation between "user management" and "collaborative editing" in the correlation matrix will be marked as high, while their correlation with the "system console" function will be weak.

[0100] The adaptive semantic segmentation model comprises:

[0101] Encode the input demand information through a bidirectional long short-term memory network to obtain the semantic features of the input vocabulary in the context;

[0102] Calculating the structural complexity of the semantic feature, calculating a word segmentation window according to the structural complexity, and performing word segmentation processing on the demand information according to the word segmentation window;

[0103] During the word segmentation process, the word segmentation results are corrected through the conditional random field model.

[0104] As a preferred embodiment of the above, for step S2, as Figure 3 As shown, the specific steps of S2 are as follows:

[0105] S2.1: Obtain a requirement description template, perform preliminary clustering on the requirement description template according to the DBSCAN clustering algorithm, obtain core points, and determine the number of cluster center clusters according to the number of core points;

[0106] In this step, the system first obtains the requirement description template input by the user. After natural language processing and functional element extraction, these templates form multiple functional element data points. In order to further organize these functional elements, the system uses the density clustering algorithm (DBSCAN) to perform preliminary clustering of the requirement description.

[0107] The core of DBSCAN is that it clusters based on the density of data points, without pre-defining the number of clusters. By setting the minimum number of points (MinPts) and the radius parameter (Eps), the DBSCAN algorithm can find high-density areas as cluster centers, while sparse data points are marked as noise points. The purpose of this step is to extract high-density areas (i.e., core points) from the demand description. The number of core points directly determines the number of initial cluster center clusters of the subsequent K-means algorithm;

[0108] Assume that the functional elements in the requirement description include "user login", "user management", "authority control", etc. Through the DBSCAN algorithm, the system may find that the functional description density of "user management" and "authority control" is high and they are clustered into the same cluster, while "user login" is divided into another cluster.

[0109] S2.2: using the core points after DBSCAN clustering as the initial center clusters of the K-means clustering algorithm, and calculating the Euclidean distance from the functional elements to each of the initial center clusters;

[0110] K-means algorithm is a distance-based partitioning clustering algorithm. The core idea is to optimize the clustering effect by minimizing the distance within the cluster. Each functional element will be assigned to the cluster center closest to it.

[0111] S2.3: performing clustering according to the Euclidean distance, calculating the average clustering error of the initial central cluster, and updating the central cluster according to the average clustering error;

[0112] S2.4: define a convergence condition, determine whether the updated central cluster meets the convergence condition, if not, continue to update the central cluster, if it meets the convergence condition, output the functional module group;

[0113] The system ensures the optimal division of functional elements by iteratively updating cluster centers and calculating errors. In the K-means algorithm, the convergence condition is a common judgment criterion, that is, the change in the position of the cluster center or the error of the distance within the cluster no longer decreases significantly. After setting the convergence condition, the algorithm terminates and outputs the final module group for system architecture design;

[0114] Specifically, by combining the two clustering algorithms, DBSCAN and K-means, cluster analysis is performed on the functional element information, and more accurate clustering results are obtained by iteratively optimizing the central cluster. DBSCAN is a density clustering algorithm used to identify closely connected data points in space and divide them into clusters. DBSCAN can be used for preliminary clustering to obtain core points. Core points refer to the core area containing at least a specified number of data points within a given radius. Since each core point may represent a cluster, the number of core points can be used to preliminarily determine the number of central clusters of clustering.

[0115] The kernel points obtained by preliminary clustering through DBSCAN are used as the initial center cluster of the K-means clustering algorithm, providing an initial cluster center position for the K-means algorithm; the Euclidean distance is used for clustering, and each functional element is assigned to the nearest center cluster by calculating the Euclidean distance from the functional element to each initial center cluster. The clustering average error refers to the average value of the Euclidean distance from all data points to the center. The clustering average error can be used to update the initial center cluster to improve the clustering effect. The position of the center cluster can be adjusted according to the calculated clustering average error, so as to update the center cluster, and the convergence condition is defined to determine whether the updated center cluster meets the condition to determine whether to end the iteration. If the convergence condition is met, the clustering result is output.

[0116] The specific steps of S3 are as follows:

[0117] S3.1: Based on the graph structure analysis algorithm, the dependency relationship of each functional module group is analyzed, and the dependency graph of the functional module group is constructed according to the dependency relationship. The interaction relationship between each functional module group and other module groups in the system is quantified to generate an inter-module dependency matrix, wherein the dependency relationship includes the data exchange frequency, function call path and logical dependency degree between modules;

[0118] In this step, the system uses a graph structure analysis algorithm to perform a detailed analysis of the dependencies between functional modules. Each functional module can be regarded as a node in the graph, while the data exchange frequency, function call path, and logical dependency between functional modules constitute the edges of the graph. By quantifying these edges, the system can construct a dependency graph between functional module groups.

[0119] The process of building a dependency graph involves a graph structure analysis algorithm that can capture the complex interactions between modules. For example, if two modules A and B frequently exchange data and call each other, the dependency relationship between them will be displayed as a higher weight value in the dependency matrix.

[0120] The dependency matrix is ​​constructed as follows:

[0121] Set the interaction frequency threshold between modules, record the data exchange frequency between module A and module B, and use it as the initial weight of the dependency relationship.

[0122] Track the function call path, the occurrence time and call order of each function call in the system will be recorded in the dependency graph.

[0123] The system also determines the interdependence between modules based on business logic. For example, if a module provides data for the input of another module, then their logical dependency is high.

[0124] S3.2: Statistically analyze the function call frequency and interaction delay of each functional module group, calculate the data call weight according to the analysis result, weight the call paths between each functional module group according to the data call weight, and calculate the data flow graph;

[0125] In this step, the system collects statistics on the function call frequency and interaction delay of each functional module group to generate more detailed interaction data. Call frequency and interaction delay are important indicators for measuring the interaction efficiency between functional modules.

[0126] The system constructs a function call frequency matrix by tracking the function call paths between each module group and recording the number of calls, response time, etc. The system also records the response time of each module and calculates the interaction delay matrix;

[0127] Then, the matrix is ​​used to construct a data flow graph, which represents the call paths and priorities between functional module groups. The edges in the graph represent the call paths between modules, and the weights of the edges represent the importance and efficiency of the calls. For example, if module A frequently calls module B and its latency is low, the data flow from module A to B will be given a higher weight.

[0128] S3.3: Calculate the function score of the function module group according to the inter-module dependency matrix and the data flow diagram, and divide the modules into different function types according to the function scores, wherein the function types include data processing type, business logic type and interface type;

[0129] In this step, the system combines the dependency matrix with the data flow diagram to calculate the functional score of each functional module group. The functional score is a comprehensive indicator to measure the role and importance of each module in the system;

[0130] In the functional score, the dependency has a larger weight, indicating that the module depends on a large amount of data input and output, identifying it as a data processing module.

[0131] The business logic module is characterized by a higher frequency of function calls, so the data call weight plays a dominant role in the function score.

[0132] The interface module usually has a higher interaction delay with other modules, but a smaller number of interactions, so its score is mainly determined by the interaction path and delay.

[0133] S3.4: Construct an architecture hierarchy matching model to map the functional types of the functional module group with the presentation layer, business logic layer, and data layer in the system architecture;

[0134] In the last step, the system matches the type of functional module group with the system's architectural layer. Specifically, the data processing module is mapped to the data layer, the business logic module is mapped to the business logic layer, and the interface module is mapped to the presentation layer.

[0135] The system achieves mapping through an architectural hierarchy matching model, which classifies and maps based on the characteristics of the function type and the system architecture. Each function type has a specific functional position in the architectural hierarchy. For example, the interface module should be located in the presentation layer, while the data processing module should be located in the data layer. Through this mapping model, the system can ensure that the function modules are reasonably distributed in the system architecture.

[0136] The specific steps of S4 are as follows:

[0137] S4.1: Generate UML class diagram based on the functional definition of the functional module group and object-oriented design principles;

[0138] In this step, the system generates a UML class diagram based on the function definition of the previously parsed function module group and the object-oriented design principle (OOD). Each function module group is regarded as a class, which contains attributes and methods. The class diagram shows the static structure of the system, including inheritance, association, and dependency between classes;

[0139] First, the functional definition of each functional module group is analyzed. The functions of each module group can be decomposed into attributes (representing the data of the module) and methods (representing the operation of the module). According to the object-oriented design principles, the attributes and methods of the module group correspond to the fields and methods of the class. The relationship between classes is modeled through inheritance (Is-A), association (Has-A), composition (Part-Of) and other relationships.

[0140] For example, suppose there are two module groups in the system: "User Management Module" and "Permission Management Module". "User Management Module" has the function of managing users, while "Permission Management Module" is responsible for managing user permissions. In the class diagram, "User Management Module" will be a class, which contains attributes such as "User ID", "User Name" and methods such as "Create User", "Delete User". "Permission Management Module" will be another class and connected to "User Management Module" through an association relationship (Has-A), indicating that each user has corresponding permissions;

[0141] The generated UML class diagram can intuitively display the static structure of the system and make the inheritance and dependency relationships between classes clear. Through object-oriented design, the maintainability and scalability of the system can be effectively improved.

[0142] S4.2: Generate a UML component diagram according to the allocation of the functional module group in the architecture layer, wherein the UML component diagram is used to show the physical deployment of the module;

[0143] In this step, the system generates a UML component diagram based on the allocation of functional module groups in the architecture layer. The component diagram is used to show the physical deployment structure of the system and describe how each functional module is implemented and deployed in the physical architecture of the system;

[0144] The core of the component diagram is to show the components in the system and their physical implementation. Each functional module group corresponds to a component, and the components communicate with other components through interfaces. The component diagram links the physical implementation with the logical architecture of the system, showing the actual operating location of the module and the communication path between modules;

[0145] For example, suppose the system contains a "user management module" and a "authority management module", which may be deployed on two different servers. In the component diagram, each module is an independent component, and the server represents the deployment node of the module. The interface communication between modules represents how they exchange data on different physical nodes;

[0146] The component diagram clearly shows the deployment of the system on the physical architecture, allowing developers to understand the physical deployment location of each module and how they communicate with each other. This helps with system expansion and deployment optimization.

[0147] S4.3: Generate a UML sequence diagram according to the data flow diagram, wherein the UML sequence diagram is used to describe the dynamic interaction process between functional modules;

[0148] In this step, the system generates a UML sequence diagram based on the data flow diagram. The sequence diagram is used to describe the dynamic interaction process between functional modules and show the message passing and function call sequence between modules.

[0149] Sequence diagrams show the dynamic behavior of a system, especially the order of interactions between modules. Each functional module is represented as a "lifeline" in a sequence diagram, and interaction information (such as function calls, return messages, etc.) is displayed in the form of arrows. Sequence diagrams can show the dependencies, call order, and return results between functional modules, helping developers understand the time series behavior of the system.

[0150] For example, suppose that when a user logs in to the system, the "user verification module" will be called first, then the "authority management module" will check the user's authority, and finally return the verification result. In the sequence diagram, the order of user verification and authority checking will be shown by vertical arrows to describe their interaction process;

[0151] The sequence diagram intuitively shows the dynamic interaction process of the system, helping developers understand the execution order and interaction between modules. This is very helpful for analyzing the business process and time dependency of the system.

[0152] The optimization strategy includes:

[0153] Perform static analysis on the generated source code, using static code analysis tools and algorithms to detect potential problems in the code, including irregular formats, unused variables, duplicate code, unhandled exceptions, and null pointer references;

[0154] Specifically, it parses the code structure through the abstract syntax tree, identifies common coding standards and potential problems through pattern matching, uses data flow analysis to track the status of variables and data, detects security vulnerabilities and logical errors, and integrates static code analysis tools (such as SonarQube, PMD, Checkstyle) to conduct a comprehensive inspection of the code;

[0155] Identify data processing functions, loop functions, and recursive functions in the code, and analyze the time and space complexity of the functions to check whether there are performance bottlenecks. If there are performance bottlenecks, automatically reconstruct them through optimization algorithms (such as dynamic programming and greedy algorithms) to reduce time and space complexity. Use memory analysis and CPU analysis techniques to optimize memory allocation, garbage collection strategies, and thread management.

[0156] Dynamic programming optimizes functions with overlapping subproblems by recording the solutions to the subproblems to avoid repeated computations.

[0157] Using memory analysis tools to detect hot code segments and optimize them can significantly reduce the average response time and resource consumption of the program.

[0158] Embodiment 2:

[0159] See also Figure 4,The present invention provides an embodiment: a software architecture code generation system based on a large language model, the system comprising a requirement parsing module, a function clustering module, an architecture mapping module, a code generation module and a code optimization module;

[0160] The demand analysis module is configured with a natural language analysis strategy, which is used to analyze the demand information through natural language processing technology, segment the demand information according to the adaptive semantic segmentation model, and perform part-of-speech tagging and semantic structure analysis through a syntax tree generation algorithm to extract functional elements;

[0161] The function clustering module is configured with a function aggregation strategy, which is used to classify the function elements after the demand analysis, perform cluster analysis on the function elements using a clustering algorithm and generate a function module group;

[0162] The architecture mapping module is used to analyze the function type of each module group according to the dependency, data flow and calling frequency of the function module group, and map it to the corresponding level of the system architecture;

[0163] The code generation module is used to generate a corresponding UML representation architecture diagram based on the functional module group, and generate source code according to the UML representation architecture diagram;

[0164] The code optimization module is used to optimize the code according to a preset optimization strategy.

[0165] The demand parsing module includes:

[0166] A word segmentation unit, used to segment the demand information according to an adaptive semantic segmentation model, wherein the word segmentation unit dynamically adjusts the word segmentation window based on a bidirectional long short-term memory network;

[0167] A part-of-speech tagging unit is used to tag the word segmentation results with parts of speech by using a syntax tree generation algorithm. The part-of-speech tagging unit identifies the subject-verb-object core structure and the modifying components by combining dependency analysis;

[0168] The semantic structure analysis unit is used to perform multi-layer semantic structure analysis on the word segmentation and part-of-speech tagged demand information through the long short-term memory network, identify the front-to-back dependency relationship between various functional elements, and generate a multi-layer semantic structure;

[0169] A functional element extraction unit is used to extract features from the extracted multi-layer semantic structure through a convolutional neural network and output the functional elements in the requirements;

[0170] The natural language parsing strategy includes dynamic word segmentation logic, dependency annotation logic and multi-layer semantic analysis logic;

[0171] The dynamic word segmentation strategy is configured in the word segmentation unit, and is used to adjust the word segmentation window size according to the complexity of the demand information, and perform word segmentation in combination with context information;

[0172] The dependency relationship annotation logic is configured in the part-of-speech tagging unit and is used to generate a subject-verb-object dependency relationship through a syntax tree;

[0173] The multi-layer semantic analysis logic is configured in the semantic structure analysis unit, and is used to process semantic structures at different levels in combination with the temporal modeling of the long short-term memory network.

[0174] The function clustering module comprises:

[0175] A preliminary clustering unit, used to perform preliminary clustering on the functional elements after demand analysis, wherein the preliminary clustering unit identifies core points in the functional elements based on the DBSCAN clustering algorithm and determines the initial clustering center according to the number of core points;

[0176] A cluster center updating unit is used to optimize the preliminary clustering results. The cluster center updating unit calculates the Euclidean distance from each functional element to the cluster center based on the K-means clustering algorithm, updates the cluster center according to the clustering average error, and iteratively optimizes the clustering results.

[0177] A clustering convergence judgment unit, used to judge whether the clustering process has reached a stable state. The clustering convergence judgment unit monitors the change of the clustering average error according to a preset convergence condition, determines the clustering convergence when the error is less than a predetermined threshold, and outputs a final functional module group;

[0178] The function module group output unit is used to output the final function module group after clustering convergence and use it as input for subsequent system architecture mapping;

[0179] The functional aggregation strategy includes:

[0180] A preliminary clustering logic, configured in the preliminary clustering unit, for identifying and clustering core functional elements according to a density threshold and a minimum number of points in a DBSCAN algorithm to form preliminary clusters;

[0181] The cluster center update logic is configured in the cluster center update unit, and is used to update the cluster center and optimize the clustering result by calculating the Euclidean distance and clustering error based on the K-means algorithm on the basis of preliminary clustering;

[0182] The convergence judgment logic is configured in the clustering convergence judgment unit and is used to judge whether the clustering is stable according to the set convergence conditions (such as error threshold or number of iterations) to ensure that the output functional module group has consistency and rationality.

[0183] The architecture mapping module comprises:

[0184] The dependency analysis unit is used to analyze the dependency between functional module groups. The unit generates a dependency matrix of functional modules by analyzing the data exchange, function call paths and their logical associations between modules.

[0185] Functional classification unit is used to classify functional module groups according to functional types. Functional types include data processing type, business logic type and interface type, etc. Classification is based on the input and output data of the module, functional complexity and module characteristics.

[0186] The architecture layer mapping unit is used to map the classified functional module groups to the corresponding layers in the system architecture. According to the functional type of the module, it is mapped to the presentation layer, business logic layer, data layer, etc.

[0187] The code optimization module comprises:

[0188] Static analysis unit: Use static analysis tools to check the syntax and format of the generated code to identify potential code errors or redundant code.

[0189] Performance optimization unit: Analyzes performance bottlenecks in generated code and optimizes key algorithms or data structures to improve code execution efficiency.

[0190] Structural optimization unit: restructure and simplify the code structure, eliminate redundant code, and improve the readability and maintainability of the code.

[0191] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.

Claims

1. A software architecture code generation method based on a large language model, characterized in that: The method comprises: Receive demand information input by the user, analyze the demand information through NLP technology, and extract functional elements; Classify the functional elements according to a clustering algorithm to generate a functional module group; Mapping the functional module group to a corresponding system architecture layer, and generating an architecture diagram represented by UML through the system architecture layer; According to the architecture diagram, corresponding source code is generated, and the source code is optimized according to a set optimization strategy.

2. According to the method for generating software architecture code based on a large language model according to claim 1, it is characterized in that: The analyzing the demand information by using NLP technology includes: Segment the demand information according to the adaptive semantic segmentation model, perform part-of-speech tagging on the segmentation results through the syntax tree generation algorithm, obtain candidate word sequences, and vectorize the candidate word sequences through the word embedding model; The subject-verb-object core structure and modifying components in the candidate word sequence are identified through a tree structure based on dependency relationships, and the demand information is divided into a multi-layer semantic structure. The multi-layer semantic structure is temporally modeled according to the long short-term memory network, the front-end dependency relationship between the models is analyzed, the relevance matrix is ​​calculated according to the front-end dependency relationship, the relevance matrix is ​​feature extracted through convolution operation, and the functional elements are output.

3. According to the method for generating software architecture code based on a large language model as described in claim 2, it is characterized in that: The adaptive semantic segmentation model comprises: Encode the input demand information through a bidirectional long short-term memory network to obtain the semantic features of the input vocabulary in the context; Calculating the structural complexity of the semantic feature, calculating a word segmentation window according to the structural complexity, and performing word segmentation processing on the demand information according to the word segmentation window; During the word segmentation process, the word segmentation results are corrected through the conditional random field model.

4. According to the method for generating software architecture code based on a large language model as described in claim 1, it is characterized in that: The classifying process of the functional elements according to the clustering algorithm includes: Obtain a requirement description template, perform preliminary clustering on the requirement description template according to a DBSCAN clustering algorithm, obtain core points, and determine the number of cluster center clusters according to the number of core points; The core points after DBSCAN clustering are used as the initial center clusters of the K-means clustering algorithm, and the Euclidean distances from the functional elements to each of the initial center clusters are calculated; Perform clustering according to the Euclidean distance, calculate the average clustering error of the initial central cluster, and update the central cluster according to the average clustering error; A convergence condition is defined, and it is determined whether the central cluster after the update satisfies the convergence condition. If the convergence condition is not satisfied, the central cluster is continuously updated. If the convergence condition is satisfied, the functional module group is output.

5. According to the method for generating software architecture code based on a large language model as described in claim 1, it is characterized in that: Mapping the functional module group to the corresponding system architecture layer includes: Based on the graph structure analysis algorithm, the dependency relationship of each functional module group is analyzed, and the dependency graph of the functional module group is constructed according to the dependency relationship. The interaction relationship between each functional module group and other module groups in the system is quantified to generate an inter-module dependency matrix, wherein the dependency relationship includes the data exchange frequency, function call path and logical dependency degree between modules; Perform statistical analysis on the function call frequency and interaction delay of each functional module group, calculate the data call weight according to the analysis result, weight the call paths between each functional module group according to the data call weight, and calculate the data flow graph; Calculate the function score of the function module group according to the inter-module dependency matrix and the data flow diagram, and divide the modules into different function types according to the function score, wherein the function types include data processing type, business logic type and interface type; Build an architectural hierarchy matching model to map the functional types of the functional module group with the presentation layer, business logic layer, and data layer in the system architecture.

6. According to claim 5, a method for generating software architecture code based on a large language model is characterized in that: The generating of the architecture diagram represented by UML includes: Generate UML class diagram based on the functional definition of functional module group and object-oriented design principles; Generate a UML component diagram based on the allocation of the functional module groups in the architecture layer, wherein the UML component diagram is used to show the physical deployment of the modules; A UML sequence diagram is generated according to the data flow diagram, and the UML sequence diagram is used to describe the dynamic interaction process between functional modules.

7. The method for generating software architecture code based on a large language model according to claim 1, characterized in that: The optimization strategy includes: Performing static analysis on the source code to identify formatting issues and potential vulnerabilities in the code; Identify data processing functions, loop functions, and recursive functions in the code, analyze the complexity of the functions, and automatically reconstruct them using dynamic programming algorithms.

8. A software architecture code generation system based on a large language model, used to implement the method according to any one of claims 1 to 7, characterized in that: The system includes a requirement parsing module, a function clustering module, an architecture mapping module, a code generation module and a code optimization module; The demand analysis module is configured with a natural language analysis strategy, which is used to analyze the demand information through natural language processing technology, segment the demand information according to the adaptive semantic segmentation model, and perform part-of-speech tagging and semantic structure analysis through a syntax tree generation algorithm to extract functional elements; The function clustering module is configured with a function aggregation strategy, which is used to classify the function elements after the demand analysis, perform cluster analysis on the function elements using a clustering algorithm and generate a function module group; The architecture mapping module is used to analyze the function type of each module group according to the dependency, data flow and calling frequency of the function module group, and map it to the corresponding level of the system architecture; The code generation module is used to generate a corresponding UML representation architecture diagram based on the functional module group, and generate source code according to the UML representation architecture diagram; The code optimization module is used to optimize the code according to a preset optimization strategy.

9. A software architecture code generation system based on a large language model according to claim 8, characterized in that: The demand parsing module includes: A word segmentation unit, used to segment the demand information according to an adaptive semantic segmentation model, wherein the word segmentation unit dynamically adjusts the word segmentation window based on a bidirectional long short-term memory network; A part-of-speech tagging unit is used to tag the word segmentation results with parts of speech by using a syntax tree generation algorithm. The part-of-speech tagging unit identifies the subject-verb-object core structure and the modifying components by combining dependency analysis; The semantic structure analysis unit is used to perform multi-layer semantic structure analysis on the word segmentation and part-of-speech tagged demand information through the long short-term memory network, identify the front-to-back dependency relationship between various functional elements, and generate a multi-layer semantic structure; A functional element extraction unit is used to extract features from the extracted multi-layer semantic structure through a convolutional neural network and output the functional elements in the requirements; The natural language parsing strategy includes dynamic word segmentation logic, dependency annotation logic and multi-layer semantic analysis logic; The dynamic word segmentation strategy is configured in the word segmentation unit, and is used to adjust the word segmentation window size according to the complexity of the demand information, and perform word segmentation in combination with context information; The dependency relationship annotation logic is configured in the part-of-speech tagging unit and is used to generate a subject-verb-object dependency relationship through a syntax tree; The multi-layer semantic analysis logic is configured in the semantic structure analysis unit, and is used to process semantic structures at different levels in combination with the temporal modeling of the long short-term memory network.

10. A software architecture code generation system based on a large language model according to claim 8, characterized in that: The function clustering module comprises: A preliminary clustering unit, used to perform preliminary clustering on the functional elements after demand analysis, wherein the preliminary clustering unit identifies core points in the functional elements based on the DBSCAN clustering algorithm and determines the initial clustering center according to the number of core points; A cluster center updating unit is used to optimize the preliminary clustering results. The cluster center updating unit calculates the Euclidean distance from each functional element to the cluster center based on the K-means clustering algorithm, updates the cluster center according to the clustering average error, and iteratively optimizes the clustering results. A clustering convergence judgment unit, used to judge whether the clustering process has reached a stable state. The clustering convergence judgment unit monitors the change of the clustering average error according to a preset convergence condition, determines the clustering convergence when the error is less than a predetermined threshold, and outputs a final functional module group; The function module group output unit is used to output the final function module group after clustering convergence and use it as input for subsequent system architecture mapping; The functional aggregation strategy includes: A preliminary clustering logic, configured in the preliminary clustering unit, for identifying and clustering core functional elements according to a density threshold and a minimum number of points in a DBSCAN algorithm to form preliminary clusters; The cluster center update logic is configured in the cluster center update unit, and is used to update the cluster center and optimize the clustering result by calculating the Euclidean distance and clustering error based on the K-means algorithm on the basis of preliminary clustering; The convergence judgment logic is configured in the clustering convergence judgment unit and is used to judge whether the clustering is stable according to the set convergence conditions to ensure that the output function module group has consistency and rationality.

Citation Information

Patent Citations

  • Application layer software development method and device, computer equipment and storage medium

    CN116931916A

Cited By

  • Multi-mode-based software architecture intelligent design and optimization system

    CN120104104A

  • Code automatic generation and optimization system based on multiple modes

    CN120276718A

  • A multi-modal code automatic generation and optimization system

    CN120276718B

  • Structured data calculation result optimization method and system

    CN120724010A

  • A method and system for optimizing structured data computation results

    CN120724010B