Document-oriented parsing method
By performing region detection and syntax repair on the document pages and reconstructing the clause tree, the problem of inconsistent document parsing results in the existing technology is solved, and structured content generation that can be directly utilized is realized.
Patent Information
- Application Number
- CN202611438402.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-16
- Publication Date
- 2026-11-20
AI Technical Summary
Existing technologies suffer from problems such as missing or mismatched delimiters in the formula recognition output text, inconsistent table splitting and splicing order during document parsing, making it difficult to use the parsing results directly and requiring users to manually correct and reorganize them.
By performing region detection on the document page, the text, title, table and formula regions are identified, and the formulas are sorted in ascending order by image area. A preset formula recognition model is used to perform grammatical repair, the clause tree is reconstructed, and the content is clustered and sorted by page coordinates to assemble the structured content.
It automatically corrects syntax errors in formula text, restores the association between tables and images, and maintains the original hierarchical structure and reading order of the parsed results, allowing users to directly utilize the structured content without manual organization.
Smart Images

Figure CN123142244A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of document content recognition technology, and specifically to a document parsing method. Background Technology
[0002] Documents are an important form of conveying technical specifications and research results, and they extensively use formulas, tables, and illustrations to express technical content. Converting paper or scanned documents into structured content that can be processed by computers is a fundamental step in document retrieval and utilization.
[0003] Current technologies for parsing document pages mostly employ optical character recognition (OCR), recognizing text page by page and then sequentially piecing together the results. For formulas, they are either embedded as a single image or converted to text using formula recognition tools before direct output. Tables and illustrations are saved separately as page slices. These methods suffer from several drawbacks: formula output may contain missing delimiters or mismatched syntax errors, making direct compilation impossible; tables are often split into multiple segments at page breaks, resulting in lost connections between segments and between tables and their corresponding clauses; and the page piecing order may not align with the original reading order of the document. After obtaining the parsed results, users still need to manually check and correct formulas, piece together tables, and reorganize the clause hierarchy, making the parsed results difficult to use directly. Summary of the Invention
[0004] To address the shortcomings of existing technologies, this invention provides a document-oriented parsing method. The parsed results can be directly used, reducing the need for manual verification and correction.
[0005] This application provides a document-oriented parsing method, the parsing method comprising: The document page is subjected to region detection to identify the main text region, title region, table region, formula region and image region; The formula images of the formula region are cropped out and arranged in ascending order according to the area occupied by the formula images. The average area of the formula images that are arranged first in a preset number is used as the base area. The average area of the current batch is detected, and the average area of the current batch is compared with the benchmark area. If the ratio is greater than a preset threshold, the number of formula images parsed in the current batch is reduced. The formula images are grouped and sent to a preset formula recognition model in batches to obtain the formula text, and the formula text is then grammatically repaired. Metadata is extracted from the main text area and the title area. A path stack is maintained for the metadata according to the numbering rules. The clause tree is reconstructed according to the path stack. The tables in the table area, the formula text, and the images in the image area are mounted to the clause nodes pointed to by the path stack. The main text, images, and formula text are clustered and sorted according to page coordinates, and then combined with the metadata and the terms tree to assemble them into structured content.
[0006] One aspect of the steps for detecting page layout areas on a document page includes: The document page is analyzed to identify text lines, table borders, formula boundaries and image outlines. Based on the identification results, the document page is divided into text area, title area, table area, formula area and image area, and the coordinate range of each area is recorded.
[0007] In one aspect, prior to the step of cropping the formula image of the formula region, the following is included: The formula region is preprocessed to remove background noise and binarize it to obtain the formula image to be cropped.
[0008] In one aspect, the step of sorting the images in ascending order according to the area occupied by the formula image includes: The pixel width and pixel height of each formula image are calculated, and the product of the pixel width and pixel height is taken as the area occupied. The formula images are then arranged in ascending order of the area occupied.
[0009] In one aspect, the steps for detecting the average area of the current batch include: The area occupied by each formula image in the current batch is calculated, and the average area of each area is taken as the average area of the current batch. The average area of the current batch is compared with the benchmark area. If the ratio exceeds the preset threshold, the number of current batches to be parsed is reduced to a value greater than or equal to the preset number of batches.
[0010] In one aspect, after the step of identifying the formula text, the following is also included: The formula text is encoded and verified to identify illegal encoded characters and replace them with normalized ones, thus obtaining the formula text to be repaired.
[0011] In one aspect, the step of performing syntax correction on the formula text includes: When an illegal character follows a delimiter in the formula text, the delimiter is replaced with an empty delimiter; When the number of left and right delimiters in the formula text is mismatched, remove the delimiter command in the formula text and retain the delimiter; Use a bracket stack to trace the pairing of delimiters that cross curly braces in the formula text and fix pairing errors.
[0012] In one aspect, the steps for fixing delimiter pairings across curly braces using bracket stack tracing include: The formula text is scanned from left to right. When a curly brace start symbol is encountered, the start symbol is pushed onto the bracket stack. When a curly brace end symbol is encountered, the start symbol at the top of the stack is popped. The nesting depth of the curly brace group where the scan position is located is recorded by the stack depth of the bracket stack. When the nesting depth of the curly brace group containing the right delimiter command is inconsistent with the nesting depth of the curly brace group containing the paired left delimiter command, the right delimiter command is moved into the curly brace group containing the left delimiter command to correct the pairing error.
[0013] In one aspect, the step of maintaining a path stack for the metadata according to a numbering rule includes: Parse the hierarchical structure of the clause numbers in each of the aforementioned metadata; When the level of a new clause number is deeper than the level of the top of the stack, the new clause number is pushed onto the path stack; When the level of the new clause number is the same as that of the top of the stack, the new clause number replaces the top of the stack number. When the level of the new clause number is shallower than the level of the top of the stack, pop the corresponding number of numbers from the path stack and push the new clause number back in, so that the path stack points to the current clause node.
[0014] In one aspect, prior to the step of mounting the table of the table region, the formula text, and the image of the image region to the clause node pointed to by the path stack, the method further includes: Merge cross-page continuation tables by comparing whether adjacent page table fragments carry table titles and their respective column counts. If the table fragment on the next page does not carry a table title and its column count is the same as that on the previous page, it is determined that the adjacent page table fragments belong to the same table. The adjacent page table fragments are then merged into a complete table, and the complete table is attached to the clause node as a table in the table area.
[0015] The beneficial effects of this invention are as follows: In the formula recognition stage, the analysis method arranges formula images in ascending order by area. The average area of the top-ranked formula images (with a predetermined number of images) is used as the baseline area. When the ratio of the average area of the current batch to the baseline area exceeds a predetermined threshold, the number of images analyzed in the current batch is reduced. Formula images with larger areas are fed into the predetermined formula recognition model in smaller batches. The amount of data per inference is adjusted according to the size of the formula image, and the formula recognition process is not limited by a fixed batch size. After syntax repair, the formula text obtained by the predetermined formula recognition model has its syntax errors corrected before assembly, allowing the formula text to be directly compiled and presented. Users do not need to manually correct formulas; the parsing method extracts metadata from the main text area and title area, maintains the path stack according to the numbering rules and reconstructs the clause tree. Tables in the table area, formula text and images in the image area are mounted to the clause nodes pointed to by the path stack. The relationship between each element and its clause is represented by the clause tree. Tables and images no longer exist in isolation as page slices. The main text, images and formula text are clustered and sorted according to page coordinates, and assembled with metadata and clause tree into structured content. The parsing results maintain the original hierarchical structure and reading order of the document. Users can directly use the structured content after obtaining it without manual secondary processing. Attached Figure Description
[0016] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the accompanying drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. In all the drawings, similar elements or parts are generally identified by similar reference numerals. In the drawings, the elements or parts are not necessarily drawn to scale.
[0017] Figure 1 This is a schematic diagram of the process steps for the document parsing method in this application. Detailed Implementation
[0018] The embodiments of the technical solution of the present invention will now be described in detail with reference to the accompanying drawings. These embodiments are merely illustrative of the technical solution of the present invention and are therefore intended to limit the scope of protection of the present invention.
[0019] It should be noted that, unless otherwise stated, the technical or scientific terms used in this application should have the ordinary meaning as understood by one of ordinary skill in the art to which this invention pertains.
[0020] like Figure 1 As shown, this application provides a document-oriented parsing method, which includes: Step S10 involves performing region detection on the document page to identify the text area, title area, table area, formula area, and image area. Region detection involves analyzing the image of the document page to determine the location and category of each content element. Page content elements include text, tables, formulas, and images. During region detection, the scanned or converted image of the document page is input into the detection model. The model outputs the bounding boxes and category labels for each content element. Based on the category labels, the bounding boxes are grouped into text areas, title areas, table areas, formula areas, and image areas. The text area contains continuous text content; the table area is an area formed by arranged cells; the formula area contains mathematical expressions; and the image area contains illustrations. The formula area includes inline formula areas and inline formula areas. Inline formulas are embedded within text lines, while inline formulas are on separate lines.
[0021] The detection models are typically Faster R-CNN, YOLO, and DETR. These models take an image of a document page as input, and after inference, output bounding boxes and category labels for various content elements such as text lines, table borders, formula boundaries, and image outlines. Based on the output bounding boxes and category labels, the text area, title area, table area, formula area, and image area can be grouped and segmented, thus completing the recognition of the document page's layout.
[0022] Step S20: Crops out the formula images from the formula region, arranges them in ascending order according to the area occupied by the formula images, and uses the average area of the top-ranked formula images (a predetermined number) as the base area. Cropping refers to extracting image blocks from the corresponding positions of the formula region's coordinate range from the document page image; one formula region is cropped to obtain one formula image. After cropping, the formula images are arranged in ascending order according to their area occupied, from smallest to largest, to obtain an ascending sequence. After arrangement, the top-ranked formula images in the ascending sequence (a predetermined number, typically 10) are selected. The average area of the formula images is calculated and used as the base area. Inline formulas are embedded within text lines and occupy a small area; therefore, the top-ranked formula images are mostly inline formulas, and the base area represents the area level of smaller formulas in the document.
[0023] Step S30: Detect the average area of the current batch and compare it with the baseline area. If the ratio is greater than a preset threshold, reduce the number of formula images parsed in the current batch. The current batch refers to a group of formula images to be sent to the preset formula recognition model. The preset threshold is generally 2. After detecting the average area of the current batch, compare it with the baseline area and calculate the ratio. Compare the ratio with the preset threshold. If the ratio is greater than the preset threshold, it indicates that the formula images in the current batch are generally too large. In this case, reduce the number of formula images parsed in the current batch. In this embodiment, the number of images in each batch is adjusted according to the actual size of the formula images. Batches with larger areas are entered for recognition in smaller quantities. The amount of data in the recognition process is adjusted according to the size of the formula images, and the formula recognition process is not limited by a fixed batch size.
[0024] Step S40: Formula images are grouped and fed into a preset formula recognition model in batches to obtain formula text. The formula text is then subjected to grammatical correction. The preset formula recognition model refers to a pre-trained recognition model that takes formula images as input and formula text as output. The recognition model can employ a neural network with an encoder and decoder structure, and training data consists of formula image samples labeled with formula text. During grouping, the number of formula images in each batch is consistent with the adjusted number of images parsed in the current batch. After the batches are fed in, the preset formula recognition model performs feature extraction and sequence decoding on each formula image within the batch to obtain the formula text describing the formula structure. After recognition, the formula text undergoes grammatical correction, correcting any parts that do not conform to grammatical rules.
[0025] Step S50: Extract metadata from the text and title areas, maintain a path stack for the metadata according to numbering rules, reconstruct the clause tree based on the path stack, and mount the tables, formula text, and images from the table area to the clause nodes pointed to by the path stack. Metadata refers to information describing document attributes and clause attributes, including clause number, clause title, document title, and publication information. The clause number is obtained from the text identified in the text and title areas. After obtaining the clause number, maintain a path stack for the metadata according to numbering rules. Numbering rules refer to the hierarchical division of clause numbers, and the path stack refers to the data structure recording the current clause's position in the hierarchical structure. The stack content updates as the clause number hierarchy changes. Reconstruct the clause tree based on the path stack. The clause tree refers to the tree structure that organizes clause nodes according to parent-child relationships. After reconstruction, mount the tables, formula text, and images from the table area to the clause nodes pointed to by the path stack. Mounting means establishing the hierarchical relationship between elements and clause nodes. This restores the subordinate relationship between elements and clauses, and tables and images no longer exist in isolation as page slices.
[0026] Step S60: Cluster and sort the main text, images, and formula text according to page coordinates, and assemble them into structured content by combining metadata and the clause tree. Page coordinates refer to the position data of each element on the document page. Clustering refers to grouping adjacent elements on the page into the same reading unit, arranging each reading unit according to page number and position within the page. The order of content spanning columns and pages is determined by page number, and the arrangement result is consistent with the original reading order of the document. The objects of clustering and sorting include main text, images, and formula text, all of which participate in merging and arrangement based on page coordinates. After sorting, the structured content is assembled into structured content by combining metadata and the clause tree. The structured content is a data whole organized by fields and hierarchical relationships. Clause number and clause title are written as fields into the corresponding clause nodes. Main text, formula text, tables, and images are attached to the corresponding nodes of the clause tree according to the arrangement result. The structured content output by this embodiment maintains the original hierarchical structure and reading order of the document. Users can directly use the structured content after obtaining it without manual secondary processing.
[0027] To further explain the technical solution of this application, for example, the input PDF (such as GB2762-2017 "National Food Safety Standard: Limits of Contaminants in Food") is first subjected to page area detection, and the page is divided into areas such as main text, chapter and article titles, tables, inline / outline formulas, and images; then, metadata such as standard number, publication date, and substitution relationship are extracted using regular expression rule chains, and a path stack is maintained to reconstruct the clause tree of "standard → chapter → article → clause" according to the numbering rules. The identified elements are mounted to the corresponding clause nodes through clause_path (clause path). Tables are merged and continued across pages according to the "title and number of columns" criterion. Formulas are first dynamically batch-scheduled based on pixel area (bucketed into the formula recognition network to prevent memory overflow) to obtain LaTeX strings, and then repaired into renderable formulas through three layers of delimiter whitelist replacement, left and right delimiter quantity balancing, and bracket stack tracing and cross-bracket grouping and pairing. Finally, Span BlockMatcher is used to cluster by Y rows of the page and sort by X to fill in the reading order, and the extended SDS is output. The model is structured as JSON; then it enters the vectorization stage, where the main text, table cells, formulas in LaTeX, and images are encoded into multimodal vectors and stored in the database. A two-layer caching system, combining "content hash primary key and database persistent cache" with Redis hot caching, eliminates duplicate vectorization calls. A multi-granularity index is built at the standard level, clause level, paragraph level, cell level, formula level, and image level. During retrieval, structural clue words such as "standard number," "Chapter X," and "limited edition" are first identified for granular routing. Then, a dual-path retrieval using the "cosine similarity vector channel and BM25 keyword channel" is performed, filtered by the clause_path prefix, and then sorted by score=w. v ×cosine similarity + w kThe ×BM25 weighted fusion returns the TopN, and also supports cross-modal image search using uploaded photos; for example, searching for "the limit value of lead in vegetables" will be routed to the cell-level index to directly hit 0.1mg / kg in the table, and an inspector taking a photo of the on-site equipment can recall the standard clause containing the corresponding device image; finally, the old and new versions of the standard are parsed into two SDSModels respectively, and the addition, deletion and modification are identified by comparing the content hash according to the clause number. Incremental index updates are only performed on the changed nodes along the clause_path to avoid a full reconstruction of the entire database. v It is the fusion weight of the vector channels, w k It is the fusion weight of the keyword channel (BM25).
[0028] In this embodiment, the parsing method arranges the formula images in ascending order of area during the formula recognition stage. The average area of the top-ranked formula images is used as the baseline area. When the ratio of the average area of the current batch to the baseline area exceeds a preset threshold, the number of images parsed in the current batch is reduced. Formula images with larger areas are sent to the preset formula recognition model in smaller batches. The amount of data per inference is adjusted according to the size of the formula image, and the formula recognition process is not limited by a fixed batch size. After the formula text obtained by the preset formula recognition model is grammatically corrected, grammatical errors are corrected before assembly, and the formula text can be directly compiled and presented without the need for manual correction by the user. The parsing method extracts metadata from the main text area and the title area, maintains the path stack according to the numbering rules, and reconstructs the clause tree. The tables in the table area, the formula text, and the images in the image area are mounted to the clause nodes pointed to by the path stack. The association between each element and its clause is represented by the clause tree, and the tables and images no longer exist in isolation as page slices. The main text, images, and formula text are clustered and sorted according to page coordinates, and assembled with metadata and the clause tree into structured content. The parsing results maintain the original hierarchical structure and reading order of the document, and the user can directly use the structured content without the need for manual secondary processing.
[0029] In one embodiment of this application, the step of performing layout area detection on a document page includes: Step S110 involves performing layout analysis on the document page, identifying text lines, table borders, formula boundaries, and image outlines. Based on the identification results, the document page is divided into a main text area, a title area, a table area, a formula area, and an image area, and the coordinate range of each area is recorded. Layout analysis refers to the process of extracting morphological information of content elements from the document page image. The extracted objects include text lines, table borders, formula boundaries, and image outlines. Text lines refer to horizontal rows and columns formed by adjacent text; table borders refer to the frames formed by the interweaving of horizontal and vertical lines in a table; formula boundaries refer to the boundary between formula content and surrounding text; and image outlines refer to the edge range of illustrations. During layout analysis, after identifying text lines, table borders, formula boundaries, and image outlines, the document page is divided into a main text area, a title area, a table area, a formula area, and an image area based on the relationship between these morphological information types, and the coordinate range of each area is recorded. The coordinate range is represented by boundary values in the page coordinate system. Both the title area and the main text area consist of text lines, and the division is based on the font size and position of the text.
[0030] In one embodiment of this application, before the step of cropping the formula image of the formula region, the following steps are included: Step S201 involves preprocessing the formula region by removing background noise and binarizing it to obtain the formula image to be cropped. Preprocessing refers to the process of cleaning and refining the image of the formula region, addressing both background noise and image color representation. During preprocessing, the formula region is denoised to remove background noise. After denoising, the formula region is binarized, converting the value of each pixel within the formula region into one of two possible values, with the formula strokes and background corresponding to different values. After binarization, the formula image to be cropped is obtained, referring to the preprocessed formula region image that is then processed for cropping. The preprocessing in this embodiment improves the cleanliness of the formula region image, resulting in a clearer formula image with sharper strokes after cropping.
[0031] In one embodiment of this application, the step of sorting the formula images in ascending order by area includes: Step S210: Calculate the pixel width and pixel height of each formula image, and use the product of the pixel width and pixel height as the area occupied. Arrange the formula images in ascending order of area occupied. During the calculation, the pixel width and pixel height of each formula image are read one by one, and the product of the pixel width and pixel height is used as the area occupied. The area occupied is represented by the product of the number of pixels. After the calculation is completed, the formula images are arranged in ascending order of area occupied. The result is an ascending sequence, where the formula images at the beginning of the ascending sequence occupy a smaller area, and the formula images at the end of the sequence occupy a larger area. This embodiment quantifies the size of the formula images using pixel values, and the sorting result intuitively reflects the area order of each formula image.
[0032] In one embodiment of this application, the step of detecting the average area of the current batch includes: Step S310: Calculate the area occupied by each formula image within the current batch, and take the average area of each area as the average area of the current batch. During the calculation, the formula images within the current batch are determined according to the ascending order. The area occupied by each formula image is read one by one, and the average area is calculated. This average area is taken as the average area of the current batch. The average area of the current batch reflects the overall size level of the formula images within the current batch. When the proportion of inline formulas in the current batch is high, the average area of the current batch is larger; when the proportion of inline formulas in the current batch is high, the average area of the current batch is smaller. In addition, this embodiment can also sequentially extract formula images according to the ascending order during batch division, with no overlap between batches, and each formula image belongs to one of the batches.
[0033] Step S320: Compare the average area of the current batch with the baseline area. If the ratio exceeds a preset threshold, reduce the number of images analyzed in the current batch to a value greater than or equal to the preset batch number. The preset batch number can be 2. During the comparison, divide the average area of the current batch by the baseline area to obtain the area ratio, and compare the area ratio with the preset threshold. If the area ratio is greater than the preset threshold, reduce the number of images analyzed in the current batch to a value not lower than the preset batch number. The preset batch number is a pre-set lower limit, and the reduced number of images analyzed in the current batch is not less than the preset batch number. An area ratio greater than the preset threshold indicates that the overall image size in the current batch is too large. Reducing the number of images decreases the amount of image data sent for recognition per cycle. Furthermore, it should be noted that if the area ratio is not greater than the preset threshold, the number of images analyzed in the current batch remains unchanged and is not adjusted.
[0034] In one embodiment of this application, after the step of identifying the formula text, the method further includes: Step S401: Perform encoding verification on the formula text, identify illegal encoded characters in the formula text, and perform normalized replacement to obtain the formula text to be repaired. Encoding verification refers to checking whether the character encoding in the formula text conforms to the set encoding specifications. Illegal encoded characters refer to characters with incorrect encoding formats or characters that exceed the set encoding range. Illegal encoded characters are displayed as garbled text or blanks in the typesetting tool. During verification, the character encoding in the formula text is checked one by one, illegal encoded characters are identified, and normalized replacement is performed on the illegal encoded characters. Normalized replacement means replacing the illegal encoded characters with characters or set symbols within the encoding specifications. After replacement, the formula text to be repaired is obtained, which refers to the formula text that has completed encoding verification and is handed over to syntax repair processing.
[0035] In one embodiment of this application, the step of performing syntax correction on formula text includes: Step S410: When an illegal character follows a delimiter in the formula text, the delimiter is replaced with an empty delimiter. A delimiter is a symbol used to mark the boundaries of an expression in the formula text. In markup languages, delimiter commands and delimiter symbols are used together. Delimiter commands control the expansion and contraction of delimiters. Syntax rules require delimiter commands to appear in pairs, and each command must be followed by a valid delimiter symbol. Valid delimiter symbols include parentheses, square brackets, and vertical bars. An empty delimiter is a delimiter represented by a set symbol that is not displayed during presentation. When an illegal character follows a delimiter in the formula text (illegal character refers to a character that is not a valid delimiter symbol), the delimiter is replaced with an empty delimiter. After replacement, the delimiter command satisfies the syntax rules, and the content of the formula is not affected. This embodiment corrects a common syntax defect, ensuring the syntax compliance of delimiter commands in formula text.
[0036] Step S420: When the number of left and right delimiters in the formula text is mismatched, remove the delimiter commands from the formula text, retaining the delimiters themselves. A mismatch in the number of left and right delimiters means that the number of left and right delimiter commands in the formula text is inconsistent. Syntax rules require left and right delimiter commands to be paired; a left delimiter command should have a corresponding right delimiter command. When the numbers are inconsistent, the formula text cannot be compiled, and the typesetting tool reports an error. During processing, the number of left and right delimiter commands in the formula text is counted, the two numbers are compared, and delimiter commands are removed. After removal, the formula text no longer contains delimiter commands, thereby eliminating the compilation error caused by the mismatch. This embodiment ensures that the pairing relationship is satisfied, and the compilation error caused by the number of delimiters is corrected before assembly, resulting in a complete syntactic structure for the formula text.
[0037] Step S430: Use a bracket stack to trace the pairing of delimiters across curly braces in the formula text and correct pairing errors. A curly brace group refers to a group of content delimited by curly braces in the formula text. This grouping affects the scope of variables. The start sign of a curly brace refers to the left curly brace, and the end sign refers to the right curly brace. Cross-brace groups refer to paired delimiter commands located in different curly brace groups. In such cases, the pairing relationship of delimiter commands is difficult to determine based on adjacent positions. A bracket stack is a data structure that records the nesting information of curly brace groups in a last-in-first-out (LIFO) manner. During tracing, the formula text is scanned. When a start sign of a curly brace is encountered, it is pushed onto the bracket stack. When an end sign of a curly brace is encountered, the start sign is popped from the top of the stack. The stack depth records the nesting depth of the curly brace group at the scanned position. When a left delimiter command and a right delimiter command are in different curly brace groups, the right delimiter command is moved into the curly brace group containing the left delimiter command, correcting pairing errors. This embodiment uses the nesting depth of curly brace groups to handle the pairing problem of delimiters across curly brace groups.
[0038] In one embodiment of this application, the step of using bracket stack tracing to repair delimiter pairings across curly braces includes: Step S431: Scan the formula text from left to right. When a curly brace start symbol is encountered, push the start symbol onto the bracket stack. When a curly brace end symbol is encountered, pop the start symbol from the top of the bracket stack. Record the nesting depth of the bracket group at the current scan position using the stack depth. During the scan, record the nesting depth of the bracket groups containing the left and right delimiter commands. If the nesting depth of the bracket group containing the right delimiter command is inconsistent with the nesting depth of the bracket group containing its paired left delimiter command, move the right delimiter command into the bracket group containing its paired left delimiter command. The moving method is to adjust the position of the right delimiter command in the formula text so that the right delimiter command and its paired left delimiter command are in the same bracket group. After the pairing is corrected, the left and right delimiter commands in the formula text are in the same bracket group, the syntax structure of the formula text is complete, and it can be directly compiled and displayed.
[0039] In one embodiment of this application, the step of maintaining a path stack for metadata according to a numbering rule includes: Step S510: Parse the hierarchical level of the clause numbers in each piece of metadata. During parsing, the clause numbers in the metadata are read. Clause numbers are in dotted and textual form. Dotted clause numbers are multiple segments of numbers connected by separators, and the number of segments in the number indicates the level depth. Taking clause number 4 as an example, clause number 4 is in the first level, clause number 4.2 is in the second level, and clause number 4.2.1 is in the third level. Textual clause numbers are represented by clause terms plus serial numbers, and the difference in serial numbers also indicates the level depth. After parsing, the level of each clause number is marked with a numerical value, and the level of the top of the stack is also marked with a numerical value. These two values are used for comparison in subsequent stack operations. This embodiment converts the numbering format into comparable hierarchical values, providing a unified quantitative basis for level determination.
[0040] In step S520, when the level of the new clause number is deeper than the level of the top of the stack, the new clause number is pushed onto the path stack. The new clause number refers to the currently parsed clause number, and the level of the top of the stack refers to the level of the number at the top of the path stack. When the level of the new clause number is deeper than the level of the top of the stack, it indicates that the current clause is a subordinate clause of the clause at the top of the stack. After being pushed onto the path stack, the new clause number is at the top of the stack, and the path stack points to the clause node corresponding to the new clause. The numbers in the stack form a clause path from the top to the bottom. Taking clause 4.2.1 as an example, when the numbers in the stack are 4 and 4.2, the level of clause 4.2.1 is deeper than the level of the top number 4.2. When clause 4.2.1 is pushed onto the path stack, the numbers in the stack become 4, 4.2, and 4.2.1. The push operation in this embodiment records the subordinate clauses, and the parent-child relationship of the clause tree is established level by level.
[0041] In step S530, if the level of the new clause number is the same as the level of the top of the stack, the new clause number replaces the top of the stack number. If the level of the new clause number is the same as the top of the stack, it means that the new clause and the top clause are sibling clauses, and their parent clauses are the same. The new clause number replaces the top of the stack number. Replacement means removing the original number from the top of the stack and placing the new clause number on top. The remaining numbers in the path stack remain unchanged, and the path stack points to the clause node corresponding to the new clause. For example, with clause 4.2.2, when the stack numbers are 4, 4.2, and 4.2.1, the level of clause 4.2.2 is the same as the level of the top of the stack number 4.2.1. After replacement, the stack numbers become 4, 4.2, and 4.2.2. This embodiment maintains the parallel relationship of sibling clauses. Sibling clauses are attached to the same parent node in the clause tree, and the sibling structure of the clause tree is correctly established.
[0042] In step S540, when the level of the new clause number is shallower than the level of the top of the stack, pop the corresponding number of clauses from the path stack and push the new clause number back onto the stack, making the path stack point to the current clause node. When the level of the new clause number is shallower than the level of the top of the stack, it indicates that the new clause is at a higher level than the top clause and is at the same level as the clause at the corresponding level in the path stack. Pop the corresponding number of clauses from the path stack; the number of pops is determined by the level difference. After popping, the level of the top clause number is the same as the level of the new clause number. Then, push the new clause number back onto the path stack, making the path stack point to the clause node corresponding to the new clause. For example, with clause 4.3, when the stack contains clauses 4, 4.2, and 4.2.1, the level of clause 4.3 is one level shallower than the top clause 4.2.1. After popping the top clause 4.2.1, push clause 4.3 back onto the stack, and the stack contains clauses 4 and 4.3. This embodiment's pop operation keeps the path stack synchronized with the clause level, ensuring accurate updates to the stack content when clauses are switched.
[0043] In one embodiment of this application, before the step of mounting the table in the table area, the formula text, and the image in the image area to the clause node pointed to by the path stack, the method further includes: Step S501: Merge cross-page continuation tables. Compare whether adjacent page table fragments carry table titles and their respective column counts. If the subsequent page table fragment does not carry a table title and its column count is the same as the previous page table fragment, the two table fragments are determined to belong to the same table. The two table fragments are merged into a complete table, which is then mounted as a table area to the clause node. During the merging process, the table titles carried by the adjacent page table fragments are read. The table title is the title text located at the beginning of the table. Cross-page tables do not repeat their table titles in subsequent pages. If the subsequent page table fragment does not carry a table title, it indicates that it is a cross-page continuation table; if it carries a table title, it indicates that it is a new table. If the subsequent page table fragment does not carry a table title and its column count is the same as the previous page table fragment, the two table fragments are determined to belong to the same table. The two table fragments are merged into a complete table. During the merging process, duplicate header rows in the subsequent page fragment are removed, and the data rows of the subsequent page fragment are appended to the end of the previous page fragment. The complete table is then mounted as a table area to the clause node. This embodiment merges the fragmented table segments, ensuring the number of table rows is complete and the table data in the structured content is coherent.
[0044] In one embodiment of this application, the steps of vectorizing and retrieving the structured content after assembling it include: Step S550: Vectorize the structured content. Vectorization refers to the process of mapping content to vectors. Vectors represent content as numerical sequences, which carry semantic information about the content. During vectorization, the main text, tables, formula text, and images in the structured content are processed separately. Main text is mapped to text vectors according to semantics, tables are mapped to table vectors according to cell content, formula text is mapped to formula vectors according to expressions, and images are mapped to image vectors according to visual features. Each vector records the corresponding content type and the clause node it belongs to. The content type represents one of the main text, table, formula text, and image, and the clause node represents the position of the content corresponding to the vector in the clause tree. After recording, the text vectors, table vectors, formula vectors, and image vectors are written to the vector library, forming a multimodal vector set. The vectors maintain a correspondence with the original content in the structured content, and the original content can be retrieved from the vectors.
[0045] Step S560: Retrieve the multimodal vector set. During the retrieval, the multimodal vector set is organized into a multimodal vector index according to content type and the clause node it belongs to. Each vector in the index carries a record of content type and clause node. A retrieval request is received, carrying query content, which can be one of the following: body text, table, formula text, or image. The query content is mapped to a query vector. The query vector and the vectors in the multimodal vector set are in the same vector space. Vectors in the same vector space can have their similarity calculated. The similarity between the query vector and each vector in the multimodal vector index is calculated. The matched content is sorted from largest to smallest similarity, and the top matched content and the clause node containing it are returned. The multimodal vector index covers multiple content types, including body text, tables, formula text, and images. When the query content belongs to any of these types, all other types of content also participate in the similarity calculation, and the matching results are not limited by the content type of the query content.
[0046] Step S570: Perform cross-modal retrieval. Cross-modal retrieval refers to a retrieval where the content type of the query content is different from the content type of the matched content. During processing, a retrieval request carrying query content is received. If the query content is an image, the image is mapped to an image query vector. The image query vector is used to search the multimodal vector index. Matched content includes text, tables, formulas, and semantically matching content within the image. The matched content and the clause node containing the matched content are returned. When a user possesses an image taken on-site, the image is used as the query content to initiate a retrieval. The image query vector and the text vector corresponding to the clause text are in the same vector space. Clauses matching the image content are retrieved, and the content described in the clause corresponds to the object shown in the image. Since images and text belong to different content types, using an image to query text is a form of cross-modal retrieval.
[0047] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention, and they should all be included in the scope of the claims and specification of the present invention.
Claims
1. A document-oriented parsing method, characterized in that, The parsing method includes: The document page is subjected to region detection to identify the main text region, title region, table region, formula region and image region; The formula images of the formula region are cropped out and arranged in ascending order according to the area occupied by the formula images. The average area of the formula images that are arranged first in a preset number is used as the base area. The average area of the current batch is detected, and the average area of the current batch is compared with the benchmark area. If the ratio is greater than a preset threshold, the number of formula images parsed in the current batch is reduced. The formula images are grouped and sent to a preset formula recognition model in batches to obtain the formula text, and the formula text is then grammatically repaired. Metadata is extracted from the main text area and the title area. A path stack is maintained for the metadata according to the numbering rules. The clause tree is reconstructed according to the path stack. The tables in the table area, the formula text, and the images in the image area are mounted to the clause nodes pointed to by the path stack. The main text, images, and formula text are clustered and sorted according to page coordinates, and then combined with the metadata and the terms tree to assemble them into structured content.
2. The analytical method according to claim 1, characterized in that, The steps for performing page layout detection on a document include: The document page is analyzed to identify text lines, table borders, formula boundaries and image outlines. Based on the identification results, the document page is divided into text area, title area, table area, formula area and image area, and the coordinate range of each area is recorded.
3. The analytical method according to claim 1, characterized in that, Before the step of cropping the formula image of the formula region, the following steps are included: The formula region is preprocessed to remove background noise and binarize it to obtain the formula image to be cropped.
4. The analytical method according to claim 1, characterized in that, The steps of sorting the images in ascending order according to the area occupied by the formula image include: The pixel width and pixel height of each formula image are calculated, and the product of the pixel width and pixel height is taken as the area occupied. The formula images are then arranged in ascending order of the area occupied.
5. The analytical method according to claim 4, characterized in that, The steps for detecting the average area of the current batch include: The area occupied by each formula image in the current batch is calculated, and the average area of each area is taken as the average area of the current batch. The average area of the current batch is compared with the benchmark area. If the ratio exceeds the preset threshold, the number of current batches to be parsed is reduced to a value greater than or equal to the preset number of batches.
6. The analytical method according to claim 1, characterized in that, After the step of identifying the formula text, the following steps are also included: The formula text is encoded and verified to identify illegal encoded characters and replace them with normalized ones, thus obtaining the formula text to be repaired.
7. The analytical method according to claim 1, characterized in that, The steps for performing syntax correction on the formula text include: When an illegal character follows a delimiter in the formula text, the delimiter is replaced with an empty delimiter; When the number of left and right delimiters in the formula text is mismatched, remove the delimiter command in the formula text and retain the delimiter; Use a bracket stack to trace the pairing of delimiters that cross curly braces in the formula text and fix pairing errors.
8. The analytical method according to claim 7, characterized in that, The steps for fixing delimiter pairings across curly braces using bracket stack tracing include: The formula text is scanned from left to right. When a curly brace start symbol is encountered, the start symbol is pushed onto the bracket stack. When a curly brace end symbol is encountered, the start symbol at the top of the stack is popped. The nesting depth of the curly brace group where the scan position is located is recorded by the stack depth of the bracket stack. When the nesting depth of the curly brace group containing the right delimiter command is inconsistent with the nesting depth of the curly brace group containing the paired left delimiter command, the right delimiter command is moved into the curly brace group containing the left delimiter command to correct the pairing error.
9. The analytical method according to claim 1, characterized in that, The steps of maintaining a path stack for the metadata according to numbering rules include: Parse the hierarchical structure of the clause numbers in each of the aforementioned metadata; When the level of a new clause number is deeper than the level of the top of the stack, the new clause number is pushed onto the path stack; When the level of the new clause number is the same as that of the top of the stack, the new clause number replaces the top of the stack number. When the level of the new clause number is shallower than the level of the top of the stack, pop the corresponding number of numbers from the path stack and push the new clause number back in, so that the path stack points to the current clause node.
10. The analytical method according to claim 1, characterized in that, Before the step of mounting the table in the table area, the formula text, and the image in the image area to the clause node pointed to by the path stack, the method further includes: Merge cross-page continuation tables by comparing whether adjacent page table fragments carry table titles and their respective column counts. If the table fragment on the next page does not carry a table title and its column count is the same as that on the previous page, it is determined that the adjacent page table fragments belong to the same table. The adjacent page table fragments are then merged into a complete table, and the complete table is attached to the clause node as a table in the table area.
