PDF thesis analysis method, electronic equipment and storage medium
Through layout analysis, area sorting and text recognition technology, PDF papers are analyzed, which solves the content loss and complex sorting problems during analysis in the existing technology, and realizes efficient and accurate text analysis and integration, ensuring the integrity of the analysis results. and accuracy.
Patent Information
- Application Number
- CN202411503832.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-25
- Publication Date
- 2025-01-03
AI Technical Summary
When analyzing PDF papers, the prior art can easily lead to partial losses of the original content of the paper and changes in expression methods. Moreover, the logic of text sorting and integration of multi-column or mixed multi-column structures is complicated, making it difficult to achieve efficient and accurate analysis.
Through layout analysis, area sorting and text recognition, we can identify the target content area in the PDF paper, perform position sorting and text content arrangement to ensure the integrity of the parsed text and the accuracy of the context connection, and use preset layout analysis, area sorting and text recognition The model processes, deleting non-target content to obtain the final parsed text.
It realizes the completeness and accuracy of contextual connection of PDF papers, ensures that the parsed text is consistent with the original document expression, improves analysis efficiency, and is suitable for complex typesettings of multiple columns or mixed columns.
Smart Images

Figure CN119250060A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a PDF paper parsing method, electronic device and storage medium. Background Art
[0002] With the continuous development of artificial intelligence and natural language processing technology, the need to efficiently collect and organize high-quality knowledge is becoming increasingly urgent. This knowledge can be used for the training of large-scale language models, knowledge base retrieval and other artificial intelligence-related technologies, and has extraordinary value and significance in promoting the development of human society.
[0003] At present, since research results are usually published in the form of papers, the knowledge in peer-reviewed papers has high quality and value. It is very necessary to systematically collect and organize the knowledge in the papers. Currently, Portable Document Format (PDF) papers are often directly parsed by training paper parsing models.
[0004] However, the above document parsing model uses technologies such as document images and text semantic information. The parsing effect of PDF papers depends largely on the model's semantic understanding of PDF papers, which may lead to partial loss of the original content of the paper and changes in the expression method. Summary of the invention
[0005] In view of this, an embodiment of the present application provides a PDF paper parsing method, an electronic device and a storage medium to ensure the integrity of the PDF paper and the accuracy of the context connection when parsing the PDF paper.
[0006] In a first aspect, an embodiment of the present application provides a PDF paper parsing method, comprising:
[0007] Performing layout analysis on the PDF paper to be parsed to obtain multiple target content areas in the PDF paper to be parsed;
[0008] Sorting the multiple target content areas to obtain a positional order of the multiple target content areas, wherein the positional order is used to indicate a front-to-back positional relationship of the multiple target content areas in the PDF paper to be parsed;
[0009] Performing text recognition on the multiple target content areas respectively to obtain regional text contents of the multiple target content areas;
[0010] According to the position sorting, the regional text contents of the multiple target content areas are arranged to obtain the target parsed text of the PDF paper to be parsed.
[0011] In an optional implementation, the page layout analysis is performed on the PDF paper to be parsed to obtain multiple target content areas in the PDF paper to be parsed, including:
[0012] Convert the PDF paper to be parsed into a target image;
[0013] Calling an application program interface of a preset layout analysis model to perform layout analysis on the target image using the preset layout analysis model to obtain region boundaries corresponding to a plurality of region type labels in the PDF paper to be parsed;
[0014] The multiple target content areas are obtained according to the area boundaries corresponding to the multiple area type tags.
[0015] In an optional implementation, obtaining the multiple target content areas according to the area boundaries corresponding to the multiple area type labels includes:
[0016] Obtaining a plurality of initial content regions according to region boundaries corresponding to the plurality of region type labels;
[0017] The multiple initial content areas are filtered according to the multiple area type tags to obtain the multiple target content areas.
[0018] In an optional implementation, the sorting of the multiple target content areas to obtain the position sorting of the multiple target content areas includes:
[0019] Calling an application program interface of a preset area sorting model to obtain sorting numbers of the plurality of target content areas using the preset area sorting model;
[0020] The multiple target content areas are sorted according to the sorting numbers of the multiple target content areas to obtain a position sorting of the multiple target content areas.
[0021] In an optional implementation, performing text recognition on the multiple target content areas respectively to obtain regional text contents of the multiple target content areas includes:
[0022] Calling an application program interface of a preset text recognition model to perform text recognition on each target content area to obtain regional text content of each target content area, wherein the regional text content of each target content area includes: at least one line text block and the position of each line text block in each target content area;
[0023] The step of arranging the regional text contents of the plurality of target content regions according to the position sorting to obtain the target parsed text of the PDF paper to be parsed includes:
[0024] Arranging the regional text contents of the plurality of target content regions according to the position sorting;
[0025] According to the positions of the text blocks in each target content area, structural processing is performed on the at least one text block in each target content area to obtain the target parsed text.
[0026] In an optional implementation, the step of performing structural processing on the at least one line of text blocks in each target content area according to the positions of each line of text blocks in each target content area to obtain the target parsed text includes:
[0027] If the multiple target content areas include a title area, sequentially splicing at least one line of text blocks in the title area according to the position of each line of text blocks in the title area to obtain a spliced line of text blocks;
[0028] The spliced line text blocks are set as a line to obtain the parsed text of the title area, and the target parsed text includes: the parsed text of the title area.
[0029] In an optional implementation, the step of performing structural processing on the at least one line of text blocks in each target content area according to the positions of each line of text blocks in each target content area to obtain the target parsed text includes:
[0030] If the multiple target content areas include a text area, determining indentation information of at least one line of text blocks in the text area according to positions of each line of text blocks in the text area;
[0031] According to the indentation information of at least one line text block in the text area, at least one line text block in the text area is divided into paragraphs to obtain the parsed text of the text area, and the target parsed text includes: the parsed text of the text area.
[0032] In an optional embodiment, the method further comprises:
[0033] Deleting at least one of the following information from the target parsed text;
[0034] Author information, figure title information, acknowledgment information, reference information, extra spaces, and reference citation annotations.
[0035] In a second aspect, an embodiment of the present application further provides an electronic device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the memory through the bus, and the processor executes the machine-readable instructions to execute any one of the methods described in the first aspect.
[0036] In a third aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the method described in any one of the first aspects is executed.
[0037] The present application provides a PDF paper parsing method, electronic device and storage medium, wherein the method comprises: performing layout analysis on the PDF paper to be parsed, obtaining multiple target content areas in the PDF paper to be parsed, sorting the multiple target content areas, obtaining position sorting of the multiple target content areas, the position sorting is used to indicate the front and back position relationship of the multiple target content areas in the PDF paper to be parsed, performing text recognition on the multiple target content areas respectively, obtaining regional text content of the multiple target content areas, arranging the regional text content of the multiple target content areas according to the position sorting, and obtaining the target parsed text of the PDF paper to be parsed. The use of this scheme to parse the PDF paper can ensure the integrity of the PDF paper and the accuracy of the context connection. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0039] Figure 1 Schematic diagram of the PDF paper parsing method provided in the embodiment of the present application Figure 1 ;
[0040] Figure 2 Schematic diagram of the PDF paper parsing method provided in the embodiment of the present application Figure 2 ;
[0041] Figure 3 A schematic diagram of the layout analysis results provided in the embodiments of the present application;
[0042] Figure 4 Schematic diagram of the PDF paper parsing method provided in the embodiment of the present application Figure 3 ;
[0043] Figure 5 A schematic diagram of the regional sorting results provided in an embodiment of the present application;
[0044] Figure 6 Schematic diagram of the PDF paper parsing method provided in the embodiment of the present application Figure 4 ;
[0045] Figure 7 A schematic diagram of text recognition results provided in an embodiment of the present application;
[0046] Figure 8 Schematic diagram of the PDF paper parsing method provided in the embodiment of the present application Figure 5 ;
[0047] Fig. 9 Schematic diagram of the PDF paper parsing method provided in the embodiment of the present application Figure 6 ;
[0048] Fig.10 A schematic diagram of a specific PDF paper parsing process provided in an embodiment of the present application;
[0049] Fig.11 A schematic diagram of the structure of a PDF paper parsing device provided in an embodiment of the present application;
[0050] Fig.12 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0052] Since PDF papers contain high quality and value, it is particularly important to parse PDF papers to extract target content. Currently, one way is to parse PDF papers through paper parsing models. However, since the document parsing model uses technologies such as document images and text semantic information, the parsing effect of PDF papers depends largely on the model's semantic understanding of PDF papers, which may lead to partial loss of the original content of the paper and changes in the expression method. Another way is to use optical character recognition (OCR) technology to identify the text content and position coordinates in PDF papers, and then integrate the text content. However, this technology is not effective in filtering non-target content. In addition, for multi-column or mixed multi-column structures, the process of text sorting and integration based on text position is logically complex and difficult to implement.
[0053] Based on this, the present application provides a PDF paper parsing tool, which parses the PDF paper into a target parsed text through layout analysis, area sorting, and text recognition, thereby ensuring the integrity of the PDF paper and the accuracy of the context connection, so that the parsed text is consistent with the expression of the PDF paper to be parsed, and the parsing efficiency is high.
[0054] Figure 1 Schematic diagram of the PDF paper parsing method provided in the embodiment of the present application Figure 1 The execution subject of this embodiment is an electronic device, such as a mobile phone, a tablet computer, a desktop computer, etc.
[0055] like Figure 1 As shown, the method may include:
[0056] S101, performing layout analysis on the PDF paper to be parsed to obtain multiple target content areas in the PDF paper to be parsed.
[0057] The layout analysis is performed on the PDF paper to be parsed to identify multiple target content areas in the PDF paper to be parsed, wherein the multiple target content areas are areas where multiple types of target content in the PDF paper to be parsed are located, and an area for one type of target content includes but is not limited to one.
[0058] Among them, multiple types of target content may include, for example, titles and texts. Accordingly, multiple target content areas may include title areas and text areas. It is worth noting that the target content in the PDF paper to be parsed can be determined according to actual conditions, including but not limited to titles and texts. This embodiment does not make any special limitations on this.
[0059] S102: Sort the multiple target content areas to obtain a position sort of the multiple target content areas.
[0060] According to the positions of the multiple target content areas in the PDF paper to be parsed, the multiple target content areas are sorted to obtain the position sorting of the multiple target content areas, wherein the position sorting is used to indicate the front and back position relationship of the multiple target content areas in the PDF paper to be parsed.
[0061] For example, in the PDF paper to be parsed, title area 1 is before body area 2, so the position sorting of title area 1 is before the position sorting of body area 2; title area 2 is after body area 2, so the position sorting of title area 2 is after the position sorting of body area 2; body area 2 is after title area 2, so the position sorting of body area 2 is after the position sorting of title area 2.
[0062] Based on the regional sorting model, it is possible to correctly connect and integrate the contents of each region, improve the accuracy of the connection between the upper and lower contents, and enable the target content areas to be connected in an orderly manner.
[0063] S103 , performing text recognition on multiple target content areas respectively to obtain regional text contents of the multiple target content areas.
[0064] Text recognition is performed on each target content region to identify and obtain regional text content of each target content region, wherein the regional text content is located in each target content region, that is, each target content region is a region where the corresponding regional text content is located.
[0065] For example, if the target content area is the title area, the regional text content of the title area is the title in the PDF paper to be parsed; if the target content area is the body area, the regional text content of the body area is the body of the PDF paper to be parsed.
[0066] S104, arranging the regional text contents of the plurality of target content regions according to the position sorting, and obtaining the target parsed text of the PDF paper to be parsed.
[0067] According to the position sorting, the regional text contents of multiple target content areas are arranged to obtain the target parsing text of the PDF paper to be parsed. The sorting of the regional text contents of multiple target content areas in the target parsing text is consistent with the position sorting of the multiple target content areas. The target parsing text can be a TXT document.
[0068] For example, if the position sorting of the title area 1 is before the position sorting of the body area 1, then in the target parsed text, the regional text content of the title area 1 is before the regional text content of the body area 1.
[0069] It is worth noting that a parsing tool can be developed for the PDF paper to be parsed, and the parsing tool can be deployed on an electronic device to execute the above steps S101-S104 by running the parsing tool.
[0070] In this embodiment, the PDF paper is parsed into a target parsed text through layout analysis, area sorting, and text recognition, thereby ensuring the integrity of the PDF paper and the accuracy of the context connection, making the parsed text consistent with the expression of the PDF paper to be parsed, and having high parsing efficiency.
[0071] In an optional embodiment, the method may further include:
[0072] Delete at least one of the following information from the target parsed text;
[0073] Author information, figure title information, acknowledgment information, reference information, extra spaces, and reference citation annotations.
[0074] Among them, regular matching can be performed on the target parsed text to identify non-target content in the target parsed text, and the non-target content in the target parsed text can be deleted through data cleaning, wherein the non-target content can include at least one of author information, figure title information, acknowledgment information, reference information, extra spaces, and reference citation annotations.
[0075] For the author information, by using regular matching, if a paragraph contains 5 or more surnames, it means that the paragraph is where the author information is located, and the paragraph can be deleted. For the icon title processing, by using regular matching, if the paragraph starts with "Figure" or "Table" and is followed by a serial number, and the paragraph length is less than the preset length (such as 15 characters), it means that the paragraph is where the chart title information is located, and the paragraph can be deleted.
[0076] For the processing of acknowledgment information, if a paragraph begins with "Acknowledgments" and contains 5 or more surnames through regular matching, it means that the paragraph is the paragraph where the acknowledgment information is located, and the paragraph can be deleted. For the processing of reference information, if a title begins with "Reference" through regular matching, the line and the content below the reference information will be deleted.
[0077] You can also delete extra spaces and reference citation marks to obtain the final parsed text and save it as a TXT document.
[0078] In this embodiment, non-target content can be deleted through data cleaning, ensuring that the parsed text obtained by parsing can better meet actual needs.
[0079] Figure 2 Schematic diagram of the PDF paper parsing method provided in the embodiment of the present application Figure 2 ,like Figure 2 As shown, in an optional implementation, the above step S101, performing layout analysis on the PDF paper to be parsed to obtain multiple target content areas in the PDF paper to be parsed, may include:
[0080] S201, converting the PDF paper to be parsed into a target image.
[0081] In an optional implementation, the PDF paper to be parsed can be converted into an image format based on the Python programming language to obtain a target image corresponding to the PDF paper to be parsed.
[0082] S202, calling an application program interface of a preset layout analysis model to perform layout analysis on a target image using the preset layout analysis model, and obtaining region boundaries corresponding to a plurality of region type labels in the PDF paper to be parsed.
[0083] Among them, the region type label in the PDF paper to be parsed is used to indicate the corresponding region type in the PDF paper to be parsed. Table 1 is a schematic diagram of region types and region type labels. For example, the label Title in Table 1 is used to indicate the title area in the PDF paper to be parsed.
[0084] Region Type Label title Title Author Information Author text Text formula Equation picture Figure Image caption Figure caption sheet Table Table Title Table caption Header Header footer Footer refer to Reference
[0085] Table 1
[0086] The preset layout analysis model is a pre-trained model for layout analysis. The application program interface of the preset layout analysis model is called to adopt the preset layout analysis model to perform layout analysis on the target image, and obtain the region boundaries corresponding to multiple region type labels in the PDF paper to be parsed, wherein the region boundaries corresponding to the region type labels are the boundaries of the region types indicated by the region type labels, for example, the boundaries of the title region, the boundaries of the author information region, and the boundaries of the text region. The region boundaries may be in coordinate form.
[0087] Figure 3 A schematic diagram of the layout analysis results provided in the embodiments of the present application, such as Figure 3 As shown, the preset layout analysis model is used to perform layout analysis to obtain the region boundary coordinates and region type labels of region A and region B.
[0088] S203 . Obtain multiple target content areas according to the area boundaries corresponding to the multiple area type tags.
[0089] According to the region boundary corresponding to each region type label, the corresponding target content region is determined from the PDF paper to be parsed, wherein the target content region can be framed out in the PDF paper to be parsed based on the region boundary corresponding to each region type label, and the region within the region boundary is used as the target content region.
[0090] In an optional implementation, the above step S203, obtaining multiple target content areas according to the area boundaries corresponding to the multiple area type tags, includes:
[0091] According to the region boundaries corresponding to the multiple region type labels, multiple initial content regions are obtained;
[0092] The multiple initial content areas are filtered according to the multiple area type labels to obtain multiple target content areas.
[0093] According to the area boundary corresponding to each area type label, the corresponding initial content area is determined in the PDF paper to be parsed, wherein the initial content area can be the area selected by the area boundary corresponding to each area type label in the PDF paper to be parsed, and then according to multiple area type labels, the content area with preset area type labels is filtered from the multiple initial content areas to obtain multiple target content areas.
[0094] Among them, multiple initial content areas include title area, author information area, text area, formula area, picture area, picture title area, table area, table title area, header area, footer area, and reference information area. The preset area type labels can be, for example, header, footer, author, reference, table, table title, picture, and picture title. That is to say, non-target areas with area type labels of header, footer, author, reference, table, table title, picture, and picture title are filtered out, and the obtained multiple target content areas include title area, author information area, text area, and formula area.
[0095] It is worth noting that the number of title area, author information area, text area, formula area, picture area, picture title area, table area, table title area, header area, footer area, and reference information area includes but is not limited to one.
[0096] In this embodiment, the region boundaries corresponding to the region type labels are identified through a preset layout analysis model, and non-target regions are filtered out, thereby achieving high availability of content, ensuring the quality of parsed content, and thereby improving text recognition efficiency.
[0097] Figure 4 Schematic diagram of the PDF paper parsing method provided in the embodiment of the present application Figure 3 ,like Figure 4 As shown, in an optional implementation, the above step S102, sorting the multiple target content areas to obtain the position sorting of the multiple target content areas, may include:
[0098] S301 : calling an application program interface of a preset area sorting model to obtain sorting numbers of multiple target content areas using the preset area sorting model.
[0099] S302 . Sort the multiple target content areas according to their sorting numbers to obtain a position sorting of the multiple target content areas.
[0100] The application program interface of the preset area sorting model is called to use the preset area sorting model to infer the sorting of multiple target content areas, obtain the sorting numbers of the multiple target content areas, and sort the multiple target content areas to obtain the position sorting of the multiple target container areas.
[0101] Among them, the sorting number and the position sorting may be positively correlated, for example, the smaller the sorting number, the earlier the position sorting, and the larger the sorting number, the later the position sorting.
[0102] It is worth noting that the layout of the PDF paper to be parsed is specific, such as multi-column layout or single-column layout. The preset area sorting model can infer the sorting of multiple target content areas of the PDF paper to be parsed with different layouts, and obtain the sorting numbers of multiple target content areas. Therefore, the preset area sorting model has a wide range of applications and is suitable for parsing PDF format papers with complex layouts of multiple columns or mixed columns.
[0103] Figure 5 A schematic diagram of the regional sorting results provided in the embodiment of the present application, such as Figure 5 As shown, the preset region sorting model is used for reasoning to obtain the sorting numbers of region A and region B, and the sorting numbers are marked for region A and region B.
[0104] In this embodiment, a region sorting model is used to sort multiple target content regions, so as to correctly connect and integrate the regional text contents of each target content region and improve the accuracy of the connection between the upper and lower contents.
[0105] Figure 6 Schematic diagram of the PDF paper parsing method provided in the embodiment of the present application Figure 4 ,like Figure 6 As shown, in an optional implementation, the above step S103, performing text recognition on multiple target content areas respectively to obtain regional text contents of the multiple target content areas, may include:
[0106] S401 , calling an application program interface of a preset text recognition model to perform text recognition on each target content area to obtain regional text content of each target content area.
[0107] An application program interface of a preset text recognition mode is called to perform text recognition on each target content area using a preset text recognition model to obtain the regional text content of each target content area. The regional text content of each target content area includes: at least one line text block and the position of each line text block in each target content area.
[0108] The line text block is a line text block composed of each line of characters in the regional text content of the target content area, that is, the line text block includes multiple characters, and the target content area includes a line text block composed of at least one line of characters.
[0109] The position of the line text block within each target content area may include the position of each character in the line text block within each target content area.
[0110] Figure 7 A schematic diagram of the text recognition result provided in the embodiment of the present application, such as Figure 7 As shown, a preset text recognition model is used to recognize at least one line text block and the position coordinates of the line text block in area A and area B.
[0111] The above step S104, arranging the regional text contents of multiple target content areas according to the position sorting to obtain the target parsed text of the PDF paper to be parsed, may include:
[0112] S402: Arrange the regional text contents of the plurality of target content regions according to the position sorting.
[0113] S403: Perform structural processing on at least one line of text blocks in each target content area according to the position of each line of text blocks in each target content area to obtain a target parsed text.
[0114] According to the position sorting of multiple target content areas, the regional text contents of the multiple target content areas are arranged, and for each target content area, according to the position of each line of text blocks in each target content area, at least one line of text blocks in each target content area is structured to obtain a target parsed text. That is to say, first starting from the global perspective, the multiple target content areas are sorted so that the position sorting of the multiple target content areas is consistent with the chronological position in the PDF paper to be parsed, and then starting from the local perspective, at least one line of text block in each target content area is structured so that the layout of each line of text blocks that has been structured meets the layout requirements corresponding to each target content area.
[0115] Figure 8 Schematic diagram of the PDF paper parsing method provided in the embodiment of the present application Figure 5 ,like Figure 8 As shown, in an optional implementation, the above step S403, according to the position of each line of text blocks in each target content area, performs structural processing on at least one line of text blocks in each target content area to obtain the target parsed text, may include:
[0116] S501: If the multiple target content areas include a title area, sequentially splice at least one line of text blocks in the title area according to positions of each line of text blocks in the title area to obtain spliced line of text blocks.
[0117] S502: Set the spliced line text blocks as a line to obtain the parsed text in the title area.
[0118] If multiple target content areas include a title area, at least one line text block in the title area is sequentially spliced according to the position of each line text block in the title area, so that the line text blocks in the title area are in the same order as the line text blocks in the PDF paper to be parsed, and the spliced line text blocks are set as a row to obtain the parsed text of the title area, wherein the target parsed text includes: the parsed text of the title area, that is, for the title area, the line text blocks inside it are spliced in the order of front and back, and the spliced line text blocks occupy a separate row.
[0119] It is worth mentioning that for the PDF paper to be parsed, the title area may include multiple line text blocks. During parsing, the line text blocks are spliced in a front-to-back order and set as one line, so that the parsed text of the title area is more in line with the title layout.
[0120] Fig. 9 Schematic diagram of the PDF paper parsing method provided in the embodiment of the present application Figure 6 ,like Fig. 9 As shown, in an optional implementation, the above step S403, according to the position of each line of text blocks in each target content area, performs structural processing on at least one line of text blocks in each target content area to obtain the target parsed text, may include:
[0121] S601: If the multiple target content areas include a text area, determine indentation information of at least one line of text blocks in the text area according to positions of each line of text blocks in the text area.
[0122] If multiple target content areas include a text area, the indentation information of at least one line of text blocks in the text area is determined based on the position of each line of text blocks in the text area, wherein the indentation information is used to indicate whether each line of text blocks is indented compared with an adjacent text block (the previous line or the next line), and the indentation includes a left indentation and a right indentation.
[0123] S602: Divide at least one line of text blocks in the text area into paragraphs according to indentation information of at least one line of text blocks in the text area to obtain parsed text of the text area.
[0124] If the text block in the text area is indented on the left, it means that the text block is the first line of the paragraph. If the text block is indented on the right, it means that the text block is the last line of the paragraph. If the text block is not indented, it means that the text block is the middle line of the paragraph.
[0125] According to the indentation information of each text block in the text area, determine whether each text block is the first line, the middle line or the middle line of the paragraph to divide the paragraphs to obtain a paragraph, and combine at least one obtained paragraph to obtain the parsed text of the text area, wherein the target parsed text includes: the parsed text of the text area.
[0126] In this embodiment, paragraph division is performed based on the indentation information of the line text blocks to structure the text content of the parsed text in the text area so that the layout of the parsed text in the text area is consistent with the layout of the line text blocks in the text area in the PDF paper to be parsed.
[0127] On the basis of the above-mentioned embodiments, a specific parsing tool is constructed by combining trained reasoning models such as layout analysis, sorting analysis and text recognition, taking into account the specific document characteristics of PDF format papers.
[0128] Fig.10 A schematic diagram of a specific PDF paper parsing process provided in the embodiment of the present application is as follows: Fig.10 As shown, it consists of two parts:
[0129] Part 1: Build the backend service, use the Python programming language, and use the FastAPI module to call the application programming interface (API) of the preset layout analysis model, preset area sorting model, and preset text recognition model to start the three interface services of layout analysis, area sorting, and text recognition.
[0130] Part 2: Convert PDF documents into image formats, layout analysis, region filtering, region sorting, text recognition, text structuring and post-processing (i.e., deleting non-target content), and parse PDF format papers into TXT documents.
[0131] The implementation process of the preset layout analysis model, the preset area sorting model and the preset text recognition model is described below:
[0132] 1. Preset layout analysis model
[0133] 1. Training the inference model
[0134] The process mainly includes data preparation and model training:
[0135] Data preparation: Collect relevant paper and literature PDF documents and annotated semi-finished data sets with similar functions on the academic resource platform, such as the Chinese Document Layout Analysis (CDLA) data set. Use annotation tools (such as LabelMe) to annotate the paper and literature PDF documents, marking the region type labels and corresponding regions defined in Table 1.
[0136] The semi-finished dataset was further processed to ensure that its annotations were consistent with the region type labels in Table 1. Finally, the annotated dataset was randomly divided into a training set and a validation set in a ratio of 5:1.
[0137] Model training: The model structure consists of three parts: backbone network, neck module and head module. The backbone network is responsible for extracting features of different resolutions, and the neck module is used to fuse these multi-scale features. Finally, multiple head modules detect targets at different resolutions. Among them, the backbone network uses LCNet, the neck module uses CSPPAN, and the head module is PicoHead. Combined with the PaddleDetection training framework, an inference model for layout analysis is finally constructed.
[0138] Based on the above model structure, the following parameter configuration is used for model training:
[0139] 1) Use LCNet as the backbone network (backbone:LCNet), CSPPAN as the neck structure (neck:CSPPAN), PicoHead as the head (head:PicoHead), the model scaling factor is set to 1.0 (scale:1.0), the feature map size is [3,4,5] (feature_maps:[3,4,5]), and the number of categories that the model needs to recognize is 5 (num_classes:12).
[0140] 2) Enabling finding unused parameters (find_unused_parameters:True) and exponentially weighted average model parameters (use_EMA:true) helps stabilize the training process.
[0141] 3) In order to efficiently load and preprocess the training data, the configuration of the training reader (TrainReader) is as follows:
[0142] The probability of random flipping of the image is 0.5 (RandomFlip:{prob:0.5}); batch transformation includes random batch resizing and image normalization (BatchRandomResize,NormalizeImage); the batch size is 24; shuffling is enabled (shuffle:true); the last batch is discarded (drop_last:true), and batch collation is not enabled (collate_batch:false).
[0143] 4) Use COCO metrics to evaluate model performance (metric:COCO), the evaluation reader (EvalReader) configuration includes image resizing and normalization, batch transformation includes padding to 32 multiples (PadBatch:{pad_to_stride:32}), the batch size is 8, and shuffle is not enabled (shuffle:false).
[0144] 5) During the training process, the model is cycled every 10 epochs (cycle_epoch:10) and a snapshot of the model is saved at the end of every 10 epochs (snapshot_epoch:10), and a total of 50 epochs (epoch:50) are trained.
[0145] 3. Reasoning service implementation
[0146] When performing layout reasoning analysis, the following main steps are usually included: image preprocessing, model prediction, and post-processing. The following is a detailed description of these three processes:
[0147] 1) Image preprocessing
[0148] Image preprocessing is the first step in the model inference process, which converts the original image into a data format and size suitable for model input.
[0149] 2) Model prediction
[0150] After preprocessing, the image data will be fed into the trained model for prediction. This process usually includes the following steps:
[0151] Load model: Use Paddle's inference.create_predictor to load the trained model weight file into the inference environment.
[0152] Forward propagation: Input the preprocessed image data into the model, perform forward propagation calculations, and obtain the output results of the model.
[0153] Result extraction: Extract the required prediction results from the model's output, which are classification labels, bounding box coordinates, confidence scores, etc.
[0154] 3) Post-processing
[0155] Post-processing is the processing of model prediction results, the purpose of which is to transform the abstract data output by the model into a form that is easy to understand and use. This step may include the following:
[0156] Non-maximum suppression (NMS): In layout analysis tasks, it is used to eliminate redundant bounding boxes and retain the most likely detection results.
[0157] Threshold filtering: Filter out low-confidence prediction results based on confidence scores or other criteria.
[0158] Result decoding: Decode the output of the model into actual visualization results, such as drawing bounding boxes and labels on the image.
[0159] Result aggregation: Aggregate multiple prediction results of the model, such as voting mechanism or average, to improve overall accuracy.
[0160] Finally, based on the above three processes, an interface service for layout analysis was built using Python programming language and FastAPI framework.
[0161] 2. Preset Regional Sorting Model
[0162] 1. Prepare the inference model
[0163] Visit the corresponding website and download the region ordering inference model vikp / surya_order for subsequent layout analysis tasks.
[0164] 2. Reasoning Service Implementation
[0165] The service performs preprocessing, model prediction, and postprocessing on the input image and its identified bounding boxes, and finally outputs the sorting results of each bounding box. The following is a brief description of these three processes:
[0166] Preprocessing: Rescale and normalize the input image to meet the requirements of the model input.
[0167] Model prediction: Load the model weights through the VisionEncoderDecoderModel of the Transformers module, and infer the probability values (logits) of each bounding box for each sorting value based on the image and bounding box information in the inference mode of torch.
[0168] Post-processing stage: Ensure that the ranking value of each bounding box is unique, and determine the final ranking value based on the maximum probability, thus completing the ranking reasoning module.
[0169] The entire process is based on the Python programming language. The sorting reasoning module is implemented through the FastAPI framework, and an interface service for regional sorting is built.
[0170] 3. Preset Text Recognition Model
[0171] 1. Prepare the inference model
[0172] Download two pre-trained models of the Chinese and English ultra-lightweight PP-OCRv4 from the corresponding website: the detection model ch_PP-OCRv4_det_infer and the recognition model ch_PP-OCRv4_rec_infer, so as to perform text detection and recognition tasks.
[0173] 2. Reasoning Service Implementation
[0174] First, the image information in each bounding box is preprocessed and converted into a data format and size suitable for model input. Then, Paddle's inference.create_predictor is used to load the text detection model ch_PP-OCRv4_det_infer and the recognition model ch_PP-OCRv4_rec_infer respectively to form predictors for text detection and recognition. These predictors detect and recognize the text parts of the processed image information, and finally obtain the ordered line text block content and its coordinate position through post-processing. The entire implementation process uses the Python programming language, and the text recognition interface service is built with the help of the FastAPI framework.
[0175] In this embodiment, multiple functional modules are combined to carry out a detailed and feasible solution process design for PDF format papers, which is suitable for removing non-target content, applicable to complex layouts of multiple columns, and paragraph-structured processing of text content, ultimately obtaining highly available text information knowledge.
[0176] Fig.11 This is a schematic diagram of the structure of a PDF paper parsing device provided in an embodiment of the present application, which can be integrated into an electronic device.
[0177] like Fig.11 As shown, the device may include:
[0178] An analysis module 701 is used to perform layout analysis on the PDF paper to be parsed, and obtain multiple target content areas in the PDF paper to be parsed;
[0179] A sorting module 702 is used to sort the multiple target content areas to obtain a position sorting of the multiple target content areas, where the position sorting is used to indicate the front and back position relationship of the multiple target content areas in the PDF paper to be parsed;
[0180] The recognition module 703 is used to perform text recognition on the multiple target content areas respectively to obtain regional text contents of the multiple target content areas;
[0181] The arrangement module 704 is used to arrange the regional text contents of multiple target content areas according to the position sorting to obtain the target parsed text of the PDF paper to be parsed.
[0182] In an optional implementation, the analysis module 701 is specifically configured to:
[0183] Convert the PDF paper to be parsed into the target image;
[0184] Calling the application program interface of the preset layout analysis model to perform layout analysis on the target image using the preset layout analysis model, and obtaining region boundaries corresponding to multiple region type labels in the PDF paper to be parsed;
[0185] According to the region boundaries corresponding to the multiple region type labels, multiple target content regions are obtained.
[0186] In an optional implementation, the analysis module 701 is specifically configured to:
[0187] According to the region boundaries corresponding to the multiple region type labels, multiple initial content regions are obtained;
[0188] The multiple initial content areas are filtered according to the multiple area type labels to obtain multiple target content areas.
[0189] In an optional implementation, the sorting module 704 is specifically configured to:
[0190] Calling an application program interface of a preset area sorting model to obtain sorting numbers of multiple target content areas using the preset area sorting model;
[0191] The multiple target content areas are sorted according to their sorting numbers to obtain a position sorting of the multiple target content areas.
[0192] In an optional implementation, the identification module 703 is specifically configured to:
[0193] Calling an application program interface of a preset text recognition model to perform text recognition on each target content area to obtain regional text content of each target content area, wherein the regional text content of each target content area includes: at least one line text block and the position of each line text block in each target content area;
[0194] The arrangement module 704 is specifically used to: arrange the regional text contents of the plurality of target content regions according to the position sorting;
[0195] According to the positions of the text blocks in each target content area, at least one text block in each target content area is subjected to structural processing to obtain a target parsed text.
[0196] In an optional implementation, the arrangement module 704 is specifically configured to:
[0197] If the multiple target content areas include a title area, sequentially splicing at least one line of text blocks in the title area according to the position of each line of text blocks in the title area to obtain a spliced line of text blocks;
[0198] The concatenated row text blocks are set as a row to obtain the parsed text of the title area. The target parsed text includes: the parsed text of the title area.
[0199] In an optional implementation, the arrangement module 704 is specifically configured to:
[0200] If the multiple target content areas include a text area, determining indentation information of at least one line of text blocks in the text area according to positions of each line of text blocks in the text area;
[0201] According to the indentation information of at least one line text block in the text area, at least one line text block in the text area is divided into paragraphs to obtain the parsed text of the text area, and the target parsed text includes: the parsed text of the text area.
[0202] In an optional embodiment, it also includes:
[0203] A deletion module 705 is used to delete at least one of the following information from the target parsed text;
[0204] Author information, figure title information, acknowledgment information, reference information, extra spaces, and reference citation annotations.
[0205] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference may be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.
[0206] Fig.12 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, such as Fig.12 As shown, the device may include: a processor 801, a memory 802 and a bus 803. The memory 802 stores machine-readable instructions executable by the processor 801. When the electronic device is running, the processor 801 communicates with the memory 802 through the bus 803, and the processor 801 executes the machine-readable instructions to perform the above method.
[0207] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the processor executes the above method.
[0208] In the embodiment of the present application, the computer program can also execute other machine-readable instructions when run by the processor to execute other methods described in the embodiment. For the specific execution method steps and principles, please refer to the description of the embodiment, which will not be repeated here.
[0209] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0210] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0211] In addition, each functional unit in the embodiments provided in the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0212] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0213] It should be noted that similar numbers and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. In addition, the terms "first", "second", "third", etc. are only used to distinguish the description and are not to be understood as indicating or implying relative importance.
[0214] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-mentioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-mentioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application. They should all be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A PDF paper parsing method, characterized in that: include: Performing layout analysis on the PDF paper to be parsed to obtain multiple target content areas in the PDF paper to be parsed; Sorting the multiple target content areas to obtain a positional order of the multiple target content areas, wherein the positional order is used to indicate a front-to-back positional relationship of the multiple target content areas in the PDF paper to be parsed; Performing text recognition on the multiple target content areas respectively to obtain regional text contents of the multiple target content areas; According to the position sorting, the regional text contents of the multiple target content areas are arranged to obtain the target parsed text of the PDF paper to be parsed.
2. The method according to claim 1, characterized in that The layout analysis of the PDF paper to be parsed is performed to obtain multiple target content areas in the PDF paper to be parsed, including: Convert the PDF paper to be parsed into a target image; Calling an application program interface of a preset layout analysis model to perform layout analysis on the target image using the preset layout analysis model to obtain region boundaries corresponding to a plurality of region type labels in the PDF paper to be parsed; The multiple target content areas are obtained according to the area boundaries corresponding to the multiple area type tags.
3. The method according to claim 2, characterized in that The obtaining the multiple target content areas according to the area boundaries corresponding to the multiple area type tags includes: Obtaining a plurality of initial content regions according to region boundaries corresponding to the plurality of region type labels; The multiple initial content areas are filtered according to the multiple area type tags to obtain the multiple target content areas.
4. The method according to claim 1, characterized in that: The step of sorting the multiple target content areas to obtain a position sorting of the multiple target content areas includes: Calling an application program interface of a preset area sorting model to obtain sorting numbers of the plurality of target content areas using the preset area sorting model; The multiple target content areas are sorted according to the sorting numbers of the multiple target content areas to obtain a position sorting of the multiple target content areas.
5. The method according to claim 1, characterized in that The performing text recognition on the multiple target content areas respectively to obtain regional text contents of the multiple target content areas includes: Calling an application program interface of a preset text recognition model to perform text recognition on each target content area to obtain regional text content of each target content area, wherein the regional text content of each target content area includes: at least one line text block and the position of each line text block in each target content area; The step of arranging the regional text contents of the plurality of target content regions according to the position sorting to obtain the target parsed text of the PDF paper to be parsed includes: Arranging the regional text contents of the plurality of target content regions according to the position sorting; According to the positions of the text blocks in each target content area, structural processing is performed on the at least one text block in each target content area to obtain the target parsed text.
6. The method according to claim 5, characterized in that The step of performing structural processing on the at least one line text block in each target content area according to the position of each line text block in each target content area to obtain the target parsed text includes: If the multiple target content areas include a title area, sequentially splicing at least one line of text blocks in the title area according to the position of each line of text blocks in the title area to obtain a spliced line of text blocks; The spliced line text blocks are set as a line to obtain the parsed text of the title area, and the target parsed text includes: the parsed text of the title area.
7. The method according to claim 5, characterized in that The step of performing structural processing on the at least one line text block in each target content area according to the position of each line text block in each target content area to obtain the target parsed text includes: If the multiple target content areas include a text area, determining indentation information of at least one line of text blocks in the text area according to positions of each line of text blocks in the text area; According to the indentation information of at least one line text block in the text area, at least one line text block in the text area is divided into paragraphs to obtain the parsed text of the text area, and the target parsed text includes: the parsed text of the text area.
8. The method according to claim 4, characterized in that The method further comprises: Deleting at least one of the following information from the target parsed text; Author information, figure title information, acknowledgment information, reference information, extra spaces, and reference citation annotations.
9. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and the processor executes the machine-readable instructions to perform the method described in any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is executed.
