Method and system for merging and extracting PDF (Portable Document Format) file cross-page tables based on logistic regression
Through a logistic regression-based method, the cross-page tables in PDF files are identified and merged, which solves the problem of cross-page table recognition difficulty, improves the accuracy and efficiency of table structure analysis, and simplifies the calculation process.
Patent Information
- Application Number
- CN202411218427.9
- 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
It is difficult for the prior art to accurately identify and merge spreadsheets in PDF files, especially due to the impact of non-text texts such as headers and footers on table recognition.
Using a logistic regression-based method, by loading PDF files, analyzing line information, building a collection of horizontal and vertical lines, calculating intersection coordinates, building a four-dimensional matrix, restoring the table structure, and merging according to the similarity of the table area, solving the spread-page merging Questions on the form.
It improves the accuracy and efficiency of the identification of the table structure, avoids excessive table problems, simplifies the calculation speed and accuracy, and corrects the misidentification of the direction of the table lines, ensuring the accuracy and calculation efficiency of row coordinates.
Smart Images

Figure CN119206750A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing and intelligent reading, and in particular to a method and system for merging and extracting a PDF file cross-page table based on logistic regression. 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] The challenge of parsing PDF files is to accurately extract the layout of the entire page. Some tables in PDF will be displayed across pages. When recognizing such tables, non-text text such as headers and footers will have a great impact on table recognition. Summary of the invention
[0004] In order to overcome the defect that it is difficult to identify cross-page tables in the PDF file parsing process in the above-mentioned prior art, the present invention proposes a merging and extraction method for cross-page tables of PDF files based on logistic regression, which can efficiently identify the table structure from the PDF file and solve the problem of merging cross-page tables.
[0005] The present invention proposes a method for merging and extracting a PDF file cross-page table based on logistic regression, comprising the following steps:
[0006] S1. First, load the PDF file, parse the line information in each page one by one, and construct the horizontal line set and vertical line set of each page;
[0007] S2. Calculate the coordinates of the intersections of all intersecting horizontal and vertical lines on the same page, and construct a four-dimensional matrix of each intersection, restore the table structure, and mark the table area page number and context; the four-dimensional matrix contains four 0 or 1 elements corresponding to the up, down, left, and right directions of the intersections;
[0008] S3, traverse all table areas of the PDF file, search for table areas that need to be merged and merge them; update the merged table areas to the large-size page and update the page number, and delete the two merged table areas.
[0009] Preferably, in step S3, the table area containing multiple tables is first split, and then the table areas to be merged are searched and merged.
[0010] Preferably, the table areas to be merged meet the following conditions:
[0011] Two table areas are adjacent or there is only a header and / or footer between them;
[0012] The two table areas have the same structure;
[0013] When two adjacent table areas both have headers, if the headers are consistent, the two table areas are judged to have consistent structures; when the latter of two adjacent table areas has no header, if the column structure of the latter table area is consistent with the column structure of the footer of the former table area, the two table areas are judged to have consistent structures.
[0014] Preferably, in S3, blank rows and blank columns in the table area are first deleted, and then it is determined whether the table area needs to be split; when there are cells in the table area that are merged in the entire row, the table is split using the cells in the entire row as the boundary.
[0015] Preferably, in step S1, first parse the page information of the PDF file, extract lines and store them in a line set corresponding to the page, and parse the extracted boxes into lines and store them in the line set; delete the inclined lines in the line set, and then divide the line set into a horizontal line set and a vertical line set, merge the lines in the horizontal line set whose distance is less than the set row spacing, and merge the lines in the vertical line set whose distance is less than the set column spacing.
[0016] Preferably, the lines classified into the horizontal line set in S1 are adjusted to horizontal lines, and the lines classified into the vertical line set are adjusted to vertical lines; the search order of the lines in the horizontal line set and the vertical line set is set, and the search is performed from front to back; in the horizontal line set, when the row spacing between two lines is less than the set row spacing, the row coordinates of the line with the front row spacing between the two lines are changed to the row coordinates of the line with the back row spacing, and so on recursively; in the vertical line set, when the column spacing between two lines is less than the set column spacing, the column coordinates of the line with the front row spacing between the two lines are changed to the column coordinates of the line with the back row spacing, and so on recursively.
[0017] Preferably, the method for extracting the intersection in step S2 is: extracting a horizontal line from the horizontal line set and a vertical line from the vertical line set to form a horizontal and vertical line pair; traversing all horizontal and vertical line pairs, extracting the intersection and constructing a four-dimensional matrix.
[0018] Preferably, S2 specifically includes the following sub-steps:
[0019] S21, initializing an intersection point set for storing the first intersection point;
[0020] S22, extracting a horizontal line from the horizontal line set, and extracting a vertical line from the vertical line set, to form a horizontal and vertical line pair;
[0021] S23, determine whether two lines in the horizontal and vertical line pairs intersect; if yes, extract the coordinates of the intersection point and execute step S24; if no, calculate the distance between the two lines, if the distance between the two lines is less than the set distance threshold, extend one of the lines so that the two lines intersect, extract the coordinates of the intersection point and execute step S24; if no, return to step S22;
[0022] S24, determine whether the intersection coordinates exist in the existing intersection set; if yes, update the four-dimensional matrix of the intersection according to the intersection of the two lines, and then return to step S22; if no, execute step S25;
[0023] S25, determining whether a line in the horizontal and vertical line pair is connected to a point in the existing intersection point set;
[0024] If the two lines are connected to each other, the multiple intersection point sets are merged, the intersection points of the horizontal and vertical line pairs are added to the merged intersection point set, and a four-dimensional matrix of the intersection points is constructed according to the intersection of the two lines, and then the process returns to step S22;
[0025] If the two lines are connected to only one point in the intersection point set, the intersection point of the horizontal and vertical line pairs is added to the intersection point set, and a four-dimensional matrix of the intersection points is constructed according to the intersection of the two lines, and then the process returns to step S22;
[0026] If not, a new intersection point combination is added, the intersection point of the horizontal and vertical line pairs is added to the newly added intersection point set, and a four-dimensional matrix of the intersection points is constructed according to the intersection of the two lines, and then the process returns to step S22;
[0027] S26. Traverse the horizontal and vertical line pairs, extract all intersection sets, and restore the corresponding table area according to the intersection set. The intersection set corresponds to the table area one by one.
[0028] Preferably, in S26, when restoring the corresponding table area according to the intersection set, all points in the intersection set are arranged on the page, and the lines in the horizontal line set and the vertical line set are arranged on the page according to the coordinates and the connection relationship with the intersection points; then the missing points are supplemented to obtain the table structure; the missing points refer to the points corresponding to the missing boundaries of the table.
[0029] The present invention proposes a system for merging and extracting a PDF file cross-page table based on logistic regression, 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 method for merging and extracting a PDF file cross-page table based on logistic regression.
[0030] The advantages of the present invention are:
[0031] (1) The present invention first analyzes the lines, then groups and adjusts the lines horizontally and vertically, then merges the lines, and finally extracts the intersection points according to the intersection of the lines; this not only ensures the extraction of the table intersection points, but also avoids the contradictory errors that may be caused by the simultaneous extraction of lines and intersection points, which is beneficial to improving the accuracy and efficiency of subsequent table structure analysis.
[0032] (2) In the process of parsing a table, the present invention splits a large table containing multiple tables, which is beneficial to the independent display of the table area, thereby avoiding the problem of the table being too large, and is beneficial to simplifying the table and improving the calculation speed and accuracy.
[0033] (3) In the present invention, the directions of the lines are corrected while dividing the line sets, that is, the lines in the horizontal line set are corrected to the horizontal direction, and the lines in the vertical line set are corrected to the vertical direction, which solves the problem of misrecognition caused by the tilt of the table lines and improves the table recognition accuracy and restoration efficiency.
[0034] (4) In the present invention, during the line qualification process, the standard row coordinates are updated to the next adjacent row coordinates, so that in the line spacing judgment, the adjacent row coordinates in the original row coordinate set are always used for judgment; the distance change of the similar row coordinates in the original row coordinate set due to the subsequent row coordinate merging is avoided, and the accuracy of the row coordinate merging is guaranteed.
[0035] (5) First, the horizontal and vertical lines are divided, and then the coordinates of the adjacent and parallel lines are updated. Finally, the lines are merged. This simplifies the line set, deletes redundant lines, and improves the subsequent calculation efficiency. At the same time, it also ensures the recognition accuracy of multiple lines on the same straight line. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 It is a flow chart of a method for merging and extracting PDF file cross-page tables based on logistic regression proposed by the present invention;
[0037] Figure 2 is a schematic diagram of a table to be split according to an embodiment of the present invention;
[0038] Figure 3 This is a schematic diagram before merging PDF cross-page tables according to an embodiment of the present invention;
[0039] Figure 4 The present invention is a schematic diagram of an HTML structure after a PDF cross-page table is merged according to an embodiment of the present invention. DETAILED DESCRIPTION
[0040] 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.
[0041] Reference Figure 1 The present invention proposes a method for merging and extracting a PDF file cross-page table based on logistic regression, comprising the following steps:
[0042] S1. Load the PDF file, parse the line information in each page one by one, and construct the horizontal line set and vertical line set of each page;
[0043] Specifically, in this step, firstly, all straight lines and rectangles are extracted from the page data, and rectangles are converted into straight lines, so as to obtain all lines of the page and filter them, and then the remaining lines are classified into a horizontal line set and a vertical line set.
[0044] S2. Calculate the coordinates of the intersections of all intersecting horizontal and vertical lines on the same page, and construct a four-dimensional matrix of each intersection; determine the table area and quantity of the page through the four-dimensional matrix of the intersection and the position information of the lines, restore the table structure, and mark the table area page number and context; to facilitate the subsequent page arrangement of the table.
[0045] 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 order of directions 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.
[0046] S3, traverse all table areas of the PDF file, and determine whether two adjacent table areas need to be merged; if yes, merge the table areas, update the merged table areas to the large-size page and update the page number, and delete the two merged table areas.
[0047] Specifically, the conditions for determining whether two adjacent table areas need to be merged include: there is no other content between the two table areas, there are only headers and / or footers between the two table areas, the table structures of the two table areas are consistent, the headers of the two table areas are consistent, or the latter table area has no header.
[0048] S4. The merged PDF table information is output in HTML format to avoid paging when the table is too long. That is, the parsed PDF file is stored as json structured data. In order to facilitate display and avoid paging, the PDF file with merged table areas is output in HTML format.
[0049] In a specific embodiment, S1 can be based on the Python programming language PDF loader, and the Python programming language fitz library is used as a parsing tool. The Python programming language fitz library is used to read PDF files. Fitz provides rich PDF processing capabilities, such as the ability to process the creation, viewing, modification and extraction of text, images and other contents of PDF documents, which is very beneficial for complex PDF document operations. Through the fitz library, PDF files can be easily read and all page number data information can be obtained.
[0050] 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.
[0051] The parsing of a single page in S1 specifically includes the following sub-steps.
[0052] S11, parsing the page information of the PDF file, extracting lines and storing them in a line set corresponding to the page, and parsing the extracted boxes into lines and storing them in the line set;
[0053] 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, if the height and width are greater than the set threshold, it is considered to be a valid box, otherwise it is an invalid box, and the vertices of the valid box are combined into a line and added to the line set. The set threshold is the minimum side length of the cell. The way to combine the vertices of the valid box into a line 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 a line. 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.
[0054] S12, defining the smaller value of the angle between the line and the horizontal direction and the angle between the line and the vertical direction as the inclination angle of the line, defining the line whose inclination angle is greater than the set inclination threshold as the inclined line; and deleting the inclined lines in the line set.
[0055] S13, dividing the line set into a horizontal line set storing horizontal lines and a vertical line set storing vertical lines; the dividing method is: if the angle between the line and the horizontal direction is small, it is divided into the horizontal line set; if the angle between the line and the vertical direction is small, it is divided into the vertical line set.
[0056] Specifically, the directions of the lines are corrected while dividing the line set, that is, the lines in the horizontal line set are corrected to the horizontal direction, which can be based on the horizontal coordinates of the left end points of the lines, or the horizontal coordinates of the right end points of the lines; similarly, the lines in the vertical line set are corrected to the vertical direction, which can be based on the column coordinates of the left end points of the lines, or the column coordinates of the right end points of the lines;
[0057] S14. Merge the lines in the horizontal line set whose distance is less than the set row spacing, and merge the lines in the vertical line set whose distance is less than the set column spacing.
[0058] Specifically, the line merging method in the horizontal line set is:
[0059] S141, firstly, arrange the lines in the horizontal line set according to row coordinates, and list the row coordinate sets of all the lines;
[0060] S142, starting from the first row coordinate, sequentially taking the row coordinates as standard row coordinates;
[0061] S143, determining whether the difference between the standard row coordinate and the next adjacent row coordinate in the row coordinate set is less than a set row spacing threshold;
[0062] If yes, the row coordinates of the line on the standard row coordinates are adjusted to the next adjacent row coordinates, the standard row coordinates are deleted from the row coordinate set, the standard row coordinates are updated to the next adjacent row coordinates, and then the step S143 is repeated;
[0063] If not, the standard row coordinate is updated to be the next row coordinate of the standard row coordinate in the row coordinate set, and then the step S143 is looped.
[0064] S144. When the standard row coordinate is updated to the last row coordinate in the row coordinate set, the overlapping lines on each row coordinate are merged.
[0065] It is worth noting that in step S143, the standard row coordinates are updated to the next adjacent row coordinates, so that in the row distance judgment, the adjacent row coordinates in the original row coordinate set are always used for judgment; this avoids the distance change of similar row coordinates in the original row coordinate set due to the subsequent row coordinate merging, thereby ensuring the accuracy of the row coordinate merging.
[0066] At the same time, in this implementation, the horizontal and vertical lines are first divided, the coordinates of the adjacent and parallel lines are updated, and then the lines are merged. This simplifies the line set, deletes redundant lines, improves subsequent calculation efficiency, and ensures the recognition accuracy of multiple lines on the same straight line.
[0067] Similarly, the line merging method in the vertical line set is:
[0068] S145, firstly arranging the lines in the vertical line set according to the column coordinates, and listing the column coordinate sets of all the lines;
[0069] S146, starting from the first column coordinate, sequentially taking the column coordinates as standard column coordinates;
[0070] S147, determining whether the difference between the standard column coordinate and the next adjacent column coordinate in the column coordinate set is less than a set column distance threshold;
[0071] If yes, the column coordinates of the line on the standard column coordinates are adjusted to the next adjacent column coordinates, the standard column coordinates are deleted from the column coordinate set, the standard column coordinates are updated to the next adjacent column coordinates, and then this step S147 is repeated;
[0072] If not, the standard column coordinate is updated to be the next column coordinate of the standard column coordinate in the column coordinate set, and then the step S147 is looped.
[0073] S148. When the standard column coordinate is updated to the last row coordinate in the column coordinate set, the overlapping lines on each column coordinate are merged.
[0074] The specific steps of extracting the intersection point in step S2 are as follows:
[0075] S21, initializing an intersection point set for storing the first intersection point;
[0076] S22, extracting a horizontal line from the horizontal line set, and extracting a vertical line from the vertical line set, to form a horizontal and vertical line pair;
[0077] S23, determine whether two lines in the horizontal and vertical line pairs intersect; if yes, extract the coordinates of the intersection point and execute step S24; if no, calculate the distance between the two lines, if the distance between the two lines is less than the set distance threshold, extend one of the lines so that the two lines intersect, extract the coordinates of the intersection point and execute step S24; if no, return to step S22;
[0078] S24, determine whether the intersection coordinates exist in the existing intersection set; if yes, update the four-dimensional matrix of the intersection according to the intersection of the two lines, and then return to step S22; if no, execute step S25;
[0079] S25, determining whether a line in the horizontal and vertical line pair is connected to a point in the existing intersection point set;
[0080] If the two lines are connected to each other, the multiple intersection point sets are merged, the intersection points of the horizontal and vertical line pairs are added to the merged intersection point set, and a four-dimensional matrix of the intersection points is constructed according to the intersection of the two lines, and then the process returns to step S22;
[0081] If the two lines are connected to only one point in the intersection point set, the intersection point of the horizontal and vertical line pairs is added to the intersection point set, and a four-dimensional matrix of the intersection points is constructed according to the intersection of the two lines, and then the process returns to step S22;
[0082] If not, a new intersection point combination is added, the intersection point of the horizontal and vertical line pairs is added to the newly added intersection point set, and a four-dimensional matrix of the intersection points is constructed according to the intersection of the two lines, and then the process returns to step S22;
[0083] S26. Traverse the horizontal and vertical line pairs, extract all intersection sets, and restore the corresponding table area according to the intersection set. The intersection set corresponds to the table area one by one.
[0084] When restoring the corresponding table area according to the intersection set, all points in the intersection set are arranged on the page, and the lines in the horizontal line set and the vertical line set are arranged on the page according to the coordinates and the connection relationship with the intersection points; then the missing points are supplemented to obtain the table structure.
[0085] Missing points refer to points corresponding to missing boundaries of a table; for example, the left side of the table area should satisfy the left dimension of 0 in the four-dimensional matrix. Therefore, if the intersection points parsed from the table area lack points with a left dimension of 0, the missing points need to be determined and supplemented. When there are missing points, first 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, extract the endpoints corresponding to the line as the missing points, and determine the coordinates of the missing points and the four-dimensional matrix, and restore the missing points to the page; determine the lines between the missing points based on the relative coordinate relationships of all 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;
[0086] In this embodiment, the lines are first analyzed, then the lines are grouped and adjusted horizontally and vertically, and then the lines are merged, and finally the intersection points are extracted according to the intersection of the lines; this not only ensures the extraction of the table intersection points, but also avoids the contradictory errors that may be caused by the simultaneous extraction of lines and intersection points, which is beneficial to improving the accuracy and efficiency of subsequent table structure analysis.
[0087] In step S3, when traversing all table areas of the PDF file, first determine whether there is a table that needs to be split, split the table that needs to be split, sort it according to the page number and position of the table area, and then determine whether the table needs to be merged.
[0088] Specifically, in step S2, the original table structure in the PDF file is restored and the missing points and lines are supplemented, which lays a foundation for the subsequent cross-row and cross-column judgment in the table area.
[0089] Step S3 specifically includes the following steps:
[0090] S31, determining the total number of rows and columns in the table area, and deleting blank rows and columns in the table area; a blank row means that all cells in the row are empty, and a blank column means that all cells in the column are empty;
[0091] S32, determine whether the entire row of cells is merged, such as Figure 2 As shown; if yes, the table is split with the whole row of merged cells as the boundary, the contents of the whole row of merged cells are converted into non-table text and placed between the corresponding cells, and then step S33 is executed; if no, step S33 is executed;
[0092] S33, determine whether there is a header or footer between the current table area and the next table area in the PDF file; if not, execute the next table area, that is, loop this step with the next table area as the current table area; if yes, execute step S34; Figure 3 There is a page number footer between the two adjacent tables shown.
[0093] S34, determining whether there is a header in the next table area; if not, executing step S35;
[0094] If yes, determine whether the header area of the next table area is consistent with the header area of the current table area; if consistent, execute step S35; if inconsistent, execute the next table area, that is, take the next table area as the current table area, and return to step S33.
[0095] S35. Determine whether the table structure of the current table area is consistent with that of the next table area; if not, execute the next table area, that is, take the next table area as the current table area, and return to step S33; if yes, merge the current table area with the next table area, update the merged table area to the large-size page and update the page number, and return to step S33 with the merged table area as the current table area.
[0096] Specifically, in this embodiment, when two adjacent table areas need to be merged and both have headers, the header of the latter table area is deleted to ensure the continuity of the merged table area. In this implementation, when two adjacent table areas both have headers, the consistency of the table structure is determined by whether the headers are consistent. If the headers are consistent, the table structures are considered to be consistent; this greatly improves the efficiency of judging the consistency of the table structure. When the latter of two adjacent table areas has no header, if the column structure of the latter table area is consistent with the column structure of the footer of the former table area, the two table areas are judged to have consistent structures. The footer is the area after the header in the table area.
[0097] In this embodiment, the merged table area is output in HXML format, such as Figure 4 shown.
[0098] 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.
[0099] 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.
[0100] The techniques, shapes, and structural parts not described in detail in the present invention are all well-known techniques.
Claims
1. A method for merging and extracting cross-page tables in PDF files based on logistic regression, characterized in that: The following steps are involved: S1. First, load the PDF file, parse the line information in each page one by one, and construct the horizontal line set and vertical line set of each page; S2. Calculate the coordinates of the intersections of all intersecting horizontal and vertical lines on the same page, and construct a four-dimensional matrix of each intersection, restore the table structure, and mark the table area page number and context; the four-dimensional matrix contains four 0 or 1 elements corresponding to the up, down, left, and right directions of the intersections; S3, traverse all table areas of the PDF file, search for table areas that need to be merged and merge them; update the merged table areas to the large-size page and update the page number, and delete the two merged table areas.
2. The method for merging and extracting PDF file cross-page tables based on logistic regression as claimed in claim 1, characterized in that: In step S3, the table area containing multiple tables is first split, and then the table area to be merged is searched and merged.
3. The method for merging and extracting PDF file cross-page tables based on logistic regression as claimed in claim 2, characterized in that: The table areas to be merged meet the following conditions: Two table areas are adjacent or there is only a header and / or footer between them; The two table areas have the same structure; When two adjacent table areas both have headers, if the headers are consistent, the two table areas are judged to have consistent structures; when the latter of two adjacent table areas has no header, if the column structure of the latter table area is consistent with the column structure of the footer of the former table area, the two table areas are judged to have consistent structures.
4. The method for merging and extracting PDF file cross-page tables based on logistic regression as claimed in claim 2, characterized in that: In S3, blank rows and blank columns in the table area are first deleted, and then it is determined whether the table area needs to be split; when there are cells in the table area that are merged in the entire row, the table is split using the cells in the entire row that are merged as the boundary.
5. The method for merging and extracting PDF file cross-page tables based on logistic regression as claimed in claim 1, characterized in that: In step S1, first parse the page information of the PDF file, extract lines and store them in the line set corresponding to the page, and parse the extracted boxes into lines and store them in the line set; delete the inclined lines in the line set, and then divide the horizontal line set and the vertical line set, merge the lines in the horizontal line set whose distance is less than the set line spacing, and merge the lines in the vertical line set whose distance is less than the set column spacing.
6. The method for merging and extracting PDF file cross-page tables based on logistic regression as claimed in claim 5, characterized in that: The lines classified into the horizontal line set in S1 are adjusted to horizontal lines, and the lines classified into the vertical line set are adjusted to vertical lines; the search order of the lines in the horizontal line set and the vertical line set is set, and the search is performed from front to back; in the horizontal line set, when the row spacing between two lines is less than the set row spacing, the row coordinates of the line with the front row spacing of the two lines are changed to the row coordinates of the line with the back row spacing, and so on recursively; in the vertical line set, when the column spacing between two lines is less than the set column spacing, the column coordinates of the line with the front row spacing of the two lines are changed to the column coordinates of the line with the back row spacing, and so on recursively.
7. The method for merging and extracting PDF file cross-page tables based on logistic regression as claimed in claim 1, characterized in that: The method for extracting the intersection in step S2 is: extracting a horizontal line from the horizontal line set and a vertical line from the vertical line set to form a horizontal and vertical line pair; traversing all horizontal and vertical line pairs, extracting the intersection and constructing a four-dimensional matrix.
8. The method for merging and extracting PDF file cross-page tables based on logistic regression as claimed in claim 7, characterized in that: S2 specifically includes the following sub-steps: S21, initializing an intersection point set for storing the first intersection point; S22, extracting a horizontal line from the horizontal line set, and extracting a vertical line from the vertical line set, to form a horizontal and vertical line pair; S23, determine whether two lines in the horizontal and vertical line pairs intersect; if yes, extract the coordinates of the intersection point and execute step S24; if no, calculate the distance between the two lines, if the distance between the two lines is less than the set distance threshold, extend one of the lines so that the two lines intersect, extract the coordinates of the intersection point and execute step S24; if no, return to step S22; S24, determine whether the intersection coordinates exist in the existing intersection set; if yes, update the four-dimensional matrix of the intersection according to the intersection of the two lines, and then return to step S22; If no, proceed to step S25; S25, determining whether a line in the horizontal and vertical line pair is connected to a point in the existing intersection point set; If the two lines are connected to each other, the multiple intersection point sets are merged, the intersection points of the horizontal and vertical line pairs are added to the merged intersection point set, and a four-dimensional matrix of the intersection points is constructed according to the intersection of the two lines, and then the process returns to step S22; If the two lines are connected to only one point in the intersection point set, the intersection point of the horizontal and vertical line pairs is added to the intersection point set, and a four-dimensional matrix of the intersection points is constructed according to the intersection of the two lines, and then the process returns to step S22; If not, a new intersection point combination is added, the intersection point of the horizontal and vertical line pairs is added to the newly added intersection point set, and a four-dimensional matrix of the intersection points is constructed according to the intersection of the two lines, and then the process returns to step S22; S26. Traverse the horizontal and vertical line pairs, extract all intersection sets, and restore the corresponding table area according to the intersection set. The intersection set corresponds to the table area one by one.
9. The method for merging and extracting PDF file cross-page tables based on logistic regression as claimed in claim 8, characterized in that: In S26, when restoring the corresponding table area according to the intersection set, all points in the intersection set are arranged on the page, and the lines in the horizontal line set and the vertical line set are arranged on the page according to the coordinates and the connection relationship with the intersection points; then the missing points are supplemented to obtain the table structure; the missing points refer to the points corresponding to the missing boundaries of the table.
10. A system for merging and extracting PDF file cross-page tables based on logistic regression, characterized in that: The invention comprises 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 method for merging and extracting cross-page tables of PDF files based on logistic regression as described in any one of claims 1 to 8.
Citation Information
Cited By
Contract detail extraction and classification method and system
CN121435939A
A method and system for contract detail extraction and classification
CN121435939B
