PDF document parsing method, parsing device, equipment, and medium
By performing information extraction and layout recognition on PDF documents and filling in target document characters, the problem of insufficient logic and contextual coherence of parsing results in the existing technology is solved, and a more efficient document parsing effect is achieved.
Patent Information
- Application Number
- CN202411051093.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-01
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2044-08-01
AI Technical Summary
Existing PDF document parsing methods cannot guarantee the logic and contextual coherence of parsing results, resulting in poor parsing results.
By extracting information from the PDF document, the document characters and their position information are determined, and the layout is recognized. The target document characters are filled in according to the layout area and character position information to ensure the contextual structure consistency and internal text logic of the parsing results.
It achieves the overall contextual coherence and logic of PDF document parsing results, and improves the accuracy and effect of document parsing.
Smart Images

Figure CN118569246B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a PDF document parsing method, a parsing device, an electronic device, and a computer-readable storage medium. Background Art
[0002] PDF (Portable Document Format) is a portable document that can protect the original style and content of the file and is not affected by software and systems. PDF document parsing can parse PDF documents into text data, which is widely used in document question answering, summary extraction and other fields.
[0003] In the existing PDF document parsing method, only the text in the PDF document can be recognized, but the logic and contextual coherence of the text in the parsing result cannot be guaranteed, resulting in poor parsing effect. Summary of the invention
[0004] The present application provides a PDF document parsing method, a parsing device, an electronic device, and a computer-readable storage medium, which can ensure the overall contextual coherence and the logic of the text in the parsing results of the PDF document.
[0005] In a first aspect, the present application provides a PDF document parsing method, which includes: extracting information from a PDF document to be parsed to obtain multiple document characters contained in the PDF document and character position information of each document character; performing layout recognition on the PDF document to determine at least two layout areas, a layout category of each layout area, and area position information of each layout area contained in the layout recognition result of the PDF document; for any layout area, determining a target document character corresponding to any layout area from the multiple document characters according to the area position information of the any layout area and the character position information of the document character; and filling the target document character corresponding to any layout area into any layout area according to a filling strategy corresponding to the layout category of the any layout area to obtain a parsing result of the PDF document.
[0006] In a second aspect, the present application provides a PDF document parsing device, which includes: an extraction module, used to extract information from a PDF document to be parsed, and obtain multiple document characters contained in the PDF document and character position information of each document character; a first determination module, used to perform layout recognition on the PDF document, and determine at least two layout areas, a layout category of each layout area, and area position information of each layout area contained in the layout recognition result of the PDF document; a second determination module, used to determine, for any layout area, a target document character corresponding to any layout area from the multiple document characters according to the area position information of the any layout area and the character position information of the document character; a filling module, used to fill the target document character corresponding to any layout area into any layout area according to the filling strategy corresponding to the layout category of the any layout area, and obtain the parsing result of the PDF document.
[0007] In a third aspect, the present application provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores one or more computer programs executable by the at least one processor, and one or more of the computer programs are executed by the at least one processor so that the at least one processor can execute the above-mentioned PDF document parsing method.
[0008] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the above-mentioned PDF document parsing method when executed by a processor / processing core.
[0009] In the embodiment provided by the present application, first, by extracting information from a PDF document to be parsed, a plurality of document characters contained in the PDF document and character position information of each document character are obtained; secondly, layout recognition is performed on the PDF document to determine at least two layout areas, a layout category of each layout area and area position information of each layout area contained in the layout recognition result of the PDF document; then, for any layout area, according to the area position information of any layout area and the character position information of the document character, a target document character corresponding to any layout area is determined from a plurality of document characters; finally, according to a filling strategy corresponding to the layout category of any layout area, the target document character corresponding to any layout area is filled into any layout area to obtain a parsing result of the PDF document. It can be seen that when parsing a PDF document, the embodiment of the present application not only extracts the document characters contained in the document and the character position information of the document characters, but also performs layout recognition on the document. It obtains the parsing result of the PDF document by determining the target document characters corresponding to the publication page area and filling the target document characters into the corresponding layout area. Since it makes full use of the document character information and layout area information of the document during parsing, the obtained parsing result can maintain contextual structure consistency with the original PDF document. In addition, the embodiment of the present application has corresponding filling strategies for different categories of layout areas. When filling document characters, character filling is performed according to the corresponding filling strategy, which ensures the logic of the internal text after filling, thereby achieving the overall contextual coherence of the parsing result on the basis of contextual structure consistency.
[0010] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The accompanying drawings are used to provide a further understanding of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the present application and do not constitute a limitation of the present application. The above and other features and advantages will become more apparent to those skilled in the art by describing detailed example embodiments with reference to the accompanying drawings. In the accompanying drawings:
[0012] Figure 1 A flowchart of a PDF document parsing method provided in an embodiment of the present application;
[0013] Figure 2 A schematic diagram of a PDF document parsing method provided in an embodiment of the present application;
[0014] Figure 3 A flowchart of a PDF document parsing method provided in an embodiment of the present application;
[0015] Figure 4 A block diagram of a PDF document parsing device provided in an embodiment of the present application;
[0016] Figure 5 A block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0017] In order to enable those skilled in the art to better understand the technical solution of the present application, the exemplary embodiments of the present application are described below in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0018] In the absence of conflict, the embodiments of the present application and the features therein may be combined with each other.
[0019] As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.
[0020] The terms used herein are only used to describe specific embodiments and are not intended to limit the present application. As used herein, the singular forms "a" and "the" are also intended to include plural forms, unless the context clearly indicates otherwise. It will also be understood that when the terms "including" and / or "made of" are used in this specification, the presence of the features, wholes, steps, operations, elements and / or components is specified, but the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof is not excluded. "Connected" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect.
[0021] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by those of ordinary skill in the art. It will also be understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and this application, and will not be interpreted as having an idealized or overly formal meaning unless explicitly defined herein.
[0022] With the development of modern big model technology, the application of big models in various fields has been continuously deepened, and the requirements for big models have become higher and higher. Due to the limitations of the current model data set, the iteration speed of the model is slow, and adding external knowledge to the model has become an indispensable method in model application. For product scenarios such as document question answering and summary extraction, model external knowledge usually comes from unstructured data (such as PDF documents). When applying, PDF documents need to be parsed into text data before they can be used as model input.
[0023] However, in the existing PDF document parsing methods, only text is extracted from the document, but the logic and contextual coherence of the extracted text cannot be guaranteed, resulting in poor parsing effect, thus affecting the effect of model generation.
[0024] According to the PDF document parsing method of the embodiment of the present application, when parsing the PDF document, it not only extracts the document characters contained in the document and the character position information of the document characters, but also performs layout recognition on the document. It obtains the parsing result of the PDF document by determining the target document characters corresponding to the publication page area and filling the target document characters into the corresponding layout area. Since it makes full use of the document character information and layout area information of the document during parsing, the obtained parsing result can maintain contextual structure consistency with the original PDF document. In addition, the embodiment of the present application has corresponding filling strategies for different categories of layout areas. When filling document characters, character filling is performed according to the corresponding filling strategy, which ensures the internal text logic after filling, thereby achieving the overall contextual coherence of the parsing result on the basis of contextual structure consistency.
[0025] The PDF document parsing method according to the embodiment of the present application can be executed by an electronic device such as a terminal device or a server. The terminal device can be a user equipment (UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. The method can be implemented by a processor calling a computer-readable program instruction stored in a memory. The server can be an independent physical server, a server cluster composed of multiple servers, or a cloud server capable of cloud computing.
[0026] Figure 1 A flowchart of a PDF document parsing method provided in an embodiment of the present application. Figure 1 , the method comprising:
[0027] Step S110: extracting information from the PDF document to be parsed, and obtaining a plurality of document characters contained in the PDF document and character position information of each document character.
[0028] The document characters are text characters extracted from the document content of the PDF document, such as text characters proposed in the document content such as text paragraphs, titles, headers, footers, pictures, tables, and charts of the PDF document.
[0029] It should be noted that when extracting document characters from a PDF document, a single document character may be extracted, or a document string consisting of multiple consecutive document characters may be extracted, and this embodiment of the present application does not impose any limitation on this.
[0030] Exemplarily, for a certain title contained in a PDF document, all text contained in the title may be extracted as a string of continuous document strings, or the text contained in the title may be extracted as separate document characters.
[0031] Among them, the character position information of the document character is the relative position of the document character in the PDF document, that is, the relative position of the document character relative to the coordinate origin of the PDF document, wherein the coordinate axis, coordinate origin, and unit length of the PDF document can be adaptively set according to actual parsing needs.
[0032] For example, for a PDF document page, the lower left corner of the document page is set as the coordinate origin, the coordinate origin is used as the starting point to extend horizontally to the right as the positive X-axis of the coordinate system, the coordinate origin is used as the starting point to extend vertically upward as the positive Y-axis of the coordinate system, and pixels are used as the unit length of the coordinate axis.
[0033] In some possible implementations, the character position information of the document character may be described by determining a text bounding box corresponding to the document character. Accordingly, the character position information of the document character is the coordinate information of the text bounding box corresponding to the document character in the PDF document.
[0034] For example, for a certain extracted document character, the coordinates of the upper left corner of its corresponding text boundary box are (x0, y0), and the coordinates of the lower right corner are (x1, y1), then the character position information of the document character can be described as (x0, y0, x1, y1).
[0035] It should be noted that for any document character in the extracted document string, the coordinate information of the text boundary box corresponding to the document character can be used as the character position information according to actual application needs, or the coordinate information of the text boundary box corresponding to the document string can be used as the character position information, that is, the document characters in the document string share the same character position information, and the embodiments of the present application do not limit this.
[0036] Among them, information extraction can be performed on the PDF document to be parsed based on conventional PDF extraction tools or by adopting OCR (Optical Character Recognition, optical character recognition technology).
[0037] In some possible implementations, in order to fully extract information from a PDF document, a text object extraction method combined with an OCR extraction method can be used. Accordingly, information extraction from a PDF document to be parsed can be implemented in the following manner: paging the PDF document to be parsed to determine the paging of the PDF document to be parsed; for any PDF document paging, determine whether there is document content that needs to be extracted by OCR; if there is document content that needs to be extracted by OCR, use OCR to extract the information of the document content to obtain an OCR extraction result; for document content that does not need to be extracted by OCR, directly extract document characters and character position information of document characters from the text object corresponding to the document content to obtain a text object extraction result; merge the OCR extraction result and the text object extraction result to obtain the information extraction result of the PDF document.
[0038] After extracting multiple document characters contained in the PDF document and the character position information of each document character, the correspondence between the document characters and the character position information can be stored in the form of associated storage. For example, an associated array is constructed based on the document characters and the character position information and stored in a designated storage space. For another example, for a document string that shares character position information, the document string and the character position information of the document string can be associated and stored, and the embodiments of the present application are not limited to this.
[0039] Step S120: performing layout recognition on the PDF document to determine at least two layout areas, a layout category of each layout area, and area position information of each layout area included in the layout recognition result of the PDF document.
[0040] The layout area of a PDF document refers to the area composed of layout elements contained in the PDF document. Any document content contained in a PDF document can be determined as a layout element of a corresponding category, such as a text category, a table category, a chart category, a title category, and the like. Similarly, the layout category of a layout area can be divided according to the category of the layout element. For example, the layout category of a layout area can be a text layout area, a chart layout area, a title layout area, and the like.
[0041] The regional position information of the layout area is used to indicate the relative position of the layout area in the PDF document, which can be determined according to the coordinate information of the regional boundary box of the layout area.
[0042] Each area boundary box is used to select a layout area. The coordinate information of the area boundary box can be composed of the upper left corner coordinate information and the lower right corner coordinate information of the area boundary box. After the area boundary box of the layout area is determined, the area position information of the layout area can be generated.
[0043] Exemplarily, for layout area A, the upper left corner coordinate information of its corresponding area boundary box is (bx0, by0), and the lower right corner coordinate information is (bx1, by1). Then, based on the coordinate information of the area boundary box, the area position information of layout area A can be expressed as (bx0, by0, bx1, by1).
[0044] The layout recognition result of a PDF document refers to the recognition result obtained by performing layout recognition on a PDF document. By performing layout recognition on a PDF document, all areas containing valid text information in the document can be divided into corresponding layout areas, and the layout area, the layout category of the layout area, and the area position information of the layout area can be saved in the layout recognition result.
[0045] In some possible implementations, the layout recognition of a PDF document may be performed based on a preset layout recognition model. The preset layout recognition model is a targeted layout recognition model trained based on layout recognition training data. The layout recognition training data may include a PDF document and layout area annotation data of the PDF document. The layout recognition model trained based on the layout recognition training data can perform efficient and accurate layout recognition on a PDF document.
[0046] After the PDF document is recognized, the recognition result includes all recognized layout areas, the layout category of each layout area, and the area location information of each layout area. The layout area, layout category, and area location information can be stored in association to facilitate quick search of the layout category and area location information of a certain layout area.
[0047] Step S130: for any layout area, according to the area position information of any layout area and the character position information of the document character, determine the target document character corresponding to any layout area from a plurality of document characters.
[0048] For any layout area, the target document character corresponding to the layout area refers to the document character whose character position information matches the regional position information of the layout area. Matching means that the character position information is within the regional range corresponding to the regional position information, or the distance between the character position information and the regional range corresponding to the regional position information is not greater than a preset threshold.
[0049] Among them, according to the regional position information of any layout area and the character position information of the document characters, it is possible to determine whether the document characters are located within the layout area. When the document characters are located within the layout area, the document characters can be determined as the target document characters corresponding to the layout area.
[0050] In some possible implementation manners, it is possible to determine the target document characters corresponding to any layout area from multiple document characters based on the regional position information of any layout area and the center coordinates of the document characters. Correspondingly, determining the target document characters corresponding to any layout area from multiple document characters according to the regional position information of any layout area and the character position information of the document characters may include: determining the center coordinates of the document characters according to the character position information of any of the document characters; determining whether the center coordinates of the document characters are included in any layout area according to the position information of any layout area. If so, the document characters are determined as the target document characters corresponding to any layout area.
[0051] Among them, determining the center coordinates of the document characters according to the character position information of the document characters can be achieved through the following method: Assume that the character position information of document character 1 is (x0, y0, x1, y1), where (x0, y0) is the upper left corner coordinate of the text bounding box, and (x1, y1) is the lower right corner coordinate of the text bounding box. Then, the center coordinates (X0, Y0) of document character 1 are: X0 = (x0 + x1) / 2; Y0 = (y0 + y1) / 2.
[0052] After determining the center coordinates of the document characters, for a certain layout area 1, its regional position information is (bx0, by0, bx1, by1), where (bx0, by0) is the upper left corner coordinate information of its regional bounding box, and (bx1, by1) is the lower right corner coordinate information of its regional bounding box. If bx0 < X0 < bx1 and by0 < Y0 < by1 are satisfied, it is determined that the document character 1 is the target document character corresponding to the layout area 1.
[0053] Step S140: Fill the target document characters corresponding to any layout area into any layout area according to the filling strategy corresponding to the layout category of any layout area to obtain the parsing result of the PDF document.
[0054] For layout areas of different layout categories, corresponding filling strategies can be set according to the characteristics of the layout areas. The filling strategy is used to characterize the filling position, filling order, and / or preprocessing method of the target document characters in the layout area of the corresponding layout type. Among them, the filling position is used to characterize the specific filling of the target document characters into the top, bottom or middle of the layout area, which can be specifically determined according to the characteristics of the layout type. The filling order is used to characterize the arrangement order of the target document characters into the layout area, such as horizontal arrangement, vertical arrangement, etc. The preprocessing method can be an error correction processing method configured according to common filling errors in the layout type, for example, the preprocessing method can include: a merging processing method, a deduplication processing method, a deletion processing method, etc. For example, for the layout area of the text layout category, since the corresponding target document characters and the character position information of the target document characters have a good extraction effect, therefore, the text-type filling strategy for the layout area of the text layout category can directly fill the target document characters into the corresponding position of the layout area according to the character position information of the target document characters.
[0055] When filling the layout area of the title layout category, the extracted document characters of the title category may have different sizes. For example, the text boundary boxes of document characters A and B are different in size. If the filling is performed directly according to the area position information corresponding to document characters A and B, the character sizes of document characters A and B will not be unified. Therefore, the target document characters can be filled into the layout area by setting the corresponding title filling strategy.
[0056] In some possible implementations, the filling strategy includes: a title-type filling strategy corresponding to the title layout category; then, when the layout category of any layout area is the title layout category, according to the title-type filling strategy, the target document characters corresponding to any layout area are filled into the any layout area, including: determining the arrangement order of the multiple target document characters according to the character position information of the multiple target document characters corresponding to the any layout area, dividing the layout area into multiple layout sub-areas according to the arrangement order of the multiple target document characters, and filling the multiple target document characters into the multiple layout sub-areas in sequence according to the arrangement order of the target document characters and the area size of the layout sub-areas.
[0057] The arrangement order of the multiple target document characters refers to the row and column arrangement order of the target document characters. For example, based on the character position information of any two target document characters A and B, the up-down and left-right position relationship of the target document character A and the target document character B can be determined, and thus, based on the left-right and up-down position relationship between all the target document characters, the row arrangement order and column arrangement order of the target document characters can be determined.
[0058] After determining the arrangement order of all the target document characters, the layout area can be divided into multiple layout sub-areas. For example, according to the column arrangement order of different target document characters, the number of target document characters contained in each column is determined, thereby determining the number of divided rows of the publication area. According to the number of divided rows, the layout area is divided by rows. According to the row arrangement order of different target document characters, the number of target document characters contained in each row is determined, thereby determining the number of divided columns of the publication area. The layout area is divided by columns.
[0059] Therefore, after the sub-area division, each target document character has its corresponding layout sub-area. Therefore, when filling, the filling boundary of the target document character can be adjusted according to the area size of the layout sub-area, such as the length and width of the area, so that the character size can adapt to the area size of the layout sub-area, and then filled into the corresponding layout sub-area in row order or column order, thereby ensuring the standardization of the target document character size in each layout sub-area.
[0060] It should be noted that before adjusting the fill boundary of the target document character, it is also possible to determine whether the target document character is a text character that requires fill boundary adjustment. Only when it is determined that the target document character is a text character that requires fill boundary adjustment, the fill boundary of the target document character is adjusted, thereby effectively avoiding incorrect adjustment of the size of special symbol-type target document characters.
[0061] In an embodiment of the present application, a corresponding title filling strategy is set for the layout area of the title layout category, and the layout area of the title layout category is filled according to the title filling strategy, thereby ensuring the standardization of the text size of the layout area of the title layout category after filling.
[0062] When extracting document characters and their character position information from a chart area, it is easy to cause position shift or omission of document characters. Therefore, the extracted document characters and their character position information can be proofread and updated by setting the corresponding chart class filling strategy, thereby ensuring the internal text logic of the chart layout area after filling.
[0063] In some possible implementations, the filling strategy includes: a chart class filling strategy corresponding to the chart layout category; then when the layout category of any layout area is a chart layout category, according to the chart class filling strategy, the target document characters corresponding to any layout area are filled into any layout area, including: according to the area position information of any layout area, obtaining the chart object corresponding to any layout area contained in the PDF document; parsing the chart object according to the chart parsing model corresponding to the layout category of any layout area, obtaining multiple parsed characters contained in the chart object and character position information of each parsed character; matching the character position information of the parsed characters with the character position information of the target document characters, and updating the target document characters and the character position information of the target document characters according to the matching results; according to the updated character position information of the target document characters, filling the updated target document characters corresponding to any layout area into any layout area.
[0064] The layout area of the chart layout category refers to the layout area containing any picture, chart, or table layout element. Correspondingly, the chart object is the picture, chart, or table object corresponding to the layout area in the PDF document.
[0065] The chart parsing model is a preset parsing model for parsing pictures, charts or table objects. For pictures, charts or table objects, corresponding chart parsing models can be set to achieve effective extraction of document characters and character position information of document characters.
[0066] The parsed characters are characters contained in the chart object obtained by parsing the chart object by the chart parsing model.
[0067] The character position information of the parsed character is the relative position of the parsed character in the chart object, that is, the relative position of the parsed character relative to the coordinate origin of the chart object (such as the lower left corner of the chart object). The character position information of the parsed character can also be determined based on its corresponding character bounding box, and the character position information of the parsed character is the coordinate information of its corresponding character bounding box.
[0068] Since the character position information of the target document characters is their relative position in the PDF document, the relative position information of the extracted parsed characters in the chart object needs to be converted into the relative position information of the parsed characters in the PDF document according to the position information of the corresponding chart object in the PDF document.
[0069] For example, the relative position information of the parsed character in the chart object is (x3, y3, x4, y4), where (x3, y3) is the coordinate of the upper left corner of the character bounding box of the parsed character, and (x4, y4) is the coordinate of the lower right corner of the character bounding box of the parsed character. The position information of the coordinate origin of the chart object (such as the lower left corner of the chart object) in the PDF document is (x a ,y a ), so according to the position information of the coordinate origin of the chart object in the PDF document, the relative position information (x3, y3, x4, y4) of the parsed character in the chart object can be converted into its relative position information (x3+x a ,y3+y a ,x4+x a ,y4+y a ).
[0070] After information extraction is performed on the PDF document to be parsed, there may be omissions in document character extraction or confusion in character position information for the chart objects in the PDF document. Therefore, in the chart class filling strategy, a targeted chart parsing model is used to perform secondary information extraction on the chart objects in the PDF document, so as to update the original extraction results according to the extraction results of the chart parsing model.
[0071] For example, for a certain table, although the document characters contained in the original extraction results can be extracted, the character position information of the document characters has been offset. Therefore, information is extracted from the table based on the graph parsing model, and the character position information of the corresponding target document characters is updated based on the extracted character position information of the document characters.
[0072] Among them, the character position information of the parsed character is matched with the character position information of the target document character. When the target document character and the character position information of the target document character are updated according to the matching result, the corresponding target document character can be matched according to the character position information of the parsed character, and the character position information of the matched target document character can be matched with the character position information of the parsed character, so as to update the character position information of the unmatched target document character, or in the case that there is no matching target document character, a new target document character is added according to the parsed character and its character position information.
[0073] In some possible implementations, in order to improve the matching effect between the parsed character and the target document character and to improve the updating accuracy of the target document character, the character position information of the parsed character is matched with the character position information of the target document character, and the target document character and the character position information of the target document character are updated according to the matching result, which may include: determining the matching position range between the parsed character and the target document character according to the character position information of the parsed character; determining whether there is a matching document character that matches the parsed character from the target document characters located within the matching position range; if there is a matching document character that matches the parsed character, when the character position information of the parsed character is inconsistent with the character position information of the matching document character, updating the character position information of the matching document character according to the character position information of the parsed character; if there is no matching document character that matches the parsed character, using the parsed character as a newly added target document character, and using the character position information of the parsed character as the character position information of the newly added target document character.
[0074] The matching position range between the parsed characters and the target document characters is a position area determined according to the character position information of the parsed characters where the target document characters can be matched. The matching position range is a relative position area in the PDF document.
[0075] It should be noted that the present application does not impose any restrictions on the shape of the range area of the matching position range. For example, the shape of the range area can be a rectangle or a circle, etc. Accordingly, when determining the matching position range of the parsed character and the target document character based on the character position information of the parsed character, the matching position range of the parsed character and the target document character can be determined based on the center coordinates of the parsed character and a preset range radius.
[0076] For example, according to the character position information of the parsed character, the center coordinates of the parsed character are determined to be (x c ,y c ), when the shape of the range area of the matching position range is a rectangle, based on the preset range short radius r a , long radius r b , the position information of the matching position range can be determined, such as the coordinates of the upper left corner of the matching position range (x c -r a / 2,y c +r b / 2), matches the lower right corner coordinate (x c +r a / 2,y c -r b / 2).
[0077] In actual applications, if the determined matching position range is too large, mismatching may occur, and if the determined matching position range is too small, the corresponding target document characters may not be matched. Therefore, based on the center coordinates of the parsed characters and the preset range radius, a reasonable and effective matching range can be determined to improve the matching effect.
[0078] Among them, whether the target document character is within the matching position range can be determined by judging whether the size of the intersection area between the target document character and the matching position range meets a preset intersection area threshold or by judging whether the center coordinates of the target document character are within the matching position range. The embodiments of the present application do not limit this.
[0079] The matching document character refers to a target document character whose character content matches the character content of the parsed character in the target document character. By performing similarity matching between the character content of the target document character and the character content of the parsed character, it is determined whether the target document character is a matching document character that matches the parsed character.
[0080] When the character position information of the matching document character is inconsistent with the resolved character, the character position information of the matching document character can be updated, or when the matching document character that matches the resolved character is not determined, the target document character and the character position information of the target document character are added based on the resolved character and the character position information of the resolved character.
[0081] In an embodiment of the present application, a corresponding chart class filling strategy is set for the layout area of the chart layout category, and the layout area of the chart layout category is filled according to the chart class filling strategy, thereby ensuring the accuracy of the text arrangement in the layout area of the filled chart layout category.
[0082] After filling all layout areas, the parsing result of the PDF document can be obtained. The parsing result of the PDF document includes all the filled layout areas, so that the text content corresponding to each layout area in the PDF document can be obtained in the parsing result, such as the title text content, paragraph text content, table text content, etc. of the PDF document. Since each layout area has corresponding area position information, the text content corresponding to different layout areas can be sorted according to the area position information of different layout areas, and the full text parsing content of the PDF document with coherent context can be obtained.
[0083] According to the PDF document parsing method of the embodiment of the present application, when parsing the PDF document, it not only extracts the document characters contained in the document and the character position information of the document characters, but also performs layout recognition on the document. It obtains the parsing result of the PDF document by determining the target document characters corresponding to the publication page area and filling the target document characters into the corresponding layout area. Since it makes full use of the document character information and layout area information of the document during parsing, the obtained parsing result can maintain contextual structure consistency with the original PDF document. In addition, the embodiment of the present application has corresponding filling strategies for different categories of layout areas. When filling document characters, character filling is performed according to the corresponding filling strategy, which ensures the internal text logic after filling, thereby achieving the overall contextual coherence of the parsing result on the basis of contextual structure consistency.
[0084] In addition, those skilled in the art may also make various modifications and variations to the method in this application:
[0085] In some possible implementations, when performing layout recognition on a PDF document, there may be a phenomenon of missing recognition. Therefore, in order to ensure the integrity of the text information of the PDF parsing result, non-target document characters that do not match any layout area can be found based on the extracted multiple document characters and layout areas, so as to generate a corresponding layout area for the non-target document characters and fill them. Accordingly, for any layout area, after determining the target document character corresponding to any layout area from multiple document characters based on the area position information of any layout area and the character position information of the document characters, the method further includes: determining the non-target document characters that do not correspond to any layout area among the multiple document characters contained in the PDF document; creating a target layout area corresponding to the non-target document characters in the layout recognition result of the PDF document based on the character position information of the non-target document characters, and filling the non-target document characters into the target layout area.
[0086] The non-target document characters refer to document characters whose character position information does not match the area position information of any layout area.
[0087] The target layout area refers to the layout area used to fill the non-target document characters. When creating the target layout area corresponding to the non-target document characters, the character position information of the non-target document characters can be directly used as the area position information of the target layout area of the non-target document characters, or the area size of the target layout area can be adjusted according to the character position information and the scaling ratio of the non-target document characters by setting the scaling ratio, and the embodiments of the present application do not limit this.
[0088] For example, for the document character "A", no corresponding layout area is found based on its character position information. Therefore, a corresponding target layout area can be created for the document character "A", and the character position information of the document character "A", such as the upper left corner coordinates and the lower right corner coordinates, can be used as the upper left corner coordinates and the lower right corner coordinates of the corresponding target layout area, thereby adding the created target layout area to the layout recognition result, so that the layout recognition result can include all layout areas. After the document characters are filled into the target layout area, the comprehensive document characters can be covered in the parsing result of the PDF document.
[0089] In an embodiment of the present application, a corresponding target layout area is created for non-target document characters that do not correspond to any layout area, thereby filling the non-document characters into the target layout area, thereby avoiding the phenomenon of missing characters in the parsing results caused by omissions in layout recognition, and improving the character information integrity of the PDF parsing results.
[0090] In some possible implementations, there may be an associated position relationship between different filled layout areas. Therefore, in order to improve the semantic coherence between the filled layout areas, different filled layout areas with associated position relationships can be associated based on the associated position relationship between the filled layout areas. Accordingly, after filling the target document characters corresponding to any layout area into any layout area, it also includes: for any filled layout area, according to the area position information of any filled layout area and the area position information of other layout areas, determining an associated layout area with an associated position relationship with any filled layout area from other layout areas; according to the associated position relationship between any filled layout area and the associated layout area, any filled layout area is associated with the associated layout area.
[0091] The associated position relationship refers to the possible intersecting position relationship or adjacent position relationship between different filled layout areas. For example, there are repeated areas between different filled layout areas, or the same text paragraph corresponds to multiple different filled layout areas, which affects the semantic coherence between different layout areas.
[0092] For any filled layout area, its associated layout area refers to a layout area in other layout areas (i.e., other filled layout areas other than the layout area) that has an associated positional relationship with the layout area, for example, a layout area that has an intersecting positional relationship with the layout area or an adjacent positional relationship with the layout area.
[0093] Among them, the association processing of any filled layout area and the associated layout area can determine the corresponding association processing strategy based on their associated position relationship. For example, the layout area and the associated layout area are deduplicated. For example, the layout area and the associated layout area are merged into a new layout area. The embodiments of the present application do not limit this.
[0094] Therefore, the embodiment of the present application determines, for any filled layout area, an associated layout area that has an associated positional relationship with it, thereby performing association processing on the layout area and the associated layout area, thereby improving the semantic coherence between the filled layout areas.
[0095] In some possible implementations, when the associated position relationship is an intersecting position relationship, any filled layout area and the associated layout area are associated according to the associated position relationship between the filled layout area and the associated layout area, including: determining the repeated area between any filled layout area and the associated layout area; when the repeated area exceeds a preset repeated threshold, detecting whether there are repeated document characters in the repeated area, and if so, deleting the repeated document characters in any filled layout area or the associated layout area.
[0096] Among them, when there is a repeated area between any filled layout area and the associated layout area, that is, when the regional position information of the two has an overlapping area range, it can be determined that there is an intersecting position relationship between them.
[0097] The preset repetition threshold is a threshold used to determine the degree of intersection between layout areas, which can be a preset repetition area size or a preset repetition area ratio. Accordingly, whether the repetition area exceeds the preset repetition threshold can be determined by determining whether the area size of the repetition area exceeds the preset repetition area size, or by determining whether the ratio of the repetition area exceeds the preset repetition area ratio, and the present application embodiment does not limit this.
[0098] When detecting whether there are repeated document characters in the repeated area, the document characters in the repeated area of the layout area and its associated layout area and the character position information of the document characters can be compared. When a certain document character and the character position information of the document character are the same in both, the document character is determined to be a repeated document character. Thus, by deleting the repeated document characters in the layout area or its associated layout area, deduplication processing of the filled layout area is achieved.
[0099] In an embodiment of the present application, repeated document characters are detected between layout areas having an intersecting positional relationship, and the detected repeated document characters are deduplicated, thereby avoiding the existence of repeated semantic content in the parsing results.
[0100] In some possible implementations, when the associated position relationship is an adjacent position relationship, any filled layout area and the associated layout area are associated based on the associated position relationship between them, including: determining the adjacent position difference between any filled layout area and the associated layout area based on the adjacent position relationship between them; and merging the area position information of any filled layout area and the associated layout area when the adjacent position difference is less than a preset adjacent threshold.
[0101] Among them, the adjacent position relationship between the filled layout area and the associated layout area can be a left-right adjacent position relationship or a top-bottom adjacent position relationship, and the embodiment of the present application does not limit this.
[0102] Among them, the adjacent position difference is used to describe the adjacent distance between the filled layout area and its associated layout area.
[0103] Among them, when determining the adjacent position difference between the filled layout area and its associated layout area based on the adjacent position relationship, the coordinate value to be compared can be determined from the area position information of the filled layout area and its associated layout area based on their adjacent position relationship, thereby obtaining the adjacent position difference based on the coordinates to be compared.
[0104] Exemplarily, for the upper and lower adjacent position relationship, if the filled layout area is located above its associated layout area, the adjacent position difference can be obtained by calculating the difference between the vertical axis coordinates of the filled layout area and its associated layout area, that is, the vertical coordinate of the lower boundary of the filled layout area and the vertical coordinate of the upper boundary of the associated layout area.
[0105] The preset adjacent threshold is a threshold used to determine the degree of adjacentness between the filled layout area and its associated layout area. If the adjacent position difference is less than the preset adjacent threshold, the filled layout area and its associated layout area can be merged, that is, the area position information of the two layout areas are merged so that the merged layout area can include the original layout area.
[0106] Reference Figure 2 , for the filled layout area A and its associated layout area B, the area position information of layout area A is (x i0 ,y i0 ,x i1 ,y i1 ), where (x i0 ,y i0 )、(x i1 ,y i1) are the coordinates of the upper left corner and the lower right corner of the layout area A. The area position information of the associated layout area B is (x i2 ,y i2 ,x i3 ,y i3 ), where (x i2 ,y i2 )、(x i3 ,y i3 ) are respectively the upper left corner coordinates and lower right corner coordinates of the associated layout area B.
[0107] When merging coordinate information, refer to the following formula to merge the regional position information of the layout area:
[0108] x new0 =min(x i0 ,x i2 ), y new0 = min(y i0 ,y i2 ), x new1 =max(x i1 ,x i3 ), y new1 = max(y i1 ,y i3 )
[0109] Among them, (x new0, y new0 ) is the coordinate of the upper left corner of the merged layout area, (x new1, y new1 ) is the lower right corner coordinate of the merged layout area. Therefore, the merged layout area C can cover the original filled layout area A and its associated layout area B.
[0110] In an embodiment of the present application, adjacent layout areas are merged. For example, the layout model may not recognize the corresponding layout area for certain lines with larger fonts. Therefore, after reconstructing the layout area for certain lines with larger fonts, the continuous upper and lower layout areas are merged to avoid line breaks in the parsing results and improve the semantic coherence of the parsing results.
[0111] For ease of understanding, the following uses an example to describe the technical implementation details in the above embodiment:
[0112] With the development of modern large model technology, the application of models in various fields has continued to deepen, and the requirements for large models have become higher and higher. Adding knowledge to the model has become an indispensable part of model application. In product scenarios such as document question answering and summary extraction, it is necessary to obtain model external knowledge from unstructured data such as PDF documents. However, the model input is all text data. Therefore, the parsing effect of parsing PDF documents into text data has greatly affected the effect of model generation.
[0113] In order to parse PDF documents, in a related technology, the first code, glyph bitmap, embedded information and font information of each text object in the PDF page are obtained to determine whether to extract text, improve the extraction accuracy, reduce the number of OCR times and improve efficiency. However, this technical solution can only recognize the text on the PDF page, and does not consider the order of the text, and cannot extract complete and reasonable text information.
[0114] In another related technology, PDF text extraction is performed by combining OCR technology. When extracting PDF data, it combines OCR technology to confirm the character content, process the second encoding of the character, and derive the result according to the character position, font and font size. At the same time, according to the position information of the character, it reconstructs according to the original layout to maintain the consistency of the position. However, in this technical solution, it uses the position information of the text to only maintain the consistency of the layout, and cannot make the parsed text have its language logic and maintain the contextual coherence of the text.
[0115] It can be seen that the above method can only extract text information from a PDF document, but cannot guarantee the logic and contextual coherence of the text in the parsing result. In order to solve the above problem, this example proposes a PDF document parsing method.
[0116] Figure 3 A schematic diagram showing a PDF document parsing method is shown, referring to Figure 3 , the method comprising:
[0117] Step S301: extract information from the PDF document to be parsed to obtain a plurality of document characters contained in the PDF document and character position information of each document character.
[0118] When extracting information from a PDF document, a combination of text extraction and OCR extraction can be used.
[0119] PDF-related tools can be used to read data information included in PDF documents, such as document characters, pictures, and other information. At the same time, PDF tools can also extract the character position information of document characters. For non-document object information included in PDF documents, such as picture information, the OCR model can be combined to extract document characters in picture information and character position information of document characters.
[0120] When a PDF document includes multiple PDF pages, the PDF document can be paged. For each PDF page, the document characters and the character position information of the document characters are extracted. Finally, the document characters and the character position information of the document characters extracted by OCR and the document characters and the character position information of the document characters extracted by the PDF tool are merged to obtain a context-coherent character array, wherein the character array contains each extracted document character and the character position information corresponding to the document character.
[0121] Step S302: performing layout recognition on the PDF document to determine at least two layout areas, a layout category of each layout area, and area position information of each layout area included in the layout recognition result of the PDF document.
[0122] Among them, the region position information and layout category of each layout area in the PDF document can be obtained through a preset layout recognition model.
[0123] Among them, the layout category of the layout area can be determined based on the layout elements contained in the area. For example, when the layout elements are header, footer, title, table, table title tab_caption, figure, chart, note and other categories, the layout category of the layout area can be header category, footer category, title category, table category, table title category and other categories.
[0124] Step S303: for any layout area, according to the area position information of any layout area and the character position information of the document character, determine the target document character corresponding to any layout area from a plurality of document characters.
[0125] Among them, for the extracted document characters, the center coordinates of the document characters can be calculated according to the character position information of the document characters. For example: the character position information of a document character is (x0, y0, x1, y1), where (x0, y0) is the upper left corner coordinate of the text bounding box of the document character, and (x1, y1) is the lower right corner coordinate of the text bounding box of the document character.
[0126] Thus, for the central coordinates (X0, Y0) of the document character, they can be calculated by: X0 = (x0 + x1) / 2, Y0 = (y0 + y1) / 2. By determining whether the central coordinates of the document character are within the regional position information of the layout area, a target document character corresponding to any layout area is determined from multiple document characters. That is, the regional position information of the layout area is: (bx0, by0, bx1, by1). If bx0 < X0 < bx1 and by0 < Y0 < by1 are satisfied, then the document character is the target document character corresponding to the layout area.
[0127] Step S304: Determine non-target document characters among the multiple document characters included in the PDF document that do not correspond to any layout area.
[0128] Step S305: According to the character position information of the non-target document characters, create a target layout area corresponding to the non-target document characters in the layout recognition result of the PDF document, and fill the non-target document characters into the target layout area.
[0129] Since the layout recognition model may have a situation where the layout area recognition is missing during layout recognition, therefore, for non-target document characters that do not correspond to the layout area, by creating a corresponding layout area for them and filling the document characters into the layout area, the missing text information in the layout area is complemented.
[0130] It should be noted that the execution time of steps S304 and S305 in the embodiments of the present application is only for illustrative purposes. For example, steps S304 and S305 can be executed after step S303 determines the target document characters corresponding to any layout area from multiple document characters, or steps S304 and S305 can be executed after step S306 fills the target document characters corresponding to any layout area into any layout area, so as to determine non-target document characters that do not correspond to any layout area, and construct a corresponding target layout area and fill the target layout area for the non-target document characters. The embodiments of the present application do not limit this.
[0131] Step S306: According to the filling strategy corresponding to the layout category of any layout area, fill the target document characters corresponding to any layout area into any layout area.
[0132] In some possible implementations, when the layout category of any layout area is a chart layout category, the target document characters corresponding to any layout area can be filled into any layout area according to the chart class filling strategy, including: obtaining a chart object corresponding to any layout area contained in the PDF document according to the area position information of any layout area; parsing the chart object according to a chart parsing model corresponding to the layout category of any layout area to obtain multiple parsed characters contained in the chart object and character position information of each parsed character; matching the character position information of the parsed characters with the character position information of the target document characters, and updating the target document characters and the character position information of the target document characters according to the matching results; and filling the updated target document characters corresponding to any layout area into any layout area according to the updated character position information of the target document characters.
[0133] Among them, for layout areas of other layout categories, such as layout areas of text layout categories, the target document characters can be directly filled into the corresponding positions of the layout areas according to the character position information of the target document characters, and the embodiments of the present application do not limit this.
[0134] Step S307: For any filled layout area, based on the area position information of any filled layout area and the area position information of other layout areas, determine an associated layout area having an associated position relationship with any filled layout area from other layout areas.
[0135] Step S308: according to the associated positional relationship between any filled layout area and the associated layout area, any filled layout area is associated with the associated layout area to obtain a parsing result of the PDF document.
[0136] The associated positional relationship refers to the intersecting positional relationship or adjacent positional relationship that may exist between different filled layout areas.
[0137] Among them, the association processing of any filled layout area and the associated layout area can determine the corresponding association processing strategy based on their associated position relationship.
[0138] For example, deduplication processing is performed on the layout area and the associated layout area, and it is calculated whether there is an intersecting position relationship such as inclusion or partial inclusion between the layout area and the associated layout area, so as to determine the repeated area between the layout area and the associated layout area, and according to the preset repetition threshold, deduplication processing is performed on the repeated document characters between the layout area and the associated layout area.
[0139] For another example, the layout area is merged with the associated layout area into a new layout area. In actual application, adjacent layout areas may be separated, resulting in semantic incoherence between the layout areas. Therefore, the coordinate difference between adjacent layout areas can be used, such as determining the adjacent position difference between the lower boundary ordinate and the upper boundary ordinate of the adjacent layout area, and based on a preset adjacent threshold value such as 2, when the adjacent position difference is less than the preset adjacent threshold value, the regional position information of any filled layout area and the associated layout area is merged.
[0140] In summary, this example makes full use of the document character information of the document, and by performing layout recognition on the document, makes full use of the layout area information in the document. Therefore, the parsing result obtained can maintain contextual structure consistency with the original PDF document, and this example has corresponding filling strategies for different categories of layout areas. When filling document characters, characters are filled according to the corresponding filling strategies, which ensures the logic of the text inside the filled layout area, thereby achieving the overall contextual coherence of the parsing result on the basis of contextual structure consistency.
[0141] It can be understood that the above-mentioned various method embodiments mentioned in this application can be combined with each other to form a combined embodiment without violating the principle logic. Due to space limitations, this application will not go into details. Those skilled in the art can understand that in the above-mentioned method of the specific implementation method, the specific execution order of each step should be determined by its function and possible internal logic.
[0142] In addition, the present application also provides a PDF document parsing device, an electronic device, and a computer-readable storage medium, all of which can be used to implement any PDF document parsing method provided by the present application. The corresponding technical solutions and descriptions are referred to in the corresponding records of the method part and will not be repeated here.
[0143] Figure 4 A block diagram of a PDF document parsing device provided in an embodiment of the present application.
[0144] Reference Figure 4 , an embodiment of the present application provides a PDF document parsing device, the PDF document parsing device comprising:
[0145] An extraction module 41 is used to extract information from the PDF document to be parsed, and obtain a plurality of document characters contained in the PDF document and character position information of each document character;
[0146] A first determination module 42 is used to perform layout recognition on the PDF document, and determine at least two layout areas, a layout category of each layout area, and area position information of each layout area included in the layout recognition result of the PDF document;
[0147] A second determination module 43 is used to determine, for any layout area, a target document character corresponding to any layout area from a plurality of document characters according to the area position information of any layout area and the character position information of the document character;
[0148] The filling module 44 is used to fill the target document characters corresponding to any layout area into any layout area according to the filling strategy corresponding to the layout category of any layout area, so as to obtain the parsing result of the PDF document.
[0149] In some possible implementations, the filling strategy includes: a chart class filling strategy corresponding to the chart layout category; then when the layout category of any layout area is the chart layout category, the filling module fills the target document characters corresponding to any layout area into the any layout area according to the chart class filling strategy, including: obtaining the chart object corresponding to the any layout area contained in the PDF document according to the area position information of the any layout area; parsing the chart object according to the chart parsing model corresponding to the layout category of the any layout area to obtain multiple parsed characters contained in the chart object and character position information of each parsed character; matching the character position information of the parsed characters with the character position information of the target document characters, and updating the target document characters and the character position information of the target document characters according to the matching results; filling the updated target document characters corresponding to any layout area into the any layout area according to the updated character position information of the target document characters.
[0150] In some possible implementations, matching the character position information of the parsed character with the character position information of the target document character, and updating the target document character and the character position information of the target document character according to the matching result, includes: determining a matching position range between the parsed character and the target document character according to the character position information of the parsed character; determining whether there is a matching document character that matches the parsed character from the target document characters within the matching position range; if there is a matching document character that matches the parsed character, updating the character position information of the matching document character according to the character position information of the parsed character when the character position information of the parsed character is inconsistent with the character position information of the matching document character; if there is no matching document character that matches the parsed character, using the parsed character as a newly added target document character, and using the character position information of the parsed character as the character position information of the newly added target document character.
[0151] In some possible implementations, after the second determination module determines, for any layout area, from the multiple document characters, the target document character corresponding to the any layout area based on the area position information of the any layout area and the character position information of the document character, the device is further used to: determine non-target document characters that do not correspond to any layout area among the multiple document characters contained in the PDF document; create a target layout area corresponding to the non-target document character in the layout recognition result of the PDF document based on the character position information of the non-target document character, and fill the non-target document character into the target layout area.
[0152] In some possible implementations, after the filling module fills the target document characters corresponding to any layout area into the any layout area, the device is also used to: for any filled layout area, determine from other layout areas an associated layout area that has an associated positional relationship with the any filled layout area based on the area position information of the any filled layout area and the area position information of other layout areas; and perform association processing on any filled layout area and the associated layout area based on the associated positional relationship between the any filled layout area and the associated layout area.
[0153] In some possible implementations, when the associated position relationship is an intersection position relationship, the any filled layout area and the associated layout area are associated based on the associated position relationship between the any filled layout area and the associated layout area, including: determining the repeated area between the any filled layout area and the associated layout area; when the repeated area exceeds a preset repeated threshold, detecting whether there are repeated document characters in the repeated area, and if so, deleting the repeated document characters in any filled layout area or the associated layout area.
[0154] In some possible implementations, when the associated position relationship is an adjacent position relationship, the associated processing is performed on any filled layout area and the associated layout area based on the associated position relationship between the any filled layout area and the associated layout area, including: determining the adjacent position difference between any filled layout area and the associated layout area based on the adjacent position relationship between the any filled layout area and the associated layout area; and merging the area position information of any filled layout area and the associated layout area when the adjacent position difference is less than a preset adjacent threshold.
[0155] Each module in the above-mentioned PDF document parsing device can be implemented in whole or in part by software, hardware or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0156] Figure 5 A block diagram of an electronic device provided in an embodiment of the present application.
[0157] Reference Figure 5 An embodiment of the present application provides an electronic device, which includes: at least one processor 501; at least one memory 502, and one or more I / O interfaces 503, connected between the processor 501 and the memory 502; wherein the memory 502 stores one or more computer programs that can be executed by the at least one processor 501, and the one or more computer programs are executed by the at least one processor 501, so that the at least one processor 501 can execute the above-mentioned PDF document parsing method.
[0158] Each module in the above electronic device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0159] The embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored, wherein the computer program implements the above-mentioned PDF document parsing method when executed by a processor / processing core. The computer-readable storage medium may be a volatile or non-volatile computer-readable storage medium.
[0160] An embodiment of the present application also provides a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the above-mentioned PDF document parsing method.
[0161] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In a hardware implementation, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable storage medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a transient medium).
[0162] As is known to those of ordinary skill in the art, the term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable program instructions, data structures, program modules or other data. Computer storage media include, but are not limited to, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), static random access memory (SRAM), flash memory or other memory technology, portable compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, as is known to those of ordinary skill in the art, communication media typically contain computer readable program instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
[0163] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0164] The computer program instructions for performing the operation of the present application may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed entirely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be personalized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present application.
[0165] The computer program product described herein may be implemented in hardware, software, or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK), etc.
[0166] Various aspects of the present application are described herein with reference to flowcharts and / or block diagrams of methods, devices (systems) and computer program products according to embodiments of the present application. It should be understood that each box in the flowchart and / or block diagram and the combination of boxes in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0167] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0168] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0169] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the logical function of the specification. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can also be executed in the opposite order sometimes, depending on the function involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be realized by a dedicated hardware-based system that performs the function or action of the specification, or can be realized by a combination of special-purpose hardware and computer instructions.
[0170] Example embodiments have been disclosed herein, and although specific terms are employed, they are used and should be interpreted only in a general illustrative sense and not for limiting purposes. In some instances, it will be apparent to those skilled in the art that, unless otherwise expressly noted, features, characteristics, and / or elements described in conjunction with a particular embodiment may be used alone or in combination with features, characteristics, and / or elements described in conjunction with other embodiments. Therefore, those skilled in the art will appreciate that various changes in form and detail may be made without departing from the scope of the present application as set forth in the appended claims.
Claims
1. A PDF document parsing method, characterized in that: The method comprises: Extracting information from the PDF document to be parsed to obtain multiple document characters contained in the PDF document and character position information of each document character; Performing layout recognition on the PDF document, determining at least two layout areas, a layout category of each layout area, and area position information of each layout area included in the layout recognition result of the PDF document; For any layout area, according to the area position information of the any layout area and the character position information of the document character, determine the target document character corresponding to the any layout area from the plurality of document characters; According to the filling strategy corresponding to the layout category of any layout area, fill the target document characters corresponding to any layout area into any layout area to obtain the parsing result of the PDF document; The filling strategy is used to characterize the filling position, filling order, and / or preprocessing method of the target document characters in the layout area of the corresponding layout category; Wherein, the filling strategy includes: a chart type filling strategy corresponding to the chart layout category; Then, when the layout category of any layout area is the chart layout category, filling the target document characters corresponding to any layout area into any layout area according to the chart type filling strategy includes: According to the area position information of any one of the layout areas, obtaining a chart object corresponding to any one of the layout areas contained in the PDF document; Parsing the chart object according to the chart parsing model corresponding to the layout category of any layout area to obtain a plurality of parsed characters contained in the chart object and character position information of each parsed character; Matching the character position information of the parsed character with the character position information of the target document character, and updating the target document character and the character position information of the target document character according to the matching result; According to the updated character position information of the target document characters, the updated target document characters corresponding to any one of the layout areas are filled into the any one of the layout areas.
2. The method according to claim 1, characterized in that: The step of matching the character position information of the parsed character with the character position information of the target document character, and updating the target document character and the character position information of the target document character according to the matching result, comprises: Determining a matching position range between the parsed character and the target document character according to the character position information of the parsed character; Determining whether there is a matching document character that matches the parsed character from among the target document characters within the matching position range; If there is a matching document character that matches the parsed character, in the case where the character position information of the parsed character is inconsistent with the character position information of the matching document character, updating the character position information of the matching document character according to the character position information of the parsed character; If there is no matching document character matching the parsed character, the parsed character is used as a newly added target document character, and the character position information of the parsed character is used as the character position information of the newly added target document character.
3. The method according to claim 1, characterized in that After determining, for any layout area, the target document character corresponding to any layout area from the plurality of document characters according to the area position information of the any layout area and the character position information of the document character, the method further comprises: Determine a non-target document character that does not correspond to any layout area among a plurality of document characters included in the PDF document; According to the character position information of the non-target document characters, a target layout area corresponding to the non-target document characters is created in the layout recognition result of the PDF document, and the non-target document characters are filled into the target layout area.
4. The method according to claim 1, characterized in that: After filling the target document characters corresponding to any layout area into any layout area, the method further includes: For any filled layout area, according to the area position information of the any filled layout area and the area position information of other layout areas, determining an associated layout area having an associated position relationship with the any filled layout area from other layout areas; According to the associated positional relationship between any of the filled layout areas and the associated layout areas, an association process is performed on any of the filled layout areas and the associated layout areas.
5. The method according to claim 4, characterized in that In the case where the associated positional relationship is an intersection positional relationship, the associating process of any filled layout area with the associated layout area according to the associated positional relationship between any filled layout area and the associated layout area includes: Determine an overlapping area between any of the filled layout areas and the associated layout area; In the case where the repeated area exceeds a preset repetition threshold, it is detected whether there are repeated document characters in the repeated area, and if so, the repeated document characters are deleted in any of the filled layout areas or the associated layout areas.
6. The method according to claim 4, characterized in that In the case where the associated positional relationship is an adjacent positional relationship, the associating process of any filled layout area with the associated layout area according to the associated positional relationship between any filled layout area and the associated layout area includes: Determine the adjacent position difference between any filled layout area and the associated layout area according to the adjacent position relationship between any filled layout area and the associated layout area; When the adjacent position difference is less than a preset adjacent threshold, the area position information of any filled layout area is merged with the area position information of the associated layout area.
7. A PDF document parsing device, characterized in that: The device comprises: An extraction module is used to extract information from the PDF document to be parsed, and obtain a plurality of document characters contained in the PDF document and character position information of each document character; A first determination module is used to perform layout recognition on the PDF document, and determine at least two layout areas, a layout category of each layout area, and area position information of each layout area included in the layout recognition result of the PDF document; A second determination module is used to determine, for any layout area, a target document character corresponding to the any layout area from the plurality of document characters according to the area position information of the any layout area and the character position information of the document character; A filling module, used for filling the target document characters corresponding to any layout area into any layout area according to the filling strategy corresponding to the layout category of any layout area, so as to obtain the parsing result of the PDF document; The filling strategy is used to characterize the filling position, filling order, and / or preprocessing method of the target document characters in the layout area of the corresponding layout category; Wherein, the filling strategy includes: a chart type filling strategy corresponding to the chart layout category; Then, when the layout category of any layout area is the chart layout category, filling the target document characters corresponding to any layout area into any layout area according to the chart type filling strategy includes: According to the area position information of any one of the layout areas, obtaining a chart object corresponding to any one of the layout areas contained in the PDF document; Parsing the chart object according to the chart parsing model corresponding to the layout category of any layout area to obtain a plurality of parsed characters contained in the chart object and character position information of each parsed character; Matching the character position information of the parsed character with the character position information of the target document character, and updating the target document character and the character position information of the target document character according to the matching result; According to the updated character position information of the target document characters, the updated target document characters corresponding to any one of the layout areas are filled into the any one of the layout areas.
8. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores one or more computer programs executable by the at least one processor, and the one or more computer programs are executed by the at least one processor so that the at least one processor can execute the PDF document parsing method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the computer program implements the PDF document parsing method according to any one of claims 1 to 6.
