Document generation method and device based on structured analysis, equipment and medium
By preprocessing the official document outline and matching multi-mode regular expressions, constructing a document node tree, and generating standardized official documents, the problem of format confusion in official document generation is solved, and the format consistency and hierarchical logic accuracy of the official document are achieved.
Patent Information
- Application Number
- CN202511222377.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-29
- Publication Date
- 2025-09-26
AI Technical Summary
The existing document generation method based on structured parsing has the problems of chaotic format, discontinuity of title and sequence numbers, and non-standard format.
By preprocessing the official document outline, the multi-level title structure is determined using a multi-mode regular expression matching algorithm, a document node tree is constructed, and official document fragments are generated based on the node tree and integrated into a standardized official document.
Ensure the standardization of official document formats, avoid confusion in paragraph titles, and improve the hierarchical logical consistency and format accuracy of official document generation.
Smart Images

Figure CN120706381A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a method, device, equipment and medium for generating official documents based on structured analysis. Background Art
[0002] Official documents are legally binding, standardized documents produced by administrative agencies during the course of administration. They are crucial tools for lawful administration and official activities. They typically have strict requirements regarding the format of the document.
[0003] Current methods for generating official documents based on structured parsing rely on AI models to directly output complete document text. However, this approach can lead to disjointed titles and numbers, as well as confusing formatting. Therefore, improving the standardization of generated documents remains a technical challenge. Summary of the Invention
[0004] In view of this, the present invention aims to provide a method, apparatus, device, and medium for generating official documents based on structured parsing. This method generates a document node tree based on each title level, and then sequentially generates official document segments based on the document node tree, thereby ensuring the format standardization of the official document. The specific solution is as follows:
[0005] In a first aspect, the present application provides a method for generating official documents based on structured parsing, which is applied to a preset official document generator, comprising:
[0006] Obtain the initial document outline input by the target user through the preset information input interface;
[0007] Based on a pre-configured preprocessing program corresponding to the non-text format data, preprocessing the target non-text data in the initial official document outline to obtain a corresponding pre-processed official document outline;
[0008] The pre-processed official document outline is processed using a multi-mode regular expression matching algorithm to determine a target multi-level title structure corresponding to the pre-processed official document outline; the target multi-level title structure includes title levels corresponding to each text segment in the pre-processed official document outline;
[0009] Constructing a corresponding target document node tree based on the target multi-level title structure; different document nodes in the target document node tree correspond to different text segments;
[0010] Based on a preset official document generation interface, official document segments corresponding to each of the text segments are generated, and based on the hierarchical relationship between the document nodes in the target document node tree, the official document segments are integrated accordingly to generate a corresponding target official document.
[0011] Optionally, the preprocessing operation on the target non-text data in the initial document outline based on a pre-configured preprocessing program corresponding to the non-text format data includes:
[0012] Utilizing the preprocessing program to count the punctuation marks in the initial document outline, constructing a target character mapping table based on the corresponding statistical results, and unifying the types of the punctuation marks in the initial document outline based on the target character mapping table; wherein the target character mapping table includes a mapping relationship between a full-width mode and a half-width mode corresponding to each punctuation mark;
[0013] The pre-processing program is used to merge consecutive spaces in the initial document outline and to delete line breaks in the initial document outline.
[0014] Optionally, the pre-processed document outline is processed using a multi-mode regular expression matching algorithm to determine a target multi-level title structure corresponding to the pre-processed document outline, including:
[0015] Calling a preset regular expression pattern library; wherein the preset regular expression pattern library includes title patterns corresponding to different title levels;
[0016] The multi-mode regular expression matching algorithm is used to match each text segment in the pre-processed official document outline with each title pattern in the preset regular expression pattern library in turn to determine the target multi-level title structure corresponding to the pre-processed official document outline.
[0017] Optionally, constructing a corresponding target document node tree based on the target multi-level title structure includes:
[0018] Based on the title levels corresponding to the text segments and a preset encoding algorithm, the title codes corresponding to the text segments are generated, and the target document node tree is constructed according to the title codes; wherein the title codes are composed of several two-digit character strings.
[0019] Optionally, generating the title codes corresponding to the text segments based on the title levels corresponding to the text segments and a preset coding algorithm includes:
[0020] generating a current title code corresponding to the current text segment based on the title level corresponding to the current text segment, and determining whether the current title code is the same as any previously generated historical title code;
[0021] If the current title code is different from any of the historical title codes, a new text segment is obtained, the new text segment is determined as the current text segment, and the process jumps to the step of generating a current title code corresponding to the current text segment based on the title level corresponding to the current text segment;
[0022] If the current title code is the same as any historical title code, an alarm message corresponding to the current title code is generated.
[0023] Optionally, generating the official document segments corresponding to the respective text segments based on a preset official document generation interface includes:
[0024] Obtaining the first-level title and the generated historical document fragments corresponding to the current text segment, calling the preset document generation interface based on the title code corresponding to the current text segment, and generating the document fragment corresponding to the current text segment using the preset document generation interface, the first-level title, and the historical document fragments;
[0025] A new text segment is determined according to each of the title codes, the new text segment is determined as the current text segment, and the process jumps to the step of obtaining the first-level title corresponding to the current text segment and the generated historical document fragment.
[0026] In a second aspect, the present application provides a document generation device based on structured parsing, which is applied to a preset document generator, including:
[0027] The outline acquisition module is used to obtain the initial document outline input by the target user through the preset information input interface;
[0028] a data preprocessing module, configured to perform a preprocessing operation on the target non-text data in the initial document outline based on a pre-configured preprocessing program corresponding to the non-text format data, so as to obtain a corresponding pre-processed document outline;
[0029] a title structure determination module for processing the pre-processed official document outline using a multi-mode regular expression matching algorithm to determine a target multi-level title structure corresponding to the pre-processed official document outline; the target multi-level title structure includes title levels corresponding to each text segment in the pre-processed official document outline;
[0030] A node tree construction module is used to construct a corresponding target document node tree based on the target multi-level title structure; different document nodes in the target document node tree correspond to different text segments;
[0031] The official document generation module is used to generate official document fragments corresponding to each of the text segments based on a preset official document generation interface, and to integrate each of the official document fragments accordingly based on the hierarchical relationship between each of the document nodes in the target document node tree to generate a corresponding target official document.
[0032] Optionally, the data preprocessing module includes:
[0033] a symbol unification unit, configured to use the preprocessing program to count the punctuation marks in the initial document outline, construct a target character mapping table based on the corresponding statistical results, and unify the types of the punctuation marks in the initial document outline based on the target character mapping table; wherein the target character mapping table includes a mapping relationship between the full-width mode and the half-width mode corresponding to each punctuation mark;
[0034] The line break deleting unit is used to merge the continuous spaces in the initial document outline by using the preprocessing program and delete the line breaks in the initial document outline.
[0035] In a third aspect, the present application provides an electronic device, comprising:
[0036] Memory, used to store computer programs;
[0037] A processor is used to execute the computer program to implement the aforementioned document generation method based on structured parsing.
[0038] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program, which, when executed by a processor, implements the aforementioned method for generating official documents based on structured parsing.
[0039] This application first obtains the initial official document outline input by the target user through a preset information input interface, and then preprocesses the target non-text data in the initial official document outline based on a pre-configured preprocessing program corresponding to the non-text format data to obtain the corresponding preprocessed official document outline, and then uses a multi-mode regular expression matching algorithm to process the preprocessed official document outline to determine the target multi-level title structure corresponding to the preprocessed official document outline; the target multi-level title structure includes the title levels corresponding to each text segment in the preprocessed official document outline, and then constructs a corresponding target document node tree based on the target multi-level title structure; different document nodes of the target document node tree correspond to different text segments, and finally, based on the preset official document generation interface, official document fragments corresponding to each text segment are generated, and based on the hierarchical relationship between each document node in the target document node tree, each official document fragment is integrated accordingly to generate the corresponding target official document.
[0040] It can be seen that this application ensures the format standardization of the pre-processed official document outline by performing pre-processing operations on the initial official document outline, thereby ensuring the reliability of the title levels corresponding to each text segment obtained; by generating a document node tree based on each title level, and splicing the generated official document fragments in sequence according to the document node data, and finally integrating them to obtain the official document, it avoids the problem of confusion in the paragraph titles in the generated official document and ensures the format standardization of the official document. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0042] Figure 1 This is a flow chart of a method for generating official documents based on structured analysis disclosed in this application;
[0043] Figure 2 This is a flowchart of a method for generating official documents based on structured analysis disclosed in this application;
[0044] Figure 3 A paragraph level division flow chart disclosed in this application;
[0045] Figure 4 This is a schematic diagram of the structure of a document generation device based on structured analysis disclosed in this application;
[0046] Figure 5 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION
[0047] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0048] The current official document generation method has the problem of chaotic format of the generated official documents. To this end, the present application provides an official document generation method based on structured parsing, which ensures the format standardization of the official document by generating a document node tree based on each title level and generating official document fragments in sequence based on the document node tree.
[0049] See also Figure 1As shown in the figure, an official document generation method based on structured parsing is disclosed in an embodiment of the present invention, which is applied to a preset official document generator and includes:
[0050] Step S11: Obtain an initial official document outline input by a target user through a preset information input interface.
[0051] The purpose of this embodiment is to solve the technical problems of poor format standardization, chaotic hierarchical logic, and high manual proofreading costs in the existing automatic official document generation technology. For example: high fault rate of title numbering (such as directly jumping from "I." to "III."), mixed use of Chinese and Western numbering (such as incorrect nesting of "(I)." and "1."), non-standard digital writing (such as miswriting "12 items" as "twelve items"), etc. Specifically, this embodiment proposes a title level parsing algorithm based on compound regular matching, which supports automatic recognition and classification of 15 numbering variants such as "I.", "(I)", "1.", etc., to solve the format error problem caused by insufficient numbering coverage of traditional methods.
[0052] Design a cross-paragraph dynamic counter array, and eliminate the defects of serial number jumps and repetitions caused by segmented generation by synchronizing the status of serial numbers at each level in real time (such as a secondary title automatically inheriting the counting benchmark of a primary title);
[0053] Integrate a Chinese digital intelligent conversion engine to accurately process complex conversion scenarios such as "1 → one" and "(11) → (eleven)" according to the GB / T 9704-2012 standard;
[0054] Establish a title depth self-adaptation mechanism to automatically detect and limit the title level not to exceed the specified 4-level depth.
[0055] The overall process in this embodiment is as Figure 2 shown. Obtain the outline text, process the outline text, divide the code, and generate an official document based on the processed data. The general process of the data division step is as Figure 3 shown. After inputting the outline text data, divide the outline text data to obtain a hierarchy and an outline array; the above process depends on the division algorithm and finally returns the outline array.
[0056] In this embodiment, it is first necessary to obtain an initial official document outline by using a preset information input interface. It can be understood that the official document outline is a guiding document for generating an official document, and the official document outline includes the skeleton structure in the official document. For example, the paragraph numbers, paragraph names of each paragraph, and summary descriptions of the key parts in the official document, such as the outline: I. Clarify the background and purpose of the notice release, (I) Explain the purpose of the notice, 1. Determine the activity objectives to ensure consistency in direction, (II) Explain the basis of the notice in detail, 1. Ensure compliance according to relevant regulations, II. Describe the specific content and arrangements of the notice.
[0057] Step S12: Based on a pre-configured pre-processing program corresponding to non-text format data, a pre-processing operation is performed on the target non-text data in the initial official document outline to obtain a corresponding pre-processed official document outline.
[0058] It is understandable that the initial document outline obtained in this embodiment may have data format issues that are not standardized. These format issues will affect the accuracy of the subsequent title level division, so in this embodiment, the initial document outline needs to be preprocessed.
[0059] The process of performing preprocessing operations on target non-text data in an initial official document outline based on a pre-configured preprocessing program corresponding to non-text format data may specifically include: using the preprocessing program to count the punctuation marks in the initial official document outline, constructing a target character mapping table based on the corresponding statistical results, and unifying the types of punctuation marks in the initial official document outline based on the target character mapping table; wherein the target character mapping table includes the mapping relationship between the full-width mode and the half-width mode corresponding to each punctuation mark; using the preprocessing program to merge consecutive spaces in the initial official document outline, and deleting line breaks in the initial official document outline.
[0060] Specifically, preprocessing is performed before parsing the original text:
[0061] Full-width character standardization: Use a regular expression global replacement strategy: text.replace( / [\(\)\[\]【】] / g, m => {const fullMap = { '(': '(', ')': ')', '[': '〔', ']': '〕'};returnfullMap[m] || m;}); The processing scope covers 15 types of punctuation marks such as brackets and quotation marks. A Unicode character map (i.e., target character map) is established to achieve two-way conversion, ensuring a uniformity rate of full-width and half-width symbols of no less than 99.8%.
[0062] Optimize whitespace processing: implement multi-level merging strategy: merge consecutive spaces: text.replace( / [ \t]+ / g,' '); replace tab characters: text.replace( / \t / g, ' '); delete newline characters: text.replace( / \r?\n / g,''); head and tail purification: text.trim().replace( / ^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$ / g, '').
[0063] By performing operations such as unifying the punctuation marks in the initial official document outline, deleting consecutive spaces, and deleting line breaks, the format standardization of the official document outline is improved, thereby enhancing the accuracy of hierarchical division of the official document outline.
[0064] Step S13: Process the preprocessed official document outline using a multi-pattern regular expression matching algorithm to determine the target multi-level heading structure corresponding to the preprocessed official document outline; the target multi-level heading structure includes the heading levels corresponding to each text segment in the preprocessed official document outline.
[0065] In this embodiment, the process of using a multi-pattern regular expression matching algorithm to process the preprocessed official document outline to determine the target multi-level heading structure corresponding to the preprocessed official document outline may specifically include: calling a preset regular expression pattern library; where the preset regular expression pattern library includes heading patterns corresponding to different heading levels; using the multi-pattern regular expression matching algorithm to sequentially match each text segment in the preprocessed official document outline with each heading pattern in the preset regular expression pattern library to determine the target multi-level heading structure corresponding to the preprocessed official document outline.
[0066] It should be noted that for the first four levels of the standard official document serial numbers, the following should be used in sequence: "one", " (one)", " 1.", "(1)". If it exceeds the current level, it is regarded as the main text.
[0067] The above process of determining the heading structure is as follows: Define the matching level, and regard it as the main text if it is outside this. Establish an identification matrix (i.e., the preset regular expression pattern library) containing 9 types of heading patterns:
[0068] const titlePatterns =
[0069] { regex: / ^[\u4e00-\u9fa5]+、 / ,level: 1}, / / Chinese semicolon heading (one,);
[0070] { regex: / ^[\u4e00-\u9fa5]+\. / , level: 1}, / / Chinese dot heading (one.);
[0071] { regex: / ^([\u4e00-\u9fa5]+) / , level: 2}, / / Second-level parenthesis heading ((one));
[0072] { regex: / ^\d+、 / ,level: 3}, / / Digital semicolon heading (1,);
[0073] { regex: / ^\d+\. / , level: 3}, / / Number dot title (1.);
[0074] { regex: / ^(\d+) / ,level: 4}, / / Level 4 bracket title ((1));
[0075] { regex: / ^-+ / ,level: 0} / / Unordered list item; ];
[0077] The parsing process uses a priority matching mechanism to automatically handle abnormal situations such as title level jumps (such as going directly from level 1 to level 3). The core method is as follows:
[0078] function parseTitle(content) {for (const pattern of titlePatterns) {const match = content.match(pattern.regex); if (match) {const splitIndex =match[0].length;return {level: pattern.level, value: content.substring(splitIndex).trim()};}} return { level: -1, value: content}; / / Untitled paragraph}.
[0079] It should be noted that this embodiment also configures a Chinese number conversion rule engine, which can realize digit reversal: starting from the ones place and processing step by step; zero value suppression: avoiding the appearance of redundant "zeros"; unit binding: dynamically adding tens / hundreds / thousands; special case optimization: handling Chinese habits such as the omission of "one ten"; boundary cleaning: special handling of the first and last zero values.
[0080] The specific code implementation of the engine is as follows:
[0081] numToChineseNum(num) {
[0082] const chineseNums = [
[0083] "Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine", ];
[0085] const units = ["", "Ten", "Hundred", "Thousand"]; / / Temporarily only processes thousands, but the logic can be extended to larger units;
[0086] let str = "";
[0087] let needZero = false; / / Mark whether "zero" needs to be added (but usually we only add it after non-zero numbers);
[0088] let lastWasZero = false; / / Mark whether the last number is zero;
[0089] if (num === 0) {
[0090] return chineseNums[0];
[0091] }
[0092] const digits = num.toString().split("").reverse();
[0093] for (let i = 0; i < digits.length; i++) {
[0094] const digit = parseInt(digits[i], 10);
[0095] const unit = units[i % 4] || ""; / / Loop through the unit array;
[0096] if (digit === 0) {
[0097] if (!str || (str[str.length - 1] !== chineseNums[0] && !lastWasZero)) {
[0098] / / Only add "zero" after a non-zero number if the current number is not a consecutive zero;
[0099] str = chineseNums[0] + str;
[0100] lastWasZero = true;
[0101] }
[0102] } else {
[0103] if (unit === "ten" && i + 1 < digits.length && digits[i + 1] !== "0") {
[0104] / / If the current is "ten" and the next is not zero, there is no need to add "one";
[0105] / / But if a unit has been added before (such as hundred, thousand), "one" still needs to be added;
[0106] if (
[0107] !str ||
[0108] str[str.length - 1]!== units[Math.floor((i - 1) / 4) * 4 + 1]
[0109] ) {
[0110] str = chineseNums[1] + str; / / Only add "one" when needed;
[0111] }
[0112] } else {
[0113] str = chineseNums[digit] + unit + str;
[0114] }
[0115] needZero = true; / / Reset needZero because a non - zero digit has been added;
[0116] lastWasZero = false;
[0117] }
[0118] }
[0119] / / Remove trailing "zero" (but keep one if it's the only digit);
[0120] str = str.replace( / zero+$ / , "");
[0121] if (str.endsWith(chineseNums[0])) {
[0122] str += " whole"; / / If the end is "zero", add "whole" (optional);
[0123] }
[0124] / / Remove "one ten" at the beginning (if any);
[0125] if (str.startsWith(chineseNums[1] + units[1])) {
[0126] str = str.slice(1);
[0127] }
[0128] return str;
[0129] }
[0130] The following effects can be achieved through this engine:
[0131] 1. Zero value processing rules:
[0132] Do not add duplicate zeros: Skip when the previous digit is already zero (to avoid "one hundred and zero zero three");
[0133] Do not prefix zeros: Do not add when the first digit is zero (e.g., 0123 → "one hundred and twenty-three");
[0134] Do not suffix zeros: Uniformly clear trailing zeros later (e.g., 100 → "one hundred" instead of "one hundred and zero").
[0135] 2. "One ten" omission rules:
[0136] Scenario 1: The tens digit is 1 and there is no higher digit → Omit one (12 → "twelve");
[0137] Scenario 2: The tens digit is 1 but there is a higher digit → Retain one (112 → "one hundred and twelve");
[0138] Scenario 3: The tens digit is not 1 → Concatenate normally (25 → "twenty-five").
[0139] 3. End cleaning rules:
[0140] 100 → "one hundred" (not "one hundred and zero");
[0141] 10 → "ten" (not "one ten");
[0142] 1000 → "one thousand" (not "one thousand and zero zero zero").
[0143] By using the conversion engine to generate the labels of the title, the standardization of the title labels is further ensured. [[ID=6�]]
[0144] Step S14: constructing a corresponding target document node tree based on the target multi-level title structure; different document nodes in the target document node tree correspond to different text segments.
[0145] In this embodiment, the process of constructing a corresponding target document node tree based on the target multi-level title structure can specifically include: generating title codes corresponding to each text segment based on the title level corresponding to each text segment and a preset encoding algorithm, and constructing a target document node tree according to each title code; wherein the title code consists of several two-digit character strings.
[0146] Specifically, this embodiment uses a five-level counter array to maintain the generation state. For example, the first-level title is 0100000000, the first text under the first-level title is 0100000001, and so on. The simplified code (i.e., the preset encoding algorithm) is as follows:
[0147] let counts = [0, 0, 0, 0, 0];
[0148] / / Corresponding to level 1-5 titles function updateCounters(currentLevel)
[0149] {const levelIndex = currentLevel - 1;counts[levelIndex]++;
[0150] / / Reset the lower level counter
[0151] for (let i = levelIndex+1; i < counts.length; i++) { counts[i] = 0}};
[0152] State maintenance algorithm:
[0153] class StateEncoder {
[0154] constructor() {
[0155] this.counters = Array(6).fill(0); / / Supports level 1-5 titles;
[0156] this.parentStack = [];
[0157] }
[0158] update(currentLevel) {
[0159] if (currentLevel <= 0) return;
[0160] const levelIndex = currentLevel - 1;
[0161] this.counters[levelIndex]++;
[0162] / / Reset the lower level counter;
[0163] for (let i = levelIndex + 1; i < 5; i++) {
[0164] this.counters[i] = 0;
[0165] }
[0166] / / Maintain parent stack;
[0167] this.parentStack = this.parentStack.slice(0, levelIndex);
[0168] this.parentStack.push(this.counters[levelIndex]);
[0169] }
[0170] get code() {
[0171] return this.parentStack.join('-').padEnd(9, '0');
[0172] }
[0173] }
[0174] For example, the outline: 1. Clarify the background and purpose of the notification (I) Explain the purpose of the notification 1. Determine the activity goals and ensure consistency in direction (II) Explain in detail the basis of the notification 1. Based on laws and regulations, ensure compliance and legality 2. Detail the specific content and arrangements of the notification.
[0175] After conversion, you will get data like this:
[0176] {outline: "According to work arrangements, the following matters are hereby notified: To ensure accurate information transmission, we hereby issue a notice on a certain topic, clearly stating the purpose, time, location, and participants.", code: "0000000001",…};
[0177] {outline: "1. Clarify the background and purpose of the notice", code: "0100000000"};
[0178] {outline: "(1) Clarification of the purpose of the notification", code: "0101000000"}; ...
[0180] {outline: "(II) Detailed explanation of the basis for the notification", code: "0102000000"};
[0181] It should be noted that this embodiment is also equipped with an error checking mechanism that can identify the generated erroneous titles. Accordingly, the process of generating the title codes corresponding to each text segment based on the title level corresponding to each text segment and the preset coding algorithm can specifically include: generating the current title code corresponding to the current text segment based on the title level corresponding to the current text segment, and judging whether the current title code is the same as any historical title code that has been generated; if the current title code is different from any historical title code, obtaining a new text segment, determining the new text segment as the current text segment, and jumping to the step of generating the current title code corresponding to the current text segment based on the title level corresponding to the current text segment; if the current title code is the same as any historical title code, generating an alarm message corresponding to the current title code.
[0182] Specifically, title conflict detection: When duplicate titles are detected at the same level, the verification process is automatically triggered:
[0183] function checkTitleDuplication(titles) {const titleMap = new Map();titles.forEach((t, i) => {const key = `${t.level}-${t.value}`;if(titleMap.has(key)) {console.error(`Duplicate title: Section ${i+1}"${t.value}"`);t.value += `(${chineseNums[titleMap.get(key)+1]})`;}titleMap.set(key,(titleMap.get(key) || 0) + 1);});
[0184] Code uniqueness check: Since the code and title are unique, the backend will make a judgment based on the current code and the generated code. If there is an exception, an error will be thrown.
[0185] By verifying the generated title hierarchy, it is determined that there is no duplicate data in each title, thus ensuring the reliability of the generated document format.
[0186] Step S15: Generate official document segments corresponding to the text segments based on a preset official document generation interface, and integrate the official document segments accordingly based on the hierarchical relationship between the document nodes in the target document node tree to generate a corresponding target official document.
[0187] In this embodiment, the process of generating official document fragments corresponding to each text segment based on the preset official document generation interface can specifically include: obtaining the first-level title corresponding to the current text segment and the generated historical official document fragments, calling the preset official document generation interface based on the title code corresponding to the current text segment, and using the preset official document generation interface, the first-level title and the historical official document fragments to generate the official document fragment corresponding to the current text segment; determining a new text segment according to each title code, determining the new text segment as the current text segment, and jumping to the step of obtaining the first-level title corresponding to the current text segment and the generated historical official document fragments.
[0188] Specifically, based on the obtained title array, the interface (i.e., the preset document generation interface) is called in sequence to generate content: each call carries complete context information. For example, if a sendData array is obtained:
[0189] sendData.value.push({ type: 'Work report', context: '', wordCount: 0, requirement: '', keywordList: [], subTitle: 'Order', firstTitle: 'Order', materialReference: [], / / basicMessageid: wsId, releaseTime:documentInfo.releaseTime, title: documentInfo.title, location:documentInfo.location,});
[0190] When passing parameters, you can add the first-level title firstTitle (that is, the first-level title corresponding to the current text segment), the generated original context (that is, the historical document fragment), reference materials, and other information to ensure that the backend can obtain as much original information as possible during processing to meet business needs.
[0191] The document generation method in this embodiment has the following effects:
[0192] (1)Hierarchical limit exceeded: Automatically convert to unnumbered paragraphs when exceeding 4 levels;
[0193] (2)Label conflict: Append secondary numbers when repeating labels (e.g., "one-1");
[0194] (3)Code tracking: Through a 10-digit code, ensure the accuracy of the outline level. Even if the interface call is abnormal, the progress can be judged through the current code and generation can continue to meet the business requirements.
[0195] Government affairs standardization: For the five-level title division of national standards, support the mixed parsing of 7 types of label formats.
[0196] Zero-dependency front-end architecture: Implemented in pure JavaScript, without relying on third-party libraries; the status object is serializable and compatible with any back-end interface.
[0197] It can be seen that through the preprocessing operation on the initial official document outline, the format standardization of the preprocessed official document outline after processing is ensured, and further the reliability of the title levels corresponding to each text segment obtained is ensured; by generating a document node tree based on each title level and splicing the generated official document fragments in sequence according to the document node data, and finally integrating to obtain the official document, the problem of chaotic paragraph titles in the generated official document is avoided, and the format standardization of the official document is ensured.
[0198] See Figure 4 As shown, an official document generation device based on structured parsing disclosed in an embodiment of the present invention is applied to a preset official document generator, and includes:
[0199] An outline acquisition module 11, configured to obtain an initial official document outline input by a target user through a preset information input interface;
[0200] [[ID=#26]]A data preprocessing module 12, configured to perform a preprocessing operation on target non-text data in the initial official document outline based on a preconfigured preprocessing program corresponding to non-text format data, so as to obtain a corresponding preprocessed official document outline;
[0201] A title structure determination module 13, configured to process the preprocessed official document outline by using a multi-mode regular expression matching algorithm to determine a target multi-level title structure corresponding to the preprocessed official document outline; the target multi-level title structure includes the title levels corresponding to each text segment in the preprocessed official document outline;
[0202] A node tree construction module 14, configured to construct a corresponding target document node tree based on the target multi-level title structure; different document nodes of the target document node tree correspond to different text segments; [[ID=#33]]
[0203] The official document generation module 15 is used to generate official document segments corresponding to each of the text segments based on a preset official document generation interface, and to integrate each of the official document segments based on the hierarchical relationship between the document nodes in the target document node tree to generate a corresponding target official document.
[0204] In some specific embodiments, the data preprocessing module 12 may specifically include:
[0205] a symbol unification unit, configured to use the preprocessing program to count the punctuation marks in the initial document outline, construct a target character mapping table based on the corresponding statistical results, and unify the types of the punctuation marks in the initial document outline based on the target character mapping table; wherein the target character mapping table includes a mapping relationship between the full-width mode and the half-width mode corresponding to each punctuation mark;
[0206] The line break deleting unit is used to merge the continuous spaces in the initial document outline by using the preprocessing program and delete the line breaks in the initial document outline.
[0207] In some specific embodiments, the title structure determination module 13 may specifically include:
[0208] A pattern library calling unit, configured to call a preset regular expression pattern library; wherein the preset regular expression pattern library includes title patterns corresponding to different title levels;
[0209] The text segment matching unit is used to use the multi-mode regular expression matching algorithm to match each text segment in the pre-processed official document outline with each title pattern in the preset regular expression pattern library in turn to determine the target multi-level title structure corresponding to the pre-processed official document outline.
[0210] In some specific embodiments, the node tree construction module 14 may specifically include:
[0211] The node tree construction submodule is used to generate the title codes corresponding to each of the text segments based on the title levels corresponding to each of the text segments and a preset coding algorithm, and construct the target document node tree according to each of the title codes; wherein the title codes are composed of several two-digit character strings.
[0212] In some specific embodiments, the node tree construction submodule may specifically include:
[0213] a code determination unit, configured to generate a current title code corresponding to the current text segment based on the title level corresponding to the current text segment, and determine whether the current title code is the same as any previously generated historical title code;
[0214] The first step jump unit is configured to obtain a new text segment if the current title code is different from any of the historical title codes, determine the new text segment as the current text segment, and jump to the step of generating a current title code corresponding to the current text segment based on the title level corresponding to the current text segment;
[0215] The warning information generating unit is configured to generate warning information corresponding to the current title code if the current title code is the same as any historical title code.
[0216] In some specific embodiments, the document generation module 15 may specifically include:
[0217] an official document segment generating unit, configured to obtain a first-level title corresponding to a current text segment and generated historical official document segments, call the preset official document generating interface based on the title code corresponding to the current text segment, and generate an official document segment corresponding to the current text segment using the preset official document generating interface, the first-level title, and the historical official document segments;
[0218] The second step is a jump unit, which is used to determine a new text segment according to each of the title codes, determine the new text segment as the current text segment, and jump to the step of obtaining the first-level title corresponding to the current text segment and the generated historical document fragment.
[0219] Furthermore, the embodiment of the present application also discloses an electronic device, Figure 5 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram should not be considered as any limitation to the scope of application of the present application.
[0220] Figure 5 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps of the document generation method based on structured parsing disclosed in any of the aforementioned embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0221] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device. The communication protocol it follows is any communication protocol that can be applied to the technical solution of this application and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world. Its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0222] In addition, the memory 22 as a carrier for resource storage can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon may include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0223] The operating system 221 is used to manage and control the hardware devices on the electronic device 20 and the computer program 222, and can be Windows Server, NetWare, Unix, Linux, etc. In addition to including a computer program capable of implementing the method for generating official documents based on structured parsing and executed by the electronic device 20 as disclosed in any of the aforementioned embodiments, the computer program 222 can further include computer programs capable of performing other specific tasks.
[0224] Furthermore, this application discloses a computer-readable storage medium for storing a computer program; wherein, when executed by a processor, the computer program implements the aforementioned method for generating official documents based on structured parsing. The specific steps of this method can be found in the corresponding contents disclosed in the aforementioned embodiments and will not be further described here.
[0225] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. Reference can be made to the descriptions of the identical or similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and the relevant parts can be referred to the descriptions of the methods.
[0226] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0227] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0228] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.
[0229] The above is a detailed introduction to the technical solution provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the ideas of the present application, there may be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for generating official documents based on structured analysis, characterized in that: Applicable to the preset document generator, including: Obtain the initial document outline input by the target user through the preset information input interface; Based on a pre-configured preprocessing program corresponding to the non-text format data, preprocessing the target non-text data in the initial official document outline to obtain a corresponding pre-processed official document outline; The pre-processed official document outline is processed using a multi-mode regular expression matching algorithm to determine a target multi-level title structure corresponding to the pre-processed official document outline; the target multi-level title structure includes title levels corresponding to each text segment in the pre-processed official document outline; Constructing a corresponding target document node tree based on the target multi-level title structure; different document nodes in the target document node tree correspond to different text segments; Based on a preset official document generation interface, official document segments corresponding to each of the text segments are generated, and based on the hierarchical relationship between the document nodes in the target document node tree, the official document segments are integrated accordingly to generate a corresponding target official document.
2. The method for generating official documents based on structured analysis according to claim 1, characterized in that: The preprocessing operation on the target non-text data in the initial document outline based on the pre-configured preprocessing program corresponding to the non-text format data includes: Utilizing the preprocessing program to count the punctuation marks in the initial document outline, constructing a target character mapping table based on the corresponding statistical results, and unifying the types of the punctuation marks in the initial document outline based on the target character mapping table; wherein the target character mapping table includes a mapping relationship between a full-width mode and a half-width mode corresponding to each punctuation mark; The pre-processing program is used to merge consecutive spaces in the initial document outline and to delete line breaks in the initial document outline.
3. The method for generating official documents based on structured analysis according to claim 1, characterized in that: The method of processing the pre-processed document outline using a multi-mode regular expression matching algorithm to determine a target multi-level title structure corresponding to the pre-processed document outline includes: Calling a preset regular expression pattern library; wherein the preset regular expression pattern library includes title patterns corresponding to different title levels; The multi-mode regular expression matching algorithm is used to match each text segment in the pre-processed official document outline with each title pattern in the preset regular expression pattern library in turn to determine the target multi-level title structure corresponding to the pre-processed official document outline.
4. The method for generating official documents based on structured analysis according to claim 1, characterized in that: The constructing a corresponding target document node tree based on the target multi-level title structure includes: Based on the title levels corresponding to the text segments and a preset encoding algorithm, the title codes corresponding to the text segments are generated, and the target document node tree is constructed according to the title codes; wherein the title codes are composed of several two-digit character strings.
5. The method for generating official documents based on structured analysis according to claim 4, characterized in that: Generating the title codes corresponding to the text segments based on the title levels corresponding to the text segments and a preset coding algorithm includes: generating a current title code corresponding to the current text segment based on the title level corresponding to the current text segment, and determining whether the current title code is the same as any previously generated historical title code; If the current title code is different from any of the historical title codes, a new text segment is obtained, the new text segment is determined as the current text segment, and the process jumps to the step of generating a current title code corresponding to the current text segment based on the title level corresponding to the current text segment; If the current title code is the same as any historical title code, an alarm message corresponding to the current title code is generated.
6. The method for generating official documents based on structured analysis according to claim 4, characterized in that: Generating the official document segments corresponding to the respective text segments based on the preset official document generation interface includes: Obtaining the first-level title and the generated historical document fragments corresponding to the current text segment, calling the preset document generation interface based on the title code corresponding to the current text segment, and generating the document fragment corresponding to the current text segment using the preset document generation interface, the first-level title, and the historical document fragments; A new text segment is determined according to each of the title codes, the new text segment is determined as the current text segment, and the process jumps to the step of obtaining the first-level title corresponding to the current text segment and the generated historical document fragment.
7. A document generation device based on structured analysis, characterized in that: Applicable to the preset document generator, including: The outline acquisition module is used to obtain the initial document outline input by the target user through the preset information input interface; a data preprocessing module, configured to perform a preprocessing operation on the target non-text data in the initial document outline based on a pre-configured preprocessing program corresponding to the non-text format data, so as to obtain a corresponding pre-processed document outline; a title structure determination module for processing the pre-processed official document outline using a multi-mode regular expression matching algorithm to determine a target multi-level title structure corresponding to the pre-processed official document outline; the target multi-level title structure includes title levels corresponding to each text segment in the pre-processed official document outline; A node tree construction module is used to construct a corresponding target document node tree based on the target multi-level title structure; different document nodes in the target document node tree correspond to different text segments; The official document generation module is used to generate official document fragments corresponding to each of the text segments based on a preset official document generation interface, and to integrate each of the official document fragments accordingly based on the hierarchical relationship between each of the document nodes in the target document node tree to generate a corresponding target official document.
8. The document generation device based on structured analysis according to claim 7 is characterized in that: The data preprocessing module includes: a symbol unification unit, configured to use the preprocessing program to count the punctuation marks in the initial document outline, construct a target character mapping table based on the corresponding statistical results, and unify the types of the punctuation marks in the initial document outline based on the target character mapping table; wherein the target character mapping table includes a mapping relationship between the full-width mode and the half-width mode corresponding to each punctuation mark; The line break deleting unit is used to merge the continuous spaces in the initial document outline by using the preprocessing program and delete the line breaks in the initial document outline.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the method for generating official documents based on structured parsing as claimed in any one of claims 1 to 6.
10. A computer-readable storage medium, characterized in that Used to store a computer program, which, when executed by a processor, implements the document generation method based on structured analysis as described in any one of claims 1 to 6.