Table data extraction method, device, computer equipment and storage medium
The preset language model identifies the master-slave relationship of table unit keywords in PDF documents and supplements the borders, which solves the problem of low table data extraction accuracy caused by missing borders and achieves higher data extraction accuracy.
Patent Information
- Application Number
- CN202011269426.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-13
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2040-11-13
AI Technical Summary
When the existing technology handles missing borders in PDF documents, the accuracy of table data extraction is low and the complete table data cannot be effectively extracted.
The preset language model is used to identify the master-slave relationship of keywords in table cells and supplement the missing table borders to extract table data.
It improves the accuracy of table data extraction and can accurately extract table data in environments with missing borders. It is suitable for complex tables such as financial report data in the financial field.
Smart Images

Figure CN112257400B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a table data extraction method, device, computer equipment and storage medium. Background Art
[0002] PDF (Portable Document Format) is a portable document format developed by Adobe Systems for file exchange. It has no interactive relationship with applications, operating systems, and other hardware. PDF documents are based on the PostScript language image model, which ensures that PDF documents can have accurate colors and accurate printing effects on any printer, that is, PDF will faithfully reproduce every character, color, image, and other content in the PDF document. With the rapid development of computer and Internet technology, PDF documents are increasingly widely used in various fields such as economy, finance, education, scientific research, and academia. Since PDF is designed only to display documents or print documents, it does not have the function of communicating and interacting with other computer programs. Therefore, the large amount of data contained in PDF documents, especially the table data contained therein, is difficult to be directly used by other computer programs.
[0003] Currently, information can be extracted from table data in PDF documents by using PDF table extraction, which extracts table data in PDF documents as structured information. However, if there are missing borders in a PDF table, the table cannot be formed, and thus the complete table data cannot be extracted.
[0004] At this time, in order to extract the complete data in the PDF table, the text position clustering method will be used. At this time, the border information will be completely discarded, and the position information of the text itself will be used instead. For example, the text in the same column of a general table will be left-aligned, right-aligned, or centered. Based on this alignment information, some algorithms are used to guess that some text may belong to a certain column, thereby extracting the table information. However, this method is similar to converting the information extraction problem into borderless table extraction, and the accuracy of table data extraction is low. Summary of the invention
[0005] Based on this, it is necessary to provide a table data extraction method, device, computer equipment and storage medium that can improve the accuracy of PDF table data extraction in a border-missing environment in response to the above technical problems.
[0006] A method for extracting table data, the method comprising:
[0007] Get the first direction border missing table;
[0008] Get the keywords in the first direction border missing table;
[0009] Identifying, by means of a preset language model, a master-slave relationship of the keywords in different table units, wherein the preset language model is used to identify the probability that the keywords belong to the same sentence, wherein the different table units are table units along a second direction in the table, wherein the first direction is a table column direction and the second direction is a table row direction, or the first direction is a table row direction and the second direction is a table column direction;
[0010] Supplement the first direction border in the first direction border missing table according to the master-slave relationship;
[0011] The table data in the supplemented table is identified and extracted.
[0012] A table data extraction device, the device comprising:
[0013] A table acquisition module, used to acquire a table with missing borders in the first direction;
[0014] A keyword acquisition module, used to acquire keywords in the first direction border missing table;
[0015] A master-slave relationship identification module, used to identify the master-slave relationship of the keywords in different table units through a preset language model, wherein the preset language model is used to identify the probability that the keywords belong to the same sentence;
[0016] a border supplementing module, used for identifying the master-slave relationship of the keywords in different table cells by using a preset language model, wherein the preset language model is used for identifying the probability that the keywords belong to the same sentence, wherein the different table cells are table cells along a second direction in the table, wherein the first direction is a table column direction and the second direction is a table row direction, or the first direction is a table row direction and the second direction is a table column direction;
[0017] The table data extraction module is used to identify and extract the table data in the supplemented table.
[0018] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0019] Get the first direction border missing table;
[0020] Get the keywords in the first direction border missing table;
[0021] Identifying, by means of a preset language model, a master-slave relationship of the keywords in different table units, wherein the preset language model is used to identify the probability that the keywords belong to the same sentence, wherein the different table units are table units along a second direction in the table, wherein the first direction is a table column direction and the second direction is a table row direction, or the first direction is a table row direction and the second direction is a table column direction;
[0022] Supplement the first direction border in the first direction border missing table according to the master-slave relationship;
[0023] The table data in the supplemented table is identified and extracted.
[0024] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0025] Get the first direction border missing table;
[0026] Get the keywords in the first direction border missing table;
[0027] Identifying, by means of a preset language model, a master-slave relationship of the keywords in different table units, wherein the preset language model is used to identify the probability that the keywords belong to the same sentence, wherein the different table units are table units along a second direction in the table, wherein the first direction is a table column direction and the second direction is a table row direction, or the first direction is a table row direction and the second direction is a table column direction;
[0028] Supplement the first direction border in the first direction border missing table according to the master-slave relationship;
[0029] The table data in the supplemented table is identified and extracted.
[0030] The above-mentioned table data extraction method, device, computer equipment and storage medium obtain a table with a missing first-direction border; obtain keywords in the table with a missing first-direction border; identify the master-slave relationship of the keywords in different table units through a preset language model, and the preset language model is used to identify the probability that the keywords belong to the same sentence; supplement the first-direction border in the table with a missing first-direction border according to the master-slave relationship; identify and extract the table data in the supplemented table. In the present application, the probability that the keywords in the table with a missing first-direction border belong to the same sentence is identified through a preset language model, thereby determining the master-slave relationship of the keywords, strengthening the correlation between the data, and then supplementing the first-direction border based on the determined master-slave relationship to obtain a complete table with the border supplemented, and extracting table data based on the complete table, which has a higher data extraction accuracy rate than borderless table data extraction. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 An application environment diagram of a table data extraction method in one embodiment;
[0032] Figure 2 A schematic diagram of a process of extracting table data in one embodiment;
[0033] Figure 3 A schematic diagram of a table with a missing vertical border in one embodiment;
[0034] Figure 4 A schematic diagram of a flow chart of a step of identifying a master-slave relationship of keywords in one embodiment;
[0035] Figure 5 A flowchart of the steps of training a preset language model in one embodiment;
[0036] Figure 6 is a schematic diagram of a complete table with a border in one embodiment;
[0037] Figure 7 A schematic diagram of model training data extracted based on a complete table with borders in one embodiment;
[0038] Figure 8 A schematic diagram of a blank segmentation process based on blank positions of a table in one embodiment;
[0039] Fig. 9 A flowchart of the steps of identifying and extracting table data in one embodiment;
[0040] Fig.10 A flowchart of the steps of identifying and extracting table data in one embodiment;
[0041] Fig.11 A schematic diagram of a complex table in which keywords include a master-slave relationship in an embodiment;
[0042] Fig.12 A flowchart of a model training step and a model application step in an embodiment;
[0043] Fig.13 is a structural block diagram of a table data extraction device in one embodiment;
[0044] Fig.14 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0045] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0046] Natural language processing (NLP) is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can achieve effective communication between people and computers using natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field will involve natural language, that is, the language people use in daily life, so it is closely related to the study of linguistics. Natural language processing technology usually includes text processing, semantic understanding, machine translation, robot question answering, knowledge graph and other technologies. This solution uses natural language processing technology to identify the relevance of the content in the table, so that the table data can be extracted even when the border is missing.
[0047] The table data extraction method provided in this application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The terminal 102 can send a first direction border missing table to the server 104, so as to extract the table data in the first direction border missing table through the server 104, and the server 104 obtains the first direction border missing table submitted by the terminal 102; obtains the keywords in the first direction border missing table; identifies the master-slave relationship of the keywords in different table units through a preset language model, and the preset language model is used to identify the probability that the keywords belong to the same sentence; supplements the first direction border in the first direction border missing table according to the master-slave relationship; identifies and extracts the table data in the supplemented table. Among them, the terminal 102 can be but is not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices, and the server 104 can be implemented with an independent server or a server cluster composed of multiple servers. In another embodiment, it is not necessary that the cousin data extraction method of the present application can also be applied to the terminal, and the user can directly execute the method on the terminal side.
[0048] In one embodiment, Figure 2 As shown, a table data extraction method is provided, which is applied to Figure 1 Taking the server 104 in the example as an example, the following steps are included:
[0049] Step 201, obtaining a first direction border missing table.
[0050] Among them, the first direction border missing table refers to the target table extracted by the table data extraction method of the present application, and the first direction border missing table is specifically a vertical border missing table or a horizontal border missing table. The first direction border missing table is specifically a table in a PDF document. Since the purpose of PDF design is only to display documents or to print documents, it does not have the function of communicating and interacting with other computer programs. Therefore, the large amount of data contained in the PDF document, especially the table data contained therein, is difficult to be directly used by other computer programs. Therefore, the table data extraction method of the present application can be used to extract the corresponding table data from a document in PDF format. In one embodiment, the table example of the first direction border missing table can be referred to. Figure 3 The table contains two parts: keywords and key values. The keyword is key, and the keyword of the table refers to the column name of the table, such as Figure 3 In the first row, there is "Company Stock Overview", and in the second row, there are "Stock Type", "Stock Listing Exchange", "Stock Short Name", "Stock Code" and "Stock Short Name Before Change", etc. The key value is Value: The key value of the table refers to the value corresponding to the keyword of the table, such as Figure 3 In the third line, there are "C shares", "XX Stock Exchange" and "601216". Figure 3 In the figure, adjacent keywords in the second row do not contain first direction borders, so the table data extraction method of the present application can be used to first add corresponding first direction borders and then perform data extraction to improve the accuracy of table data extraction.
[0051] Specifically, when the terminal staff needs to directly obtain the table data that is missing the first direction border from the obtained PDF document, since the data in the PDF document cannot directly interact with the computer program, and the usual table data extraction method cannot extract the table data that is missing the first direction border, the staff can directly input this part of the table data into the server 104, and the server 104 will perform corresponding data extraction work on the table data in this part of the PDF table.
[0052] Step 203: Obtain keywords in the first direction border missing table.
[0053] The table contains two parts: the keyword and the key value of the keyword. The keyword is the key, and the keyword of the table refers to the column name of the table.
[0054] Specifically, in one of the embodiments, the table data can be first identified through "key-value" recognition to identify which part of the table where the first direction border is missing belongs to the keyword (key) and which part belongs to the key value (value) of the keyword, and then fill in the missing first direction border in the table to extract the table data.
[0055] Step 205, through a preset language model, identify the master-slave relationship of keywords in different table cells, the preset language model is used to identify the probability that the keywords belong to the same sentence, the different table cells are table cells along the second direction in the table, the first direction is the table column direction, the second direction is the table row direction, or the first direction is the table row direction, and the second direction is the table column direction.
[0056] The preset language model refers to a model for natural language model processing. The preset language model is specifically a machine recognition model, specifically a model for the probability distribution of sentences. That is to say, for any word sequence, the probability that the sequence is a sentence can be calculated through the preset language model. For example, the word sequence A: "table|analysis|good|interesting" is obviously a sentence, and a good language model will give a high probability. For example, for the word sequence B: "table|eat|sleep|lion", it is obviously not a sentence, and a good language model will give a low probability.
[0057] Specifically, the preset language model in this application is specifically constructed by constructing model training data through complete table data with first direction borders in historical data, and then obtained through model training and model testing. In actual use, for keywords in different rows, it can be judged whether there is a master-slave relationship between them. The master-slave relationship refers to whether a certain keyword is a branch keyword of other keywords in different rows, such as Figure 3 In the first row, the keywords are "company stock profile", and the keywords in the second row are "stock type", "stock exchange", "stock abbreviation", "stock code" and "stock abbreviation before change". Obviously, the keywords "stock type", "stock exchange", "stock abbreviation", "stock code" and "stock abbreviation before change" in the second row are all subordinate keywords of the keyword "company stock profile" in the first row, and all belong to a part of the company stock profile, so they have a master-slave relationship. By presetting the language model, the master-slave relationship of keywords in different table cells can be effectively identified, and then the corresponding border filling can be performed, and the valid table data can be accurately extracted.
[0058] Step 207 , supplement the first direction border in the first direction border missing table according to the master-slave relationship.
[0059] Specifically, after obtaining the master-slave relationship, it can be determined that there is a distinction between the subordinate keywords, and the first direction border can be supplemented based on the blank part between the subordinate keywords, while the main keyword area cannot be underlined to reflect that the main keyword area has a master-slave distinction relationship with the multiple subordinate keywords below.
[0060] Step 209 , identifying and extracting the table data in the supplemented table.
[0061] Specifically, after the required first direction border is added to the first direction border missing table, the table data can be extracted according to the conventional extraction method of the table with borders. Specifically, the line segments and intersections in the table can be identified first, and then the cells can be determined. The content in the table can be identified based on the cells, and then the content in the table can be converted into structured data for storage, such as Json (JavaScript Object Notation, JS object notation), csv (Comma-Separated Values, comma separated values) or other formatted forms. Thus, graph construction, database construction, public opinion analysis, buying and selling suggestions, etc. are carried out on the basis of structured data. In another embodiment, in the recognition process, the keywords and keyword key values in the first direction border missing table can be used as keywords for recognition. After the border is recognized and added, the corresponding border table structured data is obtained. The structured table data is identified by "key-value" recognition, and then it is determined which part of the data in the first direction border missing table belongs to the keyword and which part of the data belongs to the keyword key value.
[0062] The above-mentioned table data extraction method, device, computer equipment and storage medium obtain a table with a missing first-direction border; obtain keywords in the table with a missing first-direction border; identify the master-slave relationship of the keywords in different table units through a preset language model, and the preset language model is used to identify the probability that the keywords belong to the same sentence; supplement the first-direction border in the table with a missing first-direction border according to the master-slave relationship; identify and extract the table data in the supplemented table. In this application, the probability that the keywords in the table with a missing first-direction border belong to the same sentence is identified through a preset language model, thereby determining the master-slave relationship of the keywords, and then supplementing the first-direction border based on the determined master-slave relationship to obtain a complete table after the border is supplemented, and extracting table data based on the complete table, which has a higher data extraction accuracy rate than extracting table data without borders. In the field of PDF finance, the main processing object of data processing is financial announcement data, among which financial report data is the most important. According to statistics, 55% of financial report PDFs have complex tables with missing first-direction borders, and this application provides a PDF table extraction method with missing first-direction borders, so that the data extraction of this 55% can be more complete and accurate.
[0063] In one embodiment, Figure 4 As shown, step 205 includes:
[0064] Step 401, obtaining the language model probability between keywords in different table cells through a preset language model.
[0065] Step 403: Obtain the master-slave relationship of keywords in different table cells according to the language model probability and the preset model probability threshold.
[0066] The language model probability refers to the probability predicted by the preset language model whether the keywords in different columns belong to the same sentence, and the preset model probability threshold is the criterion for judging whether the keywords have a master-slave relationship. Based on the preset model probability threshold, a judgment can be made on whether the keywords in different table cells have a master-slave relationship. The preset model probability threshold can be specifically determined based on the preset language model and applied to the table data extraction of the first direction border missing tables in those fields.
[0067] Specifically, the preset language model is obtained through historical table data with complete borders, and the historical table data with complete borders is similar to the subordinate relationship of keywords between different table units that have been marked. In the stage of model testing, the trained preset language model can be tested based on the corresponding model test data. During the model testing process, the tester can divide the language model probability corresponding to the trained preset language model based on the probability of the model output and the recognition accuracy requirements of the field in which the current table is located. Specifically, if the recognition accuracy required by the table in the financial field is high, in this case, during the model testing process, it is necessary to determine a relatively high preset model probability threshold based on the probability output during the model testing process and the mark of the model test data to ensure that the master-slave relationship identified according to the preset model probability threshold has a high accuracy. In this embodiment, the master-slave relationship of keywords in different table units is identified by a preset model probability threshold, which can more effectively realize the recognition of the master-slave relationship while ensuring the accuracy of the recognition.
[0068] In one embodiment, Figure 5 As shown, before step 205, the following steps are also included:
[0069] Step 502: Obtain a complete table with borders in the historical data.
[0070] Step 504, obtaining keywords in the complete table with borders.
[0071] Step 506: Generate model training data based on the keywords in the complete table with borders.
[0072] Step 508: Train the initial language model based on the model training data to obtain a preset language model.
[0073] Among them, historical data refers to table data in the same field as the first direction border missing table. For example, for table data in the financial field, a special preset language model can be used to identify the master-slave relationship. At this time, historical data specifically refers to a table with a border in the financial field. In one embodiment, the preset language model is updated regularly, and after the first direction border missing table is supplemented with a border, the first direction border missing table after the supplemented border can also be used as training data for model training in subsequent model updates to perform model training work in the model update process. The availability of the model is continuously maintained through model updates.
[0074] Specifically, before identifying the master-slave relationship of keywords in different table cells based on the preset language model, model training is required. At this time, the complete table with borders in the historical data needs to be used as the training data of the model. Figure 6The bordered table shown in the figure can be used to extract keywords from the table and then generate model training data. Figure 7 The initial language model can be selected according to the actual application field. In one embodiment, the language model training process can be trained using the open source MITLM software package to train the initial language model. Then the language model probability is calculated. In this embodiment, the complete table with borders in the historical data is used as the model training data to train the preset language model, which can effectively ensure the accuracy of identifying the master-slave relationship through the language model.
[0075] In one embodiment, step 207 specifically includes: when there is a master-slave relationship between keywords in different table cells, the first direction border is not added in the main keyword area, and the first direction border is added in the blank position between the slave keywords and the blank position between the key values of the slave keywords.
[0076] The blank space between keywords specifically refers to the blank space between different keywords. Although there is no first-direction border in the first-direction border-missing table, in order to facilitate readers to read the table in the PDF document, blank space is generally used to distinguish different keywords and keyword values.
[0077] Specifically, whether to draw a line in the main keyword area can be determined by judging whether there is a master-slave relationship. The master-slave relationship can determine that there is a distinction between subordinate keywords, and then the first direction border is supplemented based on the blank space between the subordinate keywords, while the main keyword area cannot be drawn to reflect that the main keyword area has a master-slave distinction relationship with the multiple subordinate keywords below. Specifically, in this embodiment, the first direction border is supplemented based on the master-slave relationship, and the first direction border is supplemented in the blank space between the subordinate keywords and the blank space between the key values of the subordinate keywords. The first direction border in the table where the first direction border is missing can be effectively filled, thereby providing more effective basic data for the subsequent table data extraction process.
[0078] In one embodiment, step 203 specifically includes: segmenting the first direction border missing table by a blank segmentation method; and extracting keywords in the segmented first direction border missing table.
[0079] Specifically, the white space segmentation method can be referred to Figure 8, mainly used for roughly segmenting tables with missing borders in the first direction, so as to distinguish different keywords in the same table row. The blank segmentation method specifically refers to, for tables with missing borders in the first direction, first detecting the vertical blank area in the table, and then arbitrarily adding a vertical line in the vertical blank area to segment the table. The table segmented by the blank segmentation method cannot be segmented for complex tables with master-slave relationships. That is, the master-slave relationship cannot be identified. When extracting keywords from the table with missing borders in the first direction, since there is no need to identify the master-slave relationship, the blank segmentation method can be used directly to segment and extract the keywords. In this embodiment, the table with missing borders in the first direction is segmented by the blank segmentation method, and the keywords in the table with missing borders in the first direction can be effectively identified.
[0080] In one embodiment, if Fig. 9 As shown, step 209 specifically includes:
[0081] Step 902, identifying the intersection points between the line segments in the supplemented table.
[0082] Step 904, determining the table cells in the supplemented table according to the line segment intersection points.
[0083] Step 906 , aggregate table cells, identify and extract table data in the supplemented table.
[0084] The line segments between the line segments in the supplemented table specifically include the original second direction border in the table and the supplemented first direction border. There are line segment intersections between the first direction border and the second direction border. The table cells in the supplemented table can be determined based on the line segment intersections. Recognizing and extracting table data specifically refers to extracting corresponding table data from the PDF table based on the cells and the cell positions.
[0085] Specifically, after obtaining a complete table with supplemented borders, when it is necessary to extract corresponding table data from the table, the line segments in the supplemented table can be identified first, and then based on the intersection of the line segments in the table, the cells in the table can be identified. Each cell contains a corresponding keyword or a key value of the keyword. After identifying the cell, the text data in the cell can be regarded as a whole. Then, extraction is performed by aggregating table cells to identify and extract the table data therein. Through this embodiment, data can be effectively extracted from the supplemented table, thereby obtaining structured table data.
[0086] In one embodiment, step 904 specifically includes: obtaining common edges between line segment intersections; and determining table cells in the supplemented table according to a minimum rectangle formed by the common edges between the line segment intersections.
[0087] Specifically, the process of table aggregation can be referred to Fig.10 , different line segments intersect to obtain intersection points. Since the cells in the table are generally in the form of rectangles, the minimum matrix with common edges between the line segment intersection points can be regarded as a cell in the table. If repeated multiple times, the complete table information can be aggregated based on the common edges of the cells. In this embodiment, each cell in the table is determined based on the minimum rectangle formed by the common edges between the line segment intersection points, and then the table data can be extracted based on the cells, thereby improving the accuracy of the data extraction process.
[0088] The present application also provides an application scenario, which applies the above table data extraction method. Specifically, the application of the table data extraction method in the application scenario is as follows:
[0089] The application scenario can specifically be a recognition scenario of a financial PDF file, and the financial PDF file is specifically a financial announcement file, which contains several PDF document data that display financial report data in tabular form. Some of the tables are complex tables with missing internal vertical borders. Since PDF is a file format mainly developed for file exchange, it has no interactive relationship with applications, operating systems and other hardware. Therefore, a specific table data extraction method is required to identify and extract the table data in the PDF document, and the ordinary PDF table data extraction method is difficult to extract complex tables with vertical borders. At this time, the table data extraction in this application can be used to identify and extract the table data. Specifically, the recognition process is carried out through the interaction between the terminal and the server. The staff at the business end sends a first direction border missing table to the server through the terminal. Here, the first direction border missing table is specifically a vertical border missing table. The brief recognition process of the present scheme includes: the server obtains the first direction border missing table submitted by the terminal; then obtains the keywords in the first direction border missing table; and identifies the master-slave relationship of the keywords in different table cells through a preset language model, the preset language model is used to identify the probability that the keywords belong to the same sentence; supplements the first direction border in the first direction border missing table according to the master-slave relationship; identifies and extracts the table data in the supplemented table. Specifically, the table data extraction method of the present application is specifically constructed based on a language model, and the borders of the border missing table are supplemented based on the language model, and then recognition is performed to improve the accuracy of the recognition process. Specifically, according to common sense, in a table, there is a master-slave relationship between the keywords (key) of different rows, such as referring to Fig.11In the table shown in , there is an obvious master-slave relationship between the keyword "dividend year" in the first row and the keywords "2015", "2016" and "2017" in the second row, and the master-slave relationship can be identified by a language model. Therefore, in the solution of the present application, it is necessary to use a language model to perform border supplementation. Specifically, before the table data is recognized, a step of training the language model is also included. At this time, the language model can be trained with a complete table with a border in the historical financial data. Then, the trained model is used to supplement the border of the financial table, and the accuracy of master-slave relationship recognition is improved by a special model, thereby improving the validity of the border data obtained by border data extraction. Specifically, the marked model training expectations are first extracted from the complete table with a border in the historical financial data. Based on these training expectations, the initial language model is trained by the open source MITLM software package to obtain an effective preset language model. The preset language model can effectively identify whether the words in the input word sequence belong to the same sentence, and output the recognition result in the form of probability. That is, by grouping the table keywords between different rows in the first direction border missing table and inputting them into the preset language model, it is possible to identify whether there is a corresponding master-slave relationship between the input table keywords. Before the master-slave relationship is identified by the model, the table keywords need to be extracted from the table first. At this time, the original PDF table can be cut by the blank segmentation method to obtain the keywords in the missing table from it. The blank segmentation method can identify the blank part in the PDF table, and then directly perform rough segmentation. This method cannot guarantee the accuracy of the master-slave relationship in the cut table data, so it is also necessary to perform relationship identification through a preset language model. After obtaining the keywords, the server can input the keywords in the first direction border missing table obtained after segmentation into the corresponding preset language model to identify the master-slave relationship between these keywords. Specifically, for the table with a missing vertical border, the identification process can refer to identifying whether there is a master-slave relationship between the keywords in different rows. The identification of the master-slave relationship by the preset language model can be specifically determined according to the probability output by the preset language model. Depending on whether the obtained probability is greater than a preset model probability threshold P, it is determined whether it is a master-slave relationship pair. If so, a line cannot be drawn in the area of the primary keyword.The probability identified by the language probability model can effectively supplement the actual borders in the table with missing borders, so as to obtain the supplemented table, which contains complete borders. The server can perform corresponding table recognition based on the table containing complete borders. First, the line segments contained in the table are identified. These line segments intersect to form intersections, and these intersections will form rectangles. The server can identify the smallest rectangle with common edges between these intersections and use it as a complete cell in the identified table. By identifying each cell in the table, combined with the position of the cell and the common edge, the entire complete table can be aggregated, and the structured data can be extracted from the table accordingly, and stored in Json, csv or other formatted forms. In one of the embodiments, the training link and application link in the scheme of this application can be specifically referred to. Fig.12 , first of all, the recognition model of the preset language model is used, including taking a complex PDF table as the model training data, extracting the marked master-slave data from it, and then training the preset language model based on MITLM, so as to obtain a master-slave relationship language model that can effectively identify the master-slave relationship. When the model is applied, the model needs to be tested first. At this time, the input data is a complex PDF table with missing borders. The PDF is first segmented by the blank segmentation method, and then the corresponding keywords of the test data are extracted from the segmented table. The trained model is used to determine whether there is a master-slave relationship between the keywords. When there is a master-slave relationship, the border segmentation table is not supplemented in the main key area. In this way, the complete data of the table is supplemented, and the test staff can also decide whether the model needs to be trained based on the table with supplemented borders.
[0090] It should be understood that although Figure 2-10 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2-10 At least part of the steps may include multiple steps or multiple stages. These steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed in turn or alternately with other steps or at least part of the steps or stages in other steps.
[0091] In one embodiment, Fig.13As shown, a table data extraction device is provided, which can be a software module or a hardware module, or a combination of the two to become a part of a computer device. The device specifically includes: a table acquisition module 1301, a keyword acquisition module 1303, a master-slave relationship identification module 1305, a border supplement module 1307 and a table data extraction module 1309, wherein:
[0092] The table acquisition module 1301 is used to acquire a first direction border missing table.
[0093] The keyword acquisition module 1303 is used to acquire keywords in the first direction border missing table.
[0094] The master-slave relationship identification module 1305 is used to identify the master-slave relationship of keywords in different table cells through a preset language model. The preset language model is used to identify the probability that the keywords belong to the same sentence. The different table cells are table cells along the second direction in the table. The first direction is the table column direction, and the second direction is the table row direction, or the first direction is the table row direction, and the second direction is the table column direction.
[0095] The border supplementing module 1307 is used to supplement the first direction border in the first direction border missing table according to the master-slave relationship.
[0096] The table data extraction module 1309 is used to identify and extract the table data in the supplemented table.
[0097] In one embodiment, the master-slave relationship identification module 1305 is specifically used to: obtain the language model probability between keywords in different table units through a preset language model; and obtain the master-slave relationship of keywords in different table units based on the language model probability and the preset model probability threshold.
[0098] In one of the embodiments, a model training module is also included, which is specifically used to: obtain a complete table with a border in historical data; obtain keywords in the complete table with a border; generate model training data based on the keywords in the complete table with a border; train an initial language model based on the model training data to obtain a preset language model.
[0099] In one of the embodiments, the border supplement module 1307 is specifically used for: when there is a master-slave relationship between keywords in different table cells, the first direction border is not supplemented in the main keyword area, and the first direction border is supplemented in the blank position between the subordinate keywords and the blank position between the key values of the subordinate keywords.
[0100] In one embodiment, the keyword acquisition module 1303 is specifically used to: segment the first direction border missing table by a blank segmentation method; and extract keywords from the segmented first direction border missing table.
[0101] In one embodiment, the table data extraction module 1309 is specifically used to: identify the intersection points between line segments in the supplemented table; determine the table cells in the supplemented table based on the line segment intersection points; aggregate the table cells, identify and extract the table data in the supplemented table.
[0102] In one embodiment, the table data extraction module 1309 is specifically used to: obtain the common edges between the intersections of the line segments; and determine the table cells in the supplemented table according to the smallest rectangle formed by the common edges between the intersections of the line segments.
[0103] The specific definition of the table data extraction device can be found in the definition of the table data extraction method above, which will not be repeated here. Each module in the above table data extraction device can be implemented in whole or in part by software, hardware and a combination thereof. The above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0104] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.14 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store table data extraction data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a table data extraction method is implemented.
[0105] Those skilled in the art will understand that Fig.14 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0106] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0107] In one embodiment, a computer-readable storage medium is provided, storing a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0108] In one embodiment, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps in the above-mentioned method embodiments.
[0109] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0110] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0111] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A method for extracting table data, characterized in that: The method comprises: Get the first direction border missing table; Get the keywords in the first direction border missing table; By using a preset language model, the language model probability between the keywords in different table units in the keywords is obtained; according to the language model probability and the preset model probability threshold, the master-slave relationship of the keywords in the different table units is obtained, the language model probability refers to the probability that the keywords in different table units belong to the same sentence, the different table units are table units along the second direction in the table, the first direction is the table column direction, the second direction is the table row direction, or the first direction is the table row direction, the second direction is the table column direction, the master-slave relationship of the keywords refers to the relationship that a certain keyword is a branch keyword of other keywords in different table units; When there is a master-slave relationship between keywords in different table cells, the first direction border is not added to the primary keyword area, and the first direction border is added to the blank position between the secondary keywords and the blank position between the key values of the secondary keywords to obtain a supplemented table; The table data in the supplemented table is identified and extracted.
2. The method according to claim 1, characterized in that Before identifying the master-slave relationship of the keywords in different table units by using a preset language model, the method further includes: Get the complete table with borders in the historical data; Obtain keywords in the complete table with borders; Generate model training data according to the keywords in the complete table with borders; The initial language model is trained based on the model training data to obtain a preset language model.
3. The method according to claim 1, characterized in that The step of obtaining the keywords in the first direction border missing table includes: Segment the table with missing borders in the first direction by using a blank segmentation method; Extract the keywords in the missing table of the first direction border after segmentation.
4. The method according to claim 1, characterized in that: The identifying and extracting the table data in the supplemented table includes: Identifying line segment intersections between line segments in the supplemented table; Determine the table cells in the supplemented table according to the line segment intersections; The table cells are aggregated, and the table data in the supplemented table is identified and extracted.
5. The method according to claim 4, characterized in that The determining of the table cells in the supplemented table according to the line segment intersections comprises: Obtaining the common edges between the intersection points of the line segments; Table cells in the supplemented table are determined according to the smallest rectangle formed by the common sides between the intersection points of the line segments.
6. A table data extraction device, characterized in that: The device comprises: A table acquisition module, used to acquire a table with missing borders in the first direction; A keyword acquisition module, used to acquire keywords in the first direction border missing table; A master-slave relationship identification module is used to obtain the language model probability between the keywords in different table units in the keywords through a preset language model; according to the language model probability and the preset model probability threshold, obtain the master-slave relationship of the keywords in different table units, the language model probability refers to the probability that the keywords in different table units belong to the same sentence, the different table units are table units along the second direction in the table, the first direction is the table column direction, the second direction is the table row direction, or the first direction is the table row direction, the second direction is the table column direction, the master-slave relationship of the keywords refers to the relationship that a certain keyword is a branch keyword of other keywords in different table units; A border supplementing module is used for not supplementing the first direction border in the main keyword area when there is a master-slave relationship between the keywords of different table cells, and supplementing the first direction border in the blank position between the subordinate keywords and the blank position between the key values of the subordinate keywords to obtain a supplemented table; The table data extraction module is used to identify and extract the table data in the supplemented table.
7. The device according to claim 6, characterized in that It also includes a model training module, which is used to: obtain a complete table with a border in the historical data; obtain keywords in the complete table with a border; generate model training data according to the keywords in the complete table with a border; The initial language model is trained based on the model training data to obtain a preset language model.
8. The device according to claim 6, characterized in that The keyword acquisition module is specifically used to: segment the first direction border missing table by a blank segmentation method; and extract keywords from the segmented first direction border missing table.
9. The device according to claim 6, characterized in that The table data extraction module is specifically used to: identify the intersection points between line segments in the supplemented table; determine the table cells in the supplemented table according to the line segment intersection points; aggregate the table cells, identify and extract the table data in the supplemented table.
10. The device according to claim 9, characterized in that The grid data extraction module is specifically used to: obtain the common edges between the intersections of the line segments; and determine the table cells in the supplemented table according to the smallest rectangle formed by the common edges between the intersections of the line segments.
11. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
12. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
