Paragraph identification method and device based on PDF file and related medium

By extracting text objects in PDF files, judging the baseline information gap and passing it into the prediction model, the problem of the accuracy dependence position of paragraph identification in the existing technology is solved, and the work efficiency and recognition accuracy of developers are improved.

CN119250057APending Publication Date: 2025-01-03SHENZHEN JINNIU TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411316950.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-20
Publication Date
2025-01-03

AI Technical Summary

Technical Problem

When the existing PDF editor divides paragraphs based on traditional condition recognition methods, the logical thinking requirements are high and the recognition accuracy depends on the paragraph position, resulting in a decrease in recognition effect during chaotic arrangements, which affects the work efficiency of developers.

Method used

By loading PDF files, extracting text objects and storing them in sequence, judging the baseline information gap, combining them into row objects, calculating basic parameters, and passing them into prediction models for paragraph recognition, improving recognition accuracy and efficiency.

Benefits of technology

Improves the work efficiency of developers, enhances the accuracy and consistency of paragraph recognition, and reduces the possibility of misclassification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119250057A_ABST
    Figure CN119250057A_ABST
Patent Text Reader

Abstract

The invention discloses a paragraph recognition method and device based on a PDF file and a related medium. The method comprises the steps that all character objects are extracted from the PDF file and stored in a character container in sequence; traversing the character object of the character container to obtain baseline information; judging whether the difference between the current baseline information and the previous baseline information meets a combination condition or not, and if yes, judging that the baseline information is in the same row; combining the character objects in the same row into row objects and storing the row objects in a row container; traversing basic parameters of a row object of the row container; calculating a combined parameter according to the basic parameter, and transmitting the row object, the basic parameter and the combined parameter into a prediction model for prediction to obtain a paragraph; and traversing character positions in the paragraphs and splicing to obtain paragraph positions. According to the method, the obtained line object, the basic parameters and the combined parameters are transmitted into the prediction model for prediction to obtain the paragraph, and then the character positions in the paragraph are spliced to obtain the final paragraph position, so that the working efficiency of developers is greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of file processing, and in particular to a paragraph recognition method and device based on PDF files and related media. Background Art

[0002] At present, most PDF editors on the market use traditional conditional recognition methods (such as if...else...) to divide paragraphs in PDF files. This conditional recognition-based paragraph division technology requires high logical thinking ability of developers, and its recognition effect depends on the position of paragraphs in the file. When the arrangement of paragraphs is chaotic, the recognition accuracy of this technology will be greatly reduced, and it is easy to make wrong divisions, which will affect the work efficiency of developers. Therefore, a new paragraph recognition solution is urgently needed to improve the work efficiency of developers. Summary of the invention

[0003] The embodiments of the present invention provide a paragraph recognition method, a device and related media based on a PDF file, aiming to solve the problem of low work efficiency of developers in recognizing paragraphs in a file in the prior art.

[0004] In a first aspect, an embodiment of the present invention provides a paragraph recognition method based on a PDF file, comprising:

[0005] Loading a PDF file, extracting all text objects from the PDF file, and storing the text objects in a text container in order;

[0006] Traversing the text objects in the text container to obtain baseline information corresponding to all the text objects;

[0007] Determine whether the difference between the baseline information of the current text object and the baseline information of the previous text object meets the combination condition, and if so, determine that they are in the same row;

[0008] Combining the text objects in the same row into a row object, and storing the row object in a row container until all the text objects are judged;

[0009] Traversing the row objects in the row container to obtain basic parameters corresponding to all the row objects;

[0010] Calculate the combined parameters according to the basic parameters, and pass the row object, basic parameters and combined parameters into the trained prediction model for prediction to obtain a paragraph;

[0011] The text positions of the text objects in the paragraph are traversed and concatenated to obtain corresponding paragraph positions.

[0012] In a second aspect, an embodiment of the present invention provides a paragraph recognition device based on a PDF file, comprising:

[0013] A data reading unit, used for loading a PDF file, extracting all text objects from the PDF file, and storing the text objects in a text container in sequence;

[0014] A text traversal unit, used for traversing the text objects in the text container to obtain baseline information corresponding to all the text objects;

[0015] A data judgment unit, used to judge whether the difference between the baseline information of the current text object and the baseline information of the previous text object meets the combination condition, and if so, judge them as the same line;

[0016] A text merging unit, used for combining the text objects in the same line into a line object, and storing the line object in a line container until all the text objects are judged;

[0017] A row number traversal unit, used for traversing the row objects in the row container to obtain basic parameters corresponding to all the row objects;

[0018] A data prediction unit, configured to calculate a combined parameter based on the basic parameter, and pass the row object, the basic parameter and the combined parameter into a trained prediction model for prediction to obtain a paragraph;

[0019] The paragraph output unit is used to traverse the text positions of the text objects in the paragraph and perform splicing to obtain the corresponding paragraph positions.

[0020] In a third aspect, an embodiment of the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the PDF file-based paragraph recognition method of the first aspect when executing the computer program.

[0021] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the paragraph recognition method based on PDF files of the first aspect is implemented.

[0022] The embodiment of the present invention provides a paragraph recognition method based on PDF files, including extracting all text objects from PDF files and storing them in order into a text container; traversing the text objects in the text container to obtain baseline information; judging whether the gap between the current baseline information and the previous baseline information meets the combination condition, if so, determining that they are the same line; combining the text objects in the same line into a line object and storing them in a line container; traversing the basic parameters of the line objects in the line container; calculating the combination parameters based on the basic parameters, and passing the line objects, basic parameters and combination parameters into a prediction model to predict and obtain a paragraph; traversing the text positions in the paragraph and splicing them to obtain the paragraph position. The present invention passes the acquired line objects, basic parameters and combination parameters into the prediction model for prediction to obtain a paragraph, and then splices the text positions in the paragraph to obtain the final paragraph position, thus greatly improving the work efficiency of developers.

[0023] The embodiment of the present invention also provides a paragraph recognition device, a computer device and a storage medium based on a PDF file, which also have the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.

[0025] Figure 1 A schematic diagram of a flow chart of a paragraph recognition method based on a PDF file provided by an embodiment of the present invention;

[0026] Figure 2 A schematic block diagram of a paragraph recognition device based on a PDF file provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0027] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0028] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.

[0029] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0030] It should be further understood that the term "and / or" used in the present description and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0031] See below Figure 1 , Figure 1 A schematic flow chart of a paragraph recognition method based on a PDF file provided by an embodiment of the present invention specifically includes steps S101 to S107.

[0032] S101, loading a PDF file, extracting all text objects from the PDF file, and storing the text objects in a text container in order;

[0033] S102, traversing the text objects in the text container to obtain baseline information corresponding to all the text objects;

[0034] S103, determining whether the difference between the baseline information of the current text object and the baseline information of the previous text object meets the combination condition, and if so, determining that they are in the same row;

[0035] S104, combining the text objects in the same row into a row object, and storing the row object in a row container until all the text objects are judged;

[0036] S105, traversing the row objects in the row container to obtain basic parameters corresponding to all the row objects;

[0037] S106, calculating a combined parameter according to the basic parameter, and passing the row object, the basic parameter and the combined parameter into a trained prediction model for prediction to obtain a paragraph;

[0038] S107, traversing the text positions of the text objects in the paragraph and concatenating them to obtain corresponding paragraph positions.

[0039] In step S101, a PDF file is loaded and parsed using a PDF parsing library (such as PDFium). During the parsing process, each page of the PDF file is traversed, and all text objects are extracted from each page by calling the API provided by the PDF parsing library. Subsequently, the extracted text objects are stored in the text container in sequence according to their order in the page, ensuring that the order of each text object is consistent with its actual arrangement order in the PDF page. In this way, basic data can be provided for subsequent line recognition and paragraph recognition.

[0040] In one embodiment, the step S101 includes:

[0041] Load the PDF file using the PDFium library;

[0042] Traverse each page of the PDF file, and call the API interface in the PDFium library to parse all the text objects in each page;

[0043] All the text objects on each page of the PDF file are stored in the text container.

[0044] In this embodiment, the PDF file is loaded using the PDF parsing library PDFium, and the PDF file is processed page by page. Specifically, each page in the PDF file is traversed, the API interface provided in the PDFium library is called, and the content of each page is parsed to extract all the text objects in the page. After the parsing is completed, all the text objects extracted from each page are stored in the text container according to their order in the page. By storing the text objects of each page in sequence, it is ensured that the arrangement order of the text objects in the container is consistent with their original arrangement in the PDF file, which lays a data foundation for subsequent line recognition and paragraph recognition.

[0045] In step S102, the baseline information of each text object is extracted by calling the API interface provided by the PDF parsing library (such as PDFium). The baseline information is the position information of the text object in the PDF page, which is usually used to determine the vertical position of the text object. During the traversal process, the baseline information of each text object is obtained one by one, and the baseline information is saved for subsequent line recognition and paragraph division operations. This step allows the baseline information of all text objects to be extracted, providing position information for further text processing.

[0046] In step S103, after obtaining the baseline information of each text object, the baseline information of the current text object is first compared with the baseline information of the previous text object. Specifically, the difference between the baseline information of the two text objects is calculated to determine whether the difference meets the preset combination condition. The combination condition may include whether the absolute value of the baseline difference is less than or equal to a predetermined threshold. For example, when the absolute value of the baseline difference is less than or equal to 1, it is considered that the current text object and the previous text object are in the same row. If the above conditions are met, the current text object and the previous text object are determined to belong to the same row, and they are combined into a row object and saved in a row container.

[0047] In one embodiment, the step S103 includes:

[0048] Calculate the difference between the baseline information of the current text object and the baseline information of the previous text object to obtain a difference value;

[0049] It is determined whether the absolute value of the difference value is less than or equal to a preset value. If so, it is determined that the current text object and the previous text object are in the same row; if not, it is determined that the current text object and the previous text object are not in the same row.

[0050] In this embodiment, the baseline information of the current text object and the previous text object is obtained, and the difference value between the two is calculated. The difference value is obtained based on the difference in the baseline information of the two. Then, it is determined whether the absolute value of the difference value is less than or equal to the preset value. The preset value is used to define the threshold of the baseline difference, which is usually a small range of values ​​(such as 1) to ensure that text objects with similar baseline heights are judged to be in the same row. If the absolute value of the difference value is less than or equal to the preset value, it is determined that the current text object is in the same row as the previous text object, and they are combined into a row object; if the absolute value of the difference value is greater than the preset value, it is determined that the current text object is not in the same row as the previous text object. Through this judgment mechanism, the accuracy and consistency of text object row division are achieved.

[0051] In step S104, when it is determined that multiple text objects belong to the same line, these text objects are combined into a line object, and all text objects in the same line are combined according to their order in the PDF page to generate a corresponding line object. Then, the generated line object is stored in the line container. This operation continues until all text objects are traversed and determined, and all line objects are stored in the line container in sequence.

[0052] In one embodiment, the step S104 includes:

[0053] Combining the text objects in the same row into the row object;

[0054] Sorting all the baseline information from large to small according to the baseline values ​​to obtain an arrangement order;

[0055] The row objects are sorted from high to low according to the arrangement order until all the text objects are judged.

[0056] In this embodiment, the text objects that are determined to be in the same row are combined into one row object. Subsequently, the baseline information of these row objects is processed and sorted according to the size of the baseline value. The sorting rule is: the larger the baseline value, the higher the row position, and the smaller the baseline value, the lower the row position. Therefore, the baseline information of all row objects is arranged in order from large to small to obtain the arrangement order of each row object. According to this arrangement order, all row objects are stored in the row container from high to low. This process continues until all text objects are judged and processed, ensuring that all row objects are correctly arranged according to the actual order in the page.

[0057] In step S105, the basic parameters include but are not limited to baseline information, line position, page width and height, type of the last character in the line, and page rotation angle, etc. Through the traversal operation, these basic parameters of each line object are obtained one by one and saved. These basic parameters will be used as input data for subsequent paragraph recognition and decision tree algorithm training.

[0058] In one embodiment, the step S105 includes:

[0059] Traverse the row objects in the row container, and use the PDFium library to extract the row information corresponding to the row objects, and use the row information as the basic parameter; wherein the row information includes the baseline, page width, page height, row position, the type of the last character, and the rotation angle of the page.

[0060] In this embodiment, by calling the API interface provided by the PDFium library, the relevant line information is obtained from each line object, and the line information is stored as basic parameters. The line information includes but is not limited to: the baseline of the line object, the page width, the page height, the position of the line, the type of the last character in the line, and the rotation angle of the page. By obtaining these basic parameters, accurate input data can be provided for subsequent paragraph recognition and decision tree training.

[0061] In step S106, the row object, basic parameters and combined parameters are input into the trained prediction model. The trained prediction model performs paragraph prediction for each row object based on the input basic parameters and combined parameters. Finally, the model outputs the paragraph to which each row object belongs, and the paragraph division is completed. In this way, paragraph division based on row information is achieved, and the accuracy and efficiency of paragraph recognition are improved.

[0062] Furthermore, for the trained prediction model, the training process is as follows:

[0063] The row objects in the row container are taken as the sample set, and then the sample set is manually marked (marking which rows are considered to be the same segment), and the collected basic parameters and combined parameters are passed into the decision tree algorithm to train the generated model (the input of the model is the row and the output is the segment). Usually, the ratio of the training set to the validation set of the sample set is 8:2.

[0064] In one embodiment, the step S106 includes:

[0065] Subtract the row position of the current row from the row position of the previous row and the row position of the current row from the row position of the next row to obtain the position offset of the previous row and the position offset of the next row respectively;

[0066] Get the type of the last character of the previous line and the type of the last character of the next line;

[0067] The position offset of the previous line, the position offset of the next line, the type of the last character of the previous line, and the type of the last character of the next line are used as the combination parameters.

[0068] In this embodiment, the position offset of the previous row is obtained by subtracting the row position of the current row from the row position of the previous row; then, the position offset of the next row is obtained by subtracting the row position of the current row from the row position of the next row. By calculating these two position offsets, the position change between the current row and the adjacent row can be reflected. Next, the type of the last character of the previous row and the type of the last character of the next row are obtained. The character type may include letters, numbers, punctuation marks, etc., which are used to assist in determining the relevance between rows. Finally, the position offset of the previous row, the position offset of the next row, the type of the last character of the previous row, and the type of the last character of the next row are used as combination parameters. These combination parameters are used together with the basic parameters as the input of the subsequent paragraph prediction model to improve the accuracy of paragraph division.

[0069] In step S107, each text object in the divided paragraph is traversed to extract the position information of each text object. Specifically, the rectangular boundary of each text object is obtained, including the coordinate values ​​of its left, right, top and bottom boundaries. Then, the position information of all text objects in the paragraph is sequentially spliced ​​and compared, and the overall position range of the entire paragraph is finally determined to obtain the accurate position information of the paragraph.

[0070] In one embodiment, the step S107 includes:

[0071] Respectively obtain the segment range of the current text object and the segment range of the next text object;

[0072] Compare the coordinates of the segment range of the next text object with the segment range of the current text object;

[0073] If the left and lower boundary coordinates of the segment range of the next text object are smaller than the left and lower boundary coordinates of the segment range of the current text object, then the left and lower boundary coordinates of the segment range of the current text object are updated to the left and lower boundary coordinates of the segment range of the next text object;

[0074] and / or, if the right and upper boundary coordinates of the segment range of the next text object are greater than the right and upper boundary coordinates of the segment range of the current text object, then the right and upper boundary coordinates of the segment range of the current text object are updated to the right and upper boundary coordinates of the segment range of the next text object;

[0075] The updated segment range of the next text object is used as the new segment range of the current text object, and is continuously compared with the new segment range of the next text object until all the text objects are traversed.

[0076] In this embodiment, the segment ranges of the current text object and the next text object are obtained respectively. The segment range includes the coordinate values ​​of the left boundary, right boundary, upper boundary and lower boundary of the text object. Then, the segment range of the next text object is compared with the segment range of the current text object in terms of coordinate size. Specifically, if the left boundary coordinate or the lower boundary coordinate of the segment range of the next text object is smaller than the left boundary coordinate or the lower boundary coordinate of the current text object, the left boundary and the lower boundary coordinate of the segment range of the current text object are updated to the left boundary and the lower boundary coordinate of the next text object. Similarly, if the right boundary coordinate or the upper boundary coordinate of the segment range of the next text object is larger than the right boundary coordinate or the upper boundary coordinate of the current text object, the right boundary and the upper boundary coordinate of the segment range of the current text object are updated to the right boundary and the upper boundary coordinate of the next text object. The updated segment range of the next text object is used as the new segment range of the current text object, and is continuously compared with the segment range of the new next text object. This cycle is repeated until all text objects are traversed, and the position information of all text objects in the paragraph is sequentially spliced ​​and compared, thereby determining the complete position range of the entire paragraph.

[0077] Combination Figure 2 As shown, Figure 2 A schematic block diagram of a paragraph recognition device based on a PDF file provided by an embodiment of the present invention, the paragraph recognition device 200 based on a PDF file includes:

[0078] The data reading unit 201 is used to load a PDF file, extract all text objects from the PDF file, and store the text objects in a text container in sequence;

[0079] A text traversal unit 202 is used to traverse the text objects in the text container to obtain baseline information corresponding to all the text objects;

[0080] The data judging unit 203 is used to judge whether the difference between the baseline information of the current text object and the baseline information of the previous text object meets the combination condition, and if so, it is judged that they are in the same row;

[0081] A text merging unit 204 is used to combine the text objects in the same row into a row object and store the row object in a row container until all the text objects are judged;

[0082] A row number traversal unit 205 is used to traverse the row objects in the row container to obtain basic parameters corresponding to all the row objects;

[0083] A data prediction unit 206 is used to calculate a combined parameter according to the basic parameter, and pass the row object, the basic parameter and the combined parameter into a trained prediction model for prediction to obtain a paragraph;

[0084] The paragraph output unit 207 is used to traverse the text positions of the text objects in the paragraph and perform splicing to obtain the corresponding paragraph positions.

[0085] In this embodiment, the data reading unit 201 loads a PDF file, extracts all text objects from the PDF file, and stores the text objects in order into a text container; the text traversal unit 202 traverses the text objects in the text container to obtain baseline information corresponding to all the text objects; the data judgment unit 203 judges whether the difference between the baseline information of the current text object and the baseline information of the previous text object meets the combination condition, and if so, it is determined to be the same line; the text merging unit 204 combines the text objects in the same line into line objects, and stores the line objects into a line container until all the text objects are judged; the line number traversal unit 205 traverses the line objects in the line container to obtain basic parameters corresponding to all the line objects; the data prediction unit 206 calculates the combination parameters based on the basic parameters, and passes the line objects, basic parameters and combination parameters into the trained prediction model for prediction to obtain paragraphs; the paragraph output unit 207 traverses the text positions of the text objects in the paragraph and splices them to obtain the corresponding paragraph positions.

[0086] In one embodiment, the data reading unit 201 includes:

[0087] A file loading unit, used for loading the PDF file using a PDFium library;

[0088] Calling a parsing unit to traverse each page in the PDF file and calling an API interface in the PDFium library to parse all the text objects in each page;

[0089] The text storage unit is used to store all the text objects of each page in the PDF file into the text container.

[0090] In one embodiment, the data determination unit 203 includes:

[0091] A gap calculation unit, used for calculating the gap between the baseline information of the current text object and the baseline information of the previous text object to obtain a gap value;

[0092] The gap judgment unit is used to judge whether the absolute value of the gap value is less than or equal to a preset value. If so, it is determined that the current text object and the previous text object are in the same row; if not, it is determined that the current text object and the previous text object are not in the same row.

[0093] In one embodiment, the text merging unit 204 includes:

[0094] An object combining unit, used for combining the text objects in the same row into the row object;

[0095] A baseline sorting unit, used to sort all the baseline information from large to small according to the baseline value to obtain an arrangement order;

[0096] A height sorting unit is used to sort the row objects from high to low according to the arrangement order until all the text objects are judged.

[0097] In one embodiment, the row number traversal unit 205 includes:

[0098] The basic parameter unit is used to traverse the row objects in the row container, and use the PDFium library to extract the row information corresponding to the row objects, and use the row information as the basic parameter; wherein the row information includes the baseline, page width, page height, row position, the type of the last character, and the rotation angle of the page.

[0099] In one embodiment, the data prediction unit 206 includes:

[0100] A difference calculation unit, used to perform difference calculations between the row position of the current row and the row position of the previous row, and between the row position of the current row and the row position of the next row, respectively, to obtain a position offset of the previous row and a position offset of the next row;

[0101] A character acquisition unit, used to acquire the type of the last character of the previous line and the type of the last character of the next line;

[0102] The offset calculation unit is used to use the position offset of the previous line, the position offset of the next line, the type of the last character of the previous line, and the type of the last character of the next line as the combination parameter.

[0103] In one embodiment, the paragraph output unit 207 includes:

[0104] A paragraph range unit, used to obtain the paragraph range of the current text object and the paragraph range of the next text object respectively;

[0105] A coordinate comparison unit, used for comparing the coordinate size of the segment range of the next text object with the segment range of the current text object;

[0106] The first judgment unit is used for updating the left and lower boundary coordinates of the segment range of the current text object to the left and lower boundary coordinates of the segment range of the next text object if the left and lower boundary coordinates of the segment range of the next text object are smaller than the left and lower boundary coordinates of the segment range of the current text object;

[0107] A second judgment unit is used for and / or, if the right and upper boundary coordinates of the segment range of the next text object are greater than the right and upper boundary coordinates of the segment range of the current text object, updating the right and upper boundary coordinates of the segment range of the current text object to the right and upper boundary coordinates of the segment range of the next text object;

[0108] The coordinate updating unit is used to use the updated segment range of the next text object as the new segment range of the current text object, and continue to compare with the new segment range of the next text object until all the text objects are traversed.

[0109] Since the embodiments of the apparatus part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the apparatus part, which will not be repeated here.

[0110] The embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed, the steps provided in the above embodiment can be implemented. The storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.

[0111] The embodiment of the present invention also provides a computer device, which may include a memory and a processor, wherein a computer program is stored in the memory, and when the processor calls the computer program in the memory, the steps provided in the above embodiment may be implemented. Of course, the computer device may also include various network interfaces, power supplies and other components.

[0112] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referred to each other. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of this application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of this application.

[0113] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprises", "comprising" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.

Claims

1. A paragraph recognition method based on PDF files, characterized in that: include: Loading a PDF file, extracting all text objects from the PDF file, and storing the text objects in a text container in order; Traversing the text objects in the text container to obtain baseline information corresponding to all the text objects; Determine whether the difference between the baseline information of the current text object and the baseline information of the previous text object meets the combination condition, and if so, determine that they are in the same row; Combining the text objects in the same row into a row object, and storing the row object in a row container until all the text objects are judged; Traversing the row objects in the row container to obtain basic parameters corresponding to all the row objects; Calculate the combined parameters according to the basic parameters, and pass the row object, basic parameters and combined parameters into the trained prediction model for prediction to obtain a paragraph; The text positions of the text objects in the paragraph are traversed and concatenated to obtain corresponding paragraph positions.

2. The paragraph recognition method based on PDF file according to claim 1, characterized in that: The step of loading a PDF file, extracting all text objects from the PDF file, and storing the text objects in order into a text container includes: Load the PDF file using the PDFium library; Traverse each page of the PDF file, and call the API interface in the PDFium library to parse all the text objects in each page; All the text objects on each page of the PDF file are stored in the text container.

3. The paragraph recognition method based on PDF file according to claim 1, characterized in that: The determining whether the difference between the baseline information of the current text object and the baseline information of the previous text object meets the combination condition, and if so, determining that they are in the same row, includes: Calculate the difference between the baseline information of the current text object and the baseline information of the previous text object to obtain a difference value; It is determined whether the absolute value of the difference value is less than or equal to a preset value. If so, it is determined that the current text object and the previous text object are in the same row; if not, it is determined that the current text object and the previous text object are not in the same row.

4. The paragraph recognition method based on PDF file according to claim 1, characterized in that: The step of combining the text objects in the same row into a row object and storing the row object in a row container until all the text objects are judged includes: Combining the text objects in the same row into the row object; Sorting all the baseline information from large to small according to the baseline values ​​to obtain an arrangement order; The row objects are sorted from high to low according to the arrangement order until all the text objects are judged.

5. The paragraph recognition method based on PDF file according to claim 1, characterized in that: The traversing the row objects in the row container to obtain basic parameters corresponding to all the row objects includes: Traverse the row objects in the row container, and use the PDFium library to extract the row information corresponding to the row objects, and use the row information as the basic parameter; wherein the row information includes the baseline, page width, page height, row position, the type of the last character, and the rotation angle of the page.

6. The paragraph recognition method based on PDF file according to claim 5, characterized in that: The step of calculating the combined parameters according to the basic parameters includes: Subtract the row position of the current row from the row position of the previous row and the row position of the current row from the row position of the next row to obtain the position offset of the previous row and the position offset of the next row respectively; Get the type of the last character of the previous line and the type of the last character of the next line; The position offset of the previous line, the position offset of the next line, the type of the last character of the previous line, and the type of the last character of the next line are used as the combination parameters.

7. The paragraph recognition method based on PDF file according to claim 1, characterized in that: The traversing the text positions of the text objects in the paragraph and splicing them to obtain the corresponding paragraph positions includes: Respectively obtain the segment range of the current text object and the segment range of the next text object; Compare the coordinates of the segment range of the next text object with the segment range of the current text object; If the left and lower boundary coordinates of the segment range of the next text object are smaller than the left and lower boundary coordinates of the segment range of the current text object, then the left and lower boundary coordinates of the segment range of the current text object are updated to the left and lower boundary coordinates of the segment range of the next text object; and / or, if the right and upper boundary coordinates of the segment range of the next text object are greater than the right and upper boundary coordinates of the segment range of the current text object, then the right and upper boundary coordinates of the segment range of the current text object are updated to the right and upper boundary coordinates of the segment range of the next text object; The updated segment range of the next text object is used as the new segment range of the current text object, and is continuously compared with the new segment range of the next text object until all the text objects are traversed.

8. A paragraph recognition device based on PDF files, characterized in that: include: A data reading unit, used for loading a PDF file, extracting all text objects from the PDF file, and storing the text objects in a text container in sequence; A text traversal unit, used for traversing the text objects in the text container to obtain baseline information corresponding to all the text objects; A data judgment unit, used to judge whether the difference between the baseline information of the current text object and the baseline information of the previous text object meets the combination condition, and if so, judge them as the same line; A text merging unit, used for combining the text objects in the same line into a line object, and storing the line object in a line container until all the text objects are judged; A row number traversal unit, used for traversing the row objects in the row container to obtain basic parameters corresponding to all the row objects; A data prediction unit, configured to calculate a combined parameter based on the basic parameter, and pass the row object, the basic parameter and the combined parameter into a trained prediction model for prediction to obtain a paragraph; The paragraph output unit is used to traverse the text positions of the text objects in the paragraph and perform splicing to obtain the corresponding paragraph positions.

9. A computer device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the paragraph recognition method based on a PDF file as claimed in any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the paragraph recognition method based on a PDF file according to any one of claims 1 to 7 is implemented.