A document text structuring and extraction method

The document text structuring and extraction method addresses the inefficiencies in handling complex logistics documents by aligning and merging data across pages and cells, enabling rapid and accurate extraction of target content, thus improving the customs declaration process.

CN113962201BActive Publication Date: 2024-12-31CHONGQING SUPERLUCY SCI & TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202110974974.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-08-24
Publication Date
2024-12-31
Estimated Expiration
2041-08-24

AI Technical Summary

Technical Problem

The process of declaring import and export of goods in the international logistics industry is cumbersome due to the need for manual handling of multiple pages of complex and varied materials, requiring skilled personnel and taking up to half an hour, which is inefficient and time-consuming.

Method used

A document text structuring and extraction method that includes identifying file content, arranging it into a unified format, and extracting target content using OCR technology for images, Python libraries for Word and Excel files, and structural processing to align and merge table data across pages and cells, followed by semantic analysis for keyword-based extraction.

Benefits of technology

This method significantly reduces the time required for order receiving, making, and reviewing to seconds, enhancing efficiency and reducing manual data entry errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113962201B_ABST
    Figure CN113962201B_ABST
Patent Text Reader

Abstract

The present invention relates to the technical field of document identification, and in particular discloses a method for text structuring and extraction of documents, comprising the following steps: S1, obtaining a file and identifying the content of the file; S2, structuring the identified file content: arranging the identified file content into a unified format; S3, extracting target content from the structured file content to obtain the required document content. Based on this method, the present invention shortens the time of the three steps of receiving, making and examining documents to the minute level, improves the efficiency of document making, and avoids manual input errors.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of document recognition, and in particular to a document text structuring and extraction method. Background Art

[0002] In the international logistics industry, the normal process of declaring the import and export of goods generally has five steps: receiving orders, making orders, reviewing orders, declaring, and inspecting. Receiving orders means that after receiving the task, the relevant staff will obtain the relevant materials required for the customs declaration from the enterprise; making orders means making the corresponding customs declaration according to the materials provided by the enterprise in a unified format; reviewing orders, as the name implies, means that the staff will review the customs declaration and finally submit it to the customs. The three steps seem simple, but they are actually very troublesome. First, the company prepares a lot of materials, generally more than 5 pages of A4 paper, with a lot of content and complexity; second, different companies have different types of materials, formats and even languages. Therefore, a relatively skilled customs declaration handler will take about half an hour to complete the above three steps, which is a waste of time. Summary of the invention

[0003] In view of the above-mentioned deficiencies in the prior art, the present invention provides a document text structuring and extraction method to solve the above-mentioned problems.

[0004] In order to solve the above technical problems, the present invention adopts the following technical solutions:

[0005] A document text structuring and extraction method comprises the following steps:

[0006] S1. Obtain the file and identify the file content;

[0007] S2. Structuring the identified file contents: arranging the identified file contents into a unified format;

[0008] S3. Extract target content from the structured file content to obtain the required document content.

[0009] As an optimization, the file formats include Excel, PDF, Word and pictures.

[0010] As an optimization, in step S1, the image is recognized by OCR technology, the word file is read by Python's docx library, the Excel file is read by Python's pandas library, and the PDF file is read by Python's pdfplumber library.

[0011] As an optimization, in step S2, the structured processing of Excel includes:

[0012] Processing of merged cells: When the table header is a merged cell, and the table body corresponding to the table header occupies multiple columns, you need to merge the multiple columns into one column;

[0013] Processing of the same data occupying multiple rows: For the same data that occupies multiple rows in Excel, analyze and classify it based on the layout information of the file content, and merge the same data into one row;

[0014] Processing of multiple columns of table header and table body data in one cell: Separate the contents of the table header and table body based on the separator, and analyze and calculate to split the table header and table body into multiple columns and align them;

[0015] Processing of misaligned table header and table body: Align the table header and table body based on data type and layout information.

[0016] As an optimization, the structured processing of PDF and image recognition results includes:

[0017] First, the preprocessing based on PDF and image recognition results is as follows:

[0018] Page merging processing: When the PDF has multiple pages, if the PDF contains pictures, first merge the non-picture content of the PDF with the recognition content of the picture, then merge the multi-page PDF set merged with the picture into a result set, and then calculate and modify the coordinate information in the result set;

[0019] Merge processing of cross-row / column content: Based on the table cell information in the PDF and / or image, calculate and find multiple text data in the same table cell, and merge them in rows / columns;

[0020] Convert the preprocessed output in the format of [text, coordinate information] into an Excel structure mode;

[0021] Structural processing: Calculate based on the coordinate information of the text and the table, put the recognized PDF and image contents into the corresponding rows and columns of Excel, and align the header and body of the table;

[0022] Merge tables across pages: Based on the line information of the table at the page break and whether the cells are closed, determine whether the content at the page break needs to be merged.

[0023] As an optimization, when processing merged cells, obtain the text in Excel, the row / column information where the text is located, and the merged cell information. The text includes the table header and table body.

[0024] First determine the number of columns where the table header is located by merging cell information, then traverse row by row starting from the next row of the table header and obtain the corresponding table body data, determine whether there is more than one non-empty cell in the table body corresponding to the column where the table header is located in each row, if so, it means that the table body has multiple columns, and merge the table body in the non-first column of the table body corresponding to the column where the table header is located into the cell of the first column body;

[0025] When the same data occupies multiple rows, determine how many rows of empty cells there are between the previous row of table body and the next row of table body, and merge the empty cells with the cells of the previous row of table body;

[0026] When processing multi-column header and body data in one cell, if the original data contains multi-column header and body content that are merged into one cell, the number of non-empty cells in each row is 1. The analysis and calculation are performed to split the header and body into multiple columns and align them. The steps are as follows: first, determine the start and end positions of the table based on keywords, and extract the content of the table; then traverse the rows to obtain the text content of the non-empty cells in each row, and the text content contains multiple words / sentences separated by spaces; split the text content with spaces to obtain a list of each row after segmentation; then search for the body content corresponding to each header based on the rules from left to right by column, and then assign the body content to each header according to the rules in sequence from right to left;

[0027] When processing the misalignment of the table header and table body, if the data has a table header and table body content that are not in the same column, or part of the table body content is not in the same column, the table header and table body are aligned based on the data type and layout information: first obtain all column contents between the current column header and the next column header, the column content includes the table header and table body content, and calculate the table body content that does not correspond to the header: traverse each column of cells, if the table header corresponding to the table body content of the cell is empty, it means that the table body content is in the column without the header, and then move the table body content that does not correspond to the header to the previous column with the header.

[0028] As an optimization, when the PDF has multiple pages, if the PDF contains a picture, convert the page containing the picture into a picture format to get the original picture, and then use the text detection algorithm to locate each text line in the original picture, and get the upper left corner xy and lower right corner xy of the text box corresponding to the original picture. Then cut each text box out of the original picture, perform text recognition, and get the text content therein; finally, assemble the text content and the coordinate information corresponding to the text content to get the text information in the format of [text, x, y, w, h], [x, y, w, h] is the coordinate information corresponding to the text, x, y are the coordinate values ​​of the upper left corner coordinate point of the text box; w, h are the width and height of the text box;

[0029] When merging content across rows / columns, first find the coordinates of the table cell in the PDF or image and the center point coordinates of the text, and map the relevant text content to the table cell based on the coordinates of the table cell in the PDF or image and the center point coordinates of the text. If there are multiple text contents in a table cell, these multiple text contents are merged into one. When merging, the text contents in the same row are merged with spaces as delimiters, and the text contents in different rows are merged with line breaks as delimiters.

[0030] During structural processing, the text information of the PDF and image output format [text, coordinate information] is converted into the structure mode of Excel, and the coordinate information of the text and the table is calculated. The recognized PDF and image contents are placed in the corresponding rows and columns of Excel, and the alignment of the table header and table body is realized. The calculation method is as follows:

[0031] a. First, find the minimum x coordinate (min_x) and the maximum x coordinate (max_x) from all the [[text, coordinate information]...] output by PDF and image;

[0032] b. Then use the coordinate information of the text box to group the text into rows, and obtain rows group data by grouping the text;

[0033] c. Based on the rows, min_x and max_x obtained in steps a and b, generate a blank excel with rows rows max_x-min_x columns and an array of all zeros with rows rows max_x-min_x columns. The blank excel is used to store text, and the array of all zeros is used to store coordinate information.

[0034] d. Traverse each set of data in step b, and then traverse each text in this set. Based on the x coordinate of the text, fill the text content into the corresponding Excel cell and fill the coordinate information into the corresponding position of the coordinate array;

[0035] e. After traversing all groups, traverse from right to left to obtain each column of Excel data, determine whether the current column and the previous column are the same column data, if so, move the content of the current column to the previous column, and after traversing all columns of Excel, delete all blank columns in Excel and the corresponding columns in the coordinate array, always keeping the shape of Excel and the coordinate array consistent;

[0036] f. Read the information of PDF and picture to obtain text information and table information, the text information is [text, x, y, h, w], the table information includes the coordinates of the upper left corner and lower right corner of the table, the coordinates of the upper left corner and lower right corner of the table row, and the coordinates of the upper left corner and lower right corner of the table cell; and calculate the rows to be merged according to the table coordinate information given by PDF and picture and the row coordinate information of Excel, perform row-level merging, and delete blank rows;

[0037] When merging tables across pages, compare the data in the last row of the previous page of the PDF with the data in the first row of the next page of the PDF, and calculate the ratio of non-empty cells in the last row of the previous page of the PDF and the first row of the next page of the PDF. If the ratio of non-empty cells in the last row of the previous page of the PDF and the first row of the next page of the PDF is greater than 60%, it indicates that the two data cannot be merged.

[0038] As an optimization, in step b, the condition for determining whether two texts are in the same row is: the overlapping length of the two texts in the y-axis direction is greater than 70%; in step e, the condition for determining whether the current column and the previous column are in the same column is: the text is right-aligned or center-aligned, and the overlapping length of the current column and the previous column in the x-axis is greater than 70%.

[0039] As an optimization, in step S3, target content extraction is performed on the content of the structured file as follows: target keywords corresponding to the target content are formulated, the target keywords are grouped into a keyword thesaurus, and the target content is standardized based on semantic analysis. The standardized target content corresponds to the keywords in the keyword thesaurus, and the corresponding target content is found in the content of the structured file by searching for keywords.

[0040] The beneficial effects of the present invention are:

[0041] Based on this method, the present invention shortens the time for the three steps of order receiving, order making and order review to seconds, improves the efficiency of order making and avoids manual data entry errors. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 The figure is a flow chart of the method of the present invention. DETAILED DESCRIPTION

[0043] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the examples cited are not intended to limit the present invention. The technical solutions in the embodiments of the present invention will be described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. The following description of at least one exemplary embodiment is actually only illustrative and is by no means intended to limit the present invention and its application or use. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present invention. It should be understood that the orientation or position relationship indicated by directional words such as "front, back", etc. is usually based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description. In the absence of any contrary description, these directional word specifications do not indicate or imply that the device or element referred to must have a specific orientation or be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the scope of protection of the present invention.

[0044] A document text structuring and extraction method comprises the following steps:

[0045] S1. Obtain the file and identify the file content;

[0046] S2. Structuring the identified file contents: arranging the identified file contents into a unified format;

[0047] S3. Extract target content from the structured file content to obtain the required document content.

[0048] In this embodiment, the formats of the files include Excel, PDF, Word and pictures.

[0049] In this embodiment, in step S1, the image is recognized by OCR technology, the docx library of word is read specifically by python, the pandas library of Excel is read by python, and the pdfplumber library of pdf is read by python.

[0050] In this embodiment, in step S2, performing structured processing on Excel includes:

[0051] Processing of merged cells: When the table header is a merged cell, and the table body corresponding to the table header occupies multiple columns, you need to merge the multiple columns into one column;

[0052] Processing of the same data occupying multiple rows: For the same data that occupies multiple rows in Excel, analyze and classify it based on the layout information of the file content, and merge the same data into one row;

[0053] Processing of multiple columns of table header and table body data in one cell: Separate the contents of the table header and table body based on the separator, and analyze and calculate to split the table header and table body into multiple columns and align them;

[0054] Processing of misaligned table header and table body: Align the table header and table body based on data type and layout information.

[0055] The structured processing of word tables is the same as that of EXCEL. After the program obtains the word table information, it directly calls the EXCEL structure processing method.

[0056] First, the preprocessing based on PDF and image recognition results is as follows:

[0057] Page merging processing: When the PDF has multiple pages, if the PDF contains pictures, firstly, the non-picture content of the PDF needs to be merged with the recognition content of the picture, and then the multi-page PDF set merged with the picture is merged into a result set, and then the coordinate information in the result set is calculated and modified; the picture can be a picture in the PDF or a separate picture, and the format of the picture can be regular formats such as jpg, png, jpeg, etc.

[0058] Merge processing of cross-row / column content: Based on the table cell information in the PDF and / or image, calculate and find multiple text data in the same table cell, and merge them in rows / columns;

[0059] Convert the preprocessed output in the format of [text, coordinate information] into an Excel structure mode;

[0060] Structural processing: Calculate based on the coordinate information of the text and the table, put the recognized PDF and image contents into the corresponding rows and columns of Excel, and align the header and body of the table;

[0061] Merge tables across pages: Based on the line information of the table at the page break and whether the cell is closed, determine whether the content at the page break needs to be merged. The line information here refers to the two ends of the table cell, endpoint 1 x1y1 and endpoint 2 x2y2. To determine whether the cell is closed, you can see whether there are lines above, below, left, and right of the cell.

[0062] First, determine the line closure of the last line of the previous page of PDF and the first line of the next page of PDF. If there is no line below the last line of the previous page and there is no line above the first line of the next page, merge the two lines of data; otherwise, compare the data of the last line of the previous page of PDF with the data of the first line of the next page of PDF, and calculate the ratio of non-empty cells of the last line of the previous page of PDF and the first line of the next page of PDF. If the non-empty ratio of the last line of the previous page of PDF and the first line of the next page of PDF is greater than 60%, it indicates that they are two pieces of data and cannot be merged. Of course, the non-empty ratio can also be set to other numbers, according to the actual situation.

[0063] In this embodiment, when processing merged cells, the text information, the row / column information where the text is located, and the merged cell information in Excel are obtained. The merged cell information refers to [[start_row, end_row, start_col, end_col]...], and statr_row is defined: the start row of the merged cell, end_row: the end row of the merged cell, start_col: the start column of the merged cell, end_col: the end column of the merged cell, and the text includes the header and the body;

[0064] First determine the number of columns where the table header is located by merging cell information, then traverse row by row starting from the next row of the table header and obtain the corresponding table body data, determine whether there is more than one non-empty cell in the table body corresponding to the column where the table header is located in each row, if so, it means that the table body has multiple columns, and merge the table body in the non-first column of the table body corresponding to the column where the table header is located into the cell of the first column body;

[0065] When the same data occupies multiple rows, determine how many rows of empty cells there are between the previous row of table body and the next row of table body, and merge the empty cells with the cells of the previous row of table body;

[0066] When processing multi-column header and body data in one cell, if the original data contains multi-column header and body contents merged into one cell, the number of non-empty cells in each row is 1. Based on this, it is necessary to use spaces as separators to automatically separate the header and body contents of each row through the program. For example, in the given original data, different header and body contents are separated by multiple spaces, so the program traverses the contents of each row and separates the contents with at least one space. After the separation, the header and body contents are aligned in the column direction. , analyze and calculate to split the table header and body into multiple columns and align them. The steps are as follows: first determine the start and end positions of the table based on keywords, and extract the table content; then traverse by row to obtain the text content of non-empty cells in each row, and the text content contains multiple words / sentences separated by spaces; split the text content with spaces to obtain a list of each row after segmentation; then search for the table body content corresponding to each table header from left to right based on the rules, and then assign the table body content to each table header in sequence from the right according to the rules; a table can have multiple rows of non-empty cells;

[0067] When processing the misalignment of the table header and table body, if the data has a table header and table body content that are not in the same column, or part of the table body content is not in the same column, the table header and table body are aligned based on the data type and layout information: first obtain all column contents between the current column header and the next column header, the column content includes the table header and table body content, and calculate the table body content that does not correspond to the header: traverse each column of cells, if the table header corresponding to the table body content of the cell is empty, it means that the table body content is in the column without the header, and then move the table body content that does not correspond to the header to the previous column with the header.

[0068] In this embodiment, during the paging merging process, when the PDF has multiple pages, if the PDF contains a picture, the page of the PDF containing the picture is converted into a picture format to obtain the original picture, and then a text detection algorithm is used to locate each text line in the original picture, and the upper left corner xy and lower right corner xy of the text box corresponding to the original picture are obtained. The text box is used to mark the position (coordinates) of the entire text line in the picture, that is: the upper left corner xy and lower right corner xy of the text line in the text box, and then each text box is cut out from the original picture, and text recognition is performed to obtain the text content therein; finally, the text content and the coordinate information corresponding to the text content are assembled to obtain text information in the format of [text, x, y, w, h], [x, y, w, h] is the coordinate information corresponding to the text, x and y are the coordinate values ​​of the upper left corner coordinate point of the text box; w and h are the width and height of the text box;

[0069] In the original data, the content of the same field may span across rows or columns. The ultimate goal of our recognition is to extract the complete content of these fields. Therefore, for the data that spans across rows / columns in the original data, it is necessary to merge them first to ensure the integrity of the field content when the subsequent content is extracted. Find the coordinates of each table cell in the table and the center coordinates of the text in the table. When reading PDF, you can get the table information in each page of PDF, including table coordinates [upper left corner xy, lower right corner xy], row coordinate information [upper left corner xy, lower right corner xy], cell coordinate information [upper left corner xy, lower right corner xy], calculate the text center coordinates (cx = (2x + w) / 2, cy = (2y + h) / 2) according to the text coordinates [x, y, w, h], traverse each cell coordinate, and determine whether the text center coordinates (cx, cy) are in the cell, that is, cell_x1 <cx<cell_x2 and cell_y1<cy<cell_y2);

[0070] That is, when merging content across rows / columns, first find out the table cell coordinates and the center point coordinates of the text in the PDF or image, and map the relevant text content to the table cell based on the table cell coordinates and the center point coordinates of the text in the PDF or image. The relevant text content here refers to the center point coordinates within the table cell coordinates. The text content information (text content information refers to the text and the coordinate information of the text, and the center point can be calculated using the coordinates when used) and the coordinate information (table cell coordinates) obtained initially are separate, and there is no mapping relationship between them, so a connection relationship needs to be established through calculation. If there are multiple text contents in a table cell, these multiple text contents are merged into one. When merging, the text contents in the same row are judged based on the y-axis coordinates of the text contents. The text contents in the same row are merged with spaces as separators, and the text contents in different rows are merged with line breaks as separators.

[0071] The specific method is as follows: First, according to the y-axis coordinate of the text content, the text content in the same row of the table cell is divided into a group. The specific method to determine whether the text is in the same row is as follows: First, use the y1 and y2 of the text box (y1: the y-axis coordinate of the upper left corner of the text box, y2: the y-axis coordinate of the lower right corner of the text box, y1 is used first, and y2 is used when y1 is the same). The text is a string of text characters, and the text box is the coordinate for locating this string of text. The coordinates are sorted from top to bottom, and then the sorted text information is traversed in order. If the y-axis overlap between the current text and the previous text is less than 70%, it is regarded as a new line, otherwise it means that the current text and the previous text are in the same line. Then these text contents are traversed in groups, and the text contents of this group are sorted from left to right using x1 (x1 is the x-coordinate of the upper left corner of the text box), and then this group of text contents is traversed from left to right to determine the distance between the current text content and the previous text content on the x-axis. If the distance is less than the set threshold (for example, 20 pixels), the two text contents are merged with a space as a separator; if the distance is greater than the threshold, no processing is performed; finally, each group of processed text contents is merged into an Excel cell using a line break as a separator;

[0072] During structural processing, the [text, coordinate information] output by PDF and images are converted into the structure mode of Excel, and calculations are performed based on the coordinate information of the text and the coordinate information of the table. The contents of the recognized PDF and images are placed in the corresponding rows and columns of Excel, and the alignment of the header and body of the table is implemented. The calculation method is as follows:

[0073] a. First, find the minimum x coordinate (min_x) and the maximum x coordinate (max_x) from all the [[text, coordinate information]...] output by PDF and image;

[0074] b. Then use the coordinate information (x, y, h, w) of the text box to group the text into rows, and obtain rows group data; the row grouping is also judged by the y-axis coordinate of the text;

[0075] c. Based on the rows, min_x and max_x obtained in steps a and b, generate a blank excel with rows rows max_x-min_x columns and an array of all zeros with rows rows max_x-min_x columns. The blank excel is used to store text, and the array of all zeros is used to store coordinate information.

[0076] d. Traverse each set of data in step b, and then traverse each text in this set, and fill the text content into the corresponding Excel cell based on the x coordinate of the text;

[0077] e. After traversing all groups, traverse from right to left to obtain each column of Excel data, determine whether the current column and the previous column are the same column data, if so, move the content of the current column to the previous column, and after traversing all columns of Excel, delete all blank columns in Excel;

[0078] f. Read the information of PDF and picture to obtain text information and table information, the text information is [text content, text box coordinates xy], the table information includes the coordinates of the upper left corner and lower right corner of the table, the upper left corner and lower right corner of the table row, and the upper left corner and lower right corner of the table cell; and calculate the rows to be merged according to the table coordinate information given by PDF and picture and the row coordinate information of Excel. First, there are two sets of coordinate information, namely the table row coordinate information given by PDF and the coordinate array corresponding to the text conversion to Excel. Traverse the PDF table row coordinates to find the Excel row index contained in the PDF row coordinates (pdf_y1<=excel_y1<=pdf_y2, pdf_y1<=excel_y2<=pdf_y2), merge at the row level, and delete blank rows;

[0079] When merging tables across pages, compare the data of the last row of the previous page of the PDF with the data of the first row of the next page of the PDF, and calculate the ratio of non-empty cells in the last row of the previous page of the PDF and the first row of the next page of the PDF. If the non-empty ratio of the last row of the previous page of the PDF and the first row of the next page of the PDF is greater than 60%, the non-empty ratio is calculated as follows: first obtain the last row of data on the previous page of the PDF and calculate the number of non-empty texts (assuming a), then obtain the first row of data on the next page of the PDF and calculate the number of non-empty texts (assuming b), then the non-empty ratio = b / a, indicating that there are two pieces of data and they cannot be merged.

[0080] In this embodiment, in step b, the condition for determining whether two texts are in the same row is: the overlapping length of the two texts in the y-axis direction is greater than 70%;

[0081] Suppose there are two texts A(a_y1, a_y2) and B(b_y1, b_y2), a_y1, a_y2 are the upper y-axis coordinates and lower y-axis coordinates of text A; b_y1, b_y2 are the upper y-axis coordinates and lower y-axis coordinates of text B;

[0082]

[0083] In step e, the condition for judging whether the current column and the previous column are in the same column is: the text is right-aligned or center-aligned, and the overlap length of the current column and the previous column on the x-axis is greater than 70%. The method for judging the overlap length on the x-axis is as follows: first obtain the text data and coordinate arrays of the two columns, and obtain the non-empty row indexes of the two columns according to the coordinate array (the coordinate array of a single text box is [x, y, w, h], if x+y+w+h=0, it means that this cell has no text), assuming that the non-empty arrays obtained are

[0084] A=[[x,y,w,h],[x,y,w,h]]=[[10,30,20,9],[10,40,50,9]...]

[0085] B=[[x,y,w,h],[x,y,w,h]]=[[15,30,20,9],[15,40,50,9]...]

[0086] First, calculate the minimum x value (a_x_min) and the maximum x value (a_x_max) of this column based on A.

[0087] First, calculate the minimum x value (b_x_min) and the maximum x value (b_x_max) of this column based on B.

[0088]

[0089] In this embodiment, in step S3, target content extraction is performed on the content of the structured file as follows: target keywords corresponding to the target content are formulated, the target keywords are grouped into a keyword thesaurus, and the target content is standardized based on semantic analysis. The standardized target content corresponds to the keywords in the keyword thesaurus, and the corresponding target content is found in the content of the structured file by searching for keywords.

[0090] Finally, it should be noted that those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A document text structuring and extraction method, characterized in that: The steps include: S1. Obtain the file and identify the file content; S2. Structuring the identified file contents: arranging the identified file contents into a unified format; S3, extracting target content from the structured document content to obtain the required document content; The formats of the files include Excel, PDF, Word and pictures; In step S2, the structured processing of Excel includes: Processing of merged cells: When the table header is a merged cell, and the table body corresponding to the table header occupies multiple columns, you need to merge the multiple columns into one column; Processing of the same data occupying multiple rows: For the same data that occupies multiple rows in Excel, analyze and classify it based on the layout information of the file content, and merge the same data into one row; Processing of multiple columns of table header and table body data in one cell: Separate the contents of the table header and table body based on the separator, and analyze and calculate to split the table header and table body into multiple columns and align them; Processing of misaligned table header and table body: Align the table header and table body based on data type and layout information; When processing merged cells, obtain the text in Excel, the row / column information where the text is located, and the merged cell information. The text includes the table header and table body. First determine the number of columns where the table header is located by merging cell information, then traverse row by row starting from the next row of the table header and obtain the corresponding table body data, determine whether there is more than one non-empty cell in the table body corresponding to the column where the table header is located in each row, if so, it means that the table body has multiple columns, and merge the table body in the non-first column of the table body corresponding to the column where the table header is located into the cell of the first column body; When the same data occupies multiple rows, determine how many rows of empty cells there are between the previous row of table body and the next row of table body, and merge the empty cells with the cells of the previous row of table body; When processing multi-column header and body data in one cell, if the original data contains multi-column header and body content that are merged into one cell, the number of non-empty cells in each row is 1. The analysis and calculation are performed to split the header and body into multiple columns and align them. The steps are as follows: first, determine the start and end positions of the table based on keywords, and extract the content of the table; then traverse the rows to obtain the text content of the non-empty cells in each row, and the text content contains multiple words / sentences separated by spaces; split the text content with spaces to obtain a list of each row after segmentation; then search for the body content corresponding to each header based on the rules from left to right by column, and then assign the body content to each header according to the rules in sequence from right to left; When processing the misalignment of the table header and table body, if the data has a table header and table body content that are not in the same column, or part of the table body content is not in the same column, the table header and table body are aligned based on the data type and layout information: first obtain all column contents between the current column header and the next column header, the column content includes the table header and table body content, and calculate the table body content that does not correspond to the header: traverse each column of cells, if the table header corresponding to the table body content of the cell is empty, it means that the table body content is in the column without the header, and then move the table body content that does not correspond to the header to the previous column with the header.

2. A document text structuring and extraction method according to claim 1, characterized in that: In step S1, the image is recognized by OCR technology, the word file is read by Python's docx library, the Excel file is read by Python's pandas library, and the PDF file is read by Python's pdfplumber library.

3. A document text structuring and extraction method according to claim 2, characterized in that: The structured processing of PDF and image recognition results includes: First, the preprocessing based on PDF and image recognition results is as follows: Page merging processing: When the PDF has multiple pages, if the PDF contains pictures, first merge the non-picture content of the PDF with the recognition content of the picture, then merge the multi-page PDF set merged with the picture into a result set, and then calculate and modify the coordinate information in the result set; Merge processing of cross-row / column content: Based on the table cell information in the PDF and / or image, calculate and find multiple text data in the same table cell, and merge them in rows / columns; Convert the preprocessed output in the format of [text, coordinate information] into an Excel structure mode; Structural processing: Calculate based on the coordinate information of the text and the table, put the recognized PDF and image contents into the corresponding rows and columns of Excel, and align the header and body of the table; Merge tables across pages: Based on the line information of the table at the page break and whether the cells are closed, determine whether the content at the page break needs to be merged.

4. A document text structuring and extraction method according to claim 3, characterized in that: During the paging merging process, when the PDF has multiple pages, if the PDF contains an image, convert the page containing the image into an image format to obtain the original image, and then use the text detection algorithm to locate each text line in the original image, and obtain the upper left corner xy and lower right corner xy of the text box corresponding to the original image, and then cut each text box out of the original image, perform text recognition, and obtain the text content therein; finally, assemble the text content and the coordinate information corresponding to the text content to obtain text information in the format of [text, x, y, w, h], [x, y, w, h] is the coordinate information corresponding to the text, x, y are the coordinate values ​​of the upper left corner coordinate point of the text box; w, h are the width and height of the text box; When merging content across rows / columns, first find the coordinates of the table cell in the PDF or image and the center point coordinates of the text, and map the relevant text content to the table cell based on the coordinates of the table cell in the PDF or image and the center point coordinates of the text. If there are multiple text contents in a table cell, these multiple text contents are merged into one. When merging, the text contents in the same row are merged with spaces as delimiters, and the text contents in different rows are merged with line breaks as delimiters. During structural processing, the text information of the PDF and image output format [text, coordinate information] is converted into the structure mode of Excel, and the coordinate information of the text and the table is calculated. The recognized PDF and image contents are placed in the corresponding rows and columns of Excel, and the alignment of the table header and table body is realized. The calculation method is as follows: a. First, find the minimum x coordinate (min_x) and the maximum x coordinate (max_x) from all the [[text, coordinate information]...] output by PDF and image; b. Then use the coordinate information of the text box to group the text into rows, and obtain rows group data by grouping the text; c. Based on the rows, min_x and max_x obtained in steps a and b, generate a blank excel with rows rows max_x-min_x columns and an array of all zeros with rows rows max_x-min_x columns. The blank excel is used to store text, and the array of all zeros is used to store coordinate information. d. Traverse each set of data in step b, and then traverse each text in this set. Based on the x coordinate of the text, fill the text content into the corresponding Excel cell and fill the coordinate information into the corresponding position of the coordinate array; e. After traversing all groups, traverse from right to left to obtain each column of Excel data, determine whether the current column and the previous column are the same column data, if so, move the content of the current column to the previous column, and after traversing all columns of Excel, delete all blank columns in Excel and the corresponding columns in the coordinate array, always keeping the shape of Excel and the coordinate array consistent; f. Read the information of PDF and picture to obtain text information and table information, the text information is [text, x, y, h, w], the table information includes the coordinates of the upper left corner and lower right corner of the table, the coordinates of the upper left corner and lower right corner of the table row, and the coordinates of the upper left corner and lower right corner of the table cell; and calculate the rows to be merged according to the table coordinate information given by PDF and picture and the row coordinate information of Excel, perform row-level merging, and delete blank rows; When merging tables across pages, compare the data in the last row of the previous page of the PDF with the data in the first row of the next page of the PDF, and calculate the ratio of non-empty cells in the last row of the previous page of the PDF and the first row of the next page of the PDF. If the ratio of non-empty cells in the last row of the previous page of the PDF and the first row of the next page of the PDF is greater than 60%, it indicates that the two data cannot be merged.

5. A document text structuring and extraction method according to claim 4, characterized in that: In step b, the condition for determining whether two texts are in the same row is that the overlapping length of the two texts in the y-axis direction is greater than 70%; in step e, the condition for determining whether the current column and the previous column are in the same column is that the text is right-aligned or center-aligned, and the overlapping length of the current column and the previous column in the x-axis is greater than 70%.

6. A document text structuring and extraction method according to claim 5, characterized in that: In step S3, target content extraction is performed on the content of the structured file as follows: target keywords corresponding to the target content are formulated, the target keywords are grouped into a keyword thesaurus, and the target content is standardized based on semantic analysis. The standardized target content corresponds to the keywords in the keyword thesaurus, and the corresponding target content is found in the content of the structured file by searching for keywords.

Citation Information

Patent Citations

  • Unstructured data processing method and device

    CN108228664A

  • Method and device for structuring resume information

    CN110377560A

  • Method and equipment for processing data information

    CN113268967A