Building field document analysis method
By preprocessing documents and persisting media, and using a stack algorithm to construct chapter trees and generate summaries from a large language model, the problems of easy loss of multimedia content and difficulty in staticizing automatic numbering in cross-platform use of architectural documents are solved. This achieves persistence of multimedia resources and accurate restoration of chapter structure, improving document manageability and generation efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CCCC WUHAN CHI HENG INT ENG CONSULTING CO LTD
- Filing Date
- 2026-03-17
- Publication Date
- 2026-05-19
AI Technical Summary
Construction documents in the building industry are easily lost when used across platforms, and automatic numbering is difficult to staticize, resulting in a chaotic chapter structure and affecting retrieval and reuse.
By preprocessing documents and persisting media, a stack algorithm is used to construct a chapter tree, generate static numbering, and a large language model is used to generate summaries and semantic vectors to establish a hybrid retrieval index, thereby achieving multimodal media persistence and automatic static numbering.
Ensure cross-platform accessibility of multimedia resources, accurately restore chapter structure, improve the manageability and reusability of document content, provide efficient semantic retrieval and intelligent recommendation, and improve document generation efficiency and quality.
Smart Images

Figure CN122065848A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent document processing technology, and in particular to a document parsing method in the field of architecture. Background Technology
[0002] In the current technological field, especially in the construction industry, the management and processing of construction documents face numerous challenges. Traditional construction documents typically contain a large number of diagrams, tables, and formulas, and are complex in structure, with unclear hierarchical relationships between chapters, and are lengthy and difficult to reuse. These documents are usually static, requiring multiple manual updates and maintenances. Especially when used across platforms, they rely on specific file formats, and their persistence, numbering, and media resource management all present numerous problems.
[0003] Architectural documents often contain a large amount of multimedia content such as diagrams, formulas, and images. This content is easily lost or fails to display correctly during document format conversion or cross-platform use. Mathematical formulas, in particular, cannot be rendered correctly in web environments or other systems without proper processing. Furthermore, media resources in documents typically rely on local storage paths, making them susceptible to loss during file migration or cross-environment use. Additionally, architectural documents commonly employ multi-level automatic numbering (e.g., "1.", "1.1", "1.1.1") to construct a clear chapter hierarchy, which forms its core logical framework. However, automatic numbering in Word documents relies on dynamically defined styles and counter logic within its internal OpenXML format, rather than static text. Existing general format conversion tools (such as direct docx to HTML conversion) often struggle to accurately capture and reconstruct this complex dynamic numbering logic during parsing, leading to issues such as lost numbering, disordered order, or flattened content resembling plain text like "1." after conversion. This not only disrupts the original hierarchical semantics of the document but also makes chapter-based location, retrieval, and subsequent automated processing extremely difficult. Therefore, there is an urgent need for a document parsing method in the field of architecture that can ensure that all media resources in the document can be stably referenced across different platforms and that the automatic numbering can be staticized so that the number of each chapter becomes fixed text in the document. Summary of the Invention
[0004] The main objective of this invention is to provide a document parsing method in the field of architecture, which solves the problems of persistence of multimodal media and static automatic numbering in the prior art.
[0005] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is to provide a document parsing method in the field of architecture, including the following steps:
[0006] S1. Document Preprocessing and Media Persistence: The input documents are formatted uniformly, static numbering is performed to solidify the dynamic numbering in the documents, and media resources in the documents are extracted and uploaded to the MinIO object storage service for persistence. S2. Structured parsing: Construct a DOM tree, use the stack algorithm to build the nested relationship of chapters according to the title level to form a chapter tree, merge non-title content into the corresponding chapter nodes, and generate path numbers for the nodes in the chapter tree; S3. Knowledge Representation and Storage: The chapter content is processed using a large language model to generate summaries and semantic vectors, and a hybrid retrieval index is built based on the chapter's text content, summary, and semantic vectors. S4. Retrieval and Application: Responding to user queries, perform a hybrid retrieval of keyword matching and semantic vector similarity calculation to obtain relevant historical chapters as templates to assist in generating new construction plan documents.
[0007] Preferably, in step S1, document preprocessing and media persistence include: When the input document is in the old .doc format, convert it to the .docx document format; Static numbering is applied to .docx documents by parsing the document's numbering definition XML structure and extracting the numbering style mapping; Traverse the document paragraphs. For paragraphs with dynamic numbering, simulate the counter logic of the document processing software to generate static numbered text, write the static numbered text to the beginning of the paragraph, and remove the original dynamic numbering attribute node.
[0008] Preferably, the static numbering process specifically includes: Parse the numbering definition instances and level format definitions in the XML document, and construct a numbering definition hash table; Traverse document paragraphs and maintain a multi-level counter cache stack. When the current paragraph title level increases, use loop logic to clear the counter cache below that level. A static number string is generated based on the counter cache value and written to the beginning of the paragraph, while the original dynamic number attribute of the paragraph is deleted.
[0009] Preferably, the counter logic of the simulated document processing software specifically includes: Maintain a counting cache for each numbered instance and its hierarchy; When processing the current paragraph number, check whether the count value of its parent number has changed; If an increment in the count value of the parent number is detected, clear the count cache of all child numbers to reset the count of the child numbers.
[0010] Preferably, extracting media resources from the document and uploading them to the MinIO object storage service for persistence includes: Convert the document to HTML format, and extract the embedded images and rendered formula images to your local machine during the process; Upload all extracted image files to the MinIO object storage service to obtain the corresponding accessible URLs; Replace the reference path to the local image in the HTML document with the corresponding MinIO object storage service URL.
[0011] Preferably, in step S2, the stack algorithm constructs the nesting relationship of chapters based on the heading level, specifically including: Traverse the elements in the Document Object Model tree sequentially; When a heading element is identified, its heading level is determined based on its tag; Maintain a stack of title nodes, where the top node represents the current context; Loop through and compare the current title level with the title level of the top node in the stack. If the stack is not empty and the title level of the top node is greater than or equal to the current title level, pop the top node from the stack. Create the current title as a node. If the stack is empty, make it one of the root nodes; otherwise, add it as a child node of the current top node of the stack. Push the current title node onto the stack.
[0012] Preferably, in step S2, merging non-title content into the corresponding chapter node specifically involves: during the traversal process, appending paragraph text, table-converted text, and image URLs to the content field of the chapter node represented by the current top node of the stack. The process of generating path numbers for nodes in the chapter tree involves: recursively traversing the completed chapter tree, assigning local indices based on the order of nodes among their sibling nodes, and generating complete path numbers by backtracking the parent node indices.
[0013] Preferably, in step S3, knowledge representation and storage include: Input the chapter node title and content text into the large language model, and use instructions to generate a despecific summary that removes item-specific information; The text embedding model is invoked to convert the content text of the chapter nodes and the generated summary text into semantic vectors, respectively.
[0014] Preferably, in step S3, establishing a hybrid retrieval index includes: creating an index in Elasticsearch, storing text fields including title, content, and summary for each chapter node, and storing a vector field that stores semantic vectors converted from the content text and summary text respectively.
[0015] Preferably, in step S4, the retrieval and application include: hybrid retrieval, which is a retrieval method that simultaneously weights and fuses keyword matching scores based on text fields and semantic similarity scores based on vector fields.
[0016] Beneficial effects: 1. Multimodal media resource persistence: Media content such as images, charts, and formulas in the document are extracted and uploaded to MinIO to generate URLs, avoiding the traditional document's dependence on local file paths and ensuring the accessibility and persistence of media resources when used across platforms; 2. Precise chapter structuring: The stack algorithm accurately restores the chapter hierarchy in the document and generates clear chapter numbers, realizing document structuring and improving the manageability and reusability of document content; 3. Intelligent summary generation and content compression: Utilizes a large language model to generate despecific summaries for each chapter, removing project-specific information and retaining general process points, thereby improving the universality and template-based nature of the document content and promoting the efficient reuse of knowledge; 4. Efficient semantic retrieval and intelligent recommendation: Combining keyword retrieval and semantic vector similarity calculation, it provides accurate search results, helps users quickly obtain relevant historical chapter templates, and generates new solutions based on historical templates that meet the current project requirements, thus improving document generation efficiency and quality. Attached Figure Description
[0017] The present invention will be further described below with reference to the accompanying drawings and embodiments: Figure 1 This is a structural diagram of a document parsing method in the field of architecture according to the present invention; Figure 2 This is a simplified flowchart of the automatic numbering static problem of the present invention; Figure 3 This is a simplified flowchart of the multimodal media persistence process of the present invention. Detailed Implementation
[0018] Example 1 like Figure 1 As shown, the present invention provides a document parsing method in the field of architecture, comprising steps S110 to S140, including: Step S110: Document preprocessing and media persistence, unify the format, perform cross-format conversion through static numbering, extract images, tables and formulas and upload them to the MinIO object storage service. Step S120: Structured parsing, constructing the conversion format through the Document Object Model (DOM), building the chapter nesting relationship based on the stack algorithm, merging the content, and generating chapter numbers; Step S130: Knowledge representation and storage. The large language model compresses the chapter content, converts the text into semantic vectors, and establishes a hybrid retrieval index. Step S140, Retrieval and Application, supports keyword, semantic and mixed retrieval, and provides historical chapter templates for generating new construction plans.
[0019] According to an embodiment of the present invention, in step S110, the system first uses the win32com library to uniformly convert the old .doc files to .docx files, and then uses the pypandoc library to convert the documents to HTML format so as to preserve the structure of headings and tables through an Abstract Syntax Tree (AST). Pypandoc is a Python document conversion library used to convert Word documents (.docx) to HTML format while extracting embedded media resources.
[0020] To address the issue of disordered dynamic numbering in Word during conversion, the system performs deep XML parsing to extract the numbering style definition. It simulates Word's internal logic using a cache-based dynamic counting algorithm. When higher-level numbering increments, a loop logic automatically clears all lower-level counting caches, ensuring that when moving from "1.1" to "1.2", the child level is correctly reset to "1.2.1". The calculated numbering is then written as static text at the beginning of the paragraph.
[0021] The statically generated docx file is converted to HTML using pypandoc. The `extract-media` parameter extracts all embedded images and charts to a local temporary directory. Simultaneously, the webtex option is used to render LaTeX formulas as images via online services like CodeCogs and save them. The MinIO client is initialized. MinIO is an open-source, high-performance object storage service compatible with the Amazon S3 API, used to store media resources in the document and generate URLs. All images and formula images are uploaded in batches to the specified MinIO bucket, generating a globally unique, publicly accessible URL for each file. The generated HTML files are then iterated through, and the `src` attribute value of all images is replaced with the corresponding MinIO URL. All media resources in the document are now persistently stored in the cloud, eliminating the need for subsequent processing on a local basis.
[0022] According to an embodiment of the present invention, in step S120, the BeautifulSoup library is used to parse the HTML string and construct an in-memory DOM tree. This tree fully preserves the nesting relationship and order of tags, transforming the document into a programmable traversable object structure. The system sequentially traverses the DOM tree, identifying all title tags. When a new title is encountered, its level is determined based on its tag. If the level of the title at the top of the stack is greater than or equal to the level of the current title, the top element of the stack is popped until the level of the top element of the stack is less than the current level. At this point, the top of the stack is the parent node of the current title. The current title is created as a tree node and added to the children list of its parent node. If the stack is empty, it becomes the root node. Then, this new node is pushed onto the top of the stack to become a new context. By constructing the chapter nesting relationship based on the stack algorithm, irregular nesting can be handled, accurately restoring the parent-child and sibling relationships between chapters.
[0023] When traversing the DOM tree, all non-heading elements (such as paragraphs) should be included. ,sheet
[0024]
[0025]
[0026]
[0027]
[0028]
[0029] Figure 2
[0030] <w:ppr>Does the following exist? <w:numpr>For child nodes, if they exist, extract their NumID and LevelArray; otherwise, skip them. Based on the extracted NumID, retrieve the corresponding counter vector from the maintained dictionary. If the NumID appears for the first time, its counter vector is initialized to all zeros. Since the appearance of this paragraph implies a possible change at the same or higher level, it needs to be updated based on the hierarchical relationship between the current level and the previous paragraph of the same instance. When processing a level of headings, the counter vector is updated according to formula (3): (3) in, For the current number The count value of the heading level. For heading level, For the updated number There are several counter vectors. The system extracts the instance ID and current level from these vectors. A multi-level counter cache stack is maintained, with a data structure of Dict[int, int]. Lower-level caches are cleared as higher-level counters increment. When the value changes from "1.1" (level=1) to "1.2", counters at level 2 and below are reset. The cached counter values are formatted into static number strings according to the defined numbering format. As shown in equation (4): (4) in, This is a template for the numbering format at each level obtained from parsing the XML document. The function converts the numerical value according to the format template. count value Convert to strings of the corresponding style and process them in order. The concatenation operation inserts the calculated statically numbered text at the beginning of the paragraph, deletes the numPr child node of that paragraph to completely remove Word's dynamic numbering mechanism, and saves the counter vector corresponding to the current NumID back to the dictionary for use in subsequent paragraphs.
[0031] Repeat the above static processing operation to determine if all paragraphs have been processed. If not, return to traversing nodes and continue processing. If yes, proceed to the end stage, serialize the modified document tree into a new .docx file, convert it to HTML using pypandoc, extract the images in the document using extract-media, and display the numbers as plain text in the HTML. After the images are uploaded to MinIO, a fully self-contained, statically numbered, and cloud-native persistent digital asset of the architectural document is formed.
[0032] Example 3 like Figure 3 As shown, the system receives the .docx document after the aforementioned numbering and static processing, using it as the input source for media extraction. After format conversion, the `--extract-media` parameter automatically unzips the `word / media / ` directory within the .docx package, extracting all embedded images to a local temporary directory while preserving the original filenames and relative path structures. The `--webtex` parameter identifies LaTeX / MathML formulas in the document, calls online rendering services such as CodeCogs or the local MathJax engine, converts the formulas into high-resolution PNG / SVG images, and saves them to the same temporary directory. The system establishes a connection with the MinIO object storage service through the minio library. The initialization process includes server endpoint discovery, authentication, and a transport layer security handshake. The system traverses the media files in the temporary directory, using chunked transfer encoding for batch uploads, generating a globally unique access URI for each uploaded object. If the storage bucket is set to public read, a URL in the format `http: / / minio-server / construction-docs / {doc_id} / {filename}` is generated. A hash table of local filenames → MinIO URLs is maintained for subsequent HTML replacement.
[0033] The system loads the HTML file content generated by pypandoc into memory, constructs a traversable DOM tree, performs resource reference rewriting, and replaces all relative or absolute paths in the HTML with URLs pointing to MinIO, thus decoupling media resources from document content. The modified DOM tree is then serialized into a UTF-8 encoded HTML5 file. The HTML document no longer contains any local file references, and all media resources are accessed via cloud URLs. The process terminates, outputting a completely cloud-native HTML document.
[0034] The above embodiments are merely preferred technical solutions of the present invention and should not be considered as limitations on the present invention. The scope of protection of the present invention should be limited to the technical solutions described in the claims, including equivalent substitutions of the technical features described in the claims. That is, equivalent substitutions and improvements within this scope are also within the scope of protection of the present invention.< / w:numpr> < / w:ppr> The text content (images) or MinIO URL is appended to the content field of the current top node of the stack for content merging. Table content is converted into plain text format with tabs separating cells and newlines separating rows to ensure information retrieval. The constructed chapter tree is recursively traversed, and each node is assigned a local sequence number (e.g., 1, 2, 3…) according to its order among sibling nodes. By backtracking the parent node sequence number, a complete path number (e.g., "1.2.1") is generated. Finally, this number is concatenated with the original node title, such as "1.2.1 Concrete Pouring Process", thereby updating the node information to form a final structure with deterministic positioning coordinates. According to an embodiment of the present invention, in step S130, for each chapter node, its title and content text are input into the large language model Llama 3.2. Through carefully designed prompt word engineering, the model is required to generate a "de-specific" summary. For example, the instruction model removes specific information such as "XX City XX Project", retaining only general process points such as "temperature difference control measures for large volume concrete". The generated summary field is a highly condensed representation of the chapter's core intent. By calling the API of the dedicated embedding model text-embedding-3, the process of converting the chapter's content and summary text into high-dimensional dense vectors maps the text's semantics to a vector space. Texts with similar semantics have vectors that are closer together in this space. When building the hybrid retrieval index, an index is created in Elasticsearch, and a document record is created for each chapter node, including: text fields such as title, content, and summary supporting keyword full-text search; metadata fields such as scheme_name and file_url for precise filtering; and vector fields such as content_vector and summary_vector storing the generated vectors for similarity calculation. Elasticsearch is an open-source search and analytics engine used to build the hybrid retrieval index and perform keyword and semantic similarity searches. The system recursively traverses the chapter tree, indexing all nodes in this format to Elasticsearch, making each chapter an independent, multi-dimensionally searchable knowledge atom. According to an embodiment of the present invention, in step S140, the system provides users with a unified retrieval interface, directly utilizing Elasticsearch to quickly match the inverted index of text fields such as title and content. The user's query is also converted into a vector, and then the nearest neighbor algorithm is used in Elasticsearch to search for the most similar chapter by calculating the cosine similarity with the content_vector or summary_vector field.Combining the above two, the final score is obtained by weighted fusion of the term frequency-inverse document frequency (BM25) score and the vector similarity score, as shown in the following formula: (1) where is the BM25 score based on Elasticsearch, is the text field node, is the cosine similarity between the query vector and the chapter vector, and are weighting coefficients, satisfying , by adjusting the coefficients to take into account both literal matching and semantic relevance, the quality and diversity of the recall results are improved. When users need to compile new schemes, the system can use the retrieval module to find the most relevant chapter fragments from the historical database. Chapter fragments carry their structured content, despecificated summaries, and original file location information. The despecificated summaries utilize a large language model, which, according to a specific prompt, calls an embedding model to map the structured content and the summary into a dimensional vector, as shown in equation (2): (2) where is the structured content and is the summary. This ensures that the cosine distance between semantically similar original chapter content in the vector space is minimized. From the original chapter content containing specific project information, one-time, unreusable specific information such as "XX City XX Project" is removed, and general process points with universal guiding significance, such as "temperature difference control measures for large-volume concrete", are extracted. Implicit project experience is transformed into explicit, widely reusable standardized knowledge. High-quality, standardized historical knowledge in the chapter fragments is used as context input to the large language model, which is instructed to "refer to the following examples and generate a scheme chapter that meets the requirements of the current new project". The large language model can imitate and innovate based on historical high-quality templates, rather than starting from scratch, which greatly improves the professionalism, standardization, and efficiency of the generated scheme, and realizes the explicit and automated reuse of the enterprise's implicit knowledge. Example 2, as shown, identifies the input format by its file extension. If it's the older .doc binary format (CompoundFile Binary Format), it proceeds to the .docx file conversion step. The win32com component calls the Microsoft Word COM interface to perform a SaveAs operation, converting .doc to .docx. If it's already in .docx format, the conversion is skipped, ensuring subsequent processing is based on a unified standard and avoiding compatibility risks associated with binary format parsing. win32com is a Python library used to interact with Microsoft Word via the COM interface to achieve document format conversion. The system decompresses the .docx file, reads word / numbering.xml and word / styles.xml, and uses an XML parser to extract the abstract numbering definition AbstractNum, the binding relationship between number instances and AbstractNum, and the format definitions for each level. It then constructs an in-memory hash table of numbering definitions: NumID → AbstractNumID → Level Array, establishing a fast lookup mapping between paragraphs and numbering format templates. LevelArray stores the format templates for each level.The static processing of paragraph-level numbering based on stacks uses the python-docx library to traverse all Paragraph objects in the document and view the paragraph XML.
Claims
1. A document parsing method in the field of architecture, characterized in that, Includes the following steps: S1. Document Preprocessing and Media Persistence: The input documents are formatted uniformly, static numbering is performed to solidify the dynamic numbering in the documents, and media resources in the documents are extracted and uploaded to the MinIO object storage service for persistence. S2. Structured parsing: Construct a DOM tree, use the stack algorithm to build the nested relationship of chapters according to the title level to form a chapter tree, merge non-title content into the corresponding chapter nodes, and generate path numbers for the nodes in the chapter tree; S3. Knowledge Representation and Storage: The chapter content is extracted using a large language model to remove specific information and generate a standardized summary that excludes project-specific information. The chapter content and the standardized summary are mapped to high-dimensional semantic vectors using an embedding model to construct a hybrid retrieval index that includes text fields and vector fields. S4. Retrieval and Application: Responding to user queries, perform a hybrid retrieval of keyword matching and semantic vector similarity calculation to obtain relevant historical chapters as templates to assist in generating new construction plan documents.
2. The document parsing method in the field of architecture according to claim 1, characterized in that, In step S1, document preprocessing and media persistence include: When the input document is in the old .doc format, convert it to the .docx document format; Static numbering is applied to .docx documents by parsing the document's numbering definition XML structure and extracting the numbering style mapping; Traverse the document paragraphs. For paragraphs with dynamic numbering, simulate the counter logic of the document processing software to generate static numbered text, write the static numbered text to the beginning of the paragraph, and remove the original dynamic numbering attribute node.
3. The document parsing method in the field of architecture according to claim 2, characterized in that, The static numbering process specifically includes: Parse the numbering definition instances and level format definitions in the XML document, and construct a numbering definition hash table; Traverse document paragraphs and maintain a multi-level counter cache stack. When the current paragraph title level increases, use loop logic to clear the counter cache below that level. A static number string is generated based on the counter cache value and written to the beginning of the paragraph, while the original dynamic number attribute of the paragraph is deleted.
4. The document parsing method in the field of architecture according to claim 2, characterized in that, The counter logic of the simulated document processing software specifically includes: Maintain a counting cache for each numbered instance and its hierarchy; When processing the current paragraph number, check whether the count value of its parent number has changed; If an increment in the count value of the parent number is detected, clear the count cache of all child numbers to reset the count of the child numbers.
5. The document parsing method in the field of architecture according to claim 2, characterized in that, Extracting media resources from a document and uploading them to the MinIO object storage service for persistence includes: Convert the document to HTML format, and extract the embedded images and rendered formula images to your local machine during the process; Upload all extracted image files to the MinIO object storage service to obtain the corresponding accessible URLs; Replace the reference path to the local image in the HTML document with the corresponding MinIO object storage service URL.
6. The document parsing method in the field of architecture according to claim 1, characterized in that, In step S2, the stack algorithm constructs the nesting relationship of chapters based on the heading level, specifically including: Traverse the elements in the DOM tree sequentially; When a heading element is identified, its heading level is determined based on its tag; Maintain a stack of title nodes, where the top node represents the current context; Loop through and compare the current title level with the title level of the top node in the stack. If the stack is not empty and the title level of the top node is greater than or equal to the current title level, pop the top node from the stack. Create the current title as a node. If the stack is empty, make it one of the root nodes; otherwise, add it as a child node of the current top node of the stack. Push the current title node onto the stack.
7. The document parsing method in the field of architecture according to claim 1, characterized in that, In step S2, merging non-title content into the corresponding chapter node specifically involves appending paragraph text, table-converted text, and image URLs to the content field of the chapter node represented by the current top node of the stack during the traversal process. The process of generating path numbers for nodes in the chapter tree involves: recursively traversing the completed chapter tree, assigning local indices based on the order of nodes among their sibling nodes, and generating complete path numbers by backtracking the parent node indices.
8. The document parsing method in the field of architecture according to claim 1, characterized in that, In step S3, knowledge representation and storage include: The chapter node titles and content text are input into the large language model, and prompt words are used to generate a despecific summary that removes project-specific information. The text embedding model is invoked to convert the content text of the chapter nodes and the generated summary text into semantic vectors, respectively.
9. The document parsing method in the field of architecture according to claim 1, characterized in that, In step S3, establishing a hybrid retrieval index includes: creating an index in Elasticsearch, storing text fields including title, content, and summary for each chapter node, and storing a vector field that stores semantic vectors converted from the content text and summary text respectively.
10. The document parsing method in the field of architecture according to claim 1, characterized in that, In step S4, retrieval and application include: hybrid retrieval is a retrieval method that simultaneously performs linear weighted fusion of keyword matching scores based on text fields and semantic similarity scores based on vector fields.