Table recognition method

By using a greedy algorithm to spread rectangular regions to identify tables, this method solves the problem of existing technologies being unable to identify multiple logically independent sub-tables. It achieves efficient and accurate identification of irregularly shaped tables, avoids interference from empty cells, and improves recognition efficiency and accuracy.

CN121706747APending Publication Date: 2026-03-20WEBANK (CHINA)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511809765.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-03
Publication Date
2026-03-20

AI Technical Summary

Technical Problem

Existing technologies cannot effectively identify multiple logically independent sub-tables, especially in irregularly shaped tables with variable header directions, and they heavily rely on manual configuration of mapping relationships, resulting in low recognition efficiency and insufficient accuracy.

Method used

By obtaining the total number of rows and columns of the target table, the cells are traversed and a rectangular area is expanded based on a greedy algorithm to identify logically independent sub-tables. No border lines or manual mapping are required. The greedy algorithm expands from the target cell downwards, to the right, or to the lower right corner until a series of empty rows or columns are accessed. The smallest bounding rectangle that forms a connected component is the sub-table.

Benefits of technology

It achieves efficient and accurate recognition of complex irregularly shaped tables, and can extract logically independent sub-tables without loss of quality, avoiding interference from individual empty cells and improving the accuracy and efficiency of recognition.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121706747A_ABST
    Figure CN121706747A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of artificial intelligence, and discloses a table recognition method, which comprises the following steps of: executing a sub-table acquisition step: traversing table cells of a target table, and if the current table cell is not accessed and is a non-empty table cell or the current table cell is an empty table cell but has a non-empty and non-accessed adjacent table cell, taking the table cell as a target table cell; and initializing the boundary of the rectangular region as the position of the target cell, spreading downwards and rightwards from the target cell or spreading towards the lower right corner from the target cell based on greedy algorithm logic by taking the target cell as a starting point until continuous M rows or continuous N columns are empty, in the process, the target cell and the bounding rectangles of all the spread cells form a sub-table. And then, continuing to traverse unaccessed cells in the target table to obtain all sub-tables in the target table. According to the method, each sub-table can be efficiently and accurately recognized in a lossless manner from various special-shaped tables with complicated layout.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, and in particular to a table recognition method. Background Technology

[0002] Enterprise core knowledge is often stored in the form of structured data in Excel documents. In an Excel document, a single worksheet often contains multiple sub-table structures with independent logical relationships (such as data blocks formed by dividing multiple data ranges, or cross-tabulations containing cross-row and cross-column statistical information, etc.).

[0003] In existing technology, one or more mappings are pre-configured based on the worksheet content. These mappings map the header of each sub-table in the worksheet to fields in a database table. When identifying a table, each row of cells in the worksheet is sequentially traversed, reading the data from each cell and matching it against each mapping. If a row matches a mapping, the data in that row is determined to be the header of a new sub-table. Matching continues; if the next row does not match any mapping, it is determined to be a data row in that new sub-table. This process continues until all rows in the worksheet have been traversed.

[0004] Existing solutions sequentially traverse each row of data in a worksheet, matching each cell's data within a row against a pre-configured mapping relationship to determine if the row is a header. This approach has limitations: First, when a single worksheet contains multiple logically independent sub-tables (i.e., multiple potential headers per row), it can only handle single-header scenarios and cannot correctly identify multi-header structures. Second, it only supports tables with headers in the row direction; it cannot effectively parse tables with headers in the column direction (i.e., column-header layout). Third, it heavily relies on user-defined mapping relationships; if the input is an unstructured worksheet without any configured mapping relationships, table extraction cannot be completed.

[0005] Therefore, there is an urgent need to provide a new table recognition method to accurately identify each sub-table from a worksheet containing multiple logically independent sub-tables. Summary of the Invention

[0006] To address the aforementioned issues, this application provides a table recognition method.

[0007] According to one aspect of the embodiments of this application, a table recognition method is disclosed, the method comprising the following steps: Obtain the total number of rows and columns of the target table. Each target table contains multiple sub-tables, which are separated by empty rows or columns, and each sub-table contains at least one non-empty cell. The sub-table acquisition steps are as follows: Traverse the cells of the target table. If the current cell is not visited and meets the area spread condition, then it is taken as the target cell. The area spread condition is: the current cell is a non-empty cell, or the current cell is an empty cell and there are non-empty but unvisited adjacent cells. Initialize the boundary of the rectangular area to the position of the target cell. Starting from the target cell, spread the rectangular area according to the area spread path until M consecutive rows or N consecutive columns are empty. The area spread path is to spread downwards and to the right from the target cell, or to spread from the target cell to the lower right corner. M and N are both integers greater than or equal to 1. Take the rectangular area formed by the target cell and the cells visited from the target cell as the starting point as a candidate sub-table. Determine whether the candidate sub-table has at least one non-empty cell. If so, extract all cells of the candidate sub-table and remove empty rows and columns to form the target sub-table; otherwise, take the candidate sub-table as the target sub-table. Continue traversing the unvisited cells in the target table and execute the sub-table acquisition step until the endpoint cell corresponding to the total number of rows and columns is accessed, so as to obtain all sub-tables in the target table.

[0008] The technical solutions provided by the embodiments of this application have at least the following beneficial effects: The scheme disclosed in this application first obtains the total number of rows and columns of the target table; then, it performs the sub-table acquisition step, that is: traversing the cells of the target table, if the current cell has not been visited and is a non-empty cell, or although it is an empty cell, it has non-empty and unvisited adjacent cells, then it is taken as the target cell; the boundary of the rectangular area is initialized as the position of the target cell, and based on the greedy algorithm logic, starting from the target cell, it spreads downward and to the right from the target cell, or spreads from the target cell to the lower right corner, to spread the rectangular area until it visits M consecutive rows or N consecutive columns that are empty. During this process, the target cell and all the cells that have been spread form a connected component, and the bounding rectangle of the entire connected component is the identified complete sub-table; then, it continues to traverse the unvisited cells in the target table and repeatedly executes the sub-table acquisition step until it visits the endpoint cell corresponding to the total number of rows and columns, thus obtaining all the sub-tables in the target table. This method does not rely on cell border markings or manual annotation mapping, and the individual empty cells inside the sub-table will not interfere with the recognition results. It can efficiently and accurately identify each sub-table from various irregularly shaped tables with complex layouts without loss. Attached Figure Description

[0009] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the specification, serve to explain the principles of this application.

[0010] Figure 1 A schematic diagram of a worksheet and mapping relationships is shown; where (a) is a worksheet and (b) is two mapping relationships configured for the worksheet shown in (a).

[0011] Figure 2 This diagram illustrates an irregularly shaped table containing multiple logically independent sub-tables.

[0012] Figure 3 A flowchart of a table recognition method according to an embodiment of this application is shown.

[0013] Figure 4 A detailed flowchart of the downward propagation steps of one embodiment of this application is shown.

[0014] Figure 5 A detailed flowchart of the rightward propagation step of one embodiment of this application is shown.

[0015] Figure 6 A detailed flowchart of the downward propagation step of another embodiment of this application is shown.

[0016] Figure 7 A detailed flowchart of the rightward spread step of another embodiment of this application is shown.

[0017] Figure 8 A detailed flowchart of the step of spreading to the lower right corner according to an embodiment of this application is shown.

[0018] Figure 9 A detailed flowchart of the calculation steps of an embodiment M of this application is shown.

[0019] Figure 10 A detailed flowchart of the calculation steps of an embodiment N of this application is shown.

[0020] Figure 11 An example of an embodiment of this application is shown in the target table.

[0021] Figure 12 The diagram illustrates the process of extracting sub-table 1 according to an embodiment of this application; wherein (a) is the starting point, (b) is the table explored in the first round of downward expansion, and (c) is the explored sub-table 1.

[0022] Figure 13 The diagram illustrates the change process of the visited table according to an embodiment of this application; wherein (a), (b), (c), and (d) are schematic diagrams of the visited table at different propagation stages.

[0023] Figure 14 The diagram illustrates the process of extracting sub-table 2 according to an embodiment of this application; where (a) is the starting point, (b) is the table explored by the second round of execution spreading to the right and downward, and (c) is the explored sub-table 2.

[0024] Figure 15 The diagram illustrates the process of extracting sub-table 3 according to an embodiment of this application; wherein, (a) is the starting point, (b) is the table explored by downward expansion in the first round, (c) is the table explored by right expansion in the first round, and (d) is the explored sub-table 3.

[0025] Figure 16 A detailed flowchart of the header recognition steps in one embodiment of this application is shown.

[0026] Figure 17 The role definition and task requirements section of a prompt word template constructed according to an embodiment of this application is shown.

[0027] Figure 18 A schematic diagram of a sub-table of one embodiment of this application is shown.

[0028] Figure 19 A block diagram of a computer device according to an embodiment of this application is shown.

[0029] Figure 20 A computer system architecture block diagram is shown for implementing some embodiments of this application.

[0030] The annotations in the attached figures are explained as follows: 1200. Computer equipment; 1201. Processor; 1202. Memory; 1300. Computer system; 1301. CPU; 1302. ROM; 1303. RAM; 1304. Bus; 1305. I / O interface; 1306. Input section; 1307. Output section; 1308. Storage section; 1309. Communication section; 1310. Driver; 1311. Removable media. Detailed Implementation

[0031] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, they are provided so that the description of this application will be more complete and fully convey the concept of the exemplary embodiments to those skilled in the art.

[0032] For worksheets containing multiple sub-tables, there are three main methods for table recognition. Method 1: First, convert the worksheet content into an image, then use an OCR model to recognize the worksheet. While OCR models can extract sub-tables to some extent, they suffer from high time consumption and low accuracy. Method 2: Use boundary detection. This method uses cell border attributes as identifiers for sub-table boundaries, scanning all cell border attributes (top / bottom / left / right borders), and then combining them into a table area using a closed rectangle detection algorithm. This method cannot be implemented when the table has no visible borders. Method 3: Use manual annotation and mapping relationships to recognize sub-table content. This method is described in detail below.

[0033] Suppose an Excel document has a worksheet like this: Figure 1 As shown in (a), Method 3 identification Figure 1 When dealing with multiple sub-tables in the worksheet shown in (a), one or more mappings need to be configured based on the worksheet content. These mappings map the header of each sub-table in the worksheet to a field in a database table. Assume two mappings are configured as follows: Figure 1 Mapping relation 1 and mapping relation 2 are shown in (b).

[0034] After configuring the mapping relationships, iterate through each row of data in the worksheet sequentially, reading the data from each cell in that row and matching it against each mapping relationship. If a row matches a mapping relationship, it means that the data in that row is the header of a new table. Figure 1 For example, when the first row of the worksheet, "Serial Number|Field Name|Type|Primary Key|Chinese Name|Field Name|Remarks", is read and matched with the mapping relationship, it is found that the row can match the mapping relationship 1. This means that the first row is a table header, which is recorded as the header of sub-table 1.

[0035] Continuing to iterate through row 2, no mapping relationship can be found, indicating that row 2 is a data row of sub-table 1. Repeating this process until row 12, where the data matches mapping relationship 2, indicates that row 12 is the header of the next new table, denoted as the header of sub-table 2. This also means that rows 1-11 constitute the content of sub-table 1.

[0036] Continue iterating through the subsequent rows until all rows of the worksheet have been traversed. Since no further rows can be matched with the mapping relationship, rows 12 to 20 are the contents of sub-table 2.

[0037] The above method requires manual configuration of mapping relationships in advance, and is essentially a "supervised" table parsing algorithm. It can only recognize the simplest top-down multi-table layouts and does not support the recognition and parsing of irregularly shaped tables. If an irregularly shaped table without a mapping relationship is given, it cannot be processed. Furthermore, each row can only have one header; if multiple sub-tables are side by side in the horizontal direction, it cannot be recognized. In addition, it can only recognize tables whose headers are extracted in the row direction; it cannot recognize tables whose headers are in the column direction.

[0038] To address this, this application provides a novel table recognition method. First, it parses the target table structure to obtain its total number of rows and columns. Then, it performs a sub-table acquisition step, specifically: traversing each cell in the target table, if the current cell has not been accessed and meets either of the following conditions—the cell itself contains valid data (a non-empty cell), or the cell is empty but has non-empty, unaccessed adjacent cells—then the cell is identified as the target cell. Starting from this target cell, the rectangular region boundary of the sub-table to be identified is initialized (the initial boundary is the row and column position of the target cell). Based on the dynamic propagation logic of a greedy algorithm, the sub-table is further refined from the target cell... Starting from a cell, the algorithm gradually expands the boundary of the rectangular area by extending downwards, to the right, or to the lower right corner, continuously incorporating adjacent cells until a region of M consecutive rows or N consecutive columns of empty cells is reached. During this expansion, the target cell and the cells traversed together form a logically connected branch, and the smallest bounding rectangle of this branch is the identified complete sub-table. Next, the algorithm continues to traverse the remaining unvisited cells in the target table, repeatedly executing the above sub-table acquisition steps until the endpoint cell corresponding to the total number of rows and columns is reached. Finally, all sub-tables identified through this sub-table acquisition step are extracted from the target table. This solution does not rely on cell border markings, does not require manual pre-annotation, and individual empty cells within the sub-table do not interfere with the recognition results. It can efficiently and accurately extract logically independent sub-tables from irregularly shaped tables with complex layouts (such as staggered cell arrangements and diverse header directions) without loss of quality.

[0039] First, we will explain some of the terms used in this application.

[0040] Retrieval-Augmented Generation (RAG) is a technical framework that integrates real-time retrieval with large language model generation. Its core processes include retrieval, augmentation, and generation. Retrieval: When a user asks a question, relevant fragments are searched in real-time from external knowledge bases (such as databases or document sets). Augmentation: The retrieved information is integrated with the internal knowledge of the large language model to form an enhanced input. Generation: Based on the augmented context, the large language model generates accurate and traceable answers.

[0041] Large Language Models (LLMs): Deep learning models trained on large amounts of text data that can generate natural language text or understand the meaning of language text. LLMs can handle a variety of natural language tasks, such as text classification, question answering, and dialogue, and are an important pathway to artificial intelligence.

[0042] Greedy Algorithms: Also known as greedy algorithms, these are algorithms that make the best (locally optimal) decision at each step, hoping to achieve a globally optimal solution. Essentially, they iteratively approach the optimal solution by finding locally optimal solutions. Key characteristics include: no backtracking (once a choice is made, it is not changed; efficiency: typically has low time complexity (e.g., O(n log n)); limitations: they do not guarantee a globally optimal solution (the accumulation of local optima does not necessarily lead to a globally optimal solution).

[0043] Irregularly shaped tables: A worksheet containing multiple logically independent sub-tables, where the layout of the tables can be arbitrarily staggered, the header direction can be either row-oriented or column-oriented, and the header may be a composite header composed of multiple rows or columns. Examples include... Figure 2 As shown.

[0044] The implementation details of the technical solutions in the embodiments of this application are described in detail below.

[0045] Figure 3 A flowchart of a table recognition method according to an embodiment of this application is shown. (See attached document.) Figure 3 As shown, the table recognition method includes at least the following steps S301 to S306, which are described in detail below.

[0046] In step S301, the total number of rows and columns of the target table are obtained.

[0047] Each target table contains multiple sub-tables. The header directions of the sub-tables can be the same or different. Sub-tables are separated by blank rows or columns; there can be multiple blank rows or columns between sub-tables. Each sub-table must contain at least one non-empty cell, that is, at least one cell containing valid data.

[0048] In step S302, the cells of the target table are traversed. If the current cell has not been visited and the area spread condition is met, it is used as the target cell.

[0049] The conditions for region spread are: the current cell is a non-empty cell; or, the current cell is an empty cell and there are non-empty but unvisited adjacent cells.

[0050] Specifically, when the area spread path in step S303 extends downwards and to the right from the target cell, the adjacent cells can be cells located to the left, right, above, or below the target cell and adjacent to that target cell. When the area spread path in step S303 extends from the target cell to the lower right corner, the adjacent cells can be cells located to the upper left or lower right of the target cell and adjacent to that target cell.

[0051] In some embodiments, the cells of the target table are traversed. If the current cell has not been accessed and the area spread condition is met, it is used as the target cell. This includes: checking whether the current cell has been accessed; if the current cell has been accessed, the cell is skipped; otherwise, checking whether the current cell belongs to a sub-table. Specifically, it is determined whether any of the following conditions are met: Condition 1: The current cell is a non-empty cell; Condition 2: The current cell is an empty cell, but its adjacent cells (to the right, below, or lower right) contain non-empty and unaccessed cells; Condition 3: The current cell is an empty cell, but its adjacent cells (to the left, above, or upper left) contain non-empty and unaccessed cells. If any of the conditions are met, it indicates that the cell belongs to a sub-table, and the following step S303 is executed. In step S303, the boundary of the rectangular area is initialized to the position of the target cell. Starting from the target cell, the rectangular area is expanded according to the area expansion path until M consecutive rows or N consecutive columns are empty.

[0052] The region spread path can extend downwards and then to the right from the target cell; that is, the region spread path includes both downward and rightward expansion. In some embodiments, it can first extend downwards from the target cell until M consecutive rows are empty; then, it extends rightwards from the target cell until N consecutive columns are empty. In other embodiments, it can first extend rightwards from the target cell until N consecutive columns are empty; then, it extends downwards from the target cell until M consecutive rows are empty. Each downward expansion increments the row count by 1; each rightward expansion increments the column count by 1.

[0053] In some embodiments, starting from the target cell, the rectangular region is spread along the region spread path, including performing a downward spread step and a rightward spread step.

[0054] In the downward propagation step, the target cell's row is set as the starting row. If the starting row does not reach the last row of the target table, check if the next M consecutive rows from the starting row are empty rows. If so, the downward propagation ends; otherwise, the next row is used as the starting row to check cells downwards.

[0055] In some embodiments, such as Figure 4 As shown, the downward propagation step includes at least the following steps S401 to S404, which are described in detail below.

[0056] In step S401, set the row containing the target cell to the start row.

[0057] In step S402, it is determined whether the starting row has reached the last row of the target table. If so, the downward propagation ends; otherwise, step S403 is executed.

[0058] In step S403, check whether the M consecutive lines starting from the next line of the starting line are empty lines. If so, end the downward propagation; otherwise, proceed to step S404.

[0059] In step S404, the next line is set as the start line, and we return to step S402 to continue checking the cells downwards.

[0060] In the rightward expansion step, the column containing the target cell is set as the starting column. If the starting column does not reach the last column of the target table, check if the next N consecutive columns starting from the starting column are empty. If so, the rightward expansion ends; otherwise, the next column is used as the starting column to check cells to the right.

[0061] In some embodiments, such as Figure 5 As shown, the rightward spread step includes at least the following steps S501 to S504, which are described in detail below.

[0062] In step S501, the column containing the target cell is set as the starting column.

[0063] In step S502, it is determined whether the starting column has reached the last column of the target table. If so, the rightward extension ends; otherwise, step S503 is executed.

[0064] In step S503, check whether the next N consecutive columns starting from the first column are empty columns. If so, stop spreading to the right; otherwise, proceed to step S504.

[0065] In step S504, starting with the next column, return to step S502 to continue checking cells to the right.

[0066] exist Figure 4 and Figure 5 In the illustrated embodiment, the algorithm expands sequentially downwards or to the right from the target cell. Each expansion only needs to consider one adjacent cell below or to the right of the current cell. When the bottom or right boundary of the table is reached, it only needs to check whether the current row has reached the total number of rows or whether the current column has reached the total number of columns. The algorithm's logic is easy to understand and implement, with low code complexity and low error rate.

[0067] In some embodiments, the starting row minR = the ending row maxR = the row containing the target cell, the starting column minC = the ending column maxC = the column containing the target cell, and then the downward propagation step and the rightward propagation step are performed.

[0068] In the downward propagation step, iterative execution is performed as follows: If maxR < total number of rows, check if the M consecutive rows starting from row maxR+1 are empty rows. If the M consecutive rows starting from row maxR+1 are empty rows, skip the empty rows, mark the cells from minC to maxC in the rows from maxR+1 to maxR+M in the access matrix as visited, and end the downward propagation. If the M consecutive rows starting from row maxR+1 are not all empty rows, set maxR = maxR+1, and check the sub-cells from minC to maxC.

[0069] That is, in step S402, determining whether the starting row has not reached the last row of the target table includes: determining whether maxR < total number of rows. If it does, the starting row is determined not to have reached the last row of the target table; otherwise, the starting row is determined to have reached the last row of the target table. In step S403, checking whether the M consecutive rows starting from the next row of the starting row are empty rows includes: checking whether the M consecutive rows starting from row maxR+1 are empty rows. If the M consecutive rows starting from row maxR+1 are empty rows, the empty rows are skipped, and the downward propagation ends; if the M consecutive rows starting from row maxR+1 are not all empty rows, then step S404 is executed. In step S404, the next row is the starting row, including: setting maxR = maxR+1.

[0070] In some embodiments, such as Figure 6 As shown, the downward propagation step includes at least the following steps S601 to S603, which are described in detail below.

[0071] In step S601, determine whether maxR < total number of rows. If yes, proceed to step S602; otherwise, end the downward propagation.

[0072] In step S602, check whether the M consecutive lines starting from line maxR+1 are empty lines. If the M consecutive lines starting from line maxR+1 are empty lines, skip the empty lines and end the downward propagation. If the M consecutive lines starting from line maxR+1 are not all empty lines, proceed to step S603.

[0073] In step S603, let maxR = maxR + 1, and return to step S601 to continue checking the sub-cells from minC to maxC in row maxR + 1.

[0074] Understandably, when returning to step S601, the new maxR is the original maxR+1, in order to check the sub-cells from minC to maxC row by row.

[0075] In the rightward expansion step, iterative execution is performed as follows: if maxC < total number of columns, check if the consecutive N columns starting from maxC+1 are empty columns. If the consecutive N columns starting from maxC+1 are empty columns, skip the empty columns and end the rightward expansion. If the consecutive N columns starting from maxC+1 are not all empty columns, set maxC = maxC+1 and check the sub-cells from minR to maxR.

[0076] That is, in step S502, determining whether the starting column has not reached the last column of the target table includes: determining whether maxC < total number of columns. If it does, the starting column is determined not to have reached the last column of the target table; otherwise, the starting column is determined to have reached the last column of the target table. In step S503, checking whether the N consecutive columns starting from the next column of the starting column are empty includes: checking whether the N consecutive columns starting from column maxC+1 are empty. If the N consecutive columns starting from column maxC+1 are empty, the empty columns are skipped, and the rightward propagation ends; if the N consecutive columns starting from column maxC+1 are not all empty, step S504 is executed. In step S504, using the next column as the starting column includes: setting maxC = maxC+1.

[0077] In some embodiments, such as Figure 7 As shown, the rightward spread step includes at least the following steps S701 to S703, which are described in detail below.

[0078] In step S701, determine whether maxC < total number of columns. If yes, proceed to step S702; otherwise, end the rightward propagation.

[0079] In step S702, check whether the consecutive N columns starting from column maxC+1 are empty columns. If the consecutive N columns starting from column maxC+1 are empty columns, skip the empty columns and end the rightward propagation. If the consecutive N columns starting from column maxC+1 are not all empty columns, proceed to step S703.

[0080] In step S703, let maxC = maxC + 1, and return to step S701 to continue checking the sub-cells from minR to maxR in row maxC + 1.

[0081] Understandably, when returning to step S701, the new maxC is the original maxC+1, in order to check the sub-cells from minR to maxR row by row.

[0082] In some embodiments, before performing the sub-table retrieval step, i.e., before performing the downward and rightward propagation steps, an access matrix is ​​first initialized. This access matrix is ​​used to mark the access status of each cell. During the downward and rightward propagation steps, after a cell is checked, the cell is marked as visited (true) in the access matrix. Therefore, when it is necessary to determine whether a cell has been visited later, it is not necessary to repeatedly check the cell; only the access matrix needs to be checked. Furthermore, it ensures that each cell belongs to only one sub-table.

[0083] In some embodiments, before performing the sub-table retrieval step, i.e., before performing the downward and rightward propagation steps, a mask matrix is ​​first initialized. This mask matrix is ​​used to mark whether each cell is empty. During the downward and rightward propagation steps, when an empty cell is detected, it is marked as empty (false) in the mask matrix; when a non-empty cell is detected, it is marked as non-empty (true) in the mask matrix. Therefore, when it is necessary to determine whether a cell is empty later, it is not necessary to repeatedly check the cell; only the mask matrix needs to be checked.

[0084] In some embodiments, before performing the sub-table retrieval step, i.e., before performing the downward and rightward spread steps, the spread flag is first initialized to spreadable. This spread flag is used to ensure that the downward and rightward spread steps are executed at least once. When performing the downward spread step, the spread flag is updated to non-spreadable. During the downward spread process, if M consecutive rows starting from the row after the starting row (maxR+1 rows) are not all empty rows, the spread flag is updated to spreadable to iterate through the downward spread steps. When performing the rightward spread step, the spread flag is updated to non-spreadable. During the rightward spread process, if N consecutive columns starting from the column after the starting column (maxC+1 columns) are not all empty columns, the spread flag is updated to spreadable to iterate through the rightward spread steps.

[0085] In some embodiments, in the sub-table acquisition step, first set the target cell (r, c) as the upper left corner of the initial rectangular area, where r is the row index (from 0 to rows - 1) and c is the column index (from 0 to cols - 1); let the starting row minR = r, the ending row maxR = r, the starting column minC = c, and the ending column maxC = c. That is, at the beginning, the table area has only one cell (r, c), and the starting row, ending row, starting column, and ending column of the table are minR, maxR, minC, and maxC respectively. Before performing downward spread, initialize the spread flag grow = true (spreadable), and when performing downward spread, set the spread flag grow = false (non-spreadable); if maxR < rows - 1 (i.e., the current rectangle has not reached the bottom boundary), then check whether the consecutive M rows starting from row maxR + 1 are all empty rows (i.e., all cells in these rows from column minC to maxC are false in the mask matrix). If these rows are empty, skip these empty rows, set the new maxR = maxR + M, and mark the skipped empty row area (rows from maxR + 1 to the new maxR, columns from minC to maxC) as visited (true) in the access matrix; if the consecutive M rows are not all empty, directly spread one row (maxR plus 1) and set grow = true. Before performing rightward spread, initialize the spread flag grow = true (spreadable), and when performing rightward spread, set the spread flag grow = false (non-spreadable); if maxC < cols - 1 (i.e., the current rectangle has not reached the right boundary), then check whether the consecutive N columns starting from column maxC + 1 are all empty columns (i.e., all cells in these columns from row minR to maxR are false in the mask matrix). If these columns are empty, skip these empty columns, set the new maxC = maxC + N, and mark the skipped empty column area (columns from maxC + 1 to the new maxC, rows from minR to maxR) as visited (true) in the access matrix; if the consecutive N columns are not all empty, directly spread one column (maxC + 1) and set grow = true.

[0086] In some embodiments, after the spread ends, the rectangular boundary is also adjusted to ensure that it does not exceed the boundary. Specifically, the rectangular boundary is adjusted based on the relationship maxR = min(maxR, rows - 1), maxC = min(maxC, cols - 1). Here, rows – 1 represents the last row, and cols - 1 represents the last column.

[0087] The area spread path can also be from the target cell to the bottom right corner, that is, from the target cell to the right and down simultaneously. Each spread increments both the row and column by one.

[0088] In some embodiments, starting from the target cell, the rectangular area is extended according to the area extension path, including: starting from the target cell, if the row where the starting point is located does not reach the last row of the target table and the column where the starting point is located does not reach the last column of the target table, then check whether the L consecutive cells starting from the downstream neighbor cell of the starting point in the lower right direction are empty. If so, the extension ends; otherwise, starting from the downstream neighbor cell, the cells are checked in the lower right direction.

[0089] In some embodiments, such as Figure 8 As shown, starting from the target cell, the process of spreading a rectangular area along the area spread path includes at least the following steps S801 to S804, which are detailed below.

[0090] In step S801, the target cell is taken as the starting point.

[0091] In step S802, determine whether the following conditions are met: the row where the starting point is located has not reached the last row of the target table, and the column where the starting point is located has not reached the last column of the target table. If so, proceed to step S803; otherwise, end the propagation.

[0092] In step S803, check if the L consecutive cells starting from the downstream neighbor cell of the starting point in the lower right direction are empty. If so, end the propagation; otherwise, proceed to step S804.

[0093] The downstream neighbor cell is the cell located at the bottom right corner of the target cell and adjacent to the target cell.

[0094] Where L is an integer greater than or equal to 1. In some embodiments, L is set to 1. In some embodiments, L is set to 2. In some embodiments, L is set to 3.

[0095] In step S804, starting from the downstream neighboring cell, return to step S802 to continue checking cells in the direction of the lower right corner.

[0096] exist Figure 8 In the illustrated embodiment, the process extends from the target cell to the bottom right corner, eliminating the need to check cells not located in the bottom right direction. This reduces the number of cells checked and improves table recognition efficiency.

[0097] Both M and N are integers greater than or equal to 1. M and N can be equal or unequal. M can be greater than N or less than N. In some embodiments, M=2 and N=1. In some embodiments, M=1 and N=2. In some embodiments, M=2 and N=2. In some embodiments, M=3 and N=2. In some embodiments, M=2 and N=3. M and N can be obtained through manual input or through data statistics.

[0098] In some embodiments, such as Figure 9 As shown, the calculation steps for M include at least the following steps S901 to S903, which are described in detail below.

[0099] In step S901, all rows of the target table are traversed, and the distribution of the number of consecutive empty rows in the target table is counted.

[0100] In step S902, the results are sorted according to the number of consecutive blank lines based on the statistical results.

[0101] Sort the results based on the number of consecutive blank lines, or sort them in ascending order based on the number of consecutive blank lines.

[0102] In step S903, the number of consecutive blank lines corresponding to the preset quantile after sorting is taken as M, and M is constrained to be ≤ 5.

[0103] The preset quantile is ≥80%. In some embodiments, the preset quantile is 90%, that is, the number of consecutive blank rows corresponding to the 90th quantile is taken as M. If a table has multiple sub-tables, the number of blank rows between most sub-tables should be greater than the number of blank rows within a single sub-table. Therefore, selecting a larger quantile to calculate M can separate most sub-tables in the row direction.

[0104] In some embodiments, such as Figure 10 As shown, the calculation steps for N include at least the following steps S1001 to S1003, which are described in detail below.

[0105] In step S1001, all columns of the target table are traversed, and the distribution of the number of consecutive empty columns in the target table is counted.

[0106] In step S1002, the results are sorted according to the number of consecutive empty columns based on the statistical results.

[0107] Sort the results based on the number of consecutive blank lines, or sort them in ascending order based on the number of consecutive blank lines.

[0108] In step S1003, the number of consecutive empty columns corresponding to the preset quantile after sorting is taken as N, and N is constrained to be ≤ 5.

[0109] The preset quantile is ≥80%. In some embodiments, the preset quantile is 90%, that is, the consecutive empty columns corresponding to the 90th quantile are taken as N. If a table has multiple sub-tables, the number of empty columns between most sub-tables should be greater than the number of empty columns within a single sub-table. Therefore, selecting a larger quantile to calculate N can separate most sub-tables in the column direction.

[0110] In step S304, the target cell and the rectangular area formed by the target cell and the cells accessed from the target cell are used as a candidate sub-table.

[0111] That is, the smallest bounding rectangle of the target cell and the cells accessed from the target cell is used as a candidate sub-table.

[0112] In step S305, it is determined whether there is at least one non-empty cell in the candidate sub-table. If so, all cells of the candidate sub-table are extracted and empty rows and columns are removed to form the target sub-table; otherwise, the candidate sub-table is used as the target sub-table.

[0113] In step S306, continue traversing the unvisited cells in the target table and determine whether the endpoint cell corresponding to the total number of rows and columns has been visited. If yes, the process ends; otherwise, return to step S302 and repeat steps S302-S305 to obtain all sub-tables in the target table.

[0114] Below, the area spread path is defined as spreading downwards and to the right from the target cell. Figure 11 Taking the target table shown as an example, the process of identifying the sub-tables will be explained.

[0115] First, configure M = 2, which represents the minimum number of consecutive blank rows required to identify two independent sub-tables. Configure N = 1, which represents the minimum number of consecutive blank columns required to identify two independent sub-tables.

[0116] Get the total number of rows (rows=6) and total number of columns (cols=6) of the target worksheet. Define a visit matrix `visited`: a Boolean two-dimensional array of size `rows × cols` (6×6), initially set to `false`, used to mark inspected cells to avoid duplicate processing. Define a mask matrix `nonEmptyMask`: a Boolean two-dimensional array of size `rows × cols` (6×6); it fills the mask matrix based on the value of each cell in the target table, marking a non-empty cell as `true` and a non-empty cell as `false`.

[0117] The algorithm begins with the first cell in the target table: (0,0) "Name". The currently explored rectangular region is minR=maxR=1, minC=maxC=1, as shown below. Figure 12 As shown in (a), it forms a rectangle with 1 row and 1 column.

[0118] First, perform a downward expansion: starting from maxR+1=2 (row 2), check downwards; check the area from column minC=1 to column maxC=1 in row 2, this area contains only one cell (1,0). Cell (1,0) is a non-empty cell with the value "Lilei", add it to the rectangular area, and continue checking downwards; check the area from column minC=1 to column maxC=1 in row 3, this area contains only one cell (2,0), which is empty, accumulating one empty row, continue checking downwards; check the area from column minC=1 to column maxC=1 in row 4, this area contains only one cell (3,0), which is empty, accumulating two empty rows, stop checking downwards. The table explored at this point is as follows. Figure 12 As shown in (b), the explored region is a rectangle bounded by minR=1, maxR=2, minC=maxC=1.

[0119] Next, proceed with the rightward expansion: starting from maxC+1=2 (column 2), check to the right; check the area from minR=1 to maxR=2 in column 2, which contains cells (0,1) and (0,2). Find the non-empty cells (0,1) "age" and (1,1) "30", add them to the explored table, and continue checking to the right; check the area from minR=1 to maxR=2 in column 3, finding empty cells (0,2) and (1,2), accumulating one empty column, and continue checking to the right; check the area from minR=1 to maxR=2 in column 4, finding empty cells (0,3) and (1,3), accumulating two empty columns, and stop checking to the right. The table now looks like... Figure 12 As shown in (c), the explored rectangular region is a 2x2 rectangle bounded by minR=1, maxR=2, minC=1, and maxC=2.

[0120] Continue downwards: Starting from maxR+1=3, i.e., row 3, check downwards; check the area from column minC=1 to column maxC=2 in row 3, finding empty cells (2,0) and (2,1), accumulating one empty row, continue checking downwards; check the area from column minC=1 to column maxC=2 in row 4, finding empty cells (3,0) and (3,1), accumulating two empty rows, stop checking downwards. The table already explored remains unchanged. Figure 12The table shown in (c) shows the explored rectangular region, which is a 2x2 rectangle bounded by minR=1, maxR=2, minC=1, and maxC=2.

[0121] Next, proceed with the rightward expansion: starting from maxC+1=3 (the 3rd column), check to the right; check the area from minR=1 to maxR=2 in the 3rd column, which contains two empty cells (0,2) and (1,2), accumulating one empty column, continue checking to the right; check the area from minR=1 to maxR=2 in the 4th column, finding empty cells (0,3) and (1,3), accumulating two empty columns, stop checking to the right. The table already explored remains unchanged. Figure 12 The table shown in (c) is an example. Because the table did not expand downwards or to the right during this spread, the spread starting at (0,0) terminated. Finally, starting at (0,0), a greedy algorithm detected a rectangular region... Figure 12 The table shown in (c) is the first sub-table. All visited cells are marked as visited. The table's visit history is then recorded in the `visited` table, as shown below. Figure 13 As shown in (a).

[0122] Continue with the next unvisited cell as the starting point to execute the propagation logic.

[0123] Check the current visited table and find the next unvisited cell (0,2). Since (0,2) is an empty cell and the cells to its right, below, and to its lower right are all empty or visited, mark (0,2) as visited and skip it. Find the next unvisited cell (0,3). (0,3) is an empty cell, but the cell to its right is not empty, satisfying the condition for a starting point (target table). Therefore, start from (0,3) and continue looping through the table.

[0124] Starting point: Cell (0,3) is an empty cell; initialize the rectangular area as an empty table, such as... Figure 14 As shown in (a).

[0125] Initialize the currently explored rectangular region as minR=1, maxR=1, minC=4, maxC=4.

[0126] The first round of downward propagation starts from (0,3): starting from maxR+1=2, i.e., the second row, the check moves downwards; the area from minC=4 to maxC=4 in the second row is checked, and there is only one empty cell (1,3) in the current area, so one empty row has been encountered and the check continues downwards; the area from minC=4 to maxC=4 in the third row is checked, and there is only one empty cell (2,3) in the current area, so two empty rows have been encountered and the check stops, at which point maxR is still =1.

[0127] The first round of rightward expansion begins at (0,3): starting from maxC+1=5 (column 5), the check moves rightward; it examines the area from minR=1 to maxR=1 in column 5, finding one non-empty cell (0,4) "Product", which is added to the rectangular area, and the check continues rightward; it then examines the area from minR=1 to maxR=1 in column 6, finding one non-empty cell (0,5) "Price", which is added to the rectangular area, and the check continues rightward. Since the current column number is 6, reaching the maximum number of columns in the table, the rightward check stops, and maxC=6. Because there is data expansion in the table during this round of downward and rightward checks, the next round of downward and rightward checks begins.

[0128] The second round of downward expansion begins at (0,3): starting from maxR+1=2 (row 2), the check moves downwards; the area from column minC=4 to column maxC=6 in row 2 is checked. The current area has one empty cell (1,3) and two non-empty cells (1,4) "Apple" and (1,5) "¥10". The current row is added to the rectangular area, maxR+1 becomes 2, and the check continues downwards; the area from column minC=4 to column maxC=6 in row 3 is checked. All three cells in the current area are empty, resulting in one empty row encountered, so the check continues downwards; the area from column minC=4 to column maxC=6 in row 4 is checked. All three cells in the current area are empty, resulting in two empty rows encountered, so the check stops, and maxR=2.

[0129] Perform the second round of rightward checking starting from (0,3): Since the current column number is 6, which has reached the maximum number of columns in the table, no further rightward checking is performed; at this point, maxC = 6. The table area that has been explored at this point is as follows: Figure 14 As shown in (b), the rectangle has 2 rows and 3 columns. The explored rectangular region is a 2x3 rectangle bounded by minR=1, maxR=2, minC=4, and maxC=6.

[0130] Remove blank rows and columns from the table area to get Figure 14The table shown in (c) is the second sub-table. All visited cells are marked as visited. The table's visit history is then recorded in the `visited` table, as shown below. Figure 13 As shown in (b).

[0131] Continue with the next unvisited cell as the starting point to execute the propagation logic.

[0132] Checking the current visited table, the next unvisited cell is (1,2). Since (1,2) is an empty cell and the cells to its right, below, and below its right are all empty or have been visited, (1,2) is marked as visited and skipped. The next unvisited cell is (2,0). (2,0) is an empty cell and the cells to its right, below, and below its right are all empty or have been visited, so (2,0) is marked as visited and skipped. Similarly, (2,1), (2,2), (2,3), (2,4), and (2,5) in row 3 do not meet the conditions for a starting point, so they are all marked as visited and skipped. The visited status of the table is now recorded in the visited table, as follows: Figure 13 As shown in (c).

[0133] Take the next unvisited cell (3,0). (3,0) is an empty cell, but the cell below it (4,0) is not empty, satisfying the condition of being the starting point (target cell). Then, starting from (3,0), continue to loop through the table.

[0134] Cell (3,0) is an empty cell; the table range is initialized to an empty table, as shown below. Figure 15 As shown in (a).

[0135] Initialize the currently explored rectangular region as minR=4, maxR=4, minC=1, maxC=1.

[0136] The first round of downward expansion starts from (3,0): Starting from maxR+1=5 (row 5), the check proceeds downwards; the area from column minC=1 to column maxC=1 in row 5 is checked. The current area contains only one non-empty cell, (4,0) "Id", which is added to the table area. maxR is incremented by 1 to become 5, and the check continues downwards; the area from column minC=1 to column maxC=1 in row 6 is checked. The current area contains only one non-empty cell, (5,0) "001", which is added to the table area. maxR is incremented by 1 to become 6, and the check continues downwards; row 7 is checked, but because the maximum number of rows in the table is only 6, the downward expansion stops. The table area explored at this point is as follows: Figure 15 As shown in (b).

[0137] Next, the first round of rightward expansion is executed, starting from (3,0): Starting from maxC+1=2 (the second column), the check moves rightward; the area from minR=4 to maxR=6 in the second column is checked. This area contains one empty cell (3,1) and two non-empty cells (4,1) "Dept" and (5,1) "IT". This is added to the rectangular area, maxC is increased by 1 to 2, and the check continues to the right; the area from minR=4 to maxR=6 in the third column is checked. This area contains three empty cells (3,2), (4,2), and (5,2), accumulating one empty column, so the check continues to the right; the area from minR=4 to maxR=6 in the fourth column is checked. This area contains one empty cell (3,3) and two non-empty cells (4,3) "Date" and (5,3) "2025-02-02". This is added to the rectangular area. Since maxC=4, continue checking to the right; check the area from minR=4 to maxR=6 in column 5. The current area contains one empty cell (3,4) and two non-empty cells (4,4) "State" and (5,4) "Active". Add this to the rectangular area, maxC=5, continue checking to the right; check the area from minR=4 to maxR=6 in column 6. The current area contains three empty cells (3,5), (4,5), and (5,5). One empty column has been encountered, continue checking to the right; check column 7. Since the current column number is 6, the maximum number of columns in the table has been reached, stop checking to the right. At this point, maxC=6. The table area explored so far is as follows: Figure 15 As shown in (c), the rectangle has 3 rows and 5 columns. The explored rectangular region is a 3x6 rectangle bounded by minR=4, maxR=6, minC=1, and maxC=6.

[0138] Remove blank rows and columns from the table area to get Figure 15 The table shown in (d) is the third sub-table detected. This round of inspection also marks all visited cells as visited. The table's visit history is now recorded in the visited table, as shown below. Figure 13 As shown in (d). At this point, all cells have been visited, so the algorithm terminates. The algorithm parses the target table into three independent sub-tables, namely... Figure 12 Sub-table 1 shown in (c) Figure 14 Sub-table 2 shown in (c) Figure 15 Sub-table 3 is shown in (d).

[0139] In some embodiments of this application, after performing the above-described sub-table identification step, a header identification step is further performed. The header identification step includes at least the following steps S1101 to S1103, which are described in detail below.

[0140] In step S1101, the sample length is determined.

[0141] The sample length can be either the row sample length or the column sample length, or it can be both the row sample length and the column sample length.

[0142] In some embodiments, the sample length includes the row sample length and the column sample length, and the step of determining the sample length includes: determining the row sample length P and the column sample length Q.

[0143] Here, the row sample length P represents the number of rows of samples that need to be extracted from the sub-table and input into the large language model.

[0144] The large language model can accept a total of 'context_size' tokens in a single dialogue. Following a naive approach, 'context_size' is divided into three equal parts: 1 / 3 for receiving row sample data, 1 / 3 for receiving column sample data, and 1 / 3 for receiving prompts and task descriptions. To ensure that the number of tokens in a row sample does not exceed 1 / 3 of 'context_size', we should have P × line_size <= context_size / 3, i.e., P <= context_size / (3 × line). Furthermore, considering that the number of rows in a row sample affects the large language model's understanding of sub-table data and header recognition, the number of rows in a row sample should be limited to at least 10 rows.

[0145] In some embodiments, determining the row sample length P includes: determining the row sample length P based on the relation P=min(10,context_size / (3×line_size)). Here, context_size is the context size of the large language model, and line_size is the average number of characters per row in the target sub-table.

[0146] Here, the column sample length Q represents how many columns of samples need to be extracted from the sub-table and input into the large language model.

[0147] The large language model can accept a total of 'context_size' tokens in a single dialogue. Following a naive approach, 'context_size' is divided into three equal parts: 1 / 3 for row sample data, 1 / 3 for column sample data, and 1 / 3 for cue words and task descriptions. To ensure that the number of tokens in a column sample does not exceed 1 / 3 of 'context_size', we should have Q × line_size <= context_size / 3, i.e., Q <= context_size / (3 × line). Furthermore, considering that the number of columns in the column sample affects the large language model's understanding of sub-table data and the effectiveness of table header recognition, the number of columns in the column sample should be limited to at least 5.

[0148] In some embodiments, determining the column sample length Q includes: determining the column sample length Q based on the relation Q=min(5,context_size / (3×column_size)). Here, context_size is the context size of the large language model, and column_size is the average number of column characters in the target sub-table.

[0149] In step S1102, starting from the first row or first column of the target sub-table, the data in the target sub-table corresponding to the sample length is converted into the target format to obtain the sample.

[0150] The target format can be HTML format, that is, the data corresponding to the sample length in the target sub-table is converted into HTML format to obtain the sample.

[0151] In embodiments where the sample length only includes the row sample length, in step S1102, starting from the first row of the target sub-table, the data corresponding to the row sample length in the target sub-table is converted to the target format (such as HTML format) to obtain the row sample. In embodiments where the sample length only includes the column sample length, in step S1102, starting from the first column of the target sub-table, the data corresponding to the column sample length in the target sub-table is converted to the target format (such as HTML format) to obtain the column sample. In embodiments where the sample length includes both row and column sample lengths, in step S1102, the first P rows of data in the target sub-table are converted to the target format to obtain the row sample; the first Q columns of data in the target sub-table are converted to the target format (such as HTML format) to obtain the column sample.

[0152] In some embodiments, the maximum row length (maxRow) allowed for generating column samples is further configured. This means that when the sub-table row length reaches this value, no column samples are provided to avoid the context length of the large language model becoming excessively long. For example, if maxRow is 100, when the sub-table row length reaches 100, only row samples are provided to the large language model, and no column samples are provided. Of course, users can also dynamically adjust the value of maxRow according to the context size of the large language model.

[0153] Accordingly, the decision-making logic of the large language model is set as follows: if the number of rows in the sub-table is less than or equal to the threshold, then provide row samples and column samples for comprehensive analysis; else, only provide row samples for analysis.

[0154] Using a large language model to recognize the header content will incur some time overhead. By dynamically adjusting the sample size input to the large language model, the time overhead caused by calling the large language model can be reduced.

[0155] In step S1103, the sample is input into the large language model, and the large language model identifies the header data of the target sub-table based on the sample and the prompt word template.

[0156] That is, the input of the large language model is row samples and / or column samples, and the output of the large language model includes the header direction, position, and sub-table titles.

[0157] In some embodiments, before inputting the sample into the large language model, the method further includes: constructing a prompt word template containing role definitions, task requirements, and output format requirements. The task requirements guide the large language model to determine the header direction based on the sample. If the header direction is row-oriented, the model outputs the recognized table column names and the number of columns according to the column order in the sample; if the header direction is column-oriented, the model outputs the table row names and the number of rows according to the row order in the sample; and summarizes the sub-table title based on the sample and the target table name to which the target sub-table belongs.

[0158] In some embodiments, the task requirements also guide the large language model to merge multiple rows of information into one row when it recognizes that the header contains multiple rows of information. In some embodiments, the task requirements also guide the large language model to, when determining if the header is a row-oriented column, if it considers the first few rows of the sample to be data rows rather than header rows, then it should derive the header column names out of thin air, and both `header_start_row_number` and `header_end_row_number` must be 0; when determining if the header is a column-oriented column, if it considers the first few columns of the sample to be data columns rather than header rows, then it should derive the header column names out of thin air, and both `header_start_row_number` and `header_end_row_number` must be 0. In some embodiments, the task requirements also guide the large language model to output a header column number corresponding to the number of input sample columns. In some embodiments, the constructed prompt word template is as follows: Figure 17 As shown.

[0159] In some embodiments, after the large language model outputs its results, the output is also verified, including the following verification points: 1. Column count consistency check: The number of output columns must equal the number of input sample columns; 2. Row count consistency check: The number of output rows must equal the number of input sample rows; 3. Header position validity verification: If the table header output by the large language model is extracted from the samples, the start and end rows of the header must be specified; if it is a self-summarized header, this is not required; 4. JSON format validity check: The output of the large language model must conform to JSON syntax.

[0160] In some embodiments, if the output of the large language model does not meet the above verification points, a degradation strategy is initiated, and the first row of the sub-table is identified as the table header based on the principle of maximum probability.

[0161] Below, with Figure 18 Taking the sub-table shown as an example, the process of recognizing the table header will be explained.

[0162] First, convert the corresponding data in the sub-table into HTML format, which the large language model can understand. For example, if the row sample length is 5, then the first 5 rows of the sub-table are used as samples and converted into HTML format, resulting in the following sample: <td rowspaln=""3”"> 6th Floor Bakery Menu Serial Number name Price 1 Mini cookies ¥1 2 Shiroi Koibito Bread ¥7 3 Golden Crispy Bread ¥8 .

[0163] Since the above subtable has fewer than 100 rows, further column samples are generated. Assuming the column samples are generated based on the first two columns, the sample would be: <td rowspaln=""3”"> 6th Floor Bakery Menu Serial Number name 1 Mini cookies 2 Shiroi Koibito Bread 3 Golden Crispy Bread 4 Seaweed crispy bread 5 Cheese Thyme Bread 6 Coconut Milk Bread 7 French-style milk bread 8 Milk Crispy Pineapple Croissant 9 Whole wheat toast 10 Donuts 11 Plain baguette 12 Butter Toast 13 Thousand-layer twisted dough stick 14 Crispy and bouncy cake 15 Christmas wreath bread 16 Cranberry Toast 17 High-fiber nut bread 18 Multigrain fiber bread 19 Chocolate Mochi 20 Honey Cookies .

[0164] After inputting the row and column samples of the example into the large language model according to the above prompts, the output of the large language model is as follows: json { "tableName": "6th Floor Bakery Menu", "headerOrientation": "ROW", "columnNames": ["Serial Number", "Name", "Price"], "columnCount": 3, "headerStartRowNumber": 2, "headerEndRowNumber": 2, "rowNames": [], "rowCount": 0, "headerStartColumnNumber": 0, "headerEndColumnNumber": 0 }

[0165] As can be seen from the above output, the large language model correctly identified the second row of the table header and summarized the table title based on the sample information.

[0166] In RAG (Retrieval Augmentation) practice, accurate identification of table headers has a crucial impact on whether a large language model can generate correct answers based on the retrieved knowledge. In a RAG interaction, the system first retrieves the most similar document data from the knowledge base based on the user's question. When a row of content in an Excel table is retrieved, the knowledge base sends this row of content along with the table header information to the large language model (i.e., based on the user's question, extracting the most relevant sub-table information from a large amount of data in the knowledge base). By combining the header information, the large language model can better understand the row data content of the table and make a more accurate answer.

[0167] For example: The following is an original performance target table. Import this table into the knowledge base.

[0168] After the knowledge base extracts the correct table headers using this application (identifying and merging the first two rows as headers), the parsed table is as follows:

[0169] After the knowledge base parses and extracts the table based on this application, it will vectorize the table data and store it in the vector database.

[0170] Suppose a user asks: What is the target number of patents for the past six months? The knowledge base vectorized the question and then retrieved it from the vector database. The retrieval results were as follows:

[0171] Then, the search results and the user's question are input into the large language model, which can then provide the correct answer of 4 based on the search results.

[0172] If the knowledge base cannot recognize the table header or recognizes an incorrect table header when processing tabular data, the tabular data retrieved by the knowledge base and sent to the large language model may be as follows:

[0173] Alternatively (use the first row of the original table as the table header)

[0174] In both cases, the large language model is unable to generate the correct answer based on the search results.

[0175] In summary, this application, in terms of sub-table recognition, is based on a greedy algorithm, requiring no reliance on cell border markings or manual mapping. Furthermore, individual empty cells within the sub-table do not affect the recognition results, enabling efficient and accurate parsing of any input worksheet into logically independent sub-tables. Regarding header content recognition, based on the identified logical sub-tables, a large language model technique is used. The first row and column content of each sub-table are constructed as sample input to the large language model. By setting appropriate prompts and model parameters, the large language model is guided to output the table header and title information. The large language model possesses stronger semantic understanding capabilities, higher noise resistance and fault tolerance, and can infer the logic between fields by combining global information from the header and data content. It also automatically adapts technical terms, thus more accurately summarizing table information. Simultaneously, an adaptive row-column dual-sample input mechanism is adopted—row samples provide the vertical structure information of the table, and column samples provide the horizontal structure information. The input samples are intelligently selected based on the table size, achieving the most accurate possible transmission of table structure information within the limited context length of the large language model.

[0176] This application not only provides a high-fidelity structured knowledge input source for Retrieval Enhanced Generation (RAG), but also significantly improves the efficiency of knowledge base construction and the reliability of multi-turn question answering by eliminating information gaps caused by the complex layout of Excel, thus strongly supporting the implementation of AI applications in high-precision scenarios such as finance and healthcare. Based on this application, enterprise users can directly upload a single Excel worksheet file containing multiple independent sub-sheets from their actual work, without having to pre-split the table into different sheets, effectively reducing the workload of document preprocessing and significantly improving the user experience.

[0177] See next. Figure 19 This embodiment provides a computer device 1200, which includes one or more processors 1201 and a memory 1202. The memory 1202 is used to store one or more programs. When one or more programs are executed by one or more processors 1201, the computer device 1200 implements the table recognition method of this application.

[0178] Figure 20 The diagram shows a computer system architecture block diagram for implementing some embodiments of this application. It should be noted that... Figure 20 The computer system shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0179] like Figure 20As shown, the computer system 1300 includes a CPU (Central Processing Unit) 1301, which can perform various appropriate actions and processes according to a program stored in ROM (Read-Only Memory) 1302 or a program loaded from storage portion 1308 into RAM (Random Access Memory) 1303, such as executing the table recognition method in the above embodiment. The RAM 1303 also stores various programs and data required for system operation. The CPU 1301, ROM 1302, and RAM 1303 are interconnected via a bus 1304. An I / O (Input / Output) interface 1305 is also connected to the bus 1304.

[0180] The following components are connected to I / O interface 1305: an input section 1306 including a keyboard, mouse, etc.; an output section 1307 including CRT (Cathode Ray Tube), LCD (Liquid Crystal Display), etc., and speakers, etc.; a storage section 1308 including a hard disk, etc.; and a communication section 1309 including a network interface card such as a LAN (Local Area Network) card, modem, etc. The communication section 1309 performs communication processing via a network such as the Internet. A drive 1310 is also connected to I / O interface 1305 as needed. Removable media 1311, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 1310 as needed so that computer programs read from them can be installed into storage section 1308 as needed.

[0181] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including a computer program for performing all or part of the steps shown in the flowcharts of the table recognition method. In such embodiments, the computer program can be downloaded and installed from a network via communication section 1309, and / or installed from removable medium 1311. When the computer program is executed by central processing unit (CPU) 1301, it performs various functions defined in the system of this application.

[0182] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, touch terminal, or network device, etc.) to execute the methods according to the embodiments of this application. Other embodiments of this application will readily conceive of by those skilled in the art upon considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary technical means in the art not disclosed in this application. The specification and embodiments are to be considered exemplary only, and the true scope and spirit of this application are indicated by the appended claims.

Claims

1. A table recognition method, characterized in that, include: Obtain the total number of rows and columns of the target table. Each target table contains multiple sub-tables, which are separated by empty rows or columns, and each sub-table contains at least one non-empty cell. The sub-table acquisition step is to traverse the cells of the target table. If the current cell has not been visited and meets the area spread condition, it is used as the target cell. The area spread condition is: the current cell is a non-empty cell, or the current cell is an empty cell and there are non-empty but unvisited adjacent cells. The boundary of the initial rectangular region is the position of the target cell. Starting from the target cell, the rectangular region is expanded according to the region expansion path until M consecutive rows or N consecutive columns are empty. The region expansion path is either expanding downwards and to the right from the target cell or expanding to the lower right corner from the target cell. M and N are both integers greater than or equal to 1. The rectangular region formed by the target cell and the cells accessed from the target cell is taken as a candidate sub-table. It is determined whether the candidate sub-table has at least one non-empty cell. If so, all cells of the candidate sub-table are extracted, and empty rows and columns are removed to form the target sub-table. Otherwise, the candidate sub-table is used as the target sub-table; Continue traversing the unvisited cells in the target table and execute the sub-table acquisition step until the endpoint cell corresponding to the total number of rows and columns is accessed, so as to obtain all sub-tables in the target table.

2. The method according to claim 1, characterized in that, The process of expanding a rectangular region from the target cell along a region expansion path includes: Perform the downward propagation step: Set the row containing the target cell as the starting row. If the starting row does not reach the last row of the target table, check whether the M consecutive rows starting from the next row of the starting row are empty rows. If so, end the downward propagation. Otherwise, use the next row as the starting row and check the cells downward. Perform the rightward expansion step: Set the column containing the target cell as the starting column. If the starting column has not reached the last column of the target table, check whether the next N consecutive columns starting from the next column of the starting column are empty columns. If so, end the rightward expansion. Otherwise, use the next column as the starting column and check the cells to the right.

3. The method according to claim 2, characterized in that, Before performing the sub-table retrieval step, the following is also included: Initialize the access matrix, which is used to mark the access status of each cell; Let the starting row minR = the ending row maxR = the row containing the target cell, and the starting column minC = the ending column maxC = the column containing the target cell; The downward propagation step includes: Iterative execution: If maxR < total number of rows, check if the M consecutive rows starting from maxR+1 are empty rows. If the M consecutive rows starting from maxR+1 are empty rows, skip the empty rows, mark the cells from minC to maxC in the rows from maxR+1 to maxR+M in the access matrix as visited, and end the downward propagation; if the M consecutive rows starting from maxR+1 are not all empty rows, set maxR = maxR+1, and check the sub-cells from minC to maxC. The rightward spread step includes: Iterative execution: If maxC < total number of columns, check if the N consecutive columns starting from maxC+1 are empty. If the N consecutive columns starting from maxC+1 are empty, skip the empty columns, mark the cells from minR to maxR in the columns from maxC+1 to maxC+N in the access matrix as visited, and end the rightward propagation; if the N consecutive columns starting from maxC+1 are not all empty, set maxC = maxC+1, and check the sub-cells from minR to maxR.

4. The method according to claim 3, characterized in that, Before performing the sub-table retrieval step, the following is also included: Initialize the mask matrix, which is used to mark whether each cell is empty; In the downward propagation step and the rightward propagation step, when an empty cell is detected, the empty cell is marked as empty in the mask matrix; when a non-empty cell is detected, the non-empty cell is marked as non-empty in the mask matrix.

5. The method according to claim 1, characterized in that, Also includes: Traverse all rows of the target table and count the distribution of the number of consecutive empty rows in the target table; Based on the statistical results, the data is sorted in order of the number of consecutive blank lines. The number of consecutive blank lines corresponding to the preset quantile after sorting is taken as M, and M is constrained to be ≤ 5. The preset quantile is ≥ 80%. and / or Traverse all columns of the target table and count the distribution of the number of consecutive empty columns in the target table; Based on the statistical results, the columns are sorted in order of the number of consecutive empty columns. The number of consecutive empty columns corresponding to the preset quantile after sorting is taken as N, and N is constrained to be ≤ 5. The preset quantile is ≥ 80%.

6. The method according to claim 1, characterized in that, The process of expanding a rectangular region from the target cell along a region expansion path includes: Starting from the target cell, if the row where the starting point is located has not reached the last row of the target table, and the column where the starting point is located has not reached the last column of the target table, then check whether the L consecutive cells starting from the downstream neighbor cell of the starting point in the lower right direction are empty. If so, the propagation ends; otherwise, starting from the downstream neighbor cell, continue to check cells in the lower right direction. L is an integer greater than or equal to 1. The downstream neighbor cell is a cell located at the lower right corner of the target cell and adjacent to the target cell.

7. The method according to any one of claims 1 to 6, characterized in that, After obtaining the target sub-table in the target table, the following is also included: Determine the sample length; Starting from the first row or column of the target sub-table, convert the data in the target sub-table corresponding to the sample length into the target format to obtain the sample; The sample is input into a large language model, which then identifies the header data of the target sub-table based on the sample and the prompt word template.

8. The method according to claim 7, characterized in that, The determination of sample length includes: determining the row sample length P and the column sample length Q; The step of converting the data corresponding to the sample length in the target sub-table into the target format, starting from the first row or first column of the target sub-table, to obtain the sample includes: Convert the first P rows of data in the target sub-table into the target format to obtain row samples; Convert the data in the first Q columns of the target sub-table into the target format to obtain column samples.

9. The method according to claim 8, characterized in that, Determine the row sample length P, including: based on the relation P=min(10,context_size / (3×line_size)), determine the row sample length P; Wherein, context_size is the context size of the large language model, and line_size is the average number of characters per row in the target sub-table; and / or Determine the column sample length Q, including: based on the relation Q=min(5,context_size / (3×column_size)), determine the column sample length Q; Wherein, context_size is the context size of the large language model, and column_size is the average number of column characters in the target sub-table.

10. The method according to claim 7, characterized in that, Before inputting the samples into the large language model, the following steps are also included: Construct a prompt template that includes role definitions, task requirements, and output format requirements; The task requires guiding the large language model to determine the header direction based on the sample. If the header direction is row-oriented, the model outputs the identified column names and the number of columns according to the order of columns in the sample. If the header direction is column-oriented, the model outputs the row names and the number of rows according to the order of rows in the sample. The model also summarizes the title of the sub-table based on the sample and the target table name to which the target sub-table belongs.