Document processing method, electronic equipment, storage medium and program product

By performing layout analysis and hierarchical relationship generation of PDF documents, the problem that the standard parsing library is difficult to deal with non-standardized PDF documents is solved, and higher processing accuracy and reliability are achieved.

CN119474028APending Publication Date: 2025-02-18KE COM (BEIJING) TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411654994.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-18
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

In the prior art, when processing non-standardized PDF documents, the standard parsing library may not be able to accurately analyze the document structure, resulting in low processing accuracy.

Method used

By performing layout analysis on the document to be processed, multiple element blocks and their locations are obtained, hierarchical relationships of element blocks are established, and tree structure data is generated to achieve accurate processing of the document.

Benefits of technology

It improves the accuracy of non-standardized PDF document processing, can effectively handle complex and deeply nested document structures, and improves the accuracy and reliability of document parsing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119474028A_ABST
    Figure CN119474028A_ABST
Patent Text Reader

Abstract

The invention provides a document processing method, electronic equipment, a storage medium and a program product. The document processing method comprises the following steps: performing layout analysis on a to-be-processed document to obtain a plurality of element blocks and positions thereof in the to-be-processed document; obtaining a hierarchical relationship of the plurality of element blocks according to the positions of the plurality of element blocks; and generating tree structure data according to the hierarchical relationship of the plurality of element blocks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to technical fields such as data processing, and more particularly to a document processing method, electronic device, storage medium, and program product. Background Art

[0002] PDF (Portable Document Format) is a widely used file format for cross-platform transmission and display of documents, ensuring that the document maintains a consistent appearance and layout on any device and operating system.

[0003] When performing data analysis, document management, information retrieval, etc. through PDF documents, it is necessary to first process the PDF documents, identify the various components of the document and their relationships (i.e., the document structure), and then parse the content of the PDF document according to the document structure. In the prior art, a standard parsing library is generally used to implement the above process.

[0004] When a PDF document is created in accordance with the PDF specification, the accuracy of processing it through the standard parsing library is high; however, since PDF documents can contain text, images, links, etc., and support multiple fonts and layouts, when the structure of the PDF document is not standardized, the content storage order is inconsistent with the display order, etc., the standard parsing library may not be able to accurately analyze the document structure, resulting in a low accuracy rate in processing non-standardized PDF documents. Summary of the invention

[0005] In order to solve at least one of the above technical problems, the present disclosure provides a document processing method, an electronic device, a storage medium and a program product.

[0006] According to one aspect of the present disclosure, there is provided a document processing method, comprising: Performing layout analysis on the document to be processed to obtain multiple element blocks and their positions in the document to be processed; Acquire a hierarchical relationship of the plurality of element blocks according to positions of the plurality of element blocks; Tree structure data is generated according to the hierarchical relationship of the plurality of element blocks.

[0007] According to at least one embodiment of the document processing method of the present disclosure, the step of performing layout analysis on the document to be processed includes: Parsing the document to be processed to obtain parsed elements and their positions; Filtering the margin information from the document to be processed according to the parsed elements and their positions to obtain a filtered document; Perform layout analysis on the parsed elements and their positions in the filtered document.

[0008] According to the document processing method of at least one embodiment of the present disclosure, filtering the margin information from the document to be processed according to the parsed elements and their positions includes: Performing page margin analysis on the document to be processed according to the parsed elements and their positions to obtain a page margin threshold; Acquire page margin information of each page from the document to be processed according to the page margin threshold; acquiring comparison page margin information from the page margin information of each page according to the information amount of the page margin information of each page; Matching the information blocks included in the comparison page margin information with the information blocks included in the page margin information of each page respectively to obtain matching blocks; Acquire a page margin removal distance according to the position of the information in the matching block; The page margin information is filtered from the document to be processed according to the page margin removal distance.

[0009] According to the document processing method of at least one embodiment of the present disclosure, the performing of page margin analysis on the document to be processed according to the parsed elements and their positions to obtain a page margin threshold comprises: Determining whether each page of the document to be processed includes an independent horizontal line greater than a width threshold; If the current page includes the independent horizontal line, obtaining a candidate value of the page margin of the current page according to the position of the independent horizontal line; If the current page does not include the independent horizontal line, obtaining a candidate value of the margin of the current page according to a fixed value or a boundary of an edge text line of the current page; A majority decision is performed on the page margin candidate values ​​of each page of the document to be processed to obtain the page margin threshold.

[0010] According to the document processing method of at least one embodiment of the present disclosure, when the parsed elements in the filtered document include non-independent line segments, performing layout analysis on the parsed elements and their positions in the filtered document includes: Obtaining a plurality of line segments from the parsed elements in the filtered document; Performing cluster analysis on the plurality of line segments to obtain at least one line segment cluster; A table structure is identified according to the at least one line segment cluster to obtain at least one table block.

[0011] According to the document processing method of at least one embodiment of the present disclosure, when the parsed elements in the filtered document include line text, the performing layout analysis on the parsed elements and their positions in the filtered document includes: Get the text attributes of the line of text; The lines of text are merged according to their text attributes and positions to obtain a text block.

[0012] According to the document processing method of at least one embodiment of the present disclosure, the step of acquiring the hierarchical relationship of the plurality of element blocks according to the positions of the plurality of element blocks includes: The multiple element blocks are processed through a stack according to positions of the multiple element blocks to obtain a hierarchical relationship of the multiple element blocks.

[0013] According to the document processing method of at least one embodiment of the present disclosure, the processing of the multiple element blocks through a stack according to the positions of the multiple element blocks includes: Create an empty stack; Read each element block in sequence according to the position of the multiple element blocks; When the start tag of the element block is read, a new node is created to represent the start tag; determine whether the stack is empty; if not, the new node is used as the child node of the current top node in the stack and the new node is pushed into the stack; if the stack is empty, the new node is pushed into the stack; When the content of the element block is read, a content node corresponding to the content is created; the content node is used as a child node of the current top node in the stack, and the stack state remains unchanged; When the end tag of an element block is read, the start tag corresponding to the end tag is popped from the stack.

[0014] According to another aspect of the present disclosure, an electronic device is provided, comprising: a memory storing execution instructions; and a processor executing the execution instructions stored in the memory, so that the processor executes the document processing method of any one embodiment of the present disclosure.

[0015] According to another aspect of the present disclosure, a readable storage medium is provided, wherein the readable storage medium stores execution instructions, and when the execution instructions are executed by a processor, the document processing method of any embodiment of the present disclosure is implemented.

[0016] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the document processing method of any one of the embodiments of the present disclosure is implemented. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The accompanying drawings illustrate exemplary embodiments of the present disclosure and together with the description serve to explain the principles of the present disclosure. These drawings are included to provide a further understanding of the present disclosure and are incorporated in and constitute a part of this specification.

[0018] Figure 1The process of the document processing method of one embodiment of the present disclosure is as follows Figure 1 .

[0019] Figure 2 yes Figure 1 A flowchart of a layout analysis method in a document processing method is shown.

[0020] Figure 3 yes Figure 2 A flowchart of the parsing method in the layout analysis method shown.

[0021] Figure 4 yes Figure 2 The flow of the page margin filtering method in the layout analysis method shown Figure 1 .

[0022] Figure 5 yes Figure 2 The flow of the page margin filtering method in the layout analysis method shown Figure 2 .

[0023] Figure 6 yes Figure 2 The flow of the page margin filtering method in the layout analysis method shown Figure 3 .

[0024] Figure 7 yes Figure 2 A flowchart of the table analysis method in the layout analysis method shown.

[0025] Figure 8 yes Figure 2 A flowchart of the text analysis method in the layout analysis method shown.

[0026] Fig. 9 The process of the document processing method of one embodiment of the present disclosure is as follows Figure 2 .

[0027] Fig.10 yes Fig. 9 A flowchart of a stack processing method in a document processing method is shown.

[0028] Fig.11 The process of the document processing method of one embodiment of the present disclosure is as follows Figure 3 .

[0029] Fig.12 The process of the document processing method of one embodiment of the present disclosure is as follows Figure 4 .

[0030] Fig.13 is a schematic flowchart of a document processing method according to an embodiment of the present disclosure.

[0031] Fig.14It is a schematic block diagram of the structure of a document processing device according to another embodiment of the present disclosure.

[0032] Fig.15 It is a schematic block diagram of the structure of an electronic device equipped with a document processing device according to another embodiment of the present disclosure. DETAILED DESCRIPTION

[0033] The present disclosure is further described in detail below in conjunction with the accompanying drawings and examples. It is understood that the specific examples described herein are only used to explain the relevant content, rather than to limit the present disclosure. It should also be noted that, for ease of description, only the parts related to the present disclosure are shown in the accompanying drawings.

[0034] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in the present disclosure can be combined with each other. The technical solution of the present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0035] PDF parsing is the process of extracting information from a PDF document. The PDF parsing process based on the standard parsing library relies on the structure and content specifications of the PDF document. During parsing, the required elements are gradually extracted through a series of steps. However, since PDF documents are mainly produced to accurately reproduce the layout, that is, PDF allows users to place text, images and other elements on the page in any order, and the ultimate goal is to ensure the accuracy of the visual effect, the document structure, content display order and storage order of PDF documents designed by different users may not be consistent. When parsing non-standardized PDF documents through the standard parsing library, the document structure may not be accurately analyzed, resulting in a disordered order of element blocks, especially in the case of multi-column, complex typesetting or table layout. The standard parsing library has a low accuracy rate in processing non-standardized PDF documents.

[0036] To this end, the present disclosure proposes a document processing method, electronic device, storage medium and program product, which performs layout analysis on the document to be processed, generates tree structure data through stack processing, and realizes document processing. When a user needs to parse a PDF document, he can first send a processing request for the PDF document to an electronic device such as a server. After receiving the processing request, the server or other electronic device executes the corresponding processing process. After the PDF document is processed, the document content can be parsed based on the processing result (tree structure data).

[0037] For the convenience of description and to make the technical solutions of the specific embodiments of the present disclosure easier to understand, before describing the document processing method implemented by the present disclosure, the technical terms involved in the specific embodiments of the present disclosure are defined as follows: An element block refers to a component or node in a document that has independent semantics or logic.

[0038] Page margin information includes header information and footer information.

[0039] Line text refers to all the characters and content contained in a line in text editing or typesetting.

[0040] Figure 1 FIG. 1 is a schematic diagram showing the overall process of a document processing method M100 according to an embodiment of the present disclosure. Figure 1 The method shown includes steps S110 to S130. The method can be executed by an electronic device such as a server.

[0041] Specifically, Figure 1 The methods shown include: Step S110, performing layout analysis on the document to be processed to obtain a plurality of element blocks and their positions in the document to be processed.

[0042] In some embodiments of the present disclosure, the layout analysis of the document to be processed in step S110 may include page segmentation (dividing the page into multiple areas, such as text areas, image areas, title areas, etc.), area position detection, element type recognition, text box recognition, image recognition, etc., to divide the document to be processed into multiple element blocks. The document to be processed may be a PDF document.

[0043] In some embodiments of the present disclosure, an element block in step S110 may represent a complete logical unit, such as a title, paragraph, image, table, etc., and exists independently of other contents. Each element block is a complete markup structure, including a start tag, content, and an end tag, and the content includes one or more of a text block (a whole composed of continuous or discontinuous text), an image block (an image or picture element embedded in a document), and a table block (one or more table elements contained in a document).

[0044] Step S120 , obtaining the hierarchical relationship of the multiple element blocks according to the positions of the multiple element blocks.

[0045] In some embodiments of the present disclosure, step S120 may obtain the hierarchical relationship of multiple element blocks through stacks, parent-child relationship mapping, sequence numbering, etc. The hierarchical relationship of an element block obtained through step S120, that is, the relative position of the element block in the document, may be described by a parent-child relationship.

[0046] In particular, in order to simplify the processing process, before obtaining the hierarchical relationship of multiple element blocks according to the positions of multiple element blocks, it is also possible to first determine whether the element block is connected to the subsequent element block (that is, there are no other elements or separators between the two element blocks), merge the connected element blocks, and then obtain the hierarchical relationship of the multiple element blocks according to the positions of the merged multiple element blocks.

[0047] Step S130: Generate tree structure data according to the hierarchical relationship of the multiple element blocks.

[0048] In some embodiments of the present disclosure, for situations where the hierarchical relationship is relatively clear, step S130 can use a recursive method to process the hierarchical relationship to generate tree structure data; for complex, deeply nested hierarchical relationships, step S130 can use a stack to process the hierarchical relationship to generate tree structure data.

[0049] The document processing method provided by the present disclosure can accurately reflect the overall structure of the document to be processed because the position can reflect the hierarchy and dependency of multiple element blocks, so the tree structure data generated according to the hierarchical relationship corresponding to the positions of multiple element blocks can accurately reflect the overall structure of the document to be processed. The method solves the problem in the prior art that since PDF documents can contain text, images, links, etc., and support multiple fonts and layouts, when the structure of the PDF document is not standardized, the content storage order is inconsistent with the display order, etc., the standard parsing library may not be able to accurately analyze the document structure, thereby resulting in a low accuracy rate in the processing of non-standardized PDF documents.

[0050] Regarding step S110, in some embodiments of the present disclosure, it may include: Figure 2 Steps S111 to S113 are shown.

[0051] Step S111, parsing the document to be processed to obtain parsed elements and their positions.

[0052] In some embodiments of the present disclosure, the parsing of the document to be processed in step S111 may be specifically fine-grained parsing, which means deeply parsing each component of the document to be processed so as to obtain detailed information of each element in the document to be processed. This step may be performed by fitz or PyMuPDF, etc., and the obtained parsed elements may include one or more of line text, line segments, and image blocks.

[0053] Step S112, filtering the margin information from the document to be processed according to the parsed elements and their positions to obtain a filtered document.

[0054] In some embodiments of the present disclosure, the page margin information filtered by step S112 may include page header information and page footer information, and the page header information or page footer information may include text and / or images, etc. When filtering the page margin information by step S112, the positions of the page header and page footer may be determined first, and then the page header and page footer information may be filtered according to the determined positions.

[0055] Step S113: Perform layout analysis on the parsed elements and their positions in the filtered document.

[0056] In some embodiments of the present disclosure, this step performs layout analysis on the parsed elements and their positions in the filtered document, that is, performs layout analysis on the main content of the document to be processed; text blocks (segmented text) and table blocks can be obtained through this analysis.

[0057] By filtering the page margin information through steps S111 to S113 and then performing layout analysis, the amount of data for layout analysis can be reduced, the calculation complexity can be lowered, and the processing speed can be improved.

[0058] Regarding step S111, in some embodiments of the present disclosure, it may include the following steps: Figure 3 Steps S1111 to S1112 are shown.

[0059] Step S1111, pre-processing the document to be processed to obtain a processed document.

[0060] In some embodiments of the present disclosure, the preprocessing in step S1111 may include removing password protection and / or removing watermarks, and in addition to removing password protection and / or removing watermarks, may also include processing processes such as page cropping and adjustment.

[0061] Step S1112, parsing the processed document.

[0062] The document is preprocessed and then parsed through steps S1111 and S1112. Preprocessing can greatly improve the accessibility, parsing accuracy and efficiency of the document, simplify the subsequent processing process, and ensure that the parsing can be performed completely and accurately.

[0063] Regarding step S112, in some embodiments of the present disclosure, it may include the following steps: Figure 4 Steps S1121 to S1126 are shown.

[0064] Step S1121, performing page margin analysis on the document to be processed according to the parsed elements and their positions to obtain a page margin threshold.

[0065] In some embodiments of the present disclosure, the page margin analysis is performed through step S1121 to analyze the position corresponding to the header and / or footer, and the obtained page margin threshold may include a header threshold and / or a footer threshold.

[0066] Step S1122, obtaining the page margin information of each page from the document to be processed according to the page margin threshold.

[0067] In some embodiments of the present disclosure, the margin information of each page acquired through step S1122 may include header information of each page and / or footer information of each page.

[0068] Step S1123, obtaining comparison margin information from the margin information of each page according to the information amount of the margin information of each page.

[0069] In some embodiments of the present disclosure, when the margin information of each page includes the header information of each page, step S1123 can use the header information with the largest amount of information among the header information of all pages as the comparison margin information; when the margin information of each page includes the footer information of each page, step S1123 can use the footer information with the largest amount of information among the footer information of all pages as the comparison margin information.

[0070] Step S1124: Match the information blocks included in the comparison margin information with the information blocks included in the margin information of each page to obtain matching blocks.

[0071] In some embodiments of the present disclosure, step S1124 may match the information block included in the comparison margin information with the information block included in the margin information of all pages, respectively, and when the matching requirement is met, the information block may be considered as one of the matching blocks. The matching requirement may be set as needed, such as the information block appears at least on a specific number of pages (the product of the total number of pages and the preset ratio is rounded up) and the number of occurrences is not less than the preset number of times, etc.

[0072] Step S1125, obtaining the page margin removal distance according to the position of the information in the matching block.

[0073] In some embodiments of the present disclosure, when the matching block includes header information, step S1125 can obtain the margin removal distance for the position of the bottommost information in all the header information in the matching block, that is, the distance from the bottom boundary of the bottommost information in the header information to the top of the page can be used as the margin removal distance; when the matching block includes footer information, step S1125 can obtain the margin removal distance for the position of the topmost information in all the footer information in the matching block, that is, the distance from the top boundary of the topmost information in the footer information to the bottom of the page can be used as the margin removal distance.

[0074] Step S1126, filtering the margin information from the document to be processed according to the margin removal distance.

[0075] In some embodiments of the present disclosure, all types of margin information, including text, pictures, etc., may be removed through step S1126.

[0076] By determining the margin removal distance through steps S1121 to S1126 and filtering the margin information, the accuracy of filtering the margin information can be improved, ensuring that the document after filtering includes only the main text content.

[0077] Regarding step S1121, in some embodiments of the present disclosure, if Figure 5 As shown, it can be replaced by steps S1127 to S1130.

[0078] Step S1127, determining whether each page of the document to be processed includes an independent horizontal line whose width is greater than a threshold value.

[0079] In some embodiments of the present disclosure, the width threshold in step S1127 can be preset as needed, and the width threshold can be related to the page width, such as using 2 / 3 of the page width as the width threshold, etc. The independent horizontal line in step S1127 is a horizontal line that is not directly connected to other content or elements. Both the header and the footer can be distinguished from the body content by a horizontal line.

[0080] In some implementations of the present disclosure, when it is determined by step S1127 that the current page includes an independent horizontal line, step S1128 is executed; when it is determined by step S1127 that the current page does not include an independent horizontal line, step S1129 is executed.

[0081] Step S1128, obtaining a candidate value of the margin of the current page according to the position of the independent horizontal line.

[0082] In some embodiments of the present disclosure, the margin candidate values ​​obtained by step S1128 may include header candidate values ​​and footer candidate values; it may be determined whether the margin candidate value is a header candidate value or a footer candidate value according to the position of the independent horizontal line; when a page includes two independent horizontal lines, the header candidate value may be obtained according to the position of the independent horizontal line at the top of the page, and the footer candidate value may be obtained according to the position of the independent horizontal line at the bottom of the page; when a page includes only one independent horizontal line, it may be determined whether the independent horizontal line is at the top or bottom of the page, and then the corresponding candidate value may be obtained according to the position. Among them, the header candidate value may be the distance from the independent horizontal line to the top of the page, and the footer candidate value may be the distance from the independent horizontal line to the bottom of the page.

[0083] Step S1129, obtaining a candidate value of the margin of the current page according to a fixed value or the boundary of the edge text line of the current page.

[0084] In some embodiments of the present disclosure, the fixed value in step S1129 is pre-set as needed, and the same or different fixed values ​​can be set for the header and the footer; the fixed value can be related to the page height, such as setting the fixed value of the header to 1 / 10 of the page height. When the page margin candidate value obtained by step S1129 is specifically a header candidate value, the boundary of the edge text row is the lower boundary of the first line of text on the current page; when the page margin candidate value obtained by step S1129 is specifically a footer candidate value, the boundary of the edge text row is the upper boundary of the last line of text on the current page. The first or last line of text can occupy a complete line or only a part of the line width. Step S1129 may include: determining whether the fixed value is less than the boundary of the edge text row of the current page; if it is less, obtaining it according to the fixed value; if it is not less, obtaining it according to the boundary of the edge text row of the current page.

[0085] Step S1130 , performing majority decision on the page margin candidate values ​​of each page of the document to be processed to obtain a page margin threshold.

[0086] In some embodiments of the present disclosure, the process of performing majority decision through step S1130 may include: collecting candidate margin values ​​of all pages of the document to be processed; counting the candidate margin values ​​and recording the frequency of occurrence of each value; and finding the value with the highest frequency of occurrence as the margin threshold.

[0087] By determining the page margin threshold based on majority decision through steps S1127 to S1130, the accuracy of the obtained page margin threshold can be improved.

[0088] Regarding step S1124, in some embodiments of the present disclosure, if Figure 6 As shown, it can be replaced by step S1131 to step S1132.

[0089] Step S1131 , respectively removing numbers from the comparison margin information and the margin information of each page to obtain first margin information and second margin information.

[0090] In some embodiments of the present disclosure, step S1131 may remove all numbers in the margin information, and the removal process may be performed by a regular expression. In order to prevent filtering of numbers other than page numbers, step S1131 may determine whether the numbers in the margin information are page numbers, and remove the numbers corresponding to the page numbers. The specific process of determining whether the numbers in the margin information are page numbers may be determined by page number patterns, context analysis, or regular expressions.

[0091] Step S1132: Match the information blocks included in the first page margin information with the information blocks included in the second page margin information respectively.

[0092] By matching the page margin information after removing the numbers through steps S1131 and S1132, the interference of variable numbers such as page numbers on the matching of page margin information can be reduced, thereby improving the matching success rate.

[0093] The above steps can effectively remove interference information in headers and footers, while retaining key information related to the document structure, ensuring that the filtered document is clean and accurate.

[0094] When the parsed elements in the filtered document include non-independent line segments, step S113, in some embodiments of the present disclosure, may include: Figure 7 Steps S1133 to S1135 are shown.

[0095] Step S1133, obtaining multiple line segments from the parsed elements in the filtered document.

[0096] In some embodiments of the present disclosure, the plurality of line segments acquired in step S1133 may include horizontal lines and vertical lines.

[0097] Step S1134: performing cluster analysis on the multiple line segments to obtain at least one line segment cluster.

[0098] In some embodiments of the present disclosure, clustering analysis is performed through step S1134, which may include: first extracting line segment information of multiple line segments, including coordinate information of their starting points and end points and possible attributes (such as color, thickness, etc.); then obtaining line segment features of the multiple line segments based on the line segment information, such as line segment length, angle, position, etc.; finally, selecting an appropriate clustering algorithm to cluster the multiple line segments based on the line segment features. The clustering algorithm may be K-means, DBSCAN, etc., and may be selected based on line segment features.

[0099] Step S1135 , performing table structure recognition according to at least one line segment cluster to obtain at least one table block.

[0100] In some embodiments of the present disclosure, the specific process of performing table structure recognition through step S1135 may include: analyzing the layout of line segment clusters to identify row boundaries and column boundaries; dividing cells according to row boundaries and column boundaries, and using OCR and other technologies to extract text content in each cell; and constructing the extracted cell content into a table block.

[0101] In some embodiments of the present disclosure, after obtaining table blocks by clustering, it is also possible to determine whether a table block is connected to other table blocks, that is, to determine whether two table blocks can constitute a continuous table after paging. If so, the two table blocks are merged into one table block for processing.

[0102] By obtaining the table block through multiple line segments through steps S1133 to S1135, the information in the document to be processed can be effectively organized and processed, thereby improving the document processing efficiency.

[0103] When the parsed elements in the filtered document include line text, step S113, in some embodiments of the present disclosure, may include: Figure 8 Steps S1136 to S1137 are shown.

[0104] Step S1136, obtaining the text attributes of the line text.

[0105] In some embodiments of the present disclosure, the text attributes acquired through step S1136 may include text spacing, font, font size, etc.

[0106] Step S1137, merging the line texts according to their text attributes and positions to obtain a text block.

[0107] In some embodiments of the present disclosure, when merging text lines in step S1137, the text lines may be merged according to a typesetting method. The typesetting method may be a default typesetting method, i.e., from left to right and from top to bottom; the typesetting method may also be a typesetting method obtained after typesetting recognition of the document to be processed, and the typesetting recognition process may include obtaining various typesetting information (including layout, typesetting elements, document style, etc.) of the document to be processed, and then obtaining the typesetting method according to the typesetting information.

[0108] In some embodiments of the present disclosure, line texts with the same text attributes can be merged through step S1137, and the merging process may include: obtaining the spacing between adjacent line texts based on the positions of the line texts; performing majority decision based on the spacing between all adjacent line texts to obtain a reference line spacing; obtaining a spacing range corresponding to the reference line spacing based on a preset threshold, and the spacing range may be (reference line spacing-preset threshold, reference line spacing+preset threshold); and merging line texts whose spacing is within the spacing range.

[0109] In particular, in order to prevent multiple paragraphs of text from being merged into the same text block when the paragraph spacing is smaller than the line spacing, after being merged through the above process, the merged text block can also be split according to punctuation marks, etc., with each independent paragraph as a text block.

[0110] Regarding step S120, in some embodiments of the present disclosure, Fig. 9 As shown, it can be replaced by the following steps: The multiple element blocks are processed through a stack according to their positions to obtain a hierarchical relationship of the multiple element blocks.

[0111] In some embodiments of the present disclosure, the process of processing multiple element blocks through a stack in this step may include pushing into the stack, popping out of the stack, determining whether the stack is empty, etc.

[0112] This step generates a hierarchical relationship of the documents to be processed by processing through a stack. Since the last-in-first-out feature of the stack can match the nested structure of the document, the hierarchical relationship in the documents to be processed of any structure can be efficiently managed through the stack.

[0113] At this time, regarding step S120, in some embodiments of the present disclosure, it may include the following: Fig.10 Steps S121 to S129 are shown.

[0114] Step S121, create an empty stack.

[0115] Step S122, reading each element block in sequence according to the position of the multiple element blocks.

[0116] In some embodiments of the present disclosure, each element block includes a start tag, content, and an end tag. When the start tag of the element block is read, step S123 is executed; when the content of the element block is read, step S127 is executed; when the end tag of the element block is read, step S129 is executed.

[0117] Step S123: create a new node to represent the start tag.

[0118] In some embodiments of the present disclosure, when a start tag is scanned, the name of the start tag and its possible attributes are identified; when a new node is created in step S123, the new node may include basic information of the start tag.

[0119] Step S124, determine whether the stack is empty.

[0120] In some embodiments of the present disclosure, when it is determined that the stack is empty by step S124, step S125 is executed; otherwise, step S126 is executed. Step S124 can determine whether the stack is empty by checking whether there are elements in the data structure of the stack.

[0121] Step S125, pushing the new node into the stack.

[0122] Step S126: The new node is used as a child node of the current top node in the stack, and the new node is pushed into the stack.

[0123] In some embodiments of the present disclosure, when a new node is pushed into the stack through step S126, the new node may be placed at the top of the stack, and the original top node of the stack may be used as the secondary top node of the stack.

[0124] Step S127: Create a content node corresponding to the content.

[0125] Step S128: The content node is used as a child node of the current top node in the stack, and the stack state remains unchanged.

[0126] Step S129: pop the start tag corresponding to the end tag from the stack.

[0127] In some embodiments of the present disclosure, in the process of processing multiple element blocks through a stack, a collection may be created to count the element blocks pushed into the stack to facilitate the management of the element blocks.

[0128] Through steps S121 to S129, a stack is used to manage multiple element blocks. By utilizing the last-in-first-out feature of the stack, when a new start tag is encountered, the start tag is pushed into the stack, indicating that a new nested layer has been entered; when an end tag is encountered, the start tag corresponding to the end tag is popped out of the stack, indicating the end of the current level, thereby ensuring that the hierarchical relationship of the document is correctly maintained.

[0129] Furthermore, if Fig.11 As shown, the document processing method provided by the present disclosure may further include, after step S130: Step S140, obtaining reference relationships of images and / or tables in the document to be processed.

[0130] In some embodiments of the present disclosure, the reference relationship in step S140 is the association between the text content and the image and / or table, that is, how to reference the table, illustration or picture in the text and ensure that these references can correspond to the content. For example: the title of the image is " Figure 1 : XX curve", the reference in the text can be "such as Figure 1 As shown in, ..." etc. The reference relationship may include one or more of direct reference, structural reference, logical reference and cross reference.

[0131] Step S150, recording the reference relationship through tree structure data.

[0132] In some embodiments of the present disclosure, step S150 may record the reference relationship by adding a specific node in the tree structure data, or may add a record of the reference relationship to an existing node in the tree structure data.

[0133] By recording the reference relationship of the image and / or the table in step S140 and step S150, the reference relationship in the document to be processed can be effectively managed, thereby improving the usability and maintainability of the document to be processed.

[0134] Furthermore, if Fig.12 As shown, the document processing method provided by the present disclosure may further include, after step S130: Step S160, formatting the tree structure data to obtain JSON format data.

[0135] In some embodiments of the present disclosure, the process of formatting the tree structure data in step S160 may be to convert the tree structure data into JSON format data through a recursive function.

[0136] By converting the tree structure data into JSON format data in step S160, complex hierarchical relationships can be clearly expressed in the form of standardized key-value pairs, which can simplify data storage and exchange, improve compatibility, and facilitate data operation and debugging.

[0137] The document processing method provided by the present invention can not only process standard PDF documents, but also flexibly process non-standard PDF documents with various complex document structures. The method can flexibly identify and parse multiple elements in PDF documents, such as images, tables, texts, etc., so that the method can be used to process various documents, such as legal documents, financial statements, technical manuals, etc. The method can improve the accuracy and reliability of document parsing and meet the high-precision parsing requirements of different business needs.

[0138] Fig.13 An exemplary flowchart of the document processing method according to the present disclosure is shown.

[0139] Fig.13 In the exemplary flow chart shown, taking the to-be-processed file as a 3-page non-standard PDF document as an example, the PDF document includes text, tables and images, and the process of document processing the non-standard PDF document may include: 1. Remove password protection and / or watermark from the document to be processed to obtain a processed document.

[0140] In some embodiments of the present disclosure, this step may remove the password protection and / or remove the watermark by using a PDF editing tool.

[0141] Second, parse the processed document to obtain the parsed elements and their positions.

[0142] In some embodiments of the present disclosure, the parsed elements obtained through this step may include line text and image blocks.

[0143] 3. Determine whether each page of the document to be processed includes an independent horizontal line greater than a width threshold.

[0144] In some embodiments of the present disclosure, the width threshold in this step may be 2 / 3 of the page width, that is, through this step, it is determined whether each page of the document to be processed includes an independent horizontal line greater than 2 / 3 of the page width. The independent horizontal line is a horizontal line that is not connected to other line segments or elements, and is generally used in headers and footers to indicate separation from the main text.

[0145] Fourth, if the current page includes an independent horizontal line, the page margin candidate value of the current page is obtained according to the position of the independent horizontal line.

[0146] In some embodiments of the present disclosure, the following steps are described by taking filtering the header information in the margin information as an example, and the process of filtering the footer information in the margin information is similar to filtering the header information. If it is determined that the second page of the PDF document includes an independent horizontal line of the header, the distance from the independent horizontal line to the top of the page can be used as a candidate margin value for the second page, such as 0.5 inches.

[0147] 5. If the current page does not include an independent horizontal line, a candidate value of the margin of the current page is obtained according to a fixed value or a boundary of an edge text line of the current page.

[0148] In some embodiments of the present disclosure, taking the page margin candidate value as the header candidate value as an example, the corresponding fixed value can be 1 / 10 of the page height (such as 1.17 inches), and the corresponding edge text row boundary is the bottom boundary of the first line of text in the page. Therefore, this step can select the smaller value of the distance between 1 / 10 of the page height and the bottom boundary of the first line of text as the header candidate value.

[0149] If it is determined that pages 1 and 3 of the PDF document do not include independent horizontal lines for the header, and assuming that the distance corresponding to the bottom border of the first line of text on page 1 is 0.5 inches, 0.5 inches can be used as a candidate margin value for page 1; and assuming that the distance corresponding to the bottom border of the first line of text on page 3 is 1.3 inches, 1.17 inches can be used as a candidate margin value for page 3.

[0150] 6. Perform majority decision on the page margin candidate values ​​of each page of the document to be processed to obtain the page margin threshold.

[0151] In some embodiments of the present disclosure, this step can combine the page margin candidate values ​​of each page and select the page margin candidate value with the highest frequency as the final page margin threshold. Through this step, a majority decision can be made based on the page margin candidate values ​​of 0.5 inches, 0.5 inches, and 1.17 inches for pages 1-3 to obtain a page margin threshold of 0.5 inches.

[0152] 7. Obtain the margin information of each page from the document to be processed according to the margin threshold.

[0153] In some embodiments of the present disclosure, this step can be used to obtain information on each page of the PDF document above 0.5 inches, and the information may include images, text, tables, etc.

[0154] 8. Obtain comparative margin information from the margin information of each page according to the amount of information of the margin information of each page.

[0155] In some embodiments of the present disclosure, assuming that page 1 of the PDF document has the most information above 0.5 inches, page 2 has the least, and page 3 is centered, then according to this step, the information above 0.5 inches on page 1 can be used as comparison margin information.

[0156] 9. Remove the numbers in the comparison margin information and the margin information of each page respectively to obtain the first margin information and the second margin information.

[0157] In some embodiments of the present disclosure, all numbers in the margin information of each page can be removed by this step, and the numbers representing the page numbers in the margin information of each page can also be removed by this step. The removal process can be implemented by regular matching. By removing the numbers, the matching can be compatible with headers with variable numbers (such as page numbers).

[0158] 10. Match the information blocks included in the first page margin information with the information blocks included in the second page margin information respectively to obtain matching blocks.

[0159] In some embodiments of the present disclosure, the first or second page margin information can be first divided into blocks through this step, and after obtaining the information blocks, each information block included in the first page margin information is matched one by one with the information blocks included in the second page margin information of each page. For example, if the page margin information of page 1 includes information block A, the information block A is matched with the information blocks included in the page margin information of pages 1-3 respectively; assuming that the page margin information of pages 1 and 2 includes information block A, it is determined whether the information block A meets the matching requirements (such as the frequency of occurrence is greater than 50% and the number of times is not less than 2 times); if the information block A meets the matching requirements, the information block A can be used as one of the matching blocks.

[0160] 11. Obtain the page margin removal distance according to the position of the information in the matching block.

[0161] In some embodiments of the present disclosure, assuming that the matching block includes information blocks A, B and C, the lower boundary of the bottommost information in information blocks A, B and C can be obtained through this step, and the distance from the lower boundary to the top of the page is used as the header removal distance.

[0162] 12. Filter the margin information from the document to be processed based on the margin removal distance.

[0163] In some embodiments of the present disclosure, this step may be used to remove all information above the margin removal distance of each page.

[0164] 13. Perform layout analysis on the parsed elements and their positions in the filtered document to obtain multiple element blocks and their positions in the document to be processed.

[0165] In some embodiments of the present disclosure, text paragraphs, table blocks, image blocks and their positions may be obtained through this step.

[0166] 14. Obtain the hierarchical relationship of multiple element blocks according to the positions of the multiple element blocks.

[0167] 15. Generate tree structure data according to the hierarchical relationship of multiple element blocks.

[0168] 16. Obtain reference relationships of images and / or tables in the document to be processed.

[0169] 17. Record reference relationships through tree structure data.

[0170] 18. Perform format processing on the tree structure data to obtain JSON format data.

[0171] Based on any of the above implementations, the present disclosure also provides a document processing device (corresponding to a document processing method).

[0172] Fig.14 It is a schematic block diagram of the structure of a document processing device according to an embodiment of the present disclosure.

[0173] like Fig.14 As shown, the document processing device includes: The layout analysis module 110 is used to perform layout analysis on the document to be processed to obtain multiple element blocks and their positions in the document to be processed.

[0174] The hierarchical acquisition module 120 is used to acquire the hierarchical relationship of the multiple element blocks according to the positions of the multiple element blocks.

[0175] The hierarchical analysis module 130 is used to generate tree structure data according to the hierarchical relationship of multiple element blocks.

[0176] The above modules can be implemented by computer program modules.

[0177] The implementation process of the functions and effects of each module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, which will not be repeated here.

[0178] The execution subject of the document processing method in the specific implementation manner of the present disclosure may be an electronic device such as a server.

[0179] Therefore, based on any of the above embodiments, the present disclosure further provides an electronic device, which can execute the document processing method of any of the embodiments described above in the present disclosure, and the document processing device of any of the embodiments described above can be configured on the electronic device.

[0180] Fig.15 1 is a schematic block diagram of the structure of an electronic device 1000 equipped with a document processing device according to an embodiment of the present disclosure.

[0181] The hardware structure of the electronic device 1000 can be implemented using a bus architecture. The bus architecture can include any number of interconnected buses and bridges, depending on the specific application and overall design constraints of the hardware. The bus 1100 connects various circuits including one or more processors 1200, memory 1300 and / or hardware modules together. The bus 1100 can also connect various other circuits 1400 such as peripherals, voltage regulators, power management circuits, external antennas, etc.

[0182] The bus 1100 may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Component (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the figure only uses one connecting line, but does not mean that there is only one bus or one type of bus.

[0183] The present disclosure also provides a readable storage medium, in which a computer program is stored, and the computer program is used to implement the above method when executed by a processor. "Readable storage medium" can be any device that can contain, store, communicate, propagate or transmit a program for use in an instruction execution system, device or equipment or in combination with these instruction execution systems, devices or equipment. More specific examples of readable storage media include the following: an electrical connection portion (electronic device) with one or more wirings, a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and editable read-only memory (EPROM or flash memory), an optical fiber device, and a portable read-only memory (CDROM), etc.

[0184] The present disclosure also provides a computer program product. The method of the present disclosure can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instruction is loaded and executed, the process or function of the present disclosure is executed in whole or in part.

[0185] The computer program or instructions may be stored in a readable storage medium or transmitted from one readable storage medium to another readable storage medium, for example, the computer program or instructions may be transmitted from one website, computer, server or data center to another website, computer, server or data center by wired or wireless means. The readable storage medium may be any available medium that can be accessed or a data storage device such as a server, data center, etc. that integrates one or more available media. The available medium may be a magnetic medium, such as a floppy disk, a hard disk, or a magnetic tape; it may also be an optical medium, such as a digital video disk; it may also be a semiconductor medium, such as a solid state drive. The computer readable storage medium may be a volatile or non-volatile storage medium, or may include both volatile and non-volatile types of storage media.

[0186] Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as methods, systems, or computer program products. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present disclosure may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0187] The present disclosure is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the present disclosure. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0188] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0189] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0190] In the description of this specification, the description with reference to the terms "one embodiment / method", "some embodiments / methods", "example", "specific example", or "some examples" etc. means that the specific features, structures, or characteristics described in conjunction with the embodiment / method or example are included in at least one embodiment / method or example of the present disclosure. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment / method or example. Moreover, the specific features, structures, or characteristics described may be combined in any one or more embodiments / methods or examples in a suitable manner. In addition, those skilled in the art may combine and combine different embodiments / methods or examples described in this specification and features of different embodiments / methods or examples, unless they are contradictory.

[0191] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present disclosure, "plurality" means at least two, such as two, three, etc., unless otherwise clearly and specifically defined.

[0192] Those skilled in the art should understand that the above embodiments are only for the purpose of clearly illustrating the present disclosure, and are not intended to limit the scope of the present disclosure. For those skilled in the art, other changes or modifications may be made based on the above disclosure, and these changes or modifications are still within the scope of the present disclosure.

Claims

1. A document processing method, characterized in that: include: Performing layout analysis on the document to be processed to obtain multiple element blocks and their positions in the document to be processed; Acquire a hierarchical relationship of the plurality of element blocks according to positions of the plurality of element blocks; Tree structure data is generated according to the hierarchical relationship of the plurality of element blocks.

2. The document processing method according to claim 1, characterized in that: The performing layout analysis on the document to be processed includes: Parsing the document to be processed to obtain parsed elements and their positions; Filtering the margin information from the document to be processed according to the parsed elements and their positions to obtain a filtered document; Perform layout analysis on the parsed elements and their positions in the filtered document.

3. The document processing method according to claim 2, characterized in that: The filtering of the margin information from the to-be-processed document according to the parsed elements and their positions includes: Performing page margin analysis on the document to be processed according to the parsed elements and their positions to obtain a page margin threshold; Acquire page margin information of each page from the document to be processed according to the page margin threshold; acquiring comparison page margin information from the page margin information of each page according to the information amount of the page margin information of each page; Matching the information blocks included in the comparison page margin information with the information blocks included in the page margin information of each page respectively to obtain matching blocks; Acquire a page margin removal distance according to the position of the information in the matching block; The page margin information is filtered from the document to be processed according to the page margin removal distance.

4. The document processing method according to claim 3, characterized in that: The performing page margin analysis on the document to be processed according to the parsed elements and their positions to obtain a page margin threshold comprises: Determining whether each page of the document to be processed includes an independent horizontal line greater than a width threshold; If the current page includes the independent horizontal line, obtaining a candidate value of the page margin of the current page according to the position of the independent horizontal line; If the current page does not include the independent horizontal line, obtaining a candidate value of the margin of the current page according to a fixed value or a boundary of an edge text line of the current page; A majority decision is performed on the page margin candidate values ​​of each page of the document to be processed to obtain the page margin threshold.

5. The document processing method according to claim 2, characterized in that: When the parsed elements in the filtered document include non-independent line segments, performing layout analysis on the parsed elements in the filtered document and their positions includes: Obtaining a plurality of line segments from the parsed elements in the filtered document; Performing cluster analysis on the plurality of line segments to obtain at least one line segment cluster; A table structure is identified according to the at least one line segment cluster to obtain at least one table block.

6. The document processing method according to claim 2, characterized in that: When the parsed elements in the filtered document include line text, the performing layout analysis on the parsed elements in the filtered document and their positions includes: Get the text attributes of the line of text; The lines of text are merged according to their text attributes and positions to obtain a text block.

7. The document processing method according to any one of claims 1 to 6, characterized in that: The acquiring the hierarchical relationship of the plurality of element blocks according to the positions of the plurality of element blocks comprises: The multiple element blocks are processed through a stack according to positions of the multiple element blocks to obtain a hierarchical relationship of the multiple element blocks.

8. The document processing method according to claim 7, characterized in that: The processing of the plurality of element blocks through a stack according to the positions of the plurality of element blocks comprises: Create an empty stack; Read each element block in sequence according to the position of the multiple element blocks; When the start tag of the element block is read, a new node is created to represent the start tag; determine whether the stack is empty; if not, the new node is used as the child node of the current top node in the stack and the new node is pushed into the stack; if the stack is empty, the new node is pushed into the stack; When the content of the element block is read, a content node corresponding to the content is created; the content node is used as a child node of the current top node in the stack, and the stack state remains unchanged; When the end tag of an element block is read, the start tag corresponding to the end tag is popped from the stack.

9. An electronic device, characterized in that: include: A memory storing execution instructions; as well as A processor, wherein the processor executes the execution instruction stored in the memory, so that the processor executes the document processing method according to any one of claims 1 to 8.

10. A readable storage medium, characterized in that: The readable storage medium stores execution instructions, which are used to implement the document processing method according to any one of claims 1 to 8 when executed by a processor.

11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the document processing method according to any one of claims 1 to 8 is implemented.