A method, device and equipment for extracting table information based on PDF document
By constructing table structure diagrams, completing table lines and splicing text content, the problem of low efficiency in extracting complex table information from ocean bill of lading PDF documents has been solved, and high-accuracy and efficient information extraction has been achieved, which is suitable for complex tables and irregular forms. Regular shaped cells, supporting multiple ocean bill of lading formats.
Patent Information
- Application Number
- CN202210159376.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-21
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2042-02-21
AI Technical Summary
Existing technology has low extraction efficiency when processing ocean bill of lading PDF documents with complex forms. Traditional heuristic algorithms are difficult to process complex forms, and methods based on deep learning are not very accurate, resulting in low efficiency in information extraction and analysis.
By extracting line elements from the ocean bill of lading PDF document, construct a table structure diagram, perform table line completion, detect connected domains, splice text content, integrate it into a data dictionary, and use the Web API interface to achieve automated extraction.
It improves the accuracy and efficiency of information extraction from ocean bill of lading tables, saves manpower and material resources, is suitable for complex tables and irregular-shaped cells, and supports multiple ocean bill of lading formats.
Smart Images

Figure CN114581930B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing, and in particular to a method, device and equipment for extracting table information based on PDF documents. Background Art
[0002] With the continuous development of the global economy, cross-border trade through maritime transport is becoming more and more frequent. After trading with international trading companies, shipping companies often use ocean bills of lading as the final contract for shipping companies to accept logistics business, and have employees of the shipping service platform check the ocean bills of lading internally to ensure the accuracy of the information. The formats of bills of lading of different shipping companies are different, and there are about sixty common formats of bills of lading. Therefore, automatic parsing of the information of ocean bills of lading in different formats will greatly improve work efficiency and save manpower and material resources.
[0003] Ocean bills of lading are mainly electronically generated PDF documents containing tables. In the prior art, there are two strategies for table extraction. One is to use a heuristic algorithm to design a table extraction process based on the relative position relationship between the elements and extract the table content; the other is a table processing method based on deep learning, which converts the PDF file into an image format and identifies the table position and cell distribution, and uses OCR to identify the text content, thereby extracting the table content in the PDF file. Traditional heuristic algorithms are difficult to process complex tables, and the tables in the PDF format of ocean bills of lading are complex, with missing table lines and curved table lines. Therefore, traditional heuristic algorithms are not suitable for parsing ocean bills of lading. The table processing method based on deep learning also has the problem of low accuracy in the parsing and extraction of complex tables, so the prior art has many deficiencies in the parsing of ocean bills of lading PDF documents.
[0004] Therefore, there is an urgent need on the market for a table processing strategy for electronically generated ocean bill of lading PDF documents to solve the problem of low content extraction and parsing efficiency caused by the complex form of the ocean bill of lading, large amount of text content, and text offset during the process of extracting ocean bill of lading information. Summary of the invention
[0005] The embodiment of the present invention provides a method, device and equipment for extracting table information based on PDF documents. By automatically extracting and integrating the electronically generated ocean bill of lading PDF document information, the problem of low content extraction and parsing efficiency caused by the complex form of the ocean bill of lading table, the large amount of text content and the text offset in the process of extracting ocean bill of lading information is solved, thereby improving the work efficiency of checking the information content of the ocean bill of lading.
[0006] In order to solve the above problem, an embodiment of the present invention provides a method for extracting table information based on a PDF document, comprising:
[0007] Extracting line elements from the PDF document of the ocean bill of lading, and constructing a first table structure diagram according to the position relationship of the line elements in the PDF document;
[0008] According to the first table structure diagram, the connected domain is detected and the character position is mapped on the document to obtain a connected domain set; wherein each connected domain in the connected domain set contains character data and physical data, and the physical data includes character position, connected domain height and connected domain area;
[0009] According to the physical data in each connected domain, the character positions in each connected domain are compared to obtain the first text content corresponding to each connected domain; all connected domains are detected to obtain the target connected domain, and according to the connected domain height and connected domain area of each target connected domain, the second text content is obtained;
[0010] The first text content and the second text content are integrated to obtain a data dictionary of the ocean bill of lading.
[0011] Furthermore, the first table structure diagram is constructed according to the position relationship of the line elements in the PDF document, specifically:
[0012] Constructing a second table structure diagram according to the positional relationship of the line elements in the PDF document;
[0013] According to the second table structure diagram, the incomplete line segments of the left border and the right border of the table are completed;
[0014] The free ends of all horizontal table lines and the free ends of all vertical table lines are completed in the vertical direction. If a horizontal table line is recognized during the completion of each free end, the completion is terminated.
[0015] After all the incomplete line segments are completed, the first table structure diagram is obtained; if all the line segments of the second table structure diagram are complete, the completion is skipped and the first table structure diagram is directly obtained.
[0016] Furthermore, the detecting of connected domains and character position mapping of the document according to the first table structure diagram to obtain a connected domain set is specifically as follows:
[0017] According to the table lines in the first table structure diagram, the table is divided into a plurality of unit areas, and the height and area of each unit area are obtained at the same time;
[0018] According to the PDF document, the text content is detected to obtain all the character data and character coordinates of the document;
[0019] According to the character coordinates, the character data are respectively mapped to the multiple unit areas, so as to obtain multiple connected domains, that is, the connected domain set.
[0020] Furthermore, the first text content corresponding to each connected domain is obtained by comparing the character positions in each connected domain according to the physical data in each connected domain, specifically:
[0021] According to the physical data in the connected domain, the character position of each character is obtained, and the vertical distance and horizontal distance between the characters are calculated;
[0022] Traverse each character from top to bottom and from left to right. When the vertical distance between adjacent characters is greater than the line separation threshold, splice the two characters into sentences in two adjacent lines.
[0023] When the vertical distance between adjacent characters is less than the line separation threshold, if the horizontal distance between adjacent characters is less than the same-word threshold, the two characters are concatenated into one word; if the horizontal distance between adjacent characters is greater than the same-word threshold and less than the same-sentence threshold, the two characters are concatenated into two adjacent words respectively; if the horizontal distance between adjacent characters is greater than the same-sentence threshold, the two characters are concatenated into two adjacent sentences respectively;
[0024] After concatenating the characters in each connected domain, the first text content corresponding to each connected domain is obtained.
[0025] Furthermore, the detecting of all connected domains to obtain the target connected domain and obtaining the second text content according to the connected domain height and connected domain area of each target connected domain is specifically:
[0026] A regular matching expression is set to match the target key value of the connected domain, determine the target connected domain, and judge whether only the key value exists in the connected domain according to the height and area of the connected domain;
[0027] If the target connected domain is a single-line text height, then there is only a key value in the connected domain, and all text contents in the connected domain of the single-line text height are extracted as key values;
[0028] If the target connected domain is not a single-line text height, then there is a "key value-content" pair in the connected domain, and the first line of text content in the connected domain of the non-single-line text height is extracted as the key value;
[0029] The key values in all target connected domains are extracted to obtain the second text content.
[0030] Furthermore, the integration of the first text content and the second text content to obtain a data dictionary of the ocean bill of lading is specifically:
[0031] Matching the first text content with the second text content;
[0032] If the connected domain where the second text content is located is multiple lines high, extract the first text content corresponding to the connected domain with multiple lines high, and integrate it into a "key-value-content" pair according to the second text content;
[0033] If the connected domain where the second text content is located is a single line height, then extract the second text content in the connected domain of the single line height, and extract the first text content in the connected domain corresponding to the connected domain directly below the connected domain of the single line height, and form a "key-content" pair;
[0034] After the first text content and the second text content are matched, all "key-value-content" pairs are integrated to obtain the data dictionary of the ocean bill of lading.
[0035] The PDF document-based table information extraction method also includes: according to a preset Web API interface, the user uploads the ocean bill of lading PDF document, and after running an algorithm on the Web server to extract the table information, outputs a data dictionary.
[0036] Correspondingly, the present invention also provides a table information extraction device based on PDF documents, comprising: an extraction module, a connected domain module, a splicing module and an output module;
[0037] The extraction module is used to extract the linear elements of the ocean bill of lading PDF document, and construct a first table structure diagram according to the position relationship of the linear elements in the PDF document;
[0038] The connected domain module is used to detect connected domains and map character positions of the document according to the first table structure diagram to obtain a connected domain set; wherein each connected domain in the connected domain set contains character data and physical data, and the physical data includes character position, connected domain height and connected domain area;
[0039] The splicing module is used to obtain the first text content corresponding to each connected domain by comparing the character positions in each connected domain according to the physical data in each connected domain; detect all connected domains to obtain the target connected domain, and obtain the second text content according to the connected domain height and connected domain area of each target connected domain;
[0040] The output module is used to integrate the first text content and the second text content to obtain a data dictionary of the ocean bill of lading.
[0041] Further, the extraction module includes: a table construction unit, a border completion unit, a table line completion unit and a table output unit;
[0042] The table construction unit is used to construct a second table structure diagram according to the position relationship of the line elements in the PDF document;
[0043] The border completion unit is used to complete the incomplete line segments of the left border and the right border of the table according to the second table structure diagram;
[0044] The table line completion unit is used to complete the free ends of all horizontal table lines and all vertical table lines in the vertical direction, and if a horizontal table line is identified in the process of completing each free end, the completion is terminated;
[0045] The table output unit is used to obtain the first table structure diagram after all incomplete line segments are completed; if all line segments of the second table structure diagram are complete, the completion is skipped to directly obtain the first table structure diagram.
[0046] Furthermore, the connected domain module includes: a segmentation unit, a detection unit and a mapping unit;
[0047] The segmentation unit is used to divide the table into a plurality of unit areas according to the table lines in the first table structure diagram, and simultaneously obtain the height and area of each unit area;
[0048] The detection unit is used to detect the text content according to the PDF document to obtain all character data and character coordinates of the document;
[0049] The mapping unit is used to map the character data to the multiple unit areas respectively according to the character coordinates, so as to obtain multiple connected domains, that is, the connected domain set.
[0050] Furthermore, the splicing module includes: a character extraction unit, a character line separation unit, a character splicing unit and a character output unit;
[0051] The character extraction unit is used to obtain the character position of each character according to the physical data in the connected domain, and calculate the vertical distance and horizontal distance between characters;
[0052] The character line branching unit is used to traverse each character in order from top to bottom and from left to right, and when the vertical distance between adjacent characters is greater than the line branching threshold, the two characters are respectively spliced into sentences in two adjacent lines;
[0053] The character splicing unit is used for splicing two characters into one word if the vertical distance between adjacent characters is less than the line separation threshold and the horizontal distance between adjacent characters is less than the same word threshold; splicing the two characters into two adjacent words if the horizontal distance between adjacent characters is greater than the same word threshold and less than the same sentence threshold; splicing the two characters into two adjacent sentences if the horizontal distance between adjacent characters is greater than the same sentence threshold;
[0054] The character output unit is used to obtain the first text content corresponding to each connected domain after splicing the characters in each connected domain.
[0055] Furthermore, the splicing module further includes: a key value matching unit, a first extraction unit, a second extraction unit and a key value output unit;
[0056] The key value matching unit is used to set a regular matching expression, perform target key value matching of a connected domain, determine a target connected domain, and judge whether only key values exist in the connected domain according to the height and area of the connected domain;
[0057] The first extraction unit is used for extracting all text contents in the connected domain of the single-line text height as key values if the target connected domain is a single-line text height and there are only key values in the connected domain;
[0058] The second extraction unit is used for extracting the first line of text content in the connected domain of the non-single-line text height as the key value if the target connected domain is not a single-line text height and there is a "key value-content" pair in the connected domain;
[0059] The key value output unit is used to extract the key values in all target connected domains to obtain the second text content.
[0060] Furthermore, the output module includes: a text matching unit, a first pairing unit, a second pairing unit and an integration unit;
[0061] The text matching unit is used to match the first text content with the second text content;
[0062] The first pairing unit is used to extract the first text content corresponding to the multi-line height connected domain if the connected domain where the second text content is located is multi-line height, and integrate it into a "key value-content" pair according to the second text content;
[0063] The second pairing unit is used for extracting the second text content in the connected domain with a single line height if the connected domain where the second text content is located is a single line height, and extracting the first text content in the connected domain corresponding to the connected domain directly below the connected domain with a single line height, and forming a "key-value-content" pair;
[0064] The integration unit is used to integrate all key-value content pairs after the first text content and the second text content are matched, so as to obtain the data dictionary of the ocean bill of lading.
[0065] Correspondingly, the PDF document-based table information extraction device provided by the present invention also includes: according to a preset Web API interface, the user uploads the ocean bill of lading PDF document, and after running the algorithm on the Web server to extract the table information, the data dictionary is output.
[0066] Correspondingly, the present invention also provides a computer terminal device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, and when the processor executes the computer program, a method for extracting table information based on a PDF document as described in the present invention is implemented.
[0067] Correspondingly, the present invention also provides a computer-readable storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute a method for extracting table information based on a PDF document as described in the present invention.
[0068] As can be seen from the above, the present invention has the following beneficial effects:
[0069] The present invention provides a method, device and equipment for extracting table information based on PDF documents, extracting the table structure of the table information of the ocean bill of lading PDF document, and completing the table line of the table structure, performing text content space division based on connected domain detection through the complete table structure, and matching, integrating and extracting the "key-value-content" pairs of the target connected domain, thereby improving the accuracy of the table information extraction in the ocean bill of lading. Through the automated parsing and extraction of the contents of the ocean bill of lading, it is beneficial to improve the verification efficiency of the ocean bill of lading information, so as to build a smart shipping information platform, thereby saving the manpower and material consumption of the shipping service company. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] Figure 1 It is a flowchart of a method for extracting table information based on a PDF document provided by an embodiment of the present invention;
[0071] Figure 2 It is a structural schematic diagram of a PDF document-based table information extraction device provided by an embodiment of the present invention;
[0072] Figure 3 is a flowchart of a method for extracting table information based on a PDF document provided by another embodiment of the present invention;
[0073] Figure 4This is a schematic diagram of the results of preliminary extraction of the ocean bill of lading form provided by an embodiment of the present invention;
[0074] Figure 5 It is a schematic diagram of table completion results and a schematic diagram of connected domain detection results of a sea waybill provided by an embodiment of the present invention;
[0075] Figure 6 is a schematic diagram of a character splicing process provided by an embodiment of the present invention;
[0076] Figure 7 is a schematic diagram of the result of character splicing provided by an embodiment of the present invention;
[0077] Figure 8 It is a schematic diagram of the structure of a terminal device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0078] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0079] See also Figure 1 , Figure 1 FIG. 1 is a flow chart of a method for extracting table information based on a PDF document provided by an embodiment of the present invention. Figure 1 As shown, this embodiment includes steps 101 to 104, and each step is specifically as follows:
[0080] Step 101: extracting line elements of a PDF document of an ocean bill of lading, and constructing a first table structure diagram according to the positional relationship of the line elements in the PDF document.
[0081] In this embodiment, the first table structure diagram is constructed according to the position relationship of the line elements in the PDF document, specifically:
[0082] Constructing a second table structure diagram according to the positional relationship of the line elements in the PDF document;
[0083] According to the second table structure diagram, the incomplete line segments of the left border and the right border of the table are completed;
[0084] The free ends of all horizontal table lines and the free ends of all vertical table lines are completed in the vertical direction. If a horizontal table line is recognized during the completion of each free end, the completion is terminated.
[0085] After all the incomplete line segments are completed, the first table structure diagram is obtained; if all the line segments of the second table structure diagram are complete, the completion is skipped and the first table structure diagram is directly obtained.
[0086] To better explain this step, the following example is provided for illustration.
[0087] Extract the linear elements such as rectangular boxes, line segments, curves, etc. in the PDF file, create a new blank picture, and draw all the extracted linear elements in the blank picture according to the corresponding positions of the linear elements in the PDF file to form the original table structure diagram; judge the completeness of the original table structure diagram, if it is complete, obtain the complete table structure diagram, if it is incomplete, use the table line completion measure to complete the table lines and obtain the complete table structure diagram.
[0088] Among them, the table line completion measures are as follows:
[0089] (1) Identify the left and right borders of the entire table, and complete the left and right borders that have no borders or borders that are discontinuous line segments into full solid lines;
[0090] (2) Find the free ends of the horizontal and vertical table lines, and draw auxiliary table lines up and down along the vertical direction of the free end points. Stop drawing lines when encountering a horizontal table line.
[0091] To better explain the extraction effect of the original table structure diagram, please refer to Figure 4 ; For a better explanation of the table line completion effect, see Figure 5 .
[0092] As an improvement of the above solution, PDF document parsing can use the python toolkit pdfminer to obtain all the elements that make up the PDF document, filter characters and punctuation marks, and thus obtain line elements.
[0093] Step 102: According to the first table structure diagram, the connected domains of the document are detected and the character positions are mapped to obtain a connected domain set; wherein each connected domain in the connected domain set contains character data and physical data, and the physical data includes character position, connected domain height and connected domain area.
[0094] In this embodiment, the detection of connected domains and character position mapping are performed on the first table structure diagram to obtain a connected domain set, specifically:
[0095] According to the table lines in the first table structure diagram, the table is divided into a plurality of unit areas, and the height and area of each unit area are obtained at the same time;
[0096] Detecting the content of the PDF document to obtain all character data and character coordinates of the document;
[0097] According to the character coordinates, the character data are respectively mapped to the multiple unit areas, so as to obtain the multiple connected domains, that is, the connected domain set.
[0098] To better explain this step, the following example is provided for illustration.
[0099] The complete table structure diagram is detected to obtain multiple unit areas, as well as the height and area of the unit areas, such as Figure 5 As shown, different areas are distinguished by different colors; the document content is parsed to obtain characters, and the characters are mapped to multiple unit areas according to their position coordinates in the document, thereby obtaining a connected domain set.
[0100] As an improvement of the above solution, the connected domain here is not necessarily a rectangle, so support for irregularly shaped cells is achieved.
[0101] Step 103: obtaining the first text content corresponding to each connected domain by comparing the character positions in each connected domain according to the physical data in each connected domain; detecting all connected domains to obtain target connected domains, and obtaining the second text content according to the connected domain height and connected domain area of each target connected domain;
[0102] In this embodiment, the character position of each character is obtained according to the physical data in the connected domain, and the vertical distance and horizontal distance between the characters are calculated;
[0103] Traverse each character from top to bottom and from left to right. When the vertical distance between adjacent characters is greater than the line separation threshold, splice the two characters into sentences in two adjacent lines.
[0104] When the vertical distance between adjacent characters is less than the line separation threshold, if the horizontal distance between adjacent characters is less than the same-word threshold, the two characters are concatenated into one word; if the horizontal distance between adjacent characters is greater than the same-word threshold and less than the same-sentence threshold, the two characters are concatenated into two adjacent words respectively; if the horizontal distance between adjacent characters is greater than the same-sentence threshold, the two characters are concatenated into two adjacent sentences respectively;
[0105] After concatenating the characters in each connected domain, the first text content corresponding to each connected domain is obtained.
[0106] To better explain this step, the following example is provided for illustration.
[0107] See also Figure 6In each connected domain, characters are traversed from top to bottom and from left to right in spatial order. Each character has a rectangular bounding box. In a coordinate system, the coordinates of the upper left corner and the lower right corner of each rectangular bounding box are determined, and then the vertical and horizontal distances between each character are calculated through the coordinates.
[0108] Assume that there are N characters, and use the character splicing model for character splicing. The model is as follows: 1) Set three thresholds: same-word threshold, same-sentence threshold, and line-break threshold; 2) Traverse each character in order from top to bottom and from left to right according to the spatial position: if the vertical distance between character n and character n-1 is greater than the line-break threshold, then splice character n and character n-1 into two adjacent lines of sentences; if the distance between character n and character n-1 is less than the line-break threshold, make the next judgment: if the horizontal distance h between character n and character n-1 is less than the same-word threshold, then splice character n and character n-1 into the same word; if h is greater than the same-word threshold and less than the same-sentence threshold, then splice character n and character n-1 into two adjacent words; if h is greater than the same-sentence threshold, then splice character n and character n-1 into two adjacent sentences; after splicing all characters, output multiple lines of text content in each connected domain. For the splicing effect, please refer to Figure 7 .
[0109] In this embodiment, the method further includes: detecting all connected domains to obtain target connected domains, and obtaining second text content according to the connected domain height and connected domain area of each target connected domain, specifically:
[0110] A regular matching expression is set to match the target key value of the connected domain, determine the target connected domain, and judge whether only the key value exists in the connected domain according to the height and area of the connected domain;
[0111] If the target connected domain is a single-line text height, then there is only a key value in the connected domain, and all text contents in the connected domain of the single-line text height are extracted as key values;
[0112] If the target connected domain is not a single-line text height, then there is a "key value-content" pair in the connected domain, and the first line of text content in the connected domain of the non-single-line text height is extracted as the key value;
[0113] The key values in all target connected domains are extracted to obtain the second text content.
[0114] In order to better explain this embodiment, the following examples are provided for illustration.
[0115] Key-value matching is performed based on ocean bills of lading. Since the design of ocean bills of lading takes into account both formal beauty and spatial compactness, if the key value and content are separated in two cells, the two cells will be arranged up and down and have the same width (this rule does not apply to general tables). Based on this feature, the regular expression method is applied to match the target key value in the text of each connected domain and find all target connected domains: according to the height and area of the target connected domain, it is determined whether there is other text content besides the key value. If it is a single-line text height, only the key value exists; if it is a multi-line text height, the text content of the first line of the multi-line text is selected as the key value; this situation occurs in the bill of lading formats of many shipping companies, such as APL, CMA, CNC, etc.; generally, the key value and its corresponding content exist in the same connected domain.
[0116] Step 104: Integrate the first text content and the second text content to obtain a data dictionary of the ocean bill of lading.
[0117] In this embodiment, the first text content and the second text content are integrated to obtain a data dictionary of the ocean bill of lading, specifically:
[0118] Matching the first text content with the second text content;
[0119] If the connected domain where the second text content is located is multiple lines high, extract the first text content corresponding to the connected domain with multiple lines high, and integrate it into a "key-value-content" pair according to the second text content;
[0120] If the connected domain where the second text content is located is a single line height, then extract the second text content in the connected domain of the single line height, and extract the first text content in the connected domain corresponding to the connected domain directly below the connected domain of the single line height, and form a "key-content" pair;
[0121] After the first text content and the second text content are matched, all key-value content pairs are integrated to obtain the data dictionary of the ocean bill of lading.
[0122] In order to better explain this embodiment, the following examples are provided for illustration.
[0123] After extracting the key value and the body content, if the connected domain where the key value is located is multi-line high, the key value and content in the connected domain are extracted and formed into a "key value-content" pair; if the connected domain where the key value is located is a single line high, the content corresponding to the key value is directly below the connected domain where the key value is located, and the key value and content are extracted separately and formed into a "key value-content" pair; all the "key value-content" pairs are integrated to obtain the data dictionary of the ocean bill of lading.
[0124] In this embodiment, it also includes: according to a preset Web API interface, the user uploads the ocean bill of lading PDF document, and after running an algorithm on the Web server to extract table information, a data dictionary is output.
[0125] For a better explanation of this embodiment, please refer to Figure 3 , Figure 3 It is a schematic diagram of the specific process of the table information extraction method based on PDF documents.
[0126] In this embodiment, this method applies line elements to reconstruct the original table structure diagram in the process of extracting the table information of the ocean bill of lading PDF document, solves the problem of irrelevant factors affecting the recognition of table lines, and uses a table line completion algorithm to complete the table lines, thereby increasing the accuracy of information extraction. By detecting the text content through the connected domain, not only the problems of complex table form, cell merging, and dislocation are overcome, but also support for irregularly shaped cells is achieved. The character set can also be directly extracted from the PDF source file, reducing the error of text extraction. Therefore, the present invention can greatly improve the working efficiency of automatic parsing of ocean bills of lading.
[0127] Embodiment 2
[0128] See also Figure 2 , Figure 2 It is a schematic diagram of the structure of a PDF document-based table information extraction device provided by an embodiment of the present invention, comprising: an extraction module 201, a connected domain module 202, a splicing module 203 and an output module 204;
[0129] The extraction module 201 is used to extract the line elements of the ocean bill of lading PDF document, and construct a first table structure diagram according to the position relationship of the line elements in the PDF document;
[0130] The connected domain module 202 is used to detect connected domains and map character positions of the document according to the first table structure diagram to obtain a connected domain set; wherein each connected domain in the connected domain set contains character data and physical data, and the physical data includes character position, connected domain height and connected domain area;
[0131] The splicing module 203 is used to obtain the first text content corresponding to each connected domain by comparing the character positions in each connected domain according to the physical data in each connected domain; detect all connected domains to obtain the target connected domain, and obtain the second text content according to the connected domain height and connected domain area of each target connected domain;
[0132] The output module 204 is used to integrate the first text content and the second text content to obtain a data dictionary of the ocean bill of lading.
[0133] Furthermore, the extraction module 201 includes: a table construction unit, a border completion unit, a table line completion unit and a table output unit;
[0134] The table construction unit is used to construct a second table structure diagram according to the position relationship of the line elements in the PDF document;
[0135] The border completion unit is used to complete the incomplete line segments of the left border and the right border of the table according to the second table structure diagram;
[0136] The table line completion unit is used to complete the free ends of all horizontal table lines and all vertical table lines in the vertical direction, and if a horizontal table line is identified in the process of completing each free end, the completion is terminated;
[0137] The table output unit is used to obtain the first table structure diagram after all incomplete line segments are completed; if all line segments of the second table structure diagram are complete, the completion is skipped to directly obtain the first table structure diagram.
[0138] Furthermore, the connected domain module 202 includes: a segmentation unit, a detection unit and a mapping unit;
[0139] The segmentation unit is used to divide the table into a plurality of unit areas according to the table lines in the first table structure diagram, and simultaneously obtain the height and area of each unit area;
[0140] The detection unit is used to detect the text content according to the document to obtain all the character data and character coordinates of the document;
[0141] The mapping unit is used to map the character data to the multiple unit areas respectively according to the character coordinates, so as to obtain multiple connected domains, that is, the connected domain set.
[0142] Furthermore, the splicing module 203 includes: a character extraction unit, a character line separation unit, a character splicing unit and a character output unit;
[0143] The character extraction unit is used to obtain the character position of each character according to the physical data in the connected domain, and calculate the vertical distance and horizontal distance between characters;
[0144] The character line branching unit is used to traverse each character in order from top to bottom and from left to right, and when the vertical distance between adjacent characters is greater than the line branching threshold, the two characters are respectively spliced into sentences in two adjacent lines;
[0145] The character splicing unit is used for splicing two characters into one word if the vertical distance between adjacent characters is less than the line separation threshold and the horizontal distance between adjacent characters is less than the same word threshold; splicing the two characters into two adjacent words if the horizontal distance between adjacent characters is greater than the same word threshold and less than the same sentence threshold; splicing the two characters into two adjacent sentences if the horizontal distance between adjacent characters is greater than the same sentence threshold;
[0146] The character output unit is used to obtain the first text content corresponding to each connected domain after splicing the characters in each connected domain.
[0147] As an improvement of the above solution, the splicing module 203 further includes: a key value matching unit, a first extraction unit, a second extraction unit and a key value output unit;
[0148] The key value matching unit is used to set a regular matching expression, perform target key value matching of a connected domain, determine a target connected domain, and judge whether only key values exist in the connected domain according to the height and area of the connected domain;
[0149] The first extraction unit is used for extracting all text contents in the connected domain of the single-line text height as key values if the target connected domain is a single-line text height and there are only key values in the connected domain;
[0150] The second extraction unit is used for extracting the first line of text content in the connected domain of the non-single-line text height as the key value if the target connected domain is not a single-line text height and there is a "key value-content" pair in the connected domain;
[0151] The key value output unit is used to extract the key values in all target connected domains to obtain the second text content.
[0152] Furthermore, the output module 204 includes: a text matching unit, a first pairing unit, a second pairing unit and an integration unit;
[0153] The text matching unit is used to match the first text content with the second text content;
[0154] The first pairing unit is used to extract the first text content corresponding to the multi-line height connected domain if the connected domain where the second text content is located is multi-line height, and integrate it into a "key value-content" pair according to the second text content;
[0155] The second pairing unit is used for extracting the second text content in the connected domain with a single line height if the connected domain where the second text content is located is a single line height, and extracting the first text content in the connected domain corresponding to the connected domain directly below the connected domain with a single line height, and forming a "key-value-content" pair;
[0156] The integration unit is used to integrate all key-value content pairs after the first text content and the second text content are matched, so as to obtain the data dictionary of the ocean bill of lading.
[0157] In this embodiment, it also includes: according to a preset Web API interface, the user uploads the ocean bill of lading PDF document, and after running an algorithm on the Web server to extract table information, a data dictionary is output.
[0158] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0159] In this embodiment, the present invention extracts the table of the PDF file of the sea waybill through the extraction module, inputs the extracted table into the connected domain module for detection and mapping, and performs sentence splicing on the detected characters in the splicing module to obtain key-value content pairs, and finally integrates the key-value content pairs through the output module to obtain the data dictionary of the sea waybill. In extracting the information of the sea waybill, the present invention overcomes the problem of complex table form and improves the accuracy of text extraction, which is conducive to the construction of a smart shipping platform to provide efficient and fast shipping information verification services.
[0160] Embodiment 3
[0161] See also Figure 8 , Figure 8 It is a schematic diagram of the structure of a terminal device provided in one embodiment of the present invention.
[0162] A terminal device of this embodiment includes: a processor 801, a memory 802, and a computer program stored in the memory 802 and executable on the processor 801. When the processor 801 executes the computer program, the steps of the above-mentioned method for extracting table information based on PDF documents in the embodiment are implemented, for example: Figure 1 Alternatively, when the processor executes the computer program, the functions of each module in the above-mentioned device embodiments are implemented, for example: Figure 2 All modules of the PDF document-based table information extraction device are shown.
[0163] In addition, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the table information extraction method based on the PDF document as described in any of the above embodiments.
[0164] Those skilled in the art will understand that the schematic diagram is merely an example of a terminal device and does not constitute a limitation on the terminal device. The terminal device may include more or fewer components than shown in the diagram, or a combination of certain components, or different components. For example, the terminal device may also include input and output devices, network access devices, buses, etc.
[0165] The processor 801 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor 801 is the control center of the terminal device, and uses various interfaces and lines to connect various parts of the entire terminal device.
[0166] The memory 802 can be used to store the computer program and / or module, and the processor 801 implements various functions of the terminal device by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory 802. The memory 802 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0167] Wherein, if the module / unit integrated in the terminal device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium, etc.
[0168] It should be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the accompanying drawings of the device embodiments provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines. A person of ordinary skill in the art may understand and implement it without paying any creative effort.
[0169] The above is a preferred embodiment of the present invention. It should be pointed out that a person skilled in the art can make several improvements and modifications without departing from the principle of the present invention. These improvements and modifications are also considered to be within the scope of protection of the present invention.
Claims
1. A method for extracting table information based on PDF documents, characterized in that: include: Extracting line elements from the PDF document of the ocean bill of lading, and constructing a first table structure diagram according to the position relationship of the line elements in the PDF document; According to the first table structure diagram, the connected domain is detected and the character position is mapped on the document to obtain a connected domain set; wherein each connected domain in the connected domain set contains character data and physical data, and the physical data includes character position, connected domain height and connected domain area; According to the physical data in each connected domain, the character positions in each connected domain are compared to obtain the first text content corresponding to each connected domain; all connected domains are detected to obtain the target connected domain, and according to the connected domain height and connected domain area of each target connected domain, the second text content is obtained; Integrate the first text content and the second text content to obtain a data dictionary of the ocean bill of lading; Among them, the first text content corresponding to each connected domain is obtained by comparing the character positions in each connected domain according to the physical data in each connected domain, specifically: according to the physical data in the connected domain, the character position of each character is obtained, and the vertical distance and horizontal distance between the characters are calculated; each character is traversed in order from top to bottom and from left to right, and when the vertical distance between adjacent characters is greater than the line separation threshold, the two characters are respectively spliced into sentences in two adjacent lines; when the vertical distance between adjacent characters is less than the line separation threshold, if the horizontal distance between adjacent characters is less than the same word threshold, the two characters are spliced into one word; if the horizontal distance between adjacent characters is greater than the same word threshold and less than the same sentence threshold, the two characters are respectively spliced into two adjacent words; if the horizontal distance between adjacent characters is greater than the same sentence threshold, the two characters are respectively spliced into two adjacent sentences; after splicing the characters in each connected domain, the first text content corresponding to each of the connected domains is obtained; The method detects all connected domains, obtains the target connected domain, and obtains the second text content according to the connected domain height and the connected domain area of each target connected domain. Specifically, a regular matching expression is set to match the target key value of the connected domain, determine the target connected domain, and judge whether only the key value exists in the connected domain according to the connected domain height and the connected domain area; if the target connected domain is a single-line text height, only the key value exists in the connected domain, and all the text contents in the connected domain of the single-line text height are extracted as the key value; if the target connected domain is not a single-line text height, "key value-content" pairs exist in the connected domain, and the first line of text content in the connected domain of the non-single-line text height is extracted as the key value; the key values in all target connected domains are extracted to obtain the second text content.
2. The method for extracting table information based on PDF documents according to claim 1, characterized in that: The step of constructing a first table structure diagram according to the positional relationship of the line elements in the PDF document is specifically as follows: Constructing a second table structure diagram according to the positional relationship of the line elements in the PDF document; According to the second table structure diagram, the incomplete line segments of the left border and the right border of the table are completed; The free ends of all horizontal table lines and the free ends of all vertical table lines are completed in the vertical direction. If a horizontal table line is recognized during the completion of each free end, the completion is terminated. After all the incomplete line segments are completed, the first table structure diagram is obtained; if all the line segments of the second table structure diagram are complete, the completion is skipped and the first table structure diagram is directly obtained.
3. The method for extracting table information based on PDF documents according to claim 1, characterized in that: The method of detecting connected domains and mapping character positions of the document according to the first table structure diagram to obtain a connected domain set is specifically as follows: According to the table lines in the first table structure diagram, the table is divided into a plurality of unit areas, and the height and area of each unit area are obtained at the same time; According to the PDF document, the text content is detected to obtain all the character data and character coordinates of the document; According to the character coordinates, the character data are respectively mapped to the multiple unit areas, so as to obtain multiple connected domains, that is, the connected domain set.
4. The method for extracting table information based on PDF documents according to claim 1, characterized in that: The integration of the first text content and the second text content to obtain a data dictionary of the ocean bill of lading is specifically: Matching the first text content with the second text content; If the connected domain where the second text content is located is multiple lines high, extract the first text content corresponding to the connected domain of multiple lines high, and integrate it into a "key value-content" pair according to the second text content; If the connected domain where the second text content is located is a single line height, then extract the second text content in the connected domain of the single line height, and extract the first text content in the connected domain corresponding to the connected domain directly below the connected domain of the single line height, and form a "key-content" pair; After the first text content and the second text content are matched, all "key-value-content" pairs are integrated to obtain the data dictionary of the ocean bill of lading.
5. The method for extracting table information based on PDF documents according to claim 1, characterized in that: Also includes: According to the preset Web API interface, the user uploads the ocean bill of lading PDF document, and runs the algorithm on the Web server to extract the table information and output the data dictionary.
6. A table information extraction device based on PDF document, characterized in that: include: Extraction module, connected domain module, splicing module and output module; The extraction module is used to extract the linear elements of the ocean bill of lading PDF document, and construct a first table structure diagram according to the position relationship of the linear elements in the PDF document; The connected domain module is used to detect connected domains and map character positions of the document according to the first table structure diagram to obtain a connected domain set; wherein each connected domain in the connected domain set contains character data and physical data, and the physical data includes character position, connected domain height and connected domain area; The splicing module is used to obtain the first text content corresponding to each connected domain by comparing the character positions in each connected domain according to the physical data in each connected domain; detect all connected domains to obtain the target connected domain, and obtain the second text content according to the connected domain height and connected domain area of each target connected domain; The output module is used to integrate the first text content and the second text content to obtain a data dictionary of the ocean bill of lading; Among them, the first text content corresponding to each connected domain is obtained by comparing the character positions in each connected domain according to the physical data in each connected domain, specifically: according to the physical data in the connected domain, the character position of each character is obtained, and the vertical distance and horizontal distance between the characters are calculated; each character is traversed in order from top to bottom and from left to right, and when the vertical distance between adjacent characters is greater than the line separation threshold, the two characters are respectively spliced into sentences in two adjacent lines; when the vertical distance between adjacent characters is less than the line separation threshold, if the horizontal distance between adjacent characters is less than the same word threshold, the two characters are spliced into one word; if the horizontal distance between adjacent characters is greater than the same word threshold and less than the same sentence threshold, the two characters are respectively spliced into two adjacent words; if the horizontal distance between adjacent characters is greater than the same sentence threshold, the two characters are respectively spliced into two adjacent sentences; after splicing the characters in each connected domain, the first text content corresponding to each of the connected domains is obtained; The method detects all connected domains, obtains the target connected domain, and obtains the second text content according to the connected domain height and the connected domain area of each target connected domain. Specifically, a regular matching expression is set to match the target key value of the connected domain, determine the target connected domain, and judge whether only the key value exists in the connected domain according to the connected domain height and the connected domain area; if the target connected domain is a single-line text height, only the key value exists in the connected domain, and all the text contents in the connected domain of the single-line text height are extracted as the key value; if the target connected domain is not a single-line text height, "key value-content" pairs exist in the connected domain, and the first line of text content in the connected domain of the non-single-line text height is extracted as the key value; the key values in all target connected domains are extracted to obtain the second text content.
7. A computer terminal device, characterized in that: The invention comprises a processor, a memory and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, a method for extracting table information based on a PDF document as claimed in any one of claims 1 to 5 is implemented.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the method for extracting table information based on a PDF document according to any one of claims 1 to 5.
Citation Information
Patent Citations
Method for extracting structured information from real estate certificate image
CN111460927A
Table information extraction method and device, equipment and storage medium
CN113408323A
