PDF (Portable Document Format) file table structure identification method and system based on position logistic regression modeling and readable medium

The method uses positional logistic regression modeling to analyze lines and intersection points in PDF files, addressing the alignment issues in table structure recognition by constructing a four-dimensional matrix and restoring missing points, thereby improving the accuracy of table data extraction.

CN119206749APending Publication Date: 2024-12-27HEFEI DAZHIHUI CAIHUI DATA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411218423.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-02
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

Existing PDF file parsing technologies struggle to accurately extract table structures due to confusion in the relationship between rows and columns, often misinterpreting table data as ordinary text and failing to maintain the correct alignment of table cells.

Method used

A method based on positional logistic regression modeling that analyzes lines and intersection points in PDF files to construct a four-dimensional matrix, identifies table areas, removes abnormal points, and restores missing points to accurately determine cell positions, thereby improving table structure recognition.

Benefits of technology

The method enhances the accuracy of table structure recognition by ensuring correct alignment of cells and reducing confusion, ensuring high precision in extracting table data from PDF files.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119206749A_ABST
    Figure CN119206749A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image recognition, in particular to a PDF (Portable Document Format) file table structure recognition method and system based on position logic regression modeling and a readable medium. The method comprises the following steps: firstly, loading a PDF file to be analyzed, traversing all pages in the PDF file, extracting lines and frames of each page, analyzing, obtaining all lines, and forming a line set; then obtaining intersection points of the lines, constructing a four-dimensional matrix of each intersection point, and grouping the generated intersection points; intersection points in each point set are processed; and finally, distinguishing cells by using the four-dimensional matrix and the point coordinates of each point in the point set and restoring a table structure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image recognition, and in particular to a method, system and readable medium for recognizing a PDF file table structure based on positional logistic regression modeling. Background Art

[0002] PDF files are a representative format of unstructured documents, and extracting information from PDF files is a very challenging process. PDF files consist of a series of instructions that instruct PDF readers or printers on how to arrange the positions and display methods of various symbols and texts on the screen or paper. They simply present this data in a human-readable way and do not store any structural information of the document.

[0003] Currently, PDF files can use OCR technology to recognize text with high precision, then place the text in the corresponding cell area, and then sort to get the correct result. The challenge of parsing PDF files is to accurately extract the layout of the entire page and convert the table into text. In this process, the table data may be incorrectly parsed as ordinary text, and the relationship between the rows and columns of the table may be confusing, resulting in the inability to accurately obtain the table numerical data. Summary of the invention

[0004] In order to overcome the defect that PDF table parsing in the above-mentioned prior art is prone to confusion in the relationship between rows and columns, the present invention proposes a PDF file table structure recognition method based on positional logistic regression modeling, which can efficiently identify the table structure from the PDF file, avoid the situation where rows and columns are not aligned when the structure recognition error is caused when the table merges cells, and improve the accuracy of parsing.

[0005] The present invention proposes a PDF file table structure recognition method based on position logistic regression modeling, comprising the following steps:

[0006] S1. Load the PDF file to be parsed, traverse all pages in the PDF file, extract the lines and frames of each page and parse them, obtain all lines and form a line set;

[0007] S2. Obtain the intersection points of the lines, and construct a four-dimensional matrix of each intersection point, group the generated intersection points, and each group constitutes a point set to determine the number of tables and the table area; the four-dimensional matrix contains four elements corresponding to the up, down, left, and right directions of the intersection points, and the element 0 indicates that there is no line in the corresponding direction, and the element 1 indicates that there is a line in the corresponding direction;

[0008] S3, processing the intersection points in each point set, including removing abnormal points and restoring missing points;

[0009] S4. Use the four-dimensional matrix and point coordinates of each point in the point set to distinguish cells and restore the table structure.

[0010] Preferably, the frame is parsed as follows: first, the information of the four vertices of the frame is extracted, and the height and width of the frame are calculated; whether the height and width are both greater than a set threshold is determined; if yes, the frame is determined to be a valid frame, and the vertices of the valid frame are combined into lines and added to the line set; if no, the frame is discarded.

[0011] Preferably, step S2 comprises the following sub-steps:

[0012] S21, constructing a point set;

[0013] S22, extracting two non-parallel lines from the line set, and determining whether the two lines intersect;

[0014] If yes, directly calculate the intersection coordinates, and then execute step S23;

[0015] If no, the distance between the two lines is calculated. If the distance is less than the set distance threshold, it is determined that the two lines have an intersection, and the coordinates of the intersection are calculated, and then step S23 is executed;

[0016] S23, determine whether the intersection point exists in the point concentration; if yes, update the four-dimensional matrix of the intersection point according to the information of the two lines; if no, execute step S24;

[0017] S24, determining whether at least one of the two lines is connected to a point in any point set; if yes, adding the intersection point to the point set, and constructing a four-dimensional matrix of the intersection point based on the information of the two lines; if no, establishing a new point set to store the intersection point, and constructing a four-dimensional matrix of the intersection point based on the information of the two lines;

[0018] S25. Traverse any combination of two lines in the line set, execute the above steps S22-S24, and complete the intersection extraction and point set division.

[0019] Preferably, in S24, if the two lines are connected to points in multiple point sets, the multiple point sets are merged, the intersection points are added to the merged point set, and the four-dimensional matrix in the merged point set is updated according to the information of the two lines.

[0020] Preferably, for two non-parallel lines that do not intersect and whose distance is less than a distance threshold, one of the lines is extended so that the two lines intersect, and the intersection point after the extension is extracted as the intersection point of the two lines.

[0021] Preferably, the method for removing abnormal points is: determine the table area according to the point set, compare each intersection in the point set with the table boundary point, determine whether the intersection exists in the table area, and filter out the intersection points that do not exist in the table area as abnormal points for removal.

[0022] Preferably, after the abnormal points are removed, the missing points are restored in the following manner: determine the positional relationship of the missing points relative to the known intersection points based on the four-dimensional matrix of the intersection points in the point set; determine the line where the missing points are located, and extract the endpoints corresponding to the line as the missing points; determine the connection lines between the missing points based on the relative coordinate relationship of all the missing points and supplement them.

[0023] Preferably, step S4 comprises the following sub-steps:

[0024] S41, assuming that the entire page area is a table area;

[0025] S42, arranging the intersection points in a table area according to the coordinates of the intersection points in the point set;

[0026] S43. Then, the intersection points are connected according to the four-dimensional matrix to obtain a table structure.

[0027] The present invention proposes a PDF file table structure recognition system based on positional logistic regression modeling, comprising a memory and a processor, wherein a computer program is stored in the memory, and the processor is connected to the memory, and the processor is used to execute the computer program to implement the PDF file table structure recognition method based on positional logistic regression modeling.

[0028] The present invention provides a readable medium storing a computer program, which is used to implement the PDF file table structure recognition method based on positional logistic regression modeling when executed.

[0029] The advantages of the present invention are:

[0030] (1) The present invention proposes a PDF file table structure recognition method based on positional logistic regression modeling, which first analyzes the lines in the table, then locates the intersection points in the table by analyzing the intersection positions of the lines; and constructs a four-dimensional matrix of the intersection points, and then determines the point missing situation in combination with the four-dimensional matrix. The present invention combines line analysis and point analysis to determine the position of each cell in the table area, realizes the restoration of the table structure, has high accuracy, and avoids the problem of cell confusion that may be caused by line restoration.

[0031] (2) In the present invention, the frame is restored to lines for line set analysis, thereby ensuring the integrity of the table line analysis; the intersection points are analyzed by line intersection, thereby achieving mutual verification of lines and points, thereby improving the efficiency and accuracy of table analysis.

[0032] (3) In the present invention, point set cleaning is achieved by eliminating abnormal points, avoiding the interference of abnormal points on table restoration; missing point restoration further improves the information perfection of table parsing, thereby facilitating subsequent table structure restoration.

[0033] (4) The PDF file table structure recognition system based on positional logistic regression modeling and the readable medium proposed in the present invention can carry the PDF file table structure recognition method based on positional logistic regression modeling, thereby facilitating the promotion and application of the method. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 It is a flow chart of a PDF file table structure recognition method based on positional logistic regression modeling;

[0035] Figure 2 It is a schematic diagram of the original PDF file content for extracting a table according to an embodiment of the present invention;

[0036] Figure 3 is a schematic diagram of a table for obtaining four-dimensional coordinates of intersection points according to an embodiment of the present invention;

[0037] Figure 4 is a schematic diagram of a table structure for completion according to an embodiment of the present invention;

[0038] Figure 5 Schematic diagram of extracting intersection points of non-intersecting lines in an embodiment. DETAILED DESCRIPTION

[0039] 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 only 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.

[0040] like Figure 1 As shown, a PDF file table structure recognition method based on position logistic regression modeling includes the following steps:

[0041] S1. Load the PDF file to be parsed, traverse all pages in the PDF file, extract the lines and frames of each page and parse them, obtain all lines and form a line set; the line set stores the position information of the lines, that is, the position coordinates of the two end points of the lines.

[0042] In this step S1, the extracted frame needs to be parsed into lines, and then both the extracted lines and the parsed lines are put into the line set. In this step, according to the needs, all the data of the lines and frames obtained through the instruction are traversed to determine whether the data type is a line. If it is a line, it is directly put into the line set; if the type is a frame, first extract the information of the four vertices of the frame, calculate the height and width of the frame, if the height and width are greater than the set threshold, it is considered to be a valid frame, otherwise it is an invalid frame, and the vertices of the valid frame are combined into lines and added to the line set. The set threshold is the minimum side length of the cell.

[0043] Theoretically, the lines in the table are horizontal and vertical. You only need to connect the vertices with equal horizontal coordinates or equal vertical coordinates into lines to get the edge of the valid frame; however, in actual extraction, the table lines may be offset due to scanning angle, light, placement, etc. Therefore, in this embodiment, the way to combine the vertices of the valid frame into lines is: connect the vertices whose horizontal coordinate difference is less than the set first deviation value or the vertical coordinate difference is less than the set second deviation value into lines. The deviation value is set according to the cell size. Specifically, the first deviation value can be set to 0.1 to 0.5 of the minimum height of the cell, and the second deviation value can be set to 0.1 to 0.5 of the length of the cell.

[0044] In a specific embodiment, a PDF loader based on the Python programming language can be used, and the fitz library of the Python programming language can be used as a parsing tool. Figure 1 As shown in the figure, the PDF file is read through the fitz library of the Python programming language. Fitz provides rich PDF processing capabilities, such as the ability to create, view, modify, and extract text, images, and other content from PDF documents, which is very helpful for complex PDF document operations. Through the fitz library, you can easily read PDF files, get all the page data information, and extract all the lines and boxes on each page.

[0045] PDF files consist of a series of instructions that instruct PDF readers or printers to arrange the positions and display methods of various symbols and texts on the screen or paper. However, these instructions only present these data in a human-readable way and do not store any structural information of the document. After reading the PDF file with fitz and obtaining all the page number data information, all the lines and boxes of each page can be extracted according to the specified instructions.

[0046] In this step S1, all the lines and frames of each page are extracted from the instructions of each page according to the specified rules, and the valid frames are also converted into lines, and invalid lines are removed. Invalid lines refer to oblique lines, that is, lines whose smaller value of the angle with the horizontal direction and the angle with the vertical direction is greater than the set angle threshold; if all the lines in the line set are horizontal or vertical, they are not removed. The set angle threshold can be specifically set to 1 to 20 degrees.

[0047] S2. Obtain the intersection points of the lines, construct a four-dimensional matrix of each intersection point, group the generated intersection points, and each group constitutes a point set to determine the number of tables and the table area.

[0048] Reference Figure 2 , Figure 3, the four-dimensional matrix contains four elements corresponding to the up, down, left, and right directions of the intersection. An element of 0 indicates that there is no line in the corresponding direction, and an element of 1 indicates that there is a line in the corresponding direction. Assuming that the direction order in the four-dimensional matrix is ​​up, down, left, and right, when the intersection is at the leftmost side of the table and is not a vertex, that is, there are lines on the top, bottom, and right sides of the intersection, but no line on the left side of the intersection, the four-dimensional matrix corresponding to the intersection is recorded as {1,1,0,1}. The four-dimensional matrix is ​​used to determine whether there are lines in the four directions of the current point, so as to find the correspondence between points and points, laying the foundation for the final restoration of the cell.

[0049] In this step, the rule for grouping intersection points is: the intersection points in the same group can be connected by one or more lines in the line set; the points between two groups do not have a connecting line in the line set. In this way, interference between different tables can be avoided.

[0050] Step S2 specifically includes the following sub-steps:

[0051] S21, constructing a point set;

[0052] S22, extracting two non-parallel lines from the line set, and determining whether the two lines intersect;

[0053] If yes, directly calculate the intersection coordinates, and then execute step S23;

[0054] If no, the distance between the two lines is calculated. If the distance is less than the set distance threshold, it is determined that the two lines have an intersection, and the coordinates of the intersection are calculated, and then step S23 is executed;

[0055] In this step, for two non-parallel lines that do not intersect and whose distance is less than the distance threshold, one of the lines is extended so that the two lines intersect, thereby extracting the intersection point. Figure 5 For example, line L1 and line L2 do not intersect and the distance between them is less than the distance threshold; after extending L1, L1 and L2 are compared to point A1, and at this time, the intersection of line L1 and line L2 can be selected as A1.

[0056] It is worth noting that the normal state of the lines in the table is horizontal and vertical; when constructing the line set in S1, the lines can be marked as horizontal or vertical lines. In this way, S22 directly extracts a horizontal line and a vertical line for judgment.

[0057] S23, determine whether the intersection point exists in the point concentration; if yes, update the four-dimensional matrix of the intersection point according to the information of the two lines; if no, execute step S24;

[0058] S24, determining whether at least one of the two lines is connected to a point in any point set; if yes, adding the intersection point to the point set, and constructing a four-dimensional matrix of the intersection point based on the information of the two lines; if no, establishing a new point set to store the intersection point, and constructing a four-dimensional matrix of the intersection point based on the information of the two lines;

[0059] If two lines are connected to points in multiple point sets, the multiple point sets are merged, the intersection is added to the merged point set, and the four-dimensional matrix in the merged point set is updated according to the information of the two lines; that is, for the points in the point set connected to the two lines, determine whether the elements of their four-dimensional matrices corresponding to the connected lines are 0. If they are 0, the corresponding elements are changed to 1 according to the positions of the lines and the points; the intersection of the two lines also needs to construct the four-dimensional matrix of the intersection according to the two lines and the position.

[0060] It is worth noting that, since the extracted lines should theoretically be the lines of the cells, the extracted lines theoretically only have L-shaped intersections. Due to the limitations of the lines, the direction of the intersection without lines is treated as a missing value; if the intersection is added to the point set for the first time, only two lines of the intersection are clear, that is, its four-dimensional matrix has only two element values, and the other two elements are missing. In actual processing, if the two lines intersect in L shape, the four-dimensional matrix of the intersection contains two missing values ​​and two 1s; if the intersection is T-shaped, the four-dimensional matrix of the intersection contains one missing value and three 1s; if the intersection is cross-shaped, the four-dimensional matrix of the intersection has all four elements of 1.

[0061] S25. Traverse the combination of any two lines in the line set, execute the above steps S22-S24, complete the intersection extraction and point set division, each point set corresponds to a table area, and the number of point sets is the number of table areas.

[0062] S3. Process the intersection points in each point set, including removing abnormal points and restoring missing points.

[0063] In this step, each individual table area is first processed for outlier removal and missing point restoration. Outlier points refer to the endpoints of lines that exist outside the table area. Missing points refer to points corresponding to the missing boundaries of the table; for example, the left side of the table area should satisfy the left dimension of 0 in the four-dimensional matrix, so if the intersection points parsed from the table area lack points with a left dimension of 0, it is necessary to determine the missing points and supplement them.

[0064] The method of removing abnormal points is as follows: determine the table area according to the point set, compare each intersection point in the point set with the table boundary point, determine whether the intersection point exists in the table area, and filter out the intersection points that do not exist in the table area as abnormal points for removal. That is, first determine the points in the point set that are located on the leftmost boundary, rightmost boundary, topmost boundary, and bottommost boundary of the table area as table boundary points; then remove the points in the point set that are outside the table boundary points as abnormal points.

[0065] After the outliers are removed, the point set is traversed in combination with the four-dimensional matrix to search for missing points and supplement them. The missing point supplement rule is:

[0066] For the boundary points of the table, determine whether its four-dimensional matrix corresponds to the boundary information. If not, the corresponding boundary points need to be supplemented. For example, for point A on the leftmost boundary of the table, if the element corresponding to the left is 1, it means that there is a line on the left side of point A, that is, the left side of point A needs to be supplemented with missing points. When supplementing, find the endpoint of the line where the missing point is located to determine the coordinates of the missing point.

[0067] Missing point restoration includes the following steps:

[0068] Determine the positional relationship of the missing points relative to the known intersection points based on the four-dimensional matrix of the intersection points in the point set;

[0069] Determine the line where the missing point is located, extract the endpoint corresponding to the line as the missing point, and determine the coordinates of the missing point;

[0070] According to the relative coordinate relationship of all missing points, determine the connection lines between the missing points and supplement them; for example, the missing points on the same column of coordinates are connected to form the vertical edge of the table;

[0071] For the points in the table area, if there are M lines between two points, M>1, it means that M-1 points are missing between the two points and need to be supplemented; at this time, it is necessary to find the endpoints of the M lines, and then combine the endpoints of the lines to supplement M-1 points; taking two points on the same vertical line as an example, assuming that there are M vertical lines between the two points, then obtain the intersection points of the M vertical lines with other horizontal lines as missing points for supplementation.

[0072] S4. Using the four-dimensional matrix and point coordinates of each point in the point set to distinguish cells and restore the table structure, specifically includes the following sub-steps.

[0073] S41, assuming that the entire page area is a table area;

[0074] S42, arranging the intersection points in a table area according to the coordinates of the intersection points in the point set;

[0075] S43, then connect the intersection points according to the four-dimensional matrix to obtain a table structure as follows Figure 4 shown.

[0076] Of course, it is obvious to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, but also includes the same or similar structures that can be implemented in other specific forms without departing from the spirit or essential features of the present invention. Therefore, no matter from which point of view, the embodiments should be regarded as exemplary and non-limiting, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any reference numerals in the claims should not be regarded as limiting the claims involved.

[0077] In addition, it should be understood that although the present specification is described according to implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation modes that can be understood by those skilled in the art.

[0078] The techniques, shapes, and structural parts not described in detail in the present invention are all well-known techniques.

Claims

1. A PDF file table structure recognition method based on position logistic regression modeling, characterized in that: The following steps are involved: S1. Load the PDF file to be parsed, traverse all pages in the PDF file, extract the lines and frames of each page and parse them, obtain all lines and form a line set; S2. Obtain the intersection points of the lines, and construct a four-dimensional matrix of each intersection point, group the generated intersection points, and each group constitutes a point set to determine the number of tables and the table area; the four-dimensional matrix contains four elements corresponding to the up, down, left, and right directions of the intersection points, and the element 0 indicates that there is no line in the corresponding direction, and the element 1 indicates that there is a line in the corresponding direction; S3, processing the intersection points in each point set, including removing abnormal points and restoring missing points; S4. Use the four-dimensional matrix and point coordinates of each point in the point set to distinguish cells and restore the table structure.

2. The PDF file table structure recognition method based on position logistic regression modeling as claimed in claim 1, characterized in that: The way to parse the box is: first extract the information of the four vertices of the box, calculate the height and width of the box; determine whether the height and width are both greater than the set threshold; if so, determine that the box is a valid box, combine the vertices of the valid box into lines and add them to the line set; if not, discard the box.

3. The PDF file table structure recognition method based on position logistic regression modeling as claimed in claim 1, characterized in that: Step S2 includes the following sub-steps: S21, constructing a point set; S22, extracting two non-parallel lines from the line set, and determining whether the two lines intersect; If yes, directly calculate the intersection coordinates, and then execute step S23; If no, the distance between the two lines is calculated. If the distance is less than the set distance threshold, it is determined that the two lines have an intersection, and the coordinates of the intersection are calculated, and then step S23 is executed; S23, determine whether the intersection point exists in the point concentration; if yes, update the four-dimensional matrix of the intersection point according to the information of the two lines; if no, execute step S24; S24, determining whether at least one of the two lines is connected to a point in any point set; if yes, adding the intersection point to the point set, and constructing a four-dimensional matrix of the intersection point based on the information of the two lines; if no, establishing a new point set to store the intersection point, and constructing a four-dimensional matrix of the intersection point based on the information of the two lines; S25. Traverse any combination of two lines in the line set, execute the above steps S22-S24, and complete the intersection extraction and point set division.

4. The PDF file table structure recognition method based on position logistic regression modeling as claimed in claim 3, characterized in that: In S24, if the two lines are connected to points in multiple point sets, the multiple point sets are merged, the intersection points are added to the merged point set, and the four-dimensional matrix in the merged point set is updated according to the information of the two lines.

5. The PDF file table structure recognition method based on position logistic regression modeling as claimed in claim 4, characterized in that: For two non-parallel lines that do not intersect and whose distance is less than a distance threshold, one of the lines is extended so that the two lines intersect, and the extended intersection point is extracted as the intersection point of the two lines.

6. The PDF file table structure recognition method based on position logistic regression modeling as claimed in claim 1, characterized in that: The method of removing abnormal points is as follows: determine the table area according to the point set, compare each intersection point in the point set with the table boundary point, determine whether the intersection point exists in the table area, and filter out the intersection points that do not exist in the table area as abnormal points for removal.

7. The PDF file table structure recognition method based on position logistic regression modeling as claimed in claim 6, characterized in that: After the abnormal points are removed, the missing points are restored. The method of restoring the missing points is as follows: determine the positional relationship of the missing points relative to the known intersection points based on the four-dimensional matrix of the intersection points in the point set; determine the line where the missing points are located, and extract the endpoints corresponding to the line as the missing points; based on the relative coordinate relationship of all the missing points, determine the connection lines between the missing points and supplement them.

8. The PDF file table structure recognition method based on position logistic regression modeling as claimed in claim 1, characterized in that: Step S4 includes the following sub-steps: S41, assuming that the entire page area is a table area; S42, arranging the intersection points in a table area according to the coordinates of the intersection points in the point set; S43. Then, the intersection points are connected according to the four-dimensional matrix to obtain a table structure.

9. A PDF file table structure recognition system based on position logistic regression modeling, characterized in that: It includes a memory and a processor, the memory stores a computer program, the processor is connected to the memory, and the processor is used to execute the computer program to implement the PDF file table structure recognition method based on position logistic regression modeling as described in any one of claims 1 to 8.

10. A readable medium, characterized in that: A computer program is stored, and when the computer program is executed, it is used to implement the PDF file table structure recognition method based on position logistic regression modeling as described in any one of claims 1 to 8.