Software design document generation method and device based on document structure splitting and parallel generation, and medium
By structurally decomposing and generating software design documents in parallel, and combining multi-level fault-tolerant parsing and template cascading replacement, the problems of long generation time, unstable quality, and standard adaptation in software design document generation are solved, achieving rapid automatic generation and high efficiency adaptability.
Patent Information
- Application Number
- CN202611709842.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-11-02
- Publication Date
- 2026-11-27
AI Technical Summary
In existing technologies, the writing of software design documents is time-consuming and of unstable quality, making it difficult to meet minute-level delivery requirements. Furthermore, the output of large language models is unstable and cannot adapt to different delivery specifications and consistency issues between modules.
By splitting the structure tree according to the title hierarchy of the requirements document, the document is divided into functional modules. The large language model is called in parallel to generate content. Combined with multi-level fault-tolerant parsing and template cascading replacement, the document can be quickly and automatically generated and adapted to the specifications.
It enables the automatic generation of software design documents within minutes, improves the robustness and adaptability of the generation process, reduces maintenance costs, and supports the reuse of multiple delivery specifications.
Smart Images

Figure CN123180109A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of software engineering document automation and artificial intelligence technology, specifically to a method, apparatus, and medium for generating software design documents based on document structure decomposition and parallel generation. Background Technology
[0002] In software engineering practice, deliverables such as preliminary design, detailed design, interface design, and database design are key outputs of project development and acceptance. However, the writing of these documents has long relied on manual labor, which has the following technical drawbacks: First, manual writing is time-consuming and of inconsistent quality. A complete preliminary design specification can easily reach tens of thousands to hundreds of thousands of words, and the manual writing cycle is often measured in weeks. Moreover, different writers have significantly different understandings and expression styles of the same requirements, resulting in unstable document quality and poor standardization.
[0003] Second, directly generating complete documents using a large language model presents issues of context overflow and output truncation. Requirements specifications are typically very long, and inputting them entirely into a large language model will exceed the model's context window limit, resulting in truncated content and omission of key modules. Even if generated in stages, it is difficult to maintain consistency in the connection and style between modules.
[0004] Third, serially calling large language models is inefficient. Large language models have high latency for a single inference iteration. If they are called sequentially module by module, the time required to generate the entire document will be unacceptable, failing to meet the timeliness requirements of minute-level delivery.
[0005] Fourth, the document specifications vary greatly among different delivery targets, making templates difficult to reuse. Existing solutions typically hard-code the generation logic for each specification, requiring code modifications to change the template, resulting in high maintenance costs and difficulty in quickly adapting to new specifications.
[0006] Fifth, the output stability of large language models is insufficient. When generating structured results (such as basic information or chapter content represented by objects), the model often outputs non-standard content such as unescaped newlines, redundant wrapping symbols, or missing fields, leading to the failure of subsequent parsing and poor robustness of the generation process.
[0007] In recent years, although some solutions have attempted to use search enhancement or template filling to assist in document generation, their search objects are mostly external knowledge fragments, and they have not solved a series of domain-specific problems in software design document generation, such as "divide and conquer according to the document structure of requirements", "parallel by module", "adapting templates according to specifications" and "output fault tolerance".
[0008] Patent application CN114139494A discloses a design document generation method, apparatus, computer device, and storage medium. The method includes obtaining a selection instruction; responding to the selection instruction to select a module identification identifier to be added; selecting at least one candidate module as a document module based on the mapping relationship between the module identification identifier and the candidate modules; obtaining layout parameters; calculating the layout rules for each document module based on the layout parameters and a preset dynamic programming algorithm; and adding each document module to a pre-created template file according to the layout rules to generate a design document. However, this patent cannot completely solve the existing technical problems, nor can it meet the needs of this invention. Summary of the Invention
[0009] To address the shortcomings of existing technologies, the purpose of this invention is to provide a method, apparatus, and medium for generating software design documents based on document structure decomposition and parallel generation.
[0010] The software design document generation method based on document structure decomposition and parallel generation provided by the present invention, the method being executed by a computer device, includes: Step S1: Receive the input requirement document, parse it into structured content, and extract the media resources from the requirement document; Step S2: Construct a structure tree according to the title hierarchy of the structured content, identify the functional chapters, mark the content before and after the functional chapters as context modules, and break down the subordinate content of the functional chapters to the smallest functional points to obtain a set of functional modules; Step S3: Using a thread pool to batch and parallelize, each functional module in the functional module set is independently called to the large language model to generate the design content of each functional module. According to the preset mapping relationship between modules and models, different functional modules are routed to different large language models for invocation. Step S4: Parse and aggregate the results returned by the large language model corresponding to each functional module, including performing multi-level fault-tolerant parsing on the structured results returned by the large language model, and dynamically calculating the heading level of each functional module in the final document according to the index of each functional module. Step S5: The aggregated content is filled into the delivery template through multi-layer placeholder cascading replacement to obtain document content that conforms to the target delivery specifications. The multi-layer placeholder cascading replacement includes prompt word template variable replacement, document skeleton placeholder replacement, and layout style template replacement. Step S6: Convert the document content into a document with uniform formatting and output it.
[0011] Preferably, in step S1, the requirement document is in DOC / DOCX format, portable document format PDF, plain text, or markup language format; a document conversion tool is called to parse the requirement document into structured content, which is markup language text; and at the same time, media resources in the requirement document are extracted to an independent directory and referenced in the structured content with relative paths.
[0012] Preferably, in step S2, identifying functional chapters includes: traversing the structure tree and determining the chapter where the title text matches the preset functional design semantic keywords as a functional chapter; merging and marking the content before and after the functional chapter as a context module, wherein the context module is not generated separately by calling the large language model, but is provided as context for the generation of each functional module; and splitting the subordinate content of the functional chapter down the title level to the smallest functional point to obtain a set of functional modules; the splitting rule of the smallest functional point is: splitting down the functional chapter down the title level to the leaf functional title that does not contain the next level functional title, and taking the content under its jurisdiction as a smallest functional point; and also includes extracting the mapping between functional names and functional codes from the functional list table in the functional chapter.
[0013] Preferably, the rule for determining functional chapters is as follows: chapters whose title text matches preset functional semantic keywords are determined to be functional chapters; for chapters that do not match the keywords, whether they are functional chapters is determined by the title level and the functional list table.
[0014] Preferably, in step S3, a fixed-size thread pool is used to process the set of functional modules in batches. The number of modules that concurrently call the large language model in each batch does not exceed the size of the thread pool, and the batches are processed sequentially. Within each batch, the calls to each module are submitted as asynchronous tasks, and the asynchronous results are collected in the index order of each functional module. For each functional module, its content is combined with the summary of the context module to form a prompt word, and then the large language model is called to generate the design content of the module. The context module is first generated and compressed in full text, and then injected into the prompt words of each functional module in a fixed format. When the total length of the module content and the context summary exceeds the upper limit of the model context window, the module's own content is retained first, and then the context summary is progressively truncated according to the importance of the title, while retaining the document type and delivery specification identification metadata.
[0015] Preferably, in step S3, the mapping relationship uses the function code as the key index to correspond to the large language model configuration, and the large language model configuration includes the access address, credentials and model name; based on the mapping relationship, the model routing dynamically adjusts the target model according to the module function type, complexity level and the historical generation quality and availability status of the candidate models; when the preferred model is unavailable or fails to be called, it is downgraded to the backup model according to the preset model priority list; the module that fails and retryes reuses the selected model and the generated context summary.
[0016] Preferably, in step S4, the multi-level fault-tolerant parsing includes: attempting standard object parsing sequentially; if it fails, using fault-tolerant parsing for unescaped newlines and redundant enclosing characters; if it still fails, using field extraction based on regular expressions; the process ends upon successful parsing at any level; specific repair actions at each parsing level include: directly deserializing standard object parsing; escaping unescaped newlines to visible escape characters before parsing; removing code block enclosing characters and redundant quotation marks and commas for redundant enclosing characters; and extracting key fields using regular expression extraction according to a preset pattern. After parsing, the integrity of key fields such as function codes, module names, and design content is checked. If any fields are missing or the types are inconsistent, the parsing proceeds to the next level. For modules that fail to parse at any level, the large language model is called again and parsing is retried. The calculation rule for the title level is as follows: the title level of the functional chapter is used as the basis, and each minimum functional point under it increases progressively. During aggregation, the title tree is rebuilt according to the module index order to restore the parent-child hierarchy between functional chapters and minimum functional points. After reconstruction, the table of contents entries are regenerated, and the figures and tables are renumbered according to their order of appearance and the cross-references in the text are updated.
[0017] Preferably, in step S5, the multi-layer placeholder cascading replacement includes three layers: the first layer is prompt word template variable replacement, which injects module content, module name, and image references into prompt words before calling the large language model; the second layer is document skeleton placeholder replacement, which injects the content generated by the large language model into the overall skeleton of the delivery document; the third layer is layout style template replacement, which applies the layout style of the target delivery specification during the format conversion stage; the target delivery specification includes a first delivery specification and a second delivery specification, which differ in chapter structure, table column definition, and terminology specification; the selection of the prompt word template, document skeleton, and layout style template is driven by the delivery specification identifier parameter that runs through the entire process; the placeholder parsing engine supports conditional rendering, loop rendering, nested placeholders, and dependency resolution; each layer of template is externally stored and supports hot loading, retaining historical versions during loading, and automatically reverting to the previous available version when the new version template is abnormal; In step S6, the document content is converted into a document format using a document conversion tool; during the conversion process, figures and tables are automatically numbered; and image captions, font colors, and mixed content recognition are processed using a pluggable filtering script; for sequence diagrams described in the form of code blocks, they are first rendered as images and then embedded; at the same time, a markup language version is retained for front-end preview.
[0018] The software design document generation apparatus provided by the present invention includes: The document parsing module receives the requirement document as its input and connects to the input of the structure splitting module as its output. It parses the input requirement document into structured content and extracts media resources. The structure splitting module connects its input to the output of the document parsing module and its output to the input of the parallel generation module. It constructs a structure tree according to the heading level, identifies functional chapters, marks context modules, and splits the content under each functional chapter to the smallest functional point to obtain a set of functional modules. The parallel generation module connects its input to the output of the structure splitting module and its output to the input of the fault-tolerant parsing module. It uses a thread pool to call the large language model independently to generate design content for each functional module in batches and in parallel. The model routing module, connected to the parallel generation module, routes different functional modules to different large language models based on the mapping relationship between modules and models; The fault-tolerant parsing module has its input connected to the output of the parallel generation module and its output connected to the input of the aggregation typesetting module. It performs multi-level fault-tolerant parsing on the structured results returned by the large language model. The aggregation typesetting module connects its input to the output of the fault tolerance parsing module and its output to the input of the format conversion module. It parses and aggregates the results of each module, dynamically calculates the title level, and delivers the template by replacing and filling multiple layers of placeholders. The format conversion module connects its input end to the output end of the aggregated typesetting module, converting the content output by the aggregated typesetting module into a document with uniform typesetting. The task and progress management module connects with the document parsing module, structure splitting module, parallel generation module, and aggregated typesetting module. It records document type, source file, delivery specification identifier, and status as task entities, with status transitioning between not started, generating, completed, and failed. The generation process is executed asynchronously in a background thread and returns the task identifier in real time. It maintains real-time progress in memory, including the total number of modules, the number of completed modules, and the current module name, for front-end polling. When a generating task has no progress update within a preset time, it is automatically marked as failed. Failed tasks are re-executed based on the original source file.
[0019] According to the computer-readable storage medium provided by the present invention, a computer program is stored thereon, which, when executed by a processor, implements the steps of the software design document generation method based on document structure splitting and parallel generation.
[0020] Compared with the prior art, the present invention has the following beneficial effects: 1. This invention intelligently splits the massive requirement document into controllable functional modules by dividing it into hierarchical structure based on the title level. Then, it uses a thread pool to call the large language model in batches in parallel. This not only avoids context overflow and output truncation caused by the overall input of a large document, but also significantly shortens the generation time, realizing the automatic generation of software design documents in minutes.
[0021] 2. This invention enables different modules in the same document generation process to call different large language models through the mapping relationship between modules and models, thereby selecting the most suitable model according to the characteristics of the module, taking into account both generation quality and cost.
[0022] 3. This invention uses a multi-level fault-tolerant parsing mechanism to sequentially downgrade the parsing for non-standard cases such as unescaped newlines, redundant wrapping symbols, or missing fields in the output of large language models, which significantly improves the robustness of the generation process under unstable model output conditions.
[0023] 4. This invention achieves the reuse of "one generation engine and multiple delivery specifications" by cascading replacement of three layers of placeholders: prompt word template, document skeleton and layout style template, and by driving template selection with delivery specification identifiers that run through the entire process. Adding or modifying delivery specifications does not require changing the code, only adjusting the external template.
[0024] 5. This invention improves the user experience by enabling long-running document generation tasks to be tracked and recovered from failures through task-based asynchronous generation, real-time memory progress, and state self-healing mechanisms. Attached Figure Description
[0025] Other features, objects, and advantages of the present invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings: Figure 1 This is a schematic diagram of the overall process of a software design document generation method based on document structure splitting and parallel generation, provided for an embodiment of the present invention. Detailed Implementation
[0026] The present invention will now be described in detail with reference to specific embodiments. These embodiments will help those skilled in the art to further understand the present invention, but do not limit the invention in any way. It should be noted that those skilled in the art can make several changes and improvements without departing from the concept of the present invention. These all fall within the protection scope of the present invention.
[0027] Example 1 In one embodiment of the present invention, a complete implementation process of a software design document generation method and system based on document structure decomposition and parallel generation is described in detail. This embodiment aims to achieve end-to-end automatic generation from requirements specification to preliminary design specification.
[0028] Reference Figure 1 This diagram illustrates the overall flow of the method provided in this embodiment of the invention. The method includes an offline template and model configuration stage, and an online document generation stage.
[0029] First, during the configuration phase: An external set of prompt word templates, delivery document skeleton templates, and layout style templates, along with a mapping table between modules and models, are deployed on the computer device. The prompt word templates are stored as text files and support dual loading from the classpath and file system for hot updates without restarting the service. The mapping table uses function codes as keys to index the corresponding large language model configurations (including access addresses, credentials, and model names).
[0030] Upon entering the online generation phase, when a requirements document is input, the system performs the following steps: Step S1: Receive the input requirement document (e.g., a requirement specification, which can be in document, PDF, plain text, or markup language format). Use a document conversion tool to parse the requirement document into structured content (markup language text in this embodiment), and simultaneously extract media resources (such as images) from the requirement document to a separate directory, referencing them in the structured content using relative paths, thereby ensuring that images are not lost during subsequent generation and layout stages.
[0031] Step S2: Construct a structure tree according to the title hierarchy of the structured content. Specifically, traverse the structure tree to identify "functional chapters"—that is, chapters whose title text conforms to the semantics of functional design (e.g., "functional overview design," "functional design," etc.); merge the content before the functional chapter (e.g., introduction, general description) with the content after it and mark it as a context module. The context module is not generated separately by calling the large language model, but is provided as context for the generation of each functional module; and break down the subordinate content of the functional chapter along the title hierarchy to the smallest functional point to obtain a set of functional modules. Further, extract the mapping between functional names and functional codes from the functional list table existing in the functional chapter for subsequent generation and numbering.
[0032] The rules for determining functional chapters are as follows: if the title text matches preset functional semantic keywords (such as "functional design" or "functional overview design"), it is determined to be a functional chapter. Chapters that do not match the keywords are determined based on the title level and the functional list table. The rule for splitting the smallest functional point is as follows: split the functional chapter down the title level to the leaf functional title that does not contain the next level functional title, and take the content under that leaf functional title as the smallest functional point.
[0033] Step S3: Using a thread pool in batches and parallel processing, independently call the large language model for each functional module in the functional module set. In this embodiment, a fixed-size thread pool (e.g., 5) is used to sequentially batch the functional modules. The number of modules called concurrently in each batch does not exceed the thread pool size, and the batches proceed serially. Within each batch, the calls to each module are submitted as asynchronous tasks, and the asynchronous results are collected according to the index order of each functional module, thereby ensuring that the module order is consistent with the original text during final aggregation. For each functional module, its content is assembled with the summary of the context module into a prompt word, and then the large language model is called to generate the design content of that module.
[0034] The context module is first generated and compressed into a full-text summary, and then injected with prompts for each functional module in a fixed format. When the total length of the module content and the context summary exceeds the upper limit of the model context window, the module's own content is retained first, and then the context summary is progressively truncated according to the importance of the title, while retaining metadata such as document type and delivery specification identifier.
[0035] Furthermore, based on the pre-defined mapping relationship between modules and models, different functional modules are routed to different large language models. For example, the general function design module is routed to the first model, and the interface design module is routed to the second model, thus selecting the most suitable model according to the characteristics of the module.
[0036] Model routing dynamically determines the target model based on the module's functional type, complexity level, and the historical generation quality and availability status of candidate models. When the preferred model is unavailable or fails to be called, it is downgraded to a backup model according to the preset model priority list. Modules that fail and retry reuse the selected model and the generated context summary to avoid repeated routing decisions and context reconstruction overhead.
[0037] Step S4: Parse and aggregate the results returned by the large language model corresponding to each functional module. Since the output of the large language model may contain structured fields, this embodiment adopts multi-level fault-tolerant parsing: it attempts to parse standard objects sequentially; if it fails, it adopts fault-tolerant parsing for unescaped newlines and redundant wrapping symbols (for example, first remove code block wrapping symbols, then escape the newlines and re-parse); if it still fails, it adopts field extraction based on regular expressions. The process ends when any level of parsing is successful, thus restoring structured results even when the model output is non-standard. After successful parsing, the results of each module are aggregated by index, and the heading level (e.g., level 2, 3, or 4 headings) of each functional module in the final document is dynamically calculated according to its level in the original document to ensure that the hierarchical structure of the generated document is consistent with the original document.
[0038] The specific repair actions at each parsing level include: direct deserialization of standard objects; escaping unescaped newlines to visible escape characters before parsing; removing code block wrappers and redundant quotation marks and commas; and extracting key fields using regular expressions according to preset patterns. After parsing, the integrity of key fields such as function code, module name, and design content is checked. If any fields are missing or of incorrect type, parsing proceeds to the next level. Modules that ultimately fail are retried a preset number of times without affecting other successful modules.
[0039] The calculation rule for heading levels is as follows: the heading level of the functional chapter is used as the baseline, and each smallest functional point under it increases progressively. During aggregation, the heading tree is rebuilt according to the module index order, restoring the parent-child hierarchy between functional chapters and the smallest functional points. After reconstruction, the table of contents entries are regenerated, figures and tables are renumbered according to their order of appearance, and cross-references in the text are updated.
[0040] Step S5: The aggregated content is filled into the delivery template through a multi-layered cascading replacement of placeholders. This embodiment uses three layers of placeholders: the first layer is for prompt word template variable replacement, used to inject variables such as module content, module name, module path, and image references into the prompt word template before calling the large language model in step S3; the second layer is for document skeleton placeholder replacement, used to inject the content generated by the large language model (such as the design content of each module, revision table, purpose, background, function list, data flow design, error handling, deployment structure, etc.) into the overall skeleton template of the delivery document; the third layer is for layout style template replacement, used to apply the layout style of the target delivery specification in the format conversion stage of step S6. The target delivery specification identifier parameter runs through the above three layers, driving the selection of each layer's template.
[0041] The placeholder parsing engine supports conditional rendering, loop rendering, nested placeholders, and dependency resolution. Delivery specification identifier parameters are integrated throughout the selection process of prompt templates, document skeleton templates, and layout style templates. Each layer of templates is stored externally and supports hot reloading, retaining historical versions during loading and automatically reverting to the previous available version if a new version template fails.
[0042] Step S6: Convert the filled document content into a document with uniform formatting and output it. In this embodiment, a document conversion tool is used to convert markup language content into document format; during the conversion process, figures and tables are automatically numbered; and a pluggable filtering script is used to process image caption generation, font color preservation, and markup language / hypertext mixed content recognition; for sequence diagrams described in the form of code blocks (e.g., using declarative sequence diagram syntax), they are first rendered as images and then embedded into the document. The final output is a document with uniform formatting (e.g., a document format file), while a markup language version is retained for front-end preview.
[0043] The system is logically divided into: an access layer, providing document upload, generation triggering, and status query; a business layer, including a structure splitting module, a parallel generation module, and an aggregation and typesetting module; an engine layer, including core engines for document parsing, module splitting, hierarchical processing, parallel scheduling, result assembly, and format conversion; and an infrastructure layer, including a large language model adapter, document conversion tools, and file storage. Input requirement documents are parsed to obtain structured content and media resources. The structure splitting module outputs a set of context modules and functional modules, which are then generated in parallel by the parallel generation module (scheduled by the model routing module using a large language model). After parsing by the fault-tolerant parsing module, the aggregation and typesetting module applies a delivery template, and the format conversion module outputs the document. The entire process is tracked by the task and progress management module.
[0044] Example 2 As an optional implementation of Embodiment 1, this embodiment aims to illustrate the adaptability of the present invention to multiple delivery specifications, and specifically describes a placeholder cascading adaptation method for multiple delivery templates.
[0045] In this embodiment, the system drives template selection through a delivery specification identifier parameter (e.g., a value of "first specification" or "second specification") that runs through the entire process: when the prompt word template variable is replaced in step S3, the corresponding prompt word template text is selected according to the parameter; when the document skeleton placeholder is replaced in step S5, the corresponding skeleton template is selected according to the parameter; when the layout style is replaced in step S6, the corresponding layout style template is selected according to the parameter.
[0046] Since all three layers of templates are stored as external files and support hot reloading, when a new or modified delivery specification is needed, only the corresponding three-layer template files need to be added or modified, without modifying the generation engine code. This allows the same generation engine to adapt to the new delivery specification. This embodiment demonstrates the reusability of the present invention: "one engine, multiple specifications".
[0047] Example 3 As an optional implementation of Embodiment 1, this embodiment aims to illustrate the robustness guarantee of the present invention under the condition of unstable output of a large language model, and specifically describes a multi-level fault-tolerant parsing method.
[0048] In step S4 of Example 1, the result returned by the large language model may carry structured fields (such as basic information or chapter content) represented in object form. However, the model often exhibits the following non-standard situations in actual output: the result is wrapped by redundant code block symbols, string fields contain unescaped newlines, or some fields are missing. If only standard object parsing is used, any of these non-standard situations will cause the overall parsing to fail.
[0049] Therefore, this embodiment employs a three-level progressive fault-tolerant parsing: the first level is standard object parsing, directly parsing the returned result into the target object; if an exception is thrown, the second level of fault-tolerant parsing is initiated, first removing redundant code block wrapping symbols, then escaping newlines within string fields before re-parsing; if the second level still fails, the third level of regular expression extraction is initiated, using regular expressions to extract the required key fields from the returned result. The process ends and returns the result upon success at any level; only when all three levels fail is the module deemed to have failed and a retry triggered.
[0050] The intended effect of this embodiment is that it can still recover the structured result with a high probability when the model output format is unstable, significantly reducing the failure rate of the overall generation process.
[0051] Example 4 This embodiment aims to demonstrate the adaptability of the technical solution of the present invention to different document types and deployment environments, and specifically describes a lightweight generation scheme that is suitable for document types with relatively fixed fields (such as test reports).
[0052] For document types with relatively fixed fields and low content dynamism, this embodiment omits the parallel generation of the large language model in step S3 and instead uses a template placeholder direct filling method: prepare a layout style template containing placeholders in advance (for example, a document format template containing positions marked with placeholders such as titles, testers, and test case tables), and directly replace the determined field values with the corresponding placeholders during generation to obtain the final document.
[0053] In this lightweight solution, the parsing in step S1, the placeholder replacement in step S5, and the format conversion in step S6 are all retained, with direct filling replacing the generation from the large language model. The expected effect is that it generates document types with fixed fields at extremely low computational and time costs, enabling the technical solution of this invention to cover a variety of document types, from highly dynamic (relying on large language model generation) to highly fixed (template filling).
[0054] Those skilled in the art will understand that, in addition to implementing the system, apparatus, and their modules provided by this invention in purely computer-readable program code, the same program can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, the system, apparatus, and their modules provided by this invention can be considered a hardware component, and the modules included therein for implementing various programs can also be considered structures within the hardware component; alternatively, modules for implementing various functions can be considered both software programs implementing the method and structures within the hardware component.
[0055] Specific embodiments of the present invention have been described above. It should be understood that the present invention is not limited to the specific embodiments described above, and those skilled in the art can make various changes or modifications within the scope of the claims, which do not affect the essence of the present invention. Unless otherwise specified, the embodiments and features described in this application can be arbitrarily combined with each other.
Claims
1. A software design document generation method based on document structure decomposition and parallel generation, characterized in that, This method is executed by a computer device and includes: Step S1: Receive the input requirement document, parse it into structured content, and extract the media resources from the requirement document; Step S2: Construct a structure tree according to the title hierarchy of the structured content, identify the functional chapters, mark the content before and after the functional chapters as context modules, and break down the subordinate content of the functional chapters to the smallest functional points to obtain a set of functional modules; Step S3: Using a thread pool to batch and parallelize, each functional module in the functional module set is independently called to the large language model to generate the design content of each functional module. According to the preset mapping relationship between modules and models, different functional modules are routed to different large language models for invocation. Step S4: Parse and aggregate the results returned by the large language model corresponding to each functional module, including performing multi-level fault-tolerant parsing on the structured results returned by the large language model, and dynamically calculating the heading level of each functional module in the final document according to the index of each functional module. Step S5: The aggregated content is filled into the delivery template through multi-layer placeholder cascading replacement to obtain document content that conforms to the target delivery specifications. The multi-layer placeholder cascading replacement includes prompt word template variable replacement, document skeleton placeholder replacement, and layout style template replacement. Step S6: Convert the document content into a document with uniform formatting and output it.
2. The software design document generation method based on document structure decomposition and parallel generation according to claim 1, characterized in that, In step S1, the requirement document is in DOC / DOCX format, portable document format PDF, plain text, or markup language format; a document conversion tool is called to parse the requirement document into structured content, which is markup language text; and at the same time, media resources in the requirement document are extracted to an independent directory and referenced in the structured content with relative paths.
3. The software design document generation method based on document structure decomposition and parallel generation according to claim 2, characterized in that, In step S2, identifying functional chapters includes: traversing the structure tree and determining the chapters where the title text matches preset functional design semantic keywords as functional chapters; merging and marking the content before and after the functional chapter as context modules, where the context modules are not generated separately by calling the large language model, but are provided as context for the generation of each functional module; and splitting the subordinate content of the functional chapter down the title level to the smallest functional point to obtain a set of functional modules; the splitting rule of the smallest functional point is: splitting down the functional chapter down the title level to the leaf functional title that does not contain the next level functional title, and taking the content under its jurisdiction as a smallest functional point; and also includes extracting the mapping between functional names and functional codes from the functional list table within the functional chapter.
4. The software design document generation method based on document structure decomposition and parallel generation according to claim 3, characterized in that, The rules for determining functional chapters are as follows: chapters whose title text matches preset functional semantic keywords are determined to be functional chapters; for chapters that do not match the keywords, whether they are functional chapters is determined by the title level and the functional list table.
5. The software design document generation method based on document structure decomposition and parallel generation according to claim 4, characterized in that, In step S3, a fixed-size thread pool is used to process the set of functional modules in batches. The number of modules that concurrently call the large language model in each batch does not exceed the size of the thread pool, and the process proceeds serially between batches. Within each batch, the calls to each module are submitted as asynchronous tasks, and the asynchronous results are collected in the index order of each functional module. For each functional module, its content is assembled with the summary of the context module into prompt words, and then the large language model is called to generate the design content of the module. The context module is first generated and compressed in full text, and then injected into the prompt words of each functional module in a fixed format. When the total length of the module content and the context summary exceeds the upper limit of the model context window, the module content itself is retained first, and then the context summary is progressively truncated according to the importance of the title, while retaining the document type and delivery specification identifier metadata.
6. The software design document generation method based on document structure decomposition and parallel generation according to claim 5, characterized in that, In step S3, the mapping relationship uses the function code as the key index to correspond to the large language model configuration, which includes the access address, credentials, and model name. Based on the mapping relationship, the model routing dynamically adjusts the target model according to the module function type, complexity level, and the historical generation quality and availability status of candidate models. When the preferred model is unavailable or fails to be called, it is downgraded to a backup model according to the preset model priority list. Modules that fail and retry reuse the selected model and the generated context summary.
7. The software design document generation method based on document structure decomposition and parallel generation according to claim 6, characterized in that, In step S4, the multi-level fault-tolerant parsing includes: attempting standard object parsing sequentially; if it fails, using fault-tolerant parsing for unescaped newlines and redundant enclosing characters; if it still fails, using field extraction based on regular expressions; the process ends upon success of any level of parsing; specific repair actions at each level of parsing include: direct deserialization of standard object parsing; escaping unescaped newlines to visible escape characters before parsing; removing code block enclosing characters and redundant quotation marks and commas for redundant enclosing characters; extracting key fields using regular expression extraction according to a preset pattern; and decryption. After analysis, the integrity of key fields such as function codes, module names, and design content is checked. If any fields are missing or the types are inconsistent, the analysis proceeds to the next level. For modules that fail to be analyzed at any level, the large language model is called again and the analysis is retried. The calculation rule for the title level is as follows: the title level of the functional chapter is used as the basis, and each minimum functional point under it increases progressively. During aggregation, the title tree is rebuilt according to the module index order to restore the parent-child hierarchy between functional chapters and minimum functional points. After reconstruction, the table of contents entries are regenerated, and the figures and tables are renumbered according to their order of appearance and the cross-references in the text are updated.
8. The software design document generation method based on document structure decomposition and parallel generation according to claim 7, characterized in that, In step S5, the multi-layered placeholder cascading replacement includes three layers: the first layer is prompt word template variable replacement, which injects module content, module name, and image references into prompt words before calling the large language model; the second layer is document skeleton placeholder replacement, which injects the content generated by the large language model into the overall skeleton of the delivered document; the third layer is layout style template replacement, which applies the layout style of the target delivery specification during the format conversion stage; the target delivery specification includes a first delivery specification and a second delivery specification, which differ in chapter structure, table column definition, and terminology specification. The selection of the prompt word template, document skeleton, and layout style template is driven by the delivery specification identification parameters throughout the entire process; The placeholder parsing engine supports conditional rendering, loop rendering, nested placeholders, and dependency resolution; each layer of templates is stored externally and supports hot reloading, retaining historical versions during loading, and automatically reverting to the previous available version when a new version template is faulty; In step S6, the document content is converted into a document format using a document conversion tool; during the conversion process, figures and tables are automatically numbered; and image captions, font colors, and mixed content recognition are processed using a pluggable filtering script; for sequence diagrams described in the form of code blocks, they are first rendered as images and then embedded. Also, keep a markup language version for front-end preview.
9. A software design document generation device, characterized in that, The software design document generation method based on document structure decomposition and parallel generation according to any one of claims 1 to 8 includes: The document parsing module receives the requirement document as its input and connects to the input of the structure splitting module as its output. It parses the input requirement document into structured content and extracts media resources. The structure splitting module connects its input to the output of the document parsing module and its output to the input of the parallel generation module. It constructs a structure tree according to the heading level, identifies functional chapters, marks context modules, and splits the content under each functional chapter to the smallest functional point to obtain a set of functional modules. The parallel generation module connects its input to the output of the structure splitting module and its output to the input of the fault-tolerant parsing module. It uses a thread pool to call the large language model independently to generate design content for each functional module in batches and in parallel. The model routing module connects to the parallel generation module and routes different functional modules to different large language models based on the mapping relationship between modules and models. The fault-tolerant parsing module has its input connected to the output of the parallel generation module and its output connected to the input of the aggregation typesetting module. It performs multi-level fault-tolerant parsing on the structured results returned by the large language model. The aggregation typesetting module connects its input to the output of the fault tolerance parsing module and its output to the input of the format conversion module. It parses and aggregates the results of each module, dynamically calculates the title level, and delivers the template by replacing and filling multiple layers of placeholders. The format conversion module connects its input end to the output end of the aggregated typesetting module, converting the content output by the aggregated typesetting module into a document with uniform typesetting. The task and progress management module connects with the document parsing module, structure splitting module, parallel generation module, and aggregated typesetting module. It records document type, source file, delivery specification identifier, and status as task entities, with status transitioning between not started, generating, completed, and failed. The generation process is executed asynchronously in a background thread and returns the task identifier in real time. It maintains real-time progress in memory, including the total number of modules, the number of completed modules, and the current module name, for front-end polling. When a generating task has no progress update within a preset time, it is automatically marked as failed. Failed tasks are re-executed based on the original source file.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the software design document generation method based on document structure splitting and parallel generation as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Design document generation method and device, computer equipment and storage medium
CN114139494A
