Document structured conversion method based on layout detection and rule engine

By combining layout detection with a rule engine, the problems of multi-level heading recognition and mixed text and image layout in document structuring were solved. This enabled high-precision reconstruction of document structure and stable control of the task process, improving the parsability and reusability of documents in knowledge bases and question-answering systems.

CN121389979APending Publication Date: 2026-01-23BEIJING MASS TRANSIT RAILWAY OPERATION CORPORATION LIMITED
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511511055.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-22
Publication Date
2026-01-23

AI Technical Summary

Technical Problem

Existing technologies for document structuring suffer from problems such as difficulty in accurately identifying multi-level headings, incomplete handling of mixed text and image structures, lack of state control during task conversion, and lack of maintainability of conversion results. These issues result in insufficient parsing and reusability of documents in knowledge bases, search engines, and question-answering systems.

Method used

A document structuring transformation method based on layout detection and rule engine is adopted. The layout detection model identifies document elements, and combined with regular expression rule matching and OCR technology, a multi-level heading structure is reconstructed. The stability and controllability of the processing process are ensured through task status tracking and control mechanism.

Benefits of technology

It improves the accuracy of document structure recognition, enhances structural integrity and semantic consistency, supports the controllability and traceability of the task process, adapts to a variety of complex document formats, and adapts to different usage scenarios and changing requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121389979A_ABST
    Figure CN121389979A_ABST
Patent Text Reader

Abstract

The invention provides a document structured conversion method based on layout detection and a rule engine, which belongs to the technical field of artificial intelligence and document information processing, and comprises the following steps: receiving and initializing a document task, identifying structural elements by a layout model, correcting a structure and reconstructing a multi-level title, associating and restoring an image and a table structure, and generating and storing a preset document. And a task process state tracking and control mechanism. The problems of unclear structure, disordered format and the like of the traditional OCR are solved, and the method adapts to various complex document formats; subsequent content reutilization, intelligent question answering and knowledge extraction are facilitated; the system stability and the engineering deployment capability are improved; and the method adapts to different use scenes and demand changes.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of artificial intelligence and document information processing technology, in particular to a document structured conversion method based on layout detection and rule engine. BACKGROUND

[0002] In the process of digital transformation of current government agencies, large enterprises and research institutions, the structured management of document materials has become a core demand. However, a large number of documents in information sources exist in unstructured formats such as PDF and Word, and the content contains complex title levels, tables, images, annotations and other structural information, which directly affects the analyzability and reusability in knowledge base, search engine, question and answer system and other scenarios.

[0003] Traditional document structuring methods mostly rely on OCR (Optical Character Recognition) and text rule matching to realize content extraction, but face the following problems:

[0004] 1. Multi-level titles are difficult to accurately identify: ordinary OCR can extract text content, but it is difficult to distinguish titles from texts based on visual layout, especially in formats such as photocopy PDF, title level information is easily ignored or recognized confused;

[0005] 2. The structure processing of mixed text and images is not complete: the recognition effect of structural elements such as tables, pictures and their descriptions is unstable, resulting in structure damage when outputting in Markdown or HTML format;

[0006] 3. Lack of state control in task conversion process: most document conversion processes are "black box" processing, which cannot track the state in real time, support task interruption and recovery, and the system stability is poor;

[0007] 4. Conversion results lack maintainability: existing methods generally do not support version control, error comparison and structure reconstruction, etc. Post-processing requirements affect the engineering practicability in large-scale scenarios.

[0008] With the rise of deep learning models in document image understanding, layout analysis-based target detection methods (such as YOLO, LayoutLM, etc.) can realize block-level recognition of document elements, becoming a key breakthrough for structured conversion. However, the output results of such models often lack semantic logic and context continuity, and still need to be combined with rule engines for post-processing to build stable and high-precision structure expressions.

[0009] Therefore, the present application provides a document structured conversion method based on layout detection and rule engine. SUMMARY

[0010] The present application provides a document structured conversion method based on layout detection and rule engine to solve the technical problems mentioned above.

[0011] The application provides a document structured conversion method based on layout detection and rule engine, comprising: step 1: document task receiving and initialization: receiving a to-be-converted document to identify a source format, generating a unique task identification and initializing a task state, recording in a task database table, and submitting to a model processing queue; step 2: layout model identifying structural elements: calling a layout detection model to perform layout analysis on a document image page by page, and outputting element block information, wherein the element block information comprises element block type, position information and confidence; step 3: structure correction and multi-level title reconstruction: combining numbering format, semantic features and style information for the title block output by the model, performing regular expression rule matching, constructing a title rule library, correcting the initial identification result in levels, and forming a multi-level title structure conforming to a preset syntax specification; step 4: image and table structure association and restoration: establishing an association relationship between a picture block and explanatory text, submitting a table block to a structure recognition module, generating a structured table through combination of an OCR and a table recognition model, and retaining a mapping relationship between the original image and the structured data; step 5: preset document generation and storage: integrating the structured information into a standardized preset document, uploading the final document to an object storage, and storing the intermediate identification block information to an ES index; step 6: task process state tracking and control mechanism: updating the task state according to stages and writing into a database.

[0012] Preferably, the layout detection model is based on a DocLayout-YOLO_ft model fine-tuned by YOLO, and is used for detecting document elements.

[0013] Preferably, the matching process of the regular expression rule comprises: maintaining a multi-level title rule library, and correcting title levels and completing missing sections according to numbering continuity and semantic keywords.

[0014] Preferably, the table block is extracted into an HTML or Markdown table syntax through an image recognition and structure inference model, and supports merged cell parsing.

[0015] Preferably, the image block and the corresponding explanatory text are processed through image group and description association, and are embedded into a corresponding position of a Markdown document.

[0016] Preferably, the task state is communicated asynchronously through a message queue and a task management module, and supports state pushing, exception callback and dead letter message management.

[0017] Preferably, the submission to the model processing queue comprises:

[0018] The complexity features of the document are analyzed while the source format of the document is identified, and the complexity features comprise the number of pages, the type and proportion of non-text elements contained.

[0019] Based on the document source format, complexity characteristics, and current model resource load, dynamically initialize task priority status and assign exclusive processing labels;

[0020] Establish a simulation connection channel between a dedicated processing tag and a model processing queue, and obtain the transmission code segment in the communication connection program that describes the simulation connection channel;

[0021] The communication parameters in the transmission code segment and the interface connection function between each communication parameter and the model processing queue are extracted, and the communication simulation implementation example of the corresponding communication parameter is determined based on the interface connection function;

[0022] Taking each of the aforementioned communication simulation embodiments as the main focus, communication simulation is performed sequentially on the simulation connection channel to obtain the improvement identifier of each communication parameter. The improvement identifier is related to the simulation step size, the variation function of the corresponding communication parameter based on the transmission code segment, and the additional parameters that match the corresponding communication parameter.

[0023] All improved identifiers are categorized by attributes, and communication threads are constructed based on the order in which communication parameters appear in the transmission code segment. Improved code based on the transmission code segment is obtained to route the exclusive processing tag to the corresponding model processing queue, wherein the model processing queue is adapted to document processing requirements of specific formats and complexity ranges.

[0024] Preferably, structured information is integrated into standardized pre-defined documents, including:

[0025] Semantic association recognition is performed on structured information to establish parent-child reference relationships and logical order indexes between elements;

[0026] Determine the first dynamic parameter of the first information in the same level child position in the parent-child reference relationship, which changes with the static parameter of the higher-level parent position, and the first static parameter that remains unchanged with the dynamic parameter of the higher-level parent position, to obtain the dynamic vector and static vector of the same level child position.

[0027] The dynamic vectors and static vectors at the same level are concatenated according to their logical index to obtain the hierarchical concatenated vector;

[0028] Determine the number of static and dynamic elements in the concatenation vector at each level, and combine this with the total number of elements in each concatenation vector to determine the standard number of elements, thus constructing the standard concatenation matrix.

[0029] Feature extraction is performed on the standard splicing matrix, and the current importance of each level in the overall document structure is quantified by analyzing the matrix eigenvalue distribution and element correlation.

[0030] According to the importance of the corresponding level of sub-information priority processing and combined with the document template engine configuration parameter of the structured information is arranged intelligently, the initial document is obtained;

[0031] The structural feature vector of the initial document is extracted, and the source feature vector of the original structured information is calculated, the structure integration error is calculated, and the error relationship of the structure integration error and the mapping structure parameter involved in each row vector in the standard splicing matrix is determined.

[0032] According to the structure integration error and all error relationships, the initial document is optimized to obtain the preset document.

[0033] Compared with the prior art, the beneficial effects of the present application are as follows:

[0034] 1. The structure recognition accuracy is significantly improved: by combining the visual model with the rule engine, the recognition accuracy of the multi-level title in the document is effectively improved, the problems of unclear structure and chaotic format of traditional OCR are solved, and various complex document formats are adapted.

[0035] 2. The structure integrity and semantic consistency are enhanced: the document logical structure can be accurately reconstructed, the original association relationship of the text and the table is preserved, the conversion result is close to the original text format, which is beneficial to subsequent content reuse, intelligent question and answer and knowledge extraction.

[0036] 3. The task process is controllable: the perfect task state management mechanism is provided, the task process tracking, abnormal interruption, resource recycling, state recovery and the like are supported, and the system stability and engineering deployment ability are improved.

[0037] 4. The conversion result can be modified and traced: the user can manually adjust the Markdown structured document, the version control and error analysis ability are provided, and different use scenarios and demand changes are adapted.

[0038] Other features and advantages of the present application will be set forth in the following description of the application, and in part will become apparent to those skilled in the art from the description, or can be learned by practice of the application. The objects and other advantages of the present application can be achieved and obtained by the structure particularly pointed out in the written description and the accompanying drawings.

[0039] The technical solutions of the present application will be further described in detail below with the help of the drawings and examples. BRIEF DESCRIPTION OF DRAWINGS

[0040] The accompanying drawings are used to provide a further understanding of the present application, and constitute a part of the specification, together with the embodiments of the present application, to explain the present application, and do not constitute a limitation on the present application. In the drawings:

[0041] Figure 1A flowchart of a document structured conversion method based on layout detection and a rule engine in an embodiment of the present application. DETAILED DESCRIPTION

[0042] The preferred embodiments of the present application are described below in conjunction with the accompanying drawings, in which it is understood that the preferred embodiments described herein are merely intended to illustrate and explain the present application, and are not intended to limit the present application.

[0043] The present application provides a document structured conversion method based on layout detection and a rule engine, comprising: step 1: document task receiving and initialization: receiving a document to be converted to identify the source format, generating a unique task identification and initializing the task state, recording to the task database table, and submitting to the model processing queue; step 2: layout model identification structure element: calling the layout detection model, performing layout analysis on the document image page by page, and outputting element block information, wherein the element block information includes element block type, position information and confidence; step 3: structure correction and multi-level title reconstruction: combining the numbered format, semantic features and style information for the title block output by the model, executing regular expression rule matching, constructing a title rule library, correcting the initial recognition result, and forming a multi-level title structure conforming to the preset syntax specification; step 4: image and table structure association and restoration: establishing a correlation between the picture block and the explanatory text, submitting the table block to the structure recognition module, generating a structured table through the combination of OCR and table recognition model, and preserving the mapping relationship between the original image and the structured data; step 5: preset document generation and storage: integrating the structured information into a standardized preset document, uploading the final document to an object storage, and storing the intermediate recognition block information to an ES index; step 6: task process state tracking and control mechanism: updating the task state according to the stage and writing it into the database.

[0044] Preferably, the layout detection model is based on the DocLayout-YOLO_ft model fine-tuned by YOLO, which is used to detect document elements.

[0045] Preferably, the matching process of the regular expression rule includes maintaining a multi-level title rule library, and correcting the title level and completing the missing section according to the numbered continuity and semantic keywords.

[0046] Preferably, the table block is extracted as an HTML or Markdown table syntax through an image recognition and structure inference model, and supports merged cell parsing.

[0047] Preferably, the image block and the corresponding explanatory text are processed through image group and description association, and are embedded into the corresponding position of the Markdown document.

[0048] Preferably, the task state communicates asynchronously through a message queue and a task management module, supports state pushing, exception callback and dead letter message management.

[0049] In this embodiment, the source format includes PDF, Word, PowerPoint, Excel, HTML, TXT; the unique task identifier includes taskId and fileKey, where taskId is a globally unique UUID, and fileKey is a unique identifier of the document file.

[0050] In this embodiment, the layout detection model is a target detection model based on the YOLOv5 architecture fine-tuning, and the training data set includes PubLayNet and DocBank; when processing the document image, the PDF is converted into an image page by page through the pdf2image tool, and the DPI is 300; the element block information output by the model includes type, bbox, content, image_path, and score, where type includes title, text, image, table, header, and footer.

[0051] In this embodiment, the corresponding preset title syntax is generated according to the title level, the continuous text block is merged into a paragraph with a blank line between paragraphs, the picture and the table are embedded according to the corresponding format, the block ID and the page number annotation information are added at the top of each page paragraph; the storage strategy includes generating a preset fragment by page segmentation, and generating a merged version of the preset document; the structure block information is written into the Elasticsearch structure index library synchronously.

[0052] In this embodiment, the task state includes queuing, execution, successful completion, error termination, user cancellation, system cancellation, and timeout failure; the processing progress is recorded by stages, including initialization task preparation, downloading original files, and document paging and image conversion stages; when the task is interrupted, the state is modified and a cancellation instruction is sent, and the processing service stops subsequent operations and cleans up resources; when restarted, the unfinished tasks are scanned, re-queued or continued processing from the breakpoint, and task recovery is realized.

[0053] In this embodiment, the input document receiving and task initialization process is as follows:

[0054] The document input supports multiple mainstream office document formats, including but not limited to: PDF (including scanned and electronically generated versions); Word (.doc / .docx); PowerPoint (.ppt / .pptx); Excel (.xls / .xlsx); HTML, TXT text, etc. The file can be uploaded through the knowledge base front end, or the API interface can be called by a third-party system (such as an OA platform, an archive system) for batch pushing.

[0055] In this embodiment, the generation of the task uniqueness identifier is that after the system receives the uploaded file, it immediately generates the following identifier information and stores it in the task table (convert_task_table): taskId: the task number, usually a globally unique UUID; fileKey: the unique identifier of the document file, used for file access in the object storage system (such as Minio); uploadTime: the task creation time; fileType: the file type identifier (PDF, Word, etc.); status: the initial status is marked as "queuing"; priority (optional): the task priority flag, used for resource control in large-scale task scheduling. This information is stored in the MySQL task database and forms the initial log record.

[0056] In this embodiment, the document storage and path recording are that the uploaded document is automatically stored in the object storage system (Minio), forming the following path:

[0057] / original_files / {date} / {taskId} / {filename.ext}. At the same time, the path information (MinioURI) is passed as a parameter to the model processing flow and version control module for subsequent access to the original data.

[0058] In this embodiment, the task enqueueing and resource preparation are that the system writes the task information into the task scheduling queue (topic: mct_convert_task) through the message queue (RabbitMQ). The message content includes:

[0059] {

[0060] "taskId": "uuid-123",

[0061] "fileKey": "1234567",

[0062] "fileName": "安全生产管理办法.pdf",

[0063] "fileType": "PDF",

[0064] "minioPath": " / original_files / 2025-05-23 / uuid-123 / 安全生产管理办法.pdf"

[0065] };

[0066] After the Python side listens to the queue, it confirms the task status locally and pre-allocates processing resources (such as GPUs, memory, temporary directories, etc.), and is ready to enter the structure analysis stage.

[0067] In this embodiment, state feedback and traceability management are used to ensure task traceability and process transparency. After receiving a task, the system writes the initial state of the task, resource allocation, and queue ranking into the task state table in real time, and supports querying the current task stage and queue order through the API.

[0068] If the task is terminated (such as canceling upload or format verification failure) at this stage, the system will perform logical deletion or mark it as -1 (canceled), and recycle the related resources to avoid generating isolated data or invalid resource occupation.

[0069] In this embodiment, the layout model identifies structural elements after the task is successfully initialized and submitted to the model processing layer. The system calls a deep learning layout detection model to perform image-level identification on the document structure, extracting key structural block information such as title, body, picture, table, etc., to provide basic data for subsequent structure repair and Markdown construction.

[0070] In this embodiment, the layout detection model used in the model selection and deployment strategy is DocLayout-YOLO_ft, which is a target detection model based on YOLOv5 architecture fine-tuning, specially trained and optimized for structured documents. The core features are as follows:

[0071] Input type: Convert PDF to image (JPG or PNG) page by page;

[0072] Training data set: PubLayNet, DocBank, and other structured document annotation sets;

[0073] Output result: Element categories (title, text, image, table, header, footer), position (bounding box), and confidence score (score) identified in each page image;

[0074] Model deployment: Implemented using PyTorch, invoked through GPU (recommended configuration: 16G memory), and deployed in a containerized Python service.

[0075] After deploying the model service, the system transmits document images and task information through HTTP or message triggering, and performs structure prediction by the model.

[0076] In this embodiment, document image processing and page disassembly are used to convert the input PDF document into image files page by page using the pdf2image tool locally. The default DPI is 300 to ensure recognition accuracy. The generated image for each page is stored in the following temporary path:

[0077] / tmp / {taskId} / page_001.jpg, page_002.jpg;

[0078] Pagination information also serves as the basis for subsequent structural block indexes.

[0079] In this embodiment, the model recognition output format is described as follows: the model returns the following structured data (represented in JSON format) per page: [

[0081] {

[0082] "type": "title",

[0083] "bbox": [163, 128, 393, 151],

[0084] "content": "Chapter 1 Safety Management Requirements",

[0085] "score": 0.97

[0086] },

[0087] {

[0088] "type": "text",

[0089] "bbox": [78, 77, 414, 94],

[0090] "content": "To ensure construction safety, the following management system is established..."

[0091] "score": 0.95

[0092] },

[0093] {

[0094] "type": "image",

[0095] "bbox": [209, 177, 419, 381],

[0096] "image_path": "page_002_img1.jpg",

[0097] "score": 0.93

[0098] },

[0099] {

[0100] "type": "table",

[0101] "bbox": [90, 151, 510, 570],

[0102] "image_path": "page_003_tbl1.jpg",

[0103] "score": 0.92

[0104] } ]

[0106] Where:

[0107] type indicates the category of the structural element;

[0108] bbox is the position of the element on the image;

[0109] content is the recognized text after OCR (if applicable);

[0110] image_path is the path of the image / table image after cutting;

[0111] score is the recognition confidence score.

[0112] Preliminary classification and labeling of structural blocks

[0113] The system preliminarily divides the elements according to the type field in the output:

[0114] Title class (title): candidate Markdown title;

[0115] Text class (text): body paragraph;

[0116] Picture class (image / image_caption): image and caption;

[0117] Table class (table / table_caption): table area and title;

[0118] Discarded class (discarded): such as page numbers, watermarks, headers and footers.

[0119] Each structural block is assigned a unique blockId and labeled with the page number to form a set of structural block metadata, which serves as an index for subsequent rule engine analysis and Markdown layout construction.

[0120] In this embodiment, the multi-level title recognition rule engine is designed and implemented. The title block output by the model can basically locate the area of the title in the document, but due to the lack of semantic understanding and structural continuity of the visual model, the following problems often occur: partial title level misjudgment, incomplete numbering, and non-title misjudgment as title. Therefore, the application designs a multi-level title recognition engine based on numbering analysis, rule library matching and logical continuity test, which can modify the preliminary recognition results at the semantic level to construct a logical Markdown document hierarchical structure.

[0121] The title format recognition logic is analyzed by the engine through regular expressions combined with natural language patterns for each title type structure block as follows:

[0122] Numbering pattern recognition: support for recognizing common title numbering formats, such as:

[0123] First-level title: Chapter 1, Section 1, 1. General provisions;

[0124] Second-level title: 1.1 Scope, Section 2 Safety Responsibility, 1.2.1 Organization Structure;

[0125] Third-level and above title: 1.2.1.1 … nested structure;

[0126] Keyword detection: keywords such as "table of contents", "chapter", "appendix" and the like are used to assist in recognizing title semantics;

[0127] Font feature assistance (optional): use OCR output font size, boldness and other attributes to strengthen structure discrimination (if OCR structure output is supported);

[0128] The engine will split the numbering part and convert it to a hierarchical vector representation (such as 1.2.3 → [1,2,3]), which is used as a direct basis for structure level judgment.

[0129] The title rule library design and matching strategy is a built-in configurable title rule library in the system, which defines common title patterns in the form of regular expressions. Examples are shown in Table 1:

[0130] Table 1

[0131]

[0132] The rule priority is executed from high to low, and after successful matching, the level of the title block is determined, which is converted to the number of # in Markdown syntax, i.e.:

[0133] level = 1 → #;

[0134] level = 2 → ##;

[0135] level = 3 → ###;

[0136] And so on, the maximum support to six levels of title.

[0137] Continuity check and missing repair algorithm is to avoid the document due to the title missing, wrong level caused by the structure of the fracture, the engine designed numbering continuity detection mechanism, the process is as follows:

[0138] Traverse all the identified title, extract the number vector;

[0139] Determine whether the number is continuous (such as 1.1 → 1.2 → 1.3);

[0140] If found skip section (such as 1.1 → 1.3), try to search in the original text to start with "1.2" paragraph, if it meets the title characteristics, then fill in the structure block;

[0141] For the existence of multi-layer nesting and model misjudgment for the first level of title, according to its number of depth and before and after the context title level recursive correction of its structure level;

[0142] All repair process generates a correction log and attached to the task details, support backtracking and manual intervention.

[0143] Error detection and exclusion mechanism is for the model misjudgment of pseudo title (such as table head, footnotes, figure name and so on misrecognized as title), the system determines that it does not meet the title characteristics and is excluded by the following way:

[0144] No number / number is not standardized and no key words;

[0145] Too short / language is not complete;

[0146] The structure of before and after is seriously damaged;

[0147] OCR confidence is low / derived from the header and footer and other abandoned blocks.

[0148] These blocks are marked as non-title after repair, excluded from the directory structure of Markdown, only keep its original content.

[0149] Output format and structure integration is the final all repair completed title structure block will form the following structure:

[0150] {

[0151] "blockId": "b123",

[0152] "type": "title",

[0153] "level": 2,

[0154] "content": "1.2 Security Responsibilities",

[0155] "page": 3,

[0156] "lineIndex": 5,

[0157] "parentId": "b101",

[0158] "markdown": "## 1.2 Security Responsibilities"

[0159] };

[0160] And as the main index node of the Markdown document generation process, it is used to link the main text and auxiliary content, ensuring the semantic coherence and clear structure of the document.

[0161] In this embodiment, the picture and table structure processing logic is in the structured document. In addition to text, images and tables are the most common structural elements. Based on the DocLayout model detecting pictures and tables, the invention completes the structured reconstruction through a special module and realizes the embedding and semantic association in Markdown format.

[0162] Picture processing and image recognition are two important information contained in the picture block (type = image) recognized by the layout model: image body (image_body); image caption (image_caption), such as Figure 1 Project organization chart.

[0163] In this embodiment, the system performs the following image processing flow:

[0164] Image cropping and saving: according to the bbox coordinates, the image is cropped from the original page image and stored as an independent picture file (jpg / png), with the path structure as follows: / converted_images / {taskId} / page_003_img1.jpg;

[0165] Caption binding logic: check if there is a caption block under or adjacent to the current picture block;

[0166] If matched (such as text starting with ": Figure 1 "), establish logical association and label as caption_of = blockId;

[0167] Integrate the image block and its caption into the Markdown format as follows:

[0168] ![ Figure 1[Project Organizational Chart](. / images / page_003_img1.jpg);

[0169] Image indexing and structure write-back: All image information is written into the ES document structure block, supporting independent retrieval in the knowledge base.

[0170] Table processing and structure reconstruction are similar to image recognition logic in terms of table block recognition, but the reconstruction process is complex and involves two paths:

[0171] Simple table structure recognition (without merged cells);

[0172] For the regular table image recognized by the model, the system first attempts to extract the table content using an OCR tool (such as PaddleOCR) and then generates two-dimensional matrix data through cell segmentation inference.

[0173] The output structure is as follows:

[0174] {

[0175] "type": "table",

[0176] "format": "markdown",

[0177] "markdown": "| Department | Responsibilities |\n|------|------|\n| Safety Supervision Department | Responsible for system development |\n| Engineering Department | Implementation and supervision |"

[0178] }

[0179] Embed the table content directly in Markdown to ensure user visualization and reproducibility.

[0180] Complex table structure recognition (including merged cells) involves the system switching to a structure table recognition model when row / column merging is detected (e.g., multi-level headers, blank cells, nested tables). This model uses either TableMaster or StructEqTable to output the HTML structure.

[0181]

[0182]

[0183]

[0184]

[0185] department division of responsibilities compilation implementation safety supervision department √

[0186] And embed it in Markdown as an HTML block:

[0187]

[0188]

[0189] ;

[0190] Table image and caption binding is similar to picture, the system automatically identifies table caption text (such as "Table 3: Construction Staff Responsibilities Table"), and binds it with the table block as the title row output.

[0191] Original table image backup is all table image files are also cropped and stored, consistent with the Markdown document structure, so that the original image is retained when the structure cannot be completely restored, and in Markdown, it is referenced as follows:

[0192] ![Table 3: Construction Staff Responsibilities Table](. / tables / page_004_tbl1.jpg)

[0193] Processing log and quality control: Each table and image processing task records the following processing log: block ID, page number, picture path; whether the caption is recognized; table structure type (Markdown / HTML / Image only); OCR extraction confidence; error reason (if not successfully recognized), etc.

[0194] In this embodiment, the present application constructs a Markdown document with clear logic, consistent visual, and editable according to the Markdown document format standard, combined with hierarchical structure information. At the same time, in order to improve the display performance of large files and support differential version management, the system realizes the paging output and block storage mechanism of the structure content.

[0195] Markdown generation rules: The system generates Markdown content according to the following rules based on the sorting results of the structure blocks (titles, text, image, table):

[0196] Title processing: According to the level field in the structure correction result, generate the corresponding level of Markdown title syntax:

[0197] Paragraph splicing and blank line control: merge consecutive text blocks into paragraphs, skip empty paragraphs, and separate paragraphs with blank lines;

[0198] Picture embedding: insert the image block in the format![caption](path), and the caption is automatically filled in as caption content;

[0199] Table insertion: prefer to use Markdown table syntax, use HTML nested blocks for complex structures, and keep the picture form for structures that cannot be recognized;

[0200] Meta information annotation: add block ID, page number, original text path, etc. annotation information at the top of each page paragraph, support traceability and editing positioning.

[0201] The pagination output and block storage strategy is to avoid Markdown document too large leading to slow loading, the system will split the document by page, each page generates a Markdown fragment independently, the naming rules are as follows:

[0202] / converted_md / {taskId} / page_001.md;

[0203] / converted_md / {taskId} / page_002.md;

[0204] The pagination document can be loaded and edited by page, and the end user can merge it into a complete version through the page merging tool.

[0205] The pagination index is recorded in the structure block as follows:

[0206] {

[0207] "fileId": "uuid-123",

[0208] "markdownPages": [

[0209] "page_001.md",

[0210] "page_002.md", ...

[0213] };

[0214] Complete document generation and object storage management is in addition to the pagination file, the system also provides a merged version of the Markdown document to splice all page content in complete logical order, the storage path is as follows: / converted_md / {taskId} / full.md;

[0215] This document is the main carrier for knowledge base system storage and display, supporting full-text preview, full-text comparison, full-text search and other functions.

[0216] Markdown files (pagination + complete) are uploaded to the object storage system Minio, and the access path and version number are recorded through the task table.

[0217] ​The structure block and full text mapping relationship storage is that all structure blocks (title, paragraph, table, etc.) are converted and written into the Elasticsearch structure index library (such as index name: analysis_result) synchronously, and each structure block includes the following fields: blockId: unique block number; type: block type (title, text, table, image); content: block text content; pageIndex: page number; markdownPath: corresponding Markdown page file; positionInPage: page order number; relatedBlocks: caption / table note binding information, etc.

[0218] The task state tracking and interruption recovery mechanism is to guarantee the stability and controllability of the structured document conversion process, and the application designs a set of task state management and recoverable mechanism refined to sub-stages. The mechanism covers the whole process from task creation, execution, completion, failure to cancellation, cooperates with the message queue and database persistent operation, and realizes the state tracking and interruption safety processing of the whole life cycle of the task.

[0219] The task life cycle and state code design is that the system defines seven basic states of the conversion task, which correspond to different processing stages and execution results, and the state code is shown in Table 2:

[0220] Table 2

[0221]

[0222] The task state is written into the MySQL convert_task_table, and each state update is written into the log table and synchronized to the front-end interface through WebSocket / API.

[0223] The stage processing log tracking is that the task records the detailed processing progress and state according to the stage during the execution process, and the stage list includes: initialization task preparation, download of original files, document page and image conversion, model structure prediction, title rule repair, picture and table analysis, Markdown output and uploading, ES structure block writing, task completion / failure, and the state is written after each stage is completed.

[0224] The MySQL task log table includes: record start time, end time, time consumption, result summary;

[0225] ES analysis result library (optional): structure block level record content processing log;

[0226] Message queue notification (RabbitMQ): send state callback message for calling system to listen to task progress.

[0227] Task interruption and cancellation mechanism is to support task interruption in any non-terminal state (i.e. state 0 or 1) actively, and the triggering methods include:

[0228] User front-end operation; system detects abnormality (such as insufficient GPU resources); timeout processing;

[0229] The interruption mechanism specifically includes: modifying the task state to -1 (user cancellation) or -2 (system cancellation); sending a cancellation instruction to the Python end processing service (queue topic: task.cancel); the Python service checks the task state after completing the current processing step, and if the cancellation instruction is found, it immediately stops subsequent processing and performs resource cleaning; the completed stage processing log and structure block data are retained, but the final Markdown file is not generated.

[0230] Task recovery mechanism is to ensure system robustness, and the invention supports the function of automatically recovering unfinished tasks after system restart, and the logic is as follows:

[0231] The system scans the tasks in the task table with the state of execution (1) or queuing (0) during initialization;

[0232] If it is in the queuing state, it is re-queued;

[0233] If it is in the execution state and the log record has the latest execution step (such as completion to structure recognition), the system judges that it has been interrupted, and re-submits it to the queue for continuous processing;

[0234] The execution context is recovered through "task ID + log offset", ensuring that the task continues from the breakpoint and guarantees processing consistency.

[0235] Consistency guarantee and retry logic

[0236] In the process of calling model layer interface, storing conversion results, writing to Minio or ES, etc., the system implements idempotency design and failure retry mechanism:

[0237] The callback interface supports a maximum of 10 failure retries;

[0238] MQ messages use an acknowledgement mechanism, and explicit ack is performed after processing is completed;

[0239] When storage writing fails, it is temporarily stored locally for retry;

[0240] All temporary file operations have timeout and automatic cleaning logic to avoid "resource leakage".

[0241] Through the above mechanisms, the system realizes the characteristics of "monitorable, interruptable, and recoverable" of structured conversion tasks, ensuring the correctness and traceability of document processing even in abnormal environments.

[0242] The Markdown version control and error detection method is a structured conversion result that is not a fixed and immutable final state. In actual knowledge system applications, users or systems may manually revise, optimize multiple rounds, or upgrade models and then generate again based on the initial conversion result. Therefore, the present application proposes a Markdown result version control mechanism and a matching error detection method to support version evolution, historical tracking, and structural difference comparison.

[0243] The version control mechanism design is that the system records a version snapshot for each completed Markdown document after generation or editing, including the following contents: versionId: version number, initially 0, and then incremented sequentially; sourceType: source type (automatically generated by the system / manual revised); updateTime: creation time; editorId: editor identity (marked as system if it is the system); markdownPath: current version file storage path; changeDesc: version change summary (user can fill in, system can automatically generate diff summary); parentVersionId: previous version ID (supports backtracking path);

[0244] The version information is saved in the database version table, which is associated with the main task table through the taskId foreign key, and supports the following structure:

[0245] convert_task_table (taskId, currentVersionId,...);

[0246] md_version_table (versionId, taskId, markdownPath, updateTime,...);

[0247] The version files are uniformly saved in the object storage system Minio, and the path rules are as follows:

[0248] / converted_md / {taskId} / v0_full.md;

[0249] / converted_md / {taskId} / v1_full.md;

[0250] The front-end editing and version submission process is that the front-end provides a what-you-see-is-what-you-get Markdown editing interface, users can modify elements such as titles, paragraphs, and tables, and after modification, click "Save New Version", the system performs the following operations:

[0251] Automatically compare the contents of the current version and the original version to generate a structural difference summary;

[0252] Store the new Markdown file and assign a version number;

[0253] Update the currentVersionId in the task master table;

[0254] Push the changes to the version record table for historical viewing and version switching.

[0255] Support editing and saving by page. If the content of a page changes, the system only saves the new version of that page, and the rest of the pages use the previous version. After merging, the system assigns a unified number.

[0256] The invention supports error analysis and structural comparison between any two Markdown versions, mainly for the following scenarios:

[0257] Check the conversion accuracy of the model (e.g., compared with the manually corrected version);

[0258] Check the output difference before and after the model upgrade;

[0259] Check the accuracy difference between different strategies.

[0260] The comparison strategy is as follows:

[0261] Text comparison: line-level text diff based on paragraph ID, using Levenshtein distance to mark the difference section;

[0262] Title comparison: check for structural problems such as missing, incorrect level, redundancy, etc. based on title content and level;

[0263] Table comparison: compare table headers, column numbers, data cell numbers, and contents for consistency;

[0264] Image comparison: check if the image path is consistent and if the caption has changed.

[0265] The comparison results are output in highlighted form, showing the difference points and impact range, and a structural difference summary report is generated for model version difference evaluation by operation and maintenance personnel.

[0266] Error detection task execution and management is a system that supports initiating error detection tasks and executing them in an asynchronous manner. The process is as follows:

[0267] The user clicks "Initiate Error Detection" on the interface;

[0268] The system creates an error detection task record and sets the status to "To be executed";

[0269] The Python detection service listens to the error detection task queue;

[0270] Pull the original version and the target version Markdown files, and perform structural comparison;

[0271] After the comparison is completed, write the results to the error result table, and push the state callback message;

[0272] The user can display the difference points by clicking "view error" in the interface.

[0273] The error detection supports archiving the comparison results, marking the difference paragraphs and structural units, and facilitating subsequent evaluation.

[0274] Model selection, parameter configuration, and running performance description are to ensure that the document structuring conversion task can achieve high recognition accuracy and processing efficiency under various document formats and different structural complexities. The model structure, deployment method, hardware resources, and performance indicators are fully designed and verified.

[0275] The model selection is based on the core structure recognition task based on the layout detection model. After technical evaluation and comparison test, the DocLayout-YOLO_ft model is finally selected. The preferred reasons are shown in Table 3:

[0276] Table 3

[0277]

[0278] Considering the high concurrency, fast response, and high availability required by the present application, DocLayout-YOLO_ft is selected as the base model, and further fine-tuning and optimization are performed on PDF structural document data.

[0279] The deployment architecture and hardware configuration are that the model deployment adopts the Python+Flask service container method, and provides parsing services through RESTful API. The overall deployment architecture is as follows:

[0280] Service container: deployed on GPU cloud host, using Docker Compose for unified scheduling;

[0281] GPU configuration: NVIDIA V100, 16GB of video memory, supporting single-model exclusive operation;

[0282] Memory / CPU configuration: vCPU 8 cores, 64GB of memory;

[0283] Object storage: Minio stores original files and conversion results;

[0284] Database: MySQL is used for task and structural block state recording;

[0285] Message queue: RabbitMQ manages task scheduling and callback communication.

[0286] The GPU resource availability is determined by the Python end before each task starts to ensure that the model execution will not be interrupted due to resource conflicts.

[0287] The model running parameters are in a production environment, and the model default configuration is as follows:

[0288] The input image size is 1024*768;

[0289] The minimum detection box threshold is 0.5;

[0290] The label block type is title, text, table, image, and discarded;

[0291] The output structure format is a JSON array containing type, bbox, score, OCR text and the like fields.

[0292] The system supports adjusting the model parameters through a configuration file to adapt to different structural document scenarios, for example, adjusting the OCR threshold, disabling the header and footer labels and the like.

[0293] The running performance evaluation is in a typical document test sample, and the running performance of the DocLayout-YOLO_ft model under the system is shown in Table 4:

[0294] Table 4

[0295]

[0296] The system supports the following extension capabilities:

[0297] Model dynamic switching: supporting configuration file switching to LayoutLM and the like models;

[0298] Task priority scheduling: allocating GPU resources according to task importance;

[0299] Model online hot update: without restarting the main system, the parsing model can be updated rolling;

[0300] Adaptive task flow limiting: automatically limiting the number of concurrent tasks in peak periods to ensure service stability.

[0301] Through the above model selection, parameter optimization and deployment strategy design, the system can realize high-precision and high-performance document structured conversion, and meet the actual needs of large-scale knowledge document storage scenarios.

[0302] The application provides a document structured conversion method based on layout detection and a rule engine, which is submitted to a model processing queue, comprising:

[0303] The document is parsed while identifying the document source format, and the complexity features of the document include the number of pages, the types and proportions of non-text elements contained;

[0304] According to the document source format, complexity features, and current model resource load, the task priority state is dynamically initialized and assigned a dedicated processing label.

[0305] A simulation connection channel is established between the dedicated processing label and the model processing queue, and a transmission code segment in the communication connection program describing the simulation connection channel is obtained.

[0306] The communication parameters in the transmission code segment and the interface connection function of each communication parameter and the model processing queue are extracted, and the communication simulation implementation of the corresponding communication parameter is determined depending on the interface connection function.

[0307] Each communication simulation implementation is taken as the main part, and the communication simulation of the simulation connection channel is performed in sequence to obtain the improvement identifier of each communication parameter, wherein the improvement identifier is related to the simulation step, the change function of the corresponding communication parameter based on the transmission code segment, and the additional parameter matched with the corresponding communication parameter.

[0308] All improvement identifiers are attribute-divided, and a communication thread is constructed depending on the appearance order of the communication parameters in the transmission code segment, and an improved code based on the transmission code segment is obtained to route the dedicated processing label to the corresponding model processing queue, wherein the model processing queue adapts to the document processing requirements of a specific format and complexity range.

[0309] In this embodiment, the complexity features are a set of indicators for quantifying the difficulty of document processing, reflecting the degree of demand for computing resources by the document. The non-text element type is a content category in the document other than pure text, such as tables, images, formulas, etc.

[0310] In this embodiment, the model resource load is the resource occupation of the current processing model, such as GPU usage, memory occupation, etc., which determines the task scheduling order. For example, when the system GPU usage is 30%, high complexity tasks can be processed preferentially; when the usage reaches 90%, low complexity tasks are processed preferentially.

[0311] The task priority state is the execution order level dynamically set according to the document source format, complexity features, and model resource load. For example, a 50-page PDF document containing 30% non-text elements has a high priority when resources are idle; a 10-page pure text Word document has a low priority.

[0312] In this embodiment, the exclusive processing label is a unique identifier generated for the task, containing information such as source format, complexity, time, etc., used for accurate routing to the appropriate processing queue. Use tools such as nvidia-smi to monitor GPU / CPU resource load; establish a priority rule base through a rule engine (such as Drools), such as source format PDF + page number > 30 + non-text ratio > 20% + resource idle → high priority, dynamically generate priority; automatically generate an exclusive processing label according to the format_complexity_date_serial number rule to ensure uniqueness and identifiability.

[0313] In this embodiment, the simulation connection channel is a virtual channel that simulates data transmission between the exclusive processing label and the model processing queue, used to test the feasibility of communication logic and avoid conflicts caused by direct invocation of real resources. For example: for the PDF_high complexity_20250823_001 label, a virtual channel is built with the high complexity PDF processing queue to simulate the data transmission process.

[0314] The communication connection program is a collection of codes that implement data transmission between the exclusive processing label and the model processing queue, including transmission protocols, data encapsulation logic, etc. For example: Python code based on RabbitMQ, which encapsulates the label as a JSON message and sends it to the queue.

[0315] The transmission code segment is the core code segment in the communication connection program responsible for actual data transmission. For example, in the RabbitMQ communication program:

[0316] channel.basic_publish(exchange='pdf_high',routing_key='high_complex',body=tag) is the transmission code segment, which implements the sending of the label to the specified queue.

[0317] Communication parameters are key parameters that affect transmission efficiency and stability in the communication process. For example: transmission rate, timeout, number of retries.

[0318] The interface connection function is a function that applies communication parameters to the model processing queue, enabling interaction between parameters and queues. For example: the set_timeout(queue, timeout) function applies the timeout parameter to the target queue, defining the maximum time the queue waits for data.

[0319] The communication simulation embodiment is based on the interface connection function, simulating the effect of communication parameters in actual scenarios, used to verify the reasonableness of parameters. For example: based on the set_timeout function, simulate whether the label data can successfully enter the high complexity PDF processing queue when the transmission rate is 100kb / s and the timeout is 5s.

[0320] Simulation step is the time interval in the communication simulation process, used to test the effect of parameters at different times. For example: simulate transmission by 10ms step, record data transmission status (such as whether timeout, whether successful transmission) every 10ms.

[0321] Variable function is a function relationship that describes the change of communication parameters with other factors in the transmission code segment. For example: the variable function of timeout time is timeout time = basic timeout (5s) + 0.5 × network delay (s), which means the larger the network delay, the longer the timeout time.

[0322] Additional parameters are additional parameters that affect communication parameters, such as network delay, data size, etc. For example: network delay 3s, label data size 200KB, which will affect the actual effect of transmission rate and timeout time.

[0323] Improvement identification is information generated based on simulation results, marking the communication parameters that need to be optimized. For example: simulation found that timeout time 5s will cause transmission failure when network delay is 3s, generate improvement identification timeout time needs to be extended to 8s. Set fixed simulation step in simulation platform, record transmission status at each time; analyze the relationship between parameters and additional parameters through function fitting tool (such as Python's scipy library), get variable function; combine simulation results and variable function, automatically generate improvement identification, and clear the optimization direction and specific value of parameters.

[0324] Attribute division is classified according to the type of improvement identification (such as transmission rate, timeout time, retry times), which is convenient for batch processing. For example: extend the timeout time to 8s, and increase the transmission rate to 150kb / s, respectively, as timeout class and rate class improvement identification.

[0325] Communication thread is an execution flow constructed according to the order of communication parameters in the transmission code segment, ensuring that parameters take effect in logical order. For example: construct the thread in the order of transmission rate → timeout time → retry times, set the rate first, then define the timeout, and finally configure the retry rule.

[0326] Improved code is the optimized transmission code segment based on improvement identification, used to realize accurate communication between tags and queues. For example: change the timeout time parameter in the original transmission code segment from 5s to 8s, generate improved code channel.basic_publish(..., timeout=8).

[0327] Model processing queue is a task queue specially adapted to documents of specific format and complexity range, such as high complexity PDF queue (adapt to PDF with more than 50 pages and non-text ratio more than 20%), low complexity Word queue (adapt to Word with less than 20 pages and mainly pure text).

[0328] The beneficial effects of the above technical solution are: by analyzing the document source format and complexity characteristics, combining model resource load to dynamically schedule task priority, and then simulating and optimizing communication parameters, the exclusive processing label is accurately routed to the adaptive queue, effectively improving the resource utilization and task execution efficiency of document processing, and avoiding resource waste and queue congestion.

[0329] The application provides a document structured conversion method based on layout detection and rule engine, which integrates structured information into a standardized preset document, comprising:

[0330] The structured information is subjected to semantic correlation recognition to establish parent-child reference relationship and logical sequence index between elements.

[0331] The first dynamic parameter in the first information at the same level child position which changes with the static parameter of the higher level parent position and the first static parameter which does not change with the dynamic parameter of the higher level parent position are determined to obtain the dynamic vector and static vector of the same level child position.

[0332] The dynamic vector and static vector of the same level child position are spliced according to the logical sequence index to obtain a hierarchical splicing vector.

[0333] The number of static elements and dynamic elements existing in each level splicing vector is determined, and the number of standard elements is determined in combination with the number of all elements in each splicing vector to obtain a standard splicing matrix.

[0334] The standard splicing matrix is subjected to feature extraction, and the importance of each level in the overall structure of the document is quantified through matrix eigenvalue distribution and element correlation analysis.

[0335] The corresponding level child information is subjected to priority processing according to the importance, and the structured information is intelligently arranged in combination with the document template engine configuration parameters to obtain an initial document.

[0336] The structure feature vector of the initial document is extracted, and the source feature vector of the original structured information is calculated to obtain the structure integration error, and the error relationship between the structure integration error and the mapping structure parameter involved in each row vector in the standard splicing matrix is determined.

[0337] The initial document is optimized according to the structure integration error and all error relationships to obtain a preset document.

[0338] In this embodiment, semantic association recognition is to recognize the logical relationship (such as inclusion, supplement, explanation) between elements through semantic analysis, and the logical order index is the order of the natural appearance of the elements in the document, reflecting the reading logic. The content of the elements is analyzed semantically using NLP tools (such as spaCy) to identify the association relationship; a tree structure (such as Python's dict nesting) is used to store the parent-child relationship, and an ordered list is used to record the logical order index.

[0339] In this embodiment, the first information of the same level sub-position is the same level element under the same parent level. For example: 2.1 Project Objective and 2.2 Project Scope are both sub-levels of Chapter 2, and they are the same level sub-information.

[0340] The static parameter of the parent position of the higher level is the attribute that does not change in the parent element (does not change with the sub-level). For example: the static parameter of the project planning in Chapter 2 is the title text: Project Planning, and the font: bold.

[0341] The first dynamic parameter is the attribute that changes with the parent static parameter in the sub-level element. For example: the numbering of 2.1 and 2.2 changes with the numbering of the parent Chapter 2 (when the parent numbering is 3, the sub-level numbering becomes 3.1 and 3.2), so the numbering is a dynamic parameter.

[0342] The first static parameter is the attribute that does not change with the parent parameter in the sub-level element. For example: the font size of 2.1 and 2.2 is 14pt, which does not change with the parent parameter, so the font size is a static parameter.

[0343] Dynamic vector: a vector composed of dynamic parameters of the same level sub-element. For example: [2.1, 2.2].

[0344] Static vector: a vector composed of static parameters of the same level sub-element. For example: [14pt, 14pt]. Use a custom Python script to extract the numbering, font, text, and other attributes of the elements, and determine whether the parameter changes with the parent level (such as the numbering contains the parent prefix, then it is a dynamic parameter); use a list to store the dynamic vector and the static vector.

[0345] In this embodiment, the hierarchical splicing vector is a vector obtained by merging the dynamic vector and the static vector of the same level sub-element according to the logical order index, reflecting the complete characteristics of the element at this level. For example: the dynamic vector [2.1, 2.2] and the static vector [14pt, 14pt] of the same level sub-information 2.1 and 2.2 are spliced according to the logical order to obtain the hierarchical splicing vector [2.1, 14pt, 2.2, 14pt].

[0346] The number of static elements is the number of static parameters in the hierarchical splicing vector, and the number of dynamic elements is the number of dynamic parameters in the hierarchical splicing vector.

[0347] The standard element quantity is the number of elements that each level should contain according to the document structure specification. For example: the standard element quantity of the second-level title is 4 (each sub-title contains 1 dynamic parameter and 1 static parameter, and 2 sub-titles contain 4 elements in total).

[0348] The standard splicing matrix is a matrix formed by splicing the vectors of all levels according to the standard element quantity, and each row corresponds to the element characteristics of a level. For example: if the document contains 3 second-level title levels, the standard splicing matrix is:

[0349] .

[0350] Feature extraction is to extract key information reflecting the characteristics of the level from the standard splicing matrix, such as element distribution and parameter correlation. For example: extract the numbering rule of the second-level title, such as X.1, X.2, font consistency, all of which are 14pt.

[0351] The matrix eigenvalue distribution is the size and distribution of the matrix eigenvalue, and the larger the eigenvalue, the stronger the influence of the level on the overall structure of the document. For example: the matrix eigenvalue corresponding to the first-level title is 0.8 (the maximum value), indicating that it plays a framework role in the document.

[0352] Element correlation degree is the degree of semantic or structural correlation between elements within a level and other elements. For example: the correlation degree between the second-level title 2.1 project goal and Table 2-1 is 0.9 (highly related), and the correlation degree with Figure 3-1 is 0.1 (low correlation).

[0353] The current importance is a numerical value of 0-1 that quantifies the importance of the level in the document, which more comprehensively and meticulously quantifies the current importance of each level in the overall structure of the document, providing more accurate basis for subsequent priority processing and intelligent arrangement. Specifically:

[0354]

[0355] wherein, is the current importance of the corresponding level m; is the semantic importance of the corresponding element j; is the correlation strength between element i and element j; is the position weight of element i in the logical order index; is the depth weight of the level m where element i is located; is the set of elements in level m; is the set of elements of all levels; is the depth weight of the level li where element i is located; N is the total length of the logical order index; k represents the position in the logical order index.

[0356] Priority processing is to sort elements by importance, and important elements are displayed first or reserved in core positions. For example, arrange the first-level title with importance 0.9 first, then arrange the second-level title with importance 0.7, and finally insert the picture with importance 0.3.

[0357] Document template engine configuration parameters are format rules defined in templates, such as title level styles (# for first level, ## for second level), table alignment (center), and image path format (. / images / xxx.jpg).

[0358] The initial document is a document obtained by preliminary arrangement according to priority and template parameters. Define document format parameters using template engines such as Jinja2; sort elements by importance values, call the template engine to fill structured information into the template, and generate the initial document.

[0359] The structure feature vector is a vector reflecting the structure features extracted from the initial document (such as element type, position, and number). For example, the structure feature vector of the initial document is [title: 2, table: 1, picture: 1].

[0360] The source feature vector is a feature vector extracted from the original structured information, which serves as a benchmark. For example, the source feature vector of the original information is [title: 2, table: 1, picture: 2].

[0361] The structure integration error is the difference between the initial document and the original information, such as element missing or position error. For example, comparing the above vectors shows that there is one less picture, and the error is one missing picture.

[0362] The mapping structure parameter is a parameter related to the error in the standard splicing matrix. For example, the matrix row vector parameter corresponding to the picture is position index: 4, and the error may be caused by this parameter error.

[0363] The error relationship is the association between the error and the mapping structure parameter (such as parameter error leading to error). For example, picture missing is related to picture position index error (should be 4 but is empty), which is: use feature extraction tools (such as custom hash algorithm) to generate structure feature vector and source feature vector; calculate the structure integration error by vector difference; use association rule mining (such as Apriori algorithm) to analyze the relationship between the error and the matrix parameter.

[0364] The preset document is the final standardized document obtained by optimizing the initial document according to the error and error relationship. For example, correct the picture missing error, supplement the picture path, and generate a complete document that meets the template specifications.

[0365] The beneficial effects of the above technical scheme are: the logical relationship of elements is established through semantic association recognition, the structured matrix is constructed by distinguishing dynamic and static parameters, intelligent arrangement is realized by combining importance quantification and template engine, and finally the preset document is generated by error analysis optimization, which significantly improves the accuracy, logic and standardization of document structuring, and is suitable for large-scale document standardization processing scenarios.

[0366] Obviously, those skilled in the art can make various modifications and variations to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application belong to the scope of the claims of the present application and their equivalent technologies, the present application also intends to include these modifications and variations.

Claims

1. A document structure transformation method based on layout detection and rule engine, characterized in that, include: Step 1: Document Task Reception and Initialization: Receive the source format of the document to be converted, generate a unique task identifier and initialize the task status, record it in the task database table, and submit it to the model processing queue; Step 2: Layout model identifies structural elements: The layout detection model is called to perform layout analysis on each page of the document image and output element block information, which includes element block type, position information and confidence level; Step 3: Structural Correction and Multi-level Heading Reconstruction: For the heading blocks output by the model, combine the numbering format, semantic features and style information, perform regular expression rule matching, build a heading rule library, perform hierarchical correction on the initial recognition results, and form a multi-level heading structure that conforms to the preset grammatical specifications; Step 4: Image and table structure association and restoration: Establish the association between image blocks and descriptive text, submit table blocks to the structure recognition module, generate a structured table by combining OCR and table recognition model, and retain the mapping relationship between the original image and structured data; Step 5: Preset document generation and storage: Integrate structured information into standardized preset documents, upload the final document to object storage, and store intermediate identification block information in the ES index; Step 6: Task process status tracking and control mechanism: Update the task status in stages and write it to the database.

2. The document structure transformation method based on layout detection and rule engine according to claim 1, characterized in that, The layout detection model is based on the DocLayout-YOLO_ft model, which is finely tuned from YOLO, and is used to detect document elements.

3. The document structure transformation method based on layout detection and rule engine according to claim 1, characterized in that, The matching process of the regular expression rules includes: maintaining a multi-level heading rule library, and correcting heading levels and filling in missing segments based on numbering continuity and semantic keywords.

4. The document structure transformation method based on layout detection and rule engine according to claim 1, characterized in that, Table blocks are extracted into HTML or Markdown table syntax through image recognition and structural reasoning models, and merged cell parsing is supported.

5. The document structure transformation method based on layout detection and rule engine according to claim 1, characterized in that, Image blocks and their corresponding descriptive text are associated with each other through image groups and embedded into the appropriate locations in the Markdown document.

6. The document structure transformation method based on layout detection and rule engine according to claim 1, characterized in that, The task status is communicated asynchronously with the task management module via a message queue, supporting status push, exception callback, and dead letter message management.

7. The document structure transformation method based on layout detection and rule engine according to claim 1, characterized in that, Submitted to the model processing queue, including: While identifying the document source format, the complexity features of the document are also analyzed. These complexity features include the number of pages, the types and proportions of non-text elements contained in the document. Based on the document source format, complexity characteristics, and current model resource load, dynamically initialize task priority status and assign exclusive processing labels; Establish a simulation connection channel between a dedicated processing tag and a model processing queue, and obtain the transmission code segment in the communication connection program that describes the simulation connection channel; The communication parameters in the transmission code segment and the interface connection function between each communication parameter and the model processing queue are extracted, and the communication simulation implementation example of the corresponding communication parameter is determined based on the interface connection function; Taking each of the aforementioned communication simulation embodiments as the main focus, communication simulation is performed sequentially on the simulation connection channel to obtain the improvement identifier of each communication parameter. The improvement identifier is related to the simulation step size, the variation function of the corresponding communication parameter based on the transmission code segment, and the additional parameters that match the corresponding communication parameter. All improved identifiers are categorized by attributes, and communication threads are constructed based on the order in which communication parameters appear in the transmission code segment. Improved code based on the transmission code segment is obtained to route the exclusive processing tag to the corresponding model processing queue, wherein the model processing queue is adapted to document processing requirements of specific formats and complexity ranges.

8. The document structure transformation method based on layout detection and rule engine according to claim 1, characterized in that, Integrate structured information into standardized pre-defined documents, including: Semantic association recognition is performed on structured information to establish parent-child reference relationships and logical order indexes between elements; Determine the first dynamic parameter of the first information in the same level child position in the parent-child reference relationship, which changes with the static parameter of the higher-level parent position, and the first static parameter that remains unchanged with the dynamic parameter of the higher-level parent position, to obtain the dynamic vector and static vector of the same level child position. The dynamic vectors and static vectors at the same level are concatenated according to their logical index to obtain the hierarchical concatenated vector; Determine the number of static and dynamic elements in the concatenation vector at each level, and combine this with the total number of elements in each concatenation vector to determine the standard number of elements, thus constructing the standard concatenation matrix. Feature extraction is performed on the standard splicing matrix, and the current importance of each level in the overall document structure is quantified by analyzing the matrix eigenvalue distribution and element correlation. The initial document is generated by prioritizing the sub-information based on its current importance and intelligently arranging the structured information in conjunction with the document template engine configuration parameters. Extract the structural feature vector of the initial document and calculate the structural integration error with the source feature vector of the original structured information. Determine the error relationship between the structural integration error and the mapping structural parameters involved in each row of the standard splicing matrix. The initial document is optimized based on the structural integration error and all error relationships to obtain the preset document.